cookutils view cook @ rev 869
modules/compressor: auto-clean the cache.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Jan 23 11:16:27 2017 +0200 (2017-01-23) |
parents | c6bbdbfdc285 |
children | 230109645bba |
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifying any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
10 . /usr/lib/slitaz/libcook.sh
12 VERSION="3.2"
13 export output=raw
16 # Internationalization.
18 export TEXTDOMAIN='cook'
21 #
22 # Functions
23 #
25 usage() {
26 cat <<EOT
28 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
30 $(boldify "$(_ 'Commands:')")
31 usage|help $(_ 'Display this short usage.')
32 setup $(_ 'Setup your build environment.')
33 *-setup $(_ 'Setup a cross environment.')
34 * = {arm|armv6hf|armv7|x86_64}
35 test $(_ 'Test environment and cook a package.')
36 list-wok $(_ 'List packages in the wok.')
37 search $(_ 'Simple packages search function.')
38 new $(_ 'Create a new package with a receipt.')
39 list $(_ 'Cook a list of packages.')
40 clean-wok $(_ 'Clean-up all packages files.')
41 clean-src $(_ 'Clean-up all packages sources.')
42 uncook $(_ 'Check for uncooked packages')
43 pkgdb $(_ 'Create packages DB lists and flavors.')
45 $(boldify "$(_ 'Options:')")
46 cook <pkg>
47 --clean -c $(_ 'clean the package in the wok.')
48 --install -i $(_ 'cook and install the package.')
49 --getsrc -gs $(_ 'get the package source tarball.')
50 --block -b $(_ 'block a package so cook will skip it.')
51 --unblock -ub $(_ 'unblock a blocked package.')
52 --cdeps $(_ 'check dependencies of cooked package.')
53 --pack $(_ 'repack an already built package.')
54 --debug $(_ 'display debugging messages.')
55 --continue $(_ 'continue running compile_rules.')
56 cook new <pkg>
57 --interactive -x $(_ 'create a receipt interactively.')
58 cook setup
59 --wok $(_ 'clone the cooking wok from Hg repo.')
60 --stable $(_ 'clone the stable wok from Hg repo.')
61 --undigest $(_ 'clone the undigest wok from Hg repo.')
62 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
63 --forced $(_ 'force reinstall of chroot packages.')
64 cook pkgdb
65 --flavors $(_ 'create up-to-date flavors files.')
67 EOT
68 exit 0
69 }
72 # We don't want these escapes in web interface.
74 clean_log() {
75 sed -i -e s'|\[70G\[ \[1;32m| |' \
76 -e s'|\[0;39m \]||' $LOGS/$pkg.log
77 }
80 # Be sure package exists in wok.
82 check_pkg_in_wok() {
83 if [ ! -d "$WOK/$pkg" ]; then
84 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
85 exit 1
86 fi
87 }
90 if_empty_value() {
91 if [ -z "$value" ]; then
92 # L10n: QA is quality assurance
93 _ 'QA: empty variable: %s' "$var=\"\""; newline
94 exit 1
95 fi
96 }
99 # Initialize files used in $CACHE
101 init_db_files() {
102 _ 'Creating directories structure in "%s"' "$SLITAZ"
103 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
104 _ 'Creating DB files in "%s"' "$CACHE"
105 for f in $activity $command $broken $blocked; do
106 touch $f
107 done
108 }
111 # QA: check a receipt consistency before building.
113 receipt_quality() {
114 _ 'QA: checking package receipt...'
115 unset online
116 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
117 online='online'
118 fi
119 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
120 unset value
121 value="$(. $receipt; eval echo \$$var)"
122 case "$var" in
123 PACKAGE|VERSION|SHORT_DESC)
124 if_empty_value ;;
125 CATEGORY)
126 value="${value:-empty}"
127 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
128 if ! echo " $valid " | grep -q " $value "; then
129 _ 'QA: unknown category "%s"' "$value"
130 longline "$(_ 'Please, use one of: %s' "$valid")"
131 newline
132 exit 1
133 fi ;;
134 WEB_SITE)
135 # We don't check WGET_URL since if dl is needed it will fail.
136 # Break also if we're not online. Here error is not fatal.
137 if_empty_value
138 [ -z "$online" ] && break
139 if ! busybox wget -T 12 -s $value 2>/dev/null; then
140 _ 'QA: unable to reach "%s"' "$value"
141 fi ;;
142 esac
143 done
144 }
147 # Paths used in receipt and by cook itself.
149 set_paths() {
150 pkgdir="$WOK/$PACKAGE"
151 . "$pkgdir/receipt"
152 basesrc="$pkgdir/source"
153 tmpsrc="$basesrc/tmp"
154 src="$basesrc/$PACKAGE-$VERSION"
155 taz="$pkgdir/taz"
156 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
157 fs="$pack/fs"
158 stuff="$pkgdir/stuff"
159 install="$pkgdir/install"
160 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
161 lzma_tarball="$pkgsrc.tar.lzma"
162 if [ -n "$PATCH" ]; then
163 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
164 fi
165 if [ -n "$WANTED" ]; then
166 basesrc="$WOK/$WANTED/source"
167 src="$basesrc/$WANTED-$VERSION"
168 install="$WOK/$WANTED/install"
169 wanted_stuff="$WOK/$WANTED/stuff"
170 fi
171 if [ -n "$SOURCE" ]; then
172 source_stuff="$WOK/$SOURCE/stuff"
173 fi
174 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
175 if [ -f "$WOK/linux/receipt" ]; then
176 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
177 kbasevers=${kvers:0:3}
178 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
179 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
180 kbasevers=${kvers:0:3}
181 fi
182 # Python version
183 if [ -f "$WOK/python/receipt" ]; then
184 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
185 fi
186 # Perl version for some packages needed it
187 if [ -f "$WOK/perl/receipt" ]; then
188 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
189 fi
190 # Old way compatibility.
191 _pkg="$install"
192 }
195 # Create source tarball when URL is a SCM.
197 create_tarball() {
198 local tarball
199 tarball="$pkgsrc.tar.bz2"
200 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
201 _ 'Creating tarball "%s"' "$tarball"
202 if [ -n "$LZMA_SRC" ]; then
203 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
204 LZMA_SRC=''
205 else
206 tar -cjf $tarball $pkgsrc || exit 1
207 mv $tarball $SRC; rm -rf $pkgsrc
208 fi
209 TARBALL="$tarball"
210 }
213 # Get package source. For SCM we are in cache so clone here and create a
214 # tarball here.
216 get_source() {
217 local url
218 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
219 set_paths
220 pwd=$(pwd)
221 case "$WGET_URL" in
222 http://*|ftp://*)
223 # Busybox Wget is better!
224 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
225 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
226 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
228 https://*)
229 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
230 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
231 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
233 hg*|mercurial*)
234 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
235 url=${WGET_URL#hg|}
236 else
237 url=${WGET_URL#mercurial|}
238 fi
239 _ 'Getting source from %s...' 'Hg'
240 _ 'URL: %s' "$url"
241 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
242 if [ -n "$BRANCH" ]; then
243 _ 'Hg branch: %s' "$BRANCH"
244 hg clone $url --rev $BRANCH $pkgsrc || \
245 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
246 else
247 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
248 fi
249 rm -rf $pkgsrc/.hg
250 create_tarball ;;
252 git*)
253 url=${WGET_URL#git|}
254 _ 'Getting source from %s...' 'Git'
255 _ 'URL: %s' "$url"
256 cd $SRC
257 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
258 if [ -n "$BRANCH" ]; then
259 _ 'Git branch: %s' "$BRANCH"
260 cd $pkgsrc; git checkout $BRANCH; cd ..
261 fi
262 cd $SRC
263 create_tarball ;;
265 cvs*)
266 url=${WGET_URL#cvs|}
267 mod=$PACKAGE
268 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
269 _ 'Getting source from %s...' 'CVS'
270 _ 'URL: %s' "$url"
271 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
272 _ 'Cloning to "%s"' "$pwd/$mod"
273 cvs -d:$url co $mod && mv $mod $pkgsrc
274 create_tarball ;;
276 svn*|subversion*)
277 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
278 url=${WGET_URL#svn|}
279 else
280 url=${WGET_URL#subversion|}
281 fi
282 _ 'Getting source from %s...' 'SVN'
283 _ 'URL: %s' "$url"
284 if [ -n "$BRANCH" ]; then
285 echo t | svn co $url -r $BRANCH $pkgsrc
286 else
287 echo t | svn co $url $pkgsrc
288 fi
289 create_tarball ;;
291 bzr*)
292 url=${WGET_URL#bzr|}
293 _ 'Getting source from %s...' 'bazaar'
294 cd $SRC
295 pkgsrc=${url#*:}
296 if [ -n "$BRANCH" ]; then
297 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
298 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
299 else
300 echo "bzr -Ossl.cert_reqs=none branch $url"
301 bzr -Ossl.cert_reqs=none branch $url
302 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
303 _ "Don't forget to add to receipt:"
304 echo -e "BRANCH=\"$BRANCH\"\n"
305 fi
306 mv $pkgsrc $pkgsrc-$BRANCH
307 pkgsrc="$pkgsrc-$BRANCH"
308 create_tarball ;;
310 *)
311 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
312 tee -a $LOGS/$PACKAGE.log
313 exit 1 ;;
314 esac
315 }
318 # Extract source package.
320 extract_source() {
321 if [ ! -s "$SRC/$TARBALL" ]; then
322 local url
323 url="$MIRROR_URL/sources/packages"
324 url="$url/${TARBALL:0:1}/$TARBALL"
325 _ 'Getting source from %s...' 'mirror'
326 _ 'URL: %s' "$url"
327 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
328 fi
329 _ 'Extracting source archive "%s"' "$TARBALL"
330 case "$TARBALL" in
331 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
332 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
333 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
334 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
335 *.tar) tar -xf $SRC/$TARBALL ;;
336 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
337 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
338 tar -xf $SRC/$TARBALL 2>/dev/null;;
339 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
340 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
341 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
342 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
343 *) cp $SRC/$TARBALL $(pwd) ;;
344 esac
345 }
348 # Display time.
350 disp_time() {
351 local sec div min
352 sec="$1"
353 div=$(( ($1 + 30) / 60))
354 case $div in
355 0) min='';;
356 # L10n: 'm' is for minutes (approximate cooking time)
357 *) min=$(_n ' ~ %dm' "$div");;
358 esac
360 # L10n: 's' is for seconds (cooking time)
361 _ '%ds%s' "$sec" "$min"
362 }
365 # Display cooked package summary.
367 summary() {
368 set_paths
369 cd $WOK/$pkg
370 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
371 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
372 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
373 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
374 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
375 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
377 _ 'Summary for: %s' "$PACKAGE $VERSION"
378 separator
380 # L10n: keep the same width of translations to get a consistent view
381 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
382 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
383 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
384 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
385 _ 'Packed : %s' "$fs"
386 _ 'Compressed : %s' "$size"
387 _ 'Files : %s' "$files"
388 _ 'Cook time : %s' "$(disp_time "$time")"
389 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
390 _ 'Host arch : %s' "$ARCH"
391 separator
392 }
395 # Display debugging error info.
397 debug_info() {
398 title 'Debug information'
399 # L10n: specify your format of date and time (to help: man date)
400 # L10n: not bad one is '+%x %R'
401 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
402 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
403 # L10n: Please, translate all messages beginning with ERROR in a same way
404 lerror=$(_n 'ERROR')
405 for error in \
406 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
407 'error:' 'fatal error:' 'undefined reference to' \
408 'Unable to connect to' 'link: cannot find the library' \
409 'CMake Error' ': No such file or directory' \
410 'Could not read symbols: File in wrong format'
411 do
412 fgrep "$error" $LOGS/$pkg.log
413 done > $LOGS/$pkg.log.debug_info 2>&1
414 cat $LOGS/$pkg.log.debug_info
415 rm -f $LOGS/$pkg.log.debug_info
416 footer
417 }
420 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
421 # so some packages need to copy these files with the receipt and genpkg_rules.
423 copy_generic_files() {
424 # $LOCALE is set in cook.conf
425 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
426 if [ -d "$install/usr/share/locale" ]; then
427 mkdir -p $fs/usr/share/locale
428 for i in $LOCALE; do
429 if [ -d "$install/usr/share/locale/$i" ]; then
430 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
431 fi
432 done
433 fi
434 fi
436 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
437 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
438 if [ -d "$install/usr/share/pixmaps" ]; then
439 mkdir -p $fs/usr/share/pixmaps
440 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
441 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
442 $fs/usr/share/pixmaps
443 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
444 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
445 $fs/usr/share/pixmaps
446 fi
447 fi
449 # Custom or homemade PNG pixmap can be in stuff.
450 if [ -f "$stuff/$PACKAGE.png" ]; then
451 mkdir -p $fs/usr/share/pixmaps
452 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
453 fi
454 fi
456 # Desktop entry (.desktop).
457 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
458 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
459 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
460 mkdir -p $fs/usr/share
461 cp -a $install/usr/share/applications $fs/usr/share
462 fi
463 fi
465 # Homemade desktop file(s) can be in stuff.
466 if [ -d "$stuff/applications" ]; then
467 mkdir -p $fs/usr/share
468 cp -a $stuff/applications $fs/usr/share
469 fi
470 if [ -f "$stuff/$PACKAGE.desktop" ]; then
471 mkdir -p $fs/usr/share/applications
472 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
473 fi
475 # Add custom licenses
476 if [ -d "$stuff/licenses" ]; then
477 mkdir -p $fs/usr/share/licenses
478 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
479 fi
480 }
483 # Remove files provided by split packages
484 # For example:
485 # 1. Package "pkg-main":
486 # SPLIT="pkg-1 pkg-2 pkg-extra"
487 # 2. Package="pkg-extra":
488 # WANTED="pkg-main"
489 # BUILD_DEPENDS="pkg-1 pkg-2"
490 # cook_copy_folders usr
491 # cook_split_rm $BUILD_DEPENDS
493 cook_split_rm() {
494 for i in $@; do
495 action 'Remove files provided by split package %s...' "$i"
496 while read j; do
497 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
498 rmdir "$(dirname "$fs$j")" 2>/dev/null
499 done < $WOK/$i/taz/$i-$VERSION/files.list
500 :; status
501 done
502 }
505 # Update installed.cook.diff
507 update_installed_cook_diff() {
508 # If a cook failed deps are removed.
509 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
510 cd $CACHE
511 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
512 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
513 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
514 }
517 # Remove installed deps.
519 remove_deps() {
520 # Now remove installed build deps.
521 diff='/tmp/installed.cook.diff'
522 if [ -s $diff ]; then
523 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
524 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
525 _n 'Build dependencies to remove:'; echo " $nb"
526 [ -n "$root" ] && echo "root=\"$root\""
527 _n 'Removing:'
528 for dep in $deps; do
529 echo -n " $dep"
530 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
531 done
532 newline; newline
533 # Keep the last diff for debug and info.
534 mv -f $diff $CACHE/installed.diff
535 fi
536 }
539 # The main cook function.
541 cookit() {
542 title 'Cook: %s' "$PACKAGE $VERSION"
543 set_paths
545 # Handle cross-tools.
546 case "$ARCH" in
547 arm*|x86_64)
548 # CROSS_COMPILE is used by at least Busybox and the kernel to set
549 # the cross-tools prefix. Sysroot is the root of our target arch
550 sysroot="$CROSS_TREE/sysroot"
551 tools="$CROSS_TREE/tools"
552 # Set root path when cross compiling. ARM tested but not x86_64
553 # When cross compiling we must install build deps in $sysroot.
554 arch="-$ARCH"
555 root="$sysroot"
556 _ '%s sysroot: %s' "$ARCH" "$sysroot"
557 _ 'Adding "%s" to PATH' "$tools/bin"
558 export PATH="$PATH:$tools/bin"
559 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
560 export CROSS_COMPILE="$HOST_SYSTEM-"
561 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
562 if [ "$ARCH" == 'x86_64' ]; then
563 export CC="$HOST_SYSTEM-gcc -m64"
564 export CXX="$HOST_SYSTEM-g++ -m64"
565 else
566 export CC="$HOST_SYSTEM-gcc"
567 export CXX="$HOST_SYSTEM-g++"
568 fi
569 export AR="$HOST_SYSTEM-ar"
570 export AS="$HOST_SYSTEM-as"
571 export RANLIB="$HOST_SYSTEM-ranlib"
572 export LD="$HOST_SYSTEM-ld"
573 export STRIP="$HOST_SYSTEM-strip"
574 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
575 esac
577 [ -n "$QA" ] && receipt_quality
578 cd $pkgdir
579 [ -z "$continue" ] && rm -rf source 2>/dev/null
580 rm -rf install taz 2>/dev/null
582 # Disable -pipe if less than 512 MB free RAM.
583 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
584 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
585 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
586 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
587 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
588 fi
589 unset free
591 # Export flags and path to be used by make and receipt.
592 DESTDIR="$pkgdir/install"
593 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
594 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
595 #LDFLAGS
597 # Check for build deps and handle implicit depends of *-dev packages
598 # (ex: libusb-dev :: libusb).
599 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
600 touch $CACHE/installed.local $CACHE/installed.web
601 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
602 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
603 for dep in $BUILD_DEPENDS; do
604 implicit="${dep%-dev}"
605 # Don't add implicit dependency if it defined in DEPENDS
606 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
607 for i in $dep $implicit; do
608 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
609 # Try local package first. In some cases implicit doesn't exist, ex:
610 # libboost-dev exists but not libboost, so check if we got vers.
611 unset vers
612 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
613 # We may have a local package.
614 if [ -z "$vers" ]; then
615 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
616 fi
617 debug "bdep: $i version: $vers"
618 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
619 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
620 else
621 # Priority to package version in wok (maybe more up-to-date)
622 # than the mirrored one.
623 if [ -n "$vers" ]; then
624 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
625 echo $i >> $CACHE/installed.web
626 else
627 # So package exists in wok but not available.
628 _ 'Missing dep (wok/pkg): %s' "$i $vers"
629 echo $i >> $CACHE/missing.dep
630 fi
631 else
632 # Package is not in wok but may be in online repo.
633 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
634 echo $i >> $CACHE/installed.web
635 else
636 _ 'ERROR: unknown dep "%s"' "$i"
637 exit 1
638 fi
639 fi
640 fi
641 fi
642 done
643 done
645 # Get the list of installed packages
646 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
648 # Have we a missing build dep to cook?
649 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
650 _ 'Auto cook config is set: %s' "$AUTO_COOK"
651 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
652 for i in $(uniq $CACHE/missing.dep); do
653 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
654 tee -a $LOGS/$PACKAGE.log.$$
655 # programmers: next two messages are exact copy from remove_deps()
656 togrep1=$(_n 'Build dependencies to remove:')
657 togrep2=$(_n 'Removing:')
658 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
659 fgrep $togrep1 $LOGS/$i.log && \
660 fgrep $togrep2 $LOGS/$i.log && newline) | \
661 tee -a $LOGS/$PACKAGE.log.$$ && break
662 done
663 rm -f $CACHE/missing.dep
664 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
665 fi
667 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
668 # is enabled and cook fails we have ERROR in log, if no auto cook we have
669 # missing dep in cached file.
670 lerror=$(_n 'ERROR')
671 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
672 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
673 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
674 exit 1
675 fi
677 # Install local packages: package-version$arch
678 cd $PKGS
679 for i in $(uniq $CACHE/installed.local); do
680 # _ 'Installing dep (pkg/local): %s' "$i"
681 tazpkg install $i --root=$root --local --quiet --cookmode
682 done
684 # Install web or cached packages (if mirror is set to $PKGS we only
685 # use local packages).
686 for i in $(uniq $CACHE/installed.web); do
687 # _ 'Installing dep (web/cache): %s' "$i"
688 tazpkg get-install $i --root=$root --quiet --cookmode
689 done
691 update_installed_cook_diff
693 # Get source tarball and make sure we have source dir named:
694 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
695 # tarball if it exists.
696 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
697 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
698 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
699 LZMA_SRC=''
700 else
701 get_source || exit 1
702 fi
703 fi
704 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
705 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
706 if ! extract_source ; then
707 get_source
708 extract_source || exit 1
709 fi
710 if [ -n "$LZMA_SRC" ]; then
711 cd $pkgdir/source
712 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
713 mv tmp tmp-1; mkdir tmp
714 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
715 fi
716 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
717 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
718 fi
719 fi
720 cd $pkgdir/source/tmp
721 # Some archives are not well done and don't extract to one dir (ex lzma).
722 files=$(ls | wc -l)
723 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
724 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
725 mv * ../$PACKAGE-$VERSION/$TARBALL
726 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
727 mv * ../$PACKAGE-$VERSION
728 cd ..; rm -rf tmp
729 fi
731 # Libtool shared libs path hack.
732 case "$ARCH" in
733 arm*) cross libhack ;;
734 esac
736 # Execute receipt rules.
737 if grep -q ^compile_rules $receipt; then
738 _ 'Executing: %s' 'compile_rules'
739 echo "CFLAGS : $CFLAGS"
740 #echo "LDFLAGS : $LDFLAGS"
741 [ -d "$src" ] && cd $src
742 compile_rules $@ || exit 1
743 # Stay compatible with _pkg
744 [ -d "$src/_pkg" ] && mv $src/_pkg $install
745 # QA: compile_rules success so valid.
746 mkdir -p $install
747 else
748 # QA: no compile_rules so no error, valid.
749 mkdir -p $install
750 fi
752 # Actions to do after compiling the package
753 # Skip all for split packages (already done in main package)
754 if [ -z "$WANTED" ]; then
755 footer
756 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
757 fi
758 footer
760 # Execute testsuite.
761 if grep -q ^testsuite $receipt; then
762 title 'Running testsuite'
763 testsuite $@ || exit 1
764 footer
765 fi
767 update_installed_cook_diff force
768 }
771 # Cook quality assurance.
773 cookit_quality() {
774 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
775 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
776 fi
777 # ERROR can be echoed any time in cookit()
778 lerror=$(_n 'ERROR')
779 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
780 grep -Eq "(^$lerror|undefined reference to)" ; then
781 debug_info | tee -a $LOGS/$pkg.log
782 rm -f $command
783 exit 1
784 fi
785 }
788 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
789 # but it doesn't handle EXTRAVERSION.
791 packit() {
792 set_paths
794 # Handle cross compilation
795 case "$ARCH" in
796 arm*|x86_64) arch="-$ARCH" ;;
797 esac
799 title 'Pack: %s' "$PACKAGE $VERSION$arch"
801 if grep -q ^genpkg_rules $receipt; then
802 _ 'Executing: %s' 'genpkg_rules'
803 set -e; cd $pkgdir; mkdir -p $fs
804 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
805 $LOGS/$pkg.log
806 else
807 _ 'No packages rules: meta package'
808 mkdir -p $fs
809 fi
811 # Check CONFIG_FILES
812 if [ -n "$CONFIG_FILES" ]; then
813 for i in $CONFIG_FILES; do
814 if [ ! -e $fs$i ]; then
815 case $i in
816 */) mkdir -p $fs$i ;;
817 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
818 esac
819 fi
820 done
821 fi
823 # First QA check to stop now if genpkg_rules failed.
824 lerror=$(_n 'ERROR')
825 if fgrep -q ^$lerror $LOGS/$pkg.log; then
826 exit 1
827 fi
829 cd $taz
830 for file in receipt description.txt; do
831 [ ! -f "../$file" ] && continue
832 action 'Copying "%s"...' "$file"
833 cp -f ../$file $pack; chown 0.0 $pack/$file; status
834 done
835 copy_generic_files
837 # Strip and stuff files.
838 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
840 # Create files.list with redirecting find output.
841 action 'Creating the list of files...'
842 cd $fs
843 find . -type f -print > ../files.list
844 find . -type l -print >> ../files.list
845 cd ..; sed -i s/'^.'/''/ files.list
846 status
848 # Md5sum of files.
849 action 'Creating md5sum of files...'
850 while read file; do
851 [ -L "fs$file" ] && continue
852 [ -f "fs$file" ] || continue
853 case "$file" in
854 /lib/modules/*/modules.*|*.pyc) continue ;;
855 esac
856 md5sum "fs$file" | sed 's/ fs/ /'
857 done < files.list > md5sum
858 status
860 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
861 2>/dev/null | awk 'END{ print $1 }')
863 # Build cpio archives.
864 action 'Compressing the FS...'
865 find fs -newer $receipt -exec touch -hr $receipt {} \;
866 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
867 rm -rf fs
868 status
870 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
871 2>/dev/null | awk 'END{ print $1 }')
873 action 'Updating receipt sizes...'
874 sed -i s/^PACKED_SIZE.*$// receipt
875 sed -i s/^UNPACKED_SIZE.*$// receipt
876 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
877 status
879 # Set extra version.
880 if [ -n "$EXTRAVERSION" ]; then
881 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
882 sed -i s/^EXTRAVERSION.*$// receipt
883 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
884 status
885 fi
887 # Compress.
888 action 'Creating full cpio archive...'
889 find . -print | cpio -o -H newc --quiet > \
890 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
891 status
893 action 'Restoring original package tree...'
894 unlzma -c fs.cpio.lzma | cpio -idm --quiet
895 status
897 rm fs.cpio.lzma; cd ..
899 # QA and give info.
900 tazpkg=$(ls *.tazpkg)
901 packit_quality
902 footer "$(_ 'Package "%s" created' "$tazpkg")"
903 }
906 # Verify package quality and consistency.
908 packit_quality() {
909 #action 'QA: checking for broken link...'
910 #link=$(find $fs/usr -type l -follow)
911 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
912 #status
914 # Exit if any error found in log file.
915 lerror=$(_n 'ERROR')
916 if fgrep -q ^$lerror $LOGS/$pkg.log; then
917 rm -f $command
918 exit 1
919 fi
921 action 'QA: checking for empty package...'
922 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
923 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
924 newline; _ 'ERROR: empty package'
925 rm -f $command
926 exit 1
927 else
928 :; status
929 # Find and remove old package(s)
930 tempd="$(mktemp -d)"; cd "$tempd"
931 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
932 # Extract receipt from each matched package
933 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
934 name=$(. receipt; echo $PACKAGE)
935 rm receipt
936 if [ "$name" == "$pkg" ]; then
937 action 'Removing old package "%s"' "$(basename "$testpkg")"
938 rm -f "$testpkg"
939 status
940 fi
941 done
942 rm -r "$tempd"
943 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
944 sed -i /^${pkg}$/d $broken
945 #action 'Removing source tree...'
946 #rm -f $WOK/$pkg/source; status
947 fi
948 }
951 # Reverse "cat" command: prints input lines in the reverse order
953 tac() {
954 sed '1!G;h;$!d' $1
955 }
958 # Install package on --install or update the chroot.
960 install_package() {
961 case "$ARCH" in
962 arm*|x86_64)
963 arch="-$ARCH"
964 root="$CROSS_TREE/sysroot" ;;
965 esac
966 # Install package if requested but skip install if target host doesn't
967 # match build system or it will break the build chroot.
968 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
969 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
970 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
971 cd $PKGS
972 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
973 else
974 _ 'Unable to install package, build has failed.'; newline
975 exit 1
976 fi
977 fi
979 # Install package if part of the chroot to keep env up-to-date.
980 if [ -d "$root$INSTALLED/$pkg" ]; then
981 . /etc/slitaz/cook.conf
982 . $WOK/$pkg/taz/$pkg-*/receipt
983 _ 'Updating %s chroot environment...' "$ARCH"
984 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
985 cd $PKGS
986 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
987 fi
988 }
991 # remove chroot jail
993 umount_aufs() {
994 tac ${1}rw/aufs-umount.sh | sh
995 rm -rf ${1}rw
996 umount ${1}root
997 rmdir ${1}r*
998 }
1001 # Launch the cook command into a chroot jail protected by aufs.
1002 # The current filesystems are used read-only and updates are
1003 # stored in a separate branch.
1005 try_aufs_chroot() {
1007 base="/dev/shm/aufsmnt$$"
1009 # Can we setup the chroot? Is it already done?
1010 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1011 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1012 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1013 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1014 mkdir ${base}root ${base}rw || return
1016 _ 'Setup aufs chroot...'
1018 # Sanity check
1019 for i in / /proc /sys /dev/shm /home ; do
1020 case " $AUFS_MOUNTS " in
1021 *\ $i\ *) ;;
1022 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1023 esac
1024 done
1025 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1026 mount --bind $mnt ${base}root$mnt
1027 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1028 _ 'Aufs mount failure'
1029 umount ${base}root
1030 rm -rf ${base}r*
1031 return
1032 fi
1033 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1034 done
1035 trap "umount_aufs ${base}" INT
1037 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1038 status=$?
1040 _ 'Leaving aufs chroot...'
1041 umount_aufs $base
1042 # Install package outside the aufs jail
1043 install_package
1044 exit $status
1045 }
1048 # Encode predefined XML entities
1050 xml_ent() {
1051 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1052 }
1055 # Create a XML feed for freshly built packages.
1057 gen_rss() {
1058 pubdate=$(date '+%a, %d %b %Y %X')
1059 cat > $FEEDS/$pkg.xml <<EOT
1060 <item>
1061 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1062 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1063 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1064 <pubDate>$pubdate</pubDate>
1065 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1066 </item>
1067 EOT
1068 }
1071 # Truncate stdout log file to $1 Mb.
1073 loglimit() {
1074 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1075 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1076 else
1077 tee /dev/stderr
1078 fi
1079 }
1082 # Search file in mirrored packages
1084 search_file_mirror() {
1085 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1086 }
1089 # Search file in local wok packages
1091 search_file_local() {
1092 # existing packages have precedence over the package/taz folder
1093 srch=$1
1094 { for package in $(find $PKGS -name '*.tazpkg'); do
1095 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1096 grep /$srch\$)" ]; then
1097 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1098 fi
1099 done } | sort -u
1100 }
1103 # Ask in multiple choice
1105 ask_multiple() {
1106 local multiples first my_choice
1107 multiples="$1"
1108 first=$(echo "$multiples" | head -n1)
1109 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1110 _ 'Select one [%s]: ' "$first"; read my_choice
1111 found="${my_choice:-$first}"
1112 }
1115 # Search file in local cache (fast), local wok packages, mirrored packages
1117 search_file() {
1118 local srch cache missing
1119 srch="$1"
1120 cache='/var/cache/ldsearch.cache'
1121 missing='/var/cache/missing.file'
1122 touch $cache $missing
1123 found=$(grep $srch $cache | cut -d$'\t' -f2)
1124 if [ -z "$found" ]; then
1125 found=$(search_file_local $srch)
1126 if [ -n "$found" ]; then
1127 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1128 ask_multiple "$found"
1129 fi
1130 echo -e "$srch\t$found" >> $cache
1131 else
1132 found=$(search_file_mirror $srch)
1133 if [ -n "$found" ]; then
1134 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1135 ask_multiple "$found"
1136 fi
1137 echo -e "$srch\t$found" >> $cache
1138 else
1139 echo "$srch" >> $missing
1140 fi
1141 fi
1142 fi
1143 }
1146 #
1147 # Receipt functions to ease packaging
1148 #
1150 get_dev_files() {
1151 action 'Getting standard devel files...'
1152 mkdir -p $fs/usr/lib
1153 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1154 cp -a $install/usr/lib/*a $fs/usr/lib
1155 cp -a $install/usr/include $fs/usr
1156 status
1157 }
1160 # Function to use in compile_rules() to copy man page from $src to $install
1162 cook_pick_manpages() {
1163 local name section
1164 action 'Copying man pages...'
1166 for i in $@; do
1167 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1168 section=${name##*/}; section=${section##*.}
1169 mkdir -p $install/usr/share/man/man$section
1170 cp -a $i $install/usr/share/man/man$section
1171 done
1172 status
1173 }
1176 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1178 cook_copy_files() {
1179 action 'Copying files...'
1180 cd $install
1181 local i j
1182 for i in $@; do
1183 for j in $(find . -name $i ! -type d); do
1184 mkdir -p $fs$(dirname ${j#.})
1185 cp -a $j $fs/${j#.}
1186 done
1187 done
1188 cd - >/dev/null
1189 status
1190 }
1193 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1195 cook_copy_folders() {
1196 action 'Copying folders...'
1197 cd $install
1198 local i j
1199 for i in $@; do
1200 for j in $(find . -name $i -type d); do
1201 mkdir -p $fs$(dirname ${j#.})
1202 cp -a $j $fs/${j#.}
1203 done
1204 done
1205 cd - >/dev/null
1206 status
1207 }
1210 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1211 # (default: 16 and 48) from $install to $fs
1213 cook_copy_icons() {
1214 local sizes=$@
1215 action 'Copying hicolor icons...'
1216 mkdir -p $fs/usr/share/icons/hicolor
1217 for i in ${sizes:-16 48}; do
1218 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1219 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1220 $fs/usr/share/icons/hicolor
1221 done
1222 status
1223 }
1228 #
1229 # Commands
1230 #
1232 case "$1" in
1233 usage|help|-u|-h)
1234 usage ;;
1236 list-wok)
1237 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1238 cd $WOK
1239 if [ "$ARCH" != 'i486' ]; then
1240 count=0
1241 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1242 do
1243 unset HOST_ARCH
1244 . $pkg
1245 count=$(($count + 1))
1246 colorize 34 "$PACKAGE"
1247 done
1248 else
1249 count=$(ls | wc -l)
1250 ls -1
1251 fi
1252 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1253 ;;
1255 activity)
1256 cat $activity ;;
1258 search)
1259 # Just a simple search function, we dont need more actually.
1260 query="$2"
1261 title 'Search results for "%s"' "$query"
1262 cd $WOK; ls -1 | grep "$query"
1263 footer ;;
1265 setup)
1266 # Setup a build environment
1267 check_root
1268 _ 'Cook: setup environment' | log
1269 title 'Setting up your environment'
1270 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1271 cd $SLITAZ
1272 init_db_files
1273 _ 'Checking for packages to install...'
1274 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1275 # ARCH-setup or 'cross check' should be used before: cook setup
1276 case "$ARCH" in
1277 arm*|x86_64)
1278 if [ ! -x '/usr/bin/cross' ]; then
1279 _ 'ERROR: %s is not installed' 'cross'
1280 exit 1
1281 fi
1282 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1283 . /etc/slitaz/cross.conf ;;
1284 esac
1285 for pkg in $SETUP_PKGS; do
1286 if [ -n "$forced" ]; then
1287 tazpkg -gi $pkg --forced
1288 else
1289 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1290 fi
1291 done
1293 # Handle --options
1294 case "$2" in
1295 --wok) hg clone $WOK_URL wok || exit 1 ;;
1296 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1297 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1298 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1299 esac
1301 # SliTaz group and permissions
1302 if ! grep -q ^slitaz /etc/group; then
1303 _ 'Adding group "%s"' 'slitaz'
1304 addgroup slitaz
1305 fi
1306 _ 'Setting permissions for group "%s"...' 'slitaz'
1307 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1308 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1309 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1311 *-setup)
1312 # Setup for cross compiling.
1313 arch="${1%-setup}"
1314 check_root
1315 . /etc/slitaz/cook.conf
1316 for pkg in $CROSS_SETUP; do
1317 if [ -n "$forced" ]; then
1318 tazpkg -gi $pkg --forced
1319 else
1320 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1321 fi
1322 done
1324 _ 'Cook: setup %s cross environment' "$arch" | log
1325 title 'Setting up your %s cross environment' "$arch"
1326 init_db_files
1327 sed -i \
1328 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1329 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1330 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1331 /etc/slitaz/cook.conf
1332 case "$arch" in
1333 arm)
1334 flags='-O2 -march=armv6'
1335 host="$ARCH-slitaz-linux-gnueabi" ;;
1336 armv6hf)
1337 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1338 host="$ARCH-slitaz-linux-gnueabi" ;;
1339 armv7)
1340 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1341 host="$ARCH-slitaz-linux-gnueabi" ;;
1342 x86_64)
1343 flags='-O2 -mtune=generic -pipe'
1344 host="$ARCH-slitaz-linux" ;;
1345 esac
1346 sed -i \
1347 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1348 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1349 . /etc/slitaz/cook.conf
1350 sysroot="$CROSS_TREE/sysroot"
1351 tools="/cross/$arch/tools"
1352 root="$sysroot"
1353 # L10n: keep the same width of translations to get a consistent view
1354 _ 'Target arch : %s' "$ARCH"
1355 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1356 _ 'Build flags : %s' "$flags"
1357 _ 'Arch sysroot : %s' "$sysroot"
1358 _ 'Tools prefix : %s' "$tools/bin"
1359 # Tell the packages manager where to find packages.
1360 _ 'Packages DB : %s' "$root$DB"
1361 mkdir -p $root$INSTALLED
1362 cd $root$DB; rm -f *.bak
1363 for list in packages.list packages.desc packages.equiv packages.md5; do
1364 rm -f $list
1365 ln -s $SLITAZ/packages/$list $list
1366 done
1367 # We must have the cross compiled glibc-base installed or default
1368 # i486 package will be used as dep by tazpkg and then break the
1369 # cross environment
1370 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1371 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1372 fi
1373 # Show GCC version or warn if not yet compiled.
1374 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1375 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1376 else
1377 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1378 _ 'Run "%s" to cook a toolchain' 'cross compile'
1379 fi
1380 footer ;;
1382 test)
1383 # Test a cook environment.
1384 _ 'Cook test: testing the cook environment' | log
1385 [ ! -d "$WOK" ] && exit 1
1386 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1387 cook cooktest ;;
1389 new)
1390 # Create the package folder and an empty receipt.
1391 pkg="$2"
1392 [ -z "$pkg" ] && usage
1393 newline
1394 if [ -d "$WOK/$pkg" ]; then
1395 _ 'Package "%s" already exists.' "$pkg"
1396 exit 1
1397 fi
1399 action 'Creating folder "%s"' "$WOK/$pkg"
1400 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1402 action 'Preparing the package receipt...'
1403 cp $DATA/receipt .
1404 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1405 status; newline
1407 # Interactive mode, asking and seding.
1408 case "$3" in
1409 --interactive|-x)
1410 _ 'Entering interactive mode...'
1411 separator
1412 _ 'Package : %s' "$pkg"
1414 _n 'Version : ' ; read answer
1415 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1417 _n 'Category : ' ; read answer
1418 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1420 # L10n: Short description
1421 _n 'Short desc : ' ; read answer
1422 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1424 _n 'Maintainer : ' ; read answer
1425 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1427 _n 'License : ' ; read answer
1428 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1430 _n 'Web site : ' ; read answer
1431 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1432 newline
1434 # Wget URL.
1435 _ 'Wget URL to download source tarball.'
1436 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1437 _n 'Wget url : ' ; read answer
1438 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1440 # Ask for a stuff dir.
1441 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1442 if [ "$?" -eq 0 ]; then
1443 action 'Creating the stuff directory...'
1444 mkdir $WOK/$pkg/stuff; status
1445 fi
1447 # Ask for a description file.
1448 confirm "$(_n 'Are you going to write a description? (y/N)')"
1449 if [ "$?" -eq 0 ]; then
1450 action 'Creating the "%s" file...' 'description.txt'
1451 touch $WOK/$pkg/description.txt; status
1452 fi
1454 footer "$(_ 'Receipt is ready to use.')" ;;
1455 esac ;;
1457 list)
1458 # Cook a list of packages (better use the Cooker since it will order
1459 # packages before executing cook).
1460 check_root
1461 if [ -z "$2" ]; then
1462 newline; _ 'No list in argument.'; newline
1463 exit 1
1464 fi
1465 if [ ! -f "$2" ]; then
1466 newline; _ 'List "%s" not found.' "$2"; newline
1467 exit 1
1468 fi
1470 _ 'Starting cooking the list "%s"' "$2" | log
1472 for pkg in $(cat $2); do
1473 cook $pkg || broken
1474 done ;;
1476 clean-wok)
1477 check_root
1478 newline; action 'Cleaning all packages files...'
1479 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1480 status; newline ;;
1482 clean-src)
1483 check_root
1484 newline; action 'Cleaning all packages sources...'
1485 rm -rf $WOK/*/source
1486 status; newline ;;
1488 uncook)
1489 cd $WOK
1490 count=0
1491 title 'Checking for uncooked packages'
1493 for pkg in *; do
1494 unset HOST_ARCH EXTRAVERSION
1495 [ ! -e $pkg/receipt ] && continue
1496 . $pkg/receipt
1497 # Source cooked pkg receipt to get EXTRAVERSION
1498 if [ -d "$WOK/$pkg/taz" ]; then
1499 cd $WOK/$pkg/taz/$pkg-*
1500 . receipt; cd $WOK
1501 fi
1502 case "$ARCH" in
1503 i486)
1504 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1505 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1506 count=$(($count + 1))
1507 colorize 34 "$pkg"
1508 fi ;;
1509 arm*)
1510 # Check only packages included in arch
1511 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1512 # *.tazpkg
1513 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1514 count=$(($count + 1))
1515 colorize 34 "$pkg"
1516 fi
1517 fi ;;
1518 esac
1519 done
1521 if [ "$count" -gt "0" ]; then
1522 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1523 else
1524 _ 'All packages are cooked :-)'
1525 newline
1526 fi
1527 ;;
1529 pkgdb)
1530 # Create suitable packages list for TazPkg and only for built packages
1531 # as well as flavors files for TazLiTo. We don't need logs since we do it
1532 # manually to ensure everything is fine before syncing the mirror.
1533 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1534 ;;
1536 *)
1537 # Just cook and generate a package.
1538 check_root
1539 time=$(date +%s)
1540 pkg="$1"
1541 [ -z "$pkg" ] && usage
1542 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1543 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1544 receipt="$WOK/$pkg/receipt"
1545 check_pkg_in_wok
1546 newline
1548 unset inst
1549 unset_receipt
1550 . $receipt
1552 # Handle cross compilation.
1553 case "$ARCH" in
1554 arm*)
1555 if [ -z "$HOST_ARCH" ]; then
1556 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1557 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1558 _ 'cook: %s' "$error"
1559 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1560 _ 'Cook skip: %s' "$error" | log
1561 newline
1562 exit 1
1563 fi ;;
1564 esac
1566 # Some packages are not included in some arch or fail to cross compile.
1567 : ${HOST_ARCH=i486}
1568 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1569 # Handle arm{v6hf,v7,..}
1570 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1571 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1572 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1573 _ 'cook: %s' "error"
1574 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1575 _ 'Cook skip: %s' "$error" | log
1576 sed -i /^${pkg}$/d $broken
1577 newline
1578 exit 0
1579 fi
1581 # Skip blocked, 3 lines also for the Cooker.
1582 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1583 _ 'Package "%s" is blocked' "$pkg"; newline
1584 exit 0
1585 fi
1587 try_aufs_chroot "$@"
1589 # Log and source receipt.
1590 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1591 echo "cook:$pkg" > $command
1592 [ "$lastcooktime" ] &&
1593 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1594 while read cmd duration start; do
1595 [ $(($start + $duration)) -lt $(date +%s) ] &&
1596 echo "sed -i '/^$cmd $duration/d' $cooktime"
1597 done < $cooktime | sh
1599 # Display and log info if cook process stopped.
1600 # FIXME: gettext not working (in single quotes) here!
1601 trap '_ "\n\nCook stopped: control-C\n\n" | \
1602 tee -a $LOGS/$pkg.log' INT
1604 # Handle --options
1605 case "$2" in
1606 --clean|-c)
1607 action 'Cleaning "%s"' "$pkg"
1608 cd $WOK/$pkg; rm -rf install taz source
1609 status; newline
1610 exit 0 ;;
1612 --install|-i)
1613 inst='yes' ;;
1615 --getsrc|-gs)
1616 title 'Getting source for "%s"' "$pkg"
1617 get_source
1618 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1619 exit 0 ;;
1621 --block|-b)
1622 action 'Blocking package "%s"' "$pkg"
1623 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1624 status; newline
1625 exit 0 ;;
1627 --unblock|-ub)
1628 action 'Unblocking package "%s"' "$pkg"
1629 sed -i "/^${pkg}$/"d $blocked
1630 status; newline
1631 exit 0 ;;
1633 --pack)
1634 if [ -d $WOK/$pkg/taz ]; then
1635 rm -rf $WOK/$pkg/taz
1636 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1637 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1638 clean_log
1639 else
1640 _ 'Need to build "%s"' "$pkg"
1641 exit 0
1642 fi
1643 exit 0 ;;
1645 --cdeps)
1646 if [ ! -d $WOK/$pkg/taz ]; then
1647 _ 'Need to build "%s"' "$pkg"
1648 exit 0
1649 fi
1651 title 'Checking depends'
1652 lddlist='/tmp/lddlist'; touch $lddlist
1653 missing='/var/cache/missing.file'
1655 # find all deps using ldd
1656 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1657 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1658 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1659 done #"
1661 # remove exe/so duplicates
1662 sort -u $lddlist > $lddlist.sorted
1664 # search packages
1665 for exefile in $(cat $lddlist.sorted); do
1666 search_file $exefile
1667 echo "$found" >> $lddlist.pkgs
1668 echo -n '.'
1669 done
1670 echo
1672 # remove packages duplicates
1673 sort -u $lddlist.pkgs > $lddlist.final
1674 sort -u $missing > $missing.final
1675 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1676 exit 0 ;;
1677 esac
1679 # Rotate log
1680 for i in $(seq 9 -1 1); do
1681 j=$(($i - 1))
1682 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1683 done
1684 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1686 # Check if wanted is built now so we have separate log files.
1687 for wanted in $WANTED ; do
1688 if grep -q "^$wanted$" $blocked; then
1689 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1690 newline
1691 rm -f $command
1692 exit 1
1693 fi
1694 if grep -q "^$wanted$" $broken; then
1695 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1696 newline
1697 rm -f $command
1698 exit 1
1699 fi
1700 if [ ! -d "$WOK/$wanted/install" ]; then
1701 cook "$wanted" || exit 1
1702 fi
1703 done
1705 # Cook and pack or exit on error and log everything.
1706 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1707 remove_deps | tee -a $LOGS/$pkg.log
1708 cookit_quality
1709 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1710 clean_log
1712 # Exit if any error in packing.
1713 lerror=$(_n 'ERROR')
1714 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1715 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1716 debug_info | tee -a $LOGS/$pkg.log
1717 rm -f $command
1718 exit 1
1719 fi
1721 # Create an XML feed
1722 gen_rss
1724 # Time and summary
1725 time=$(($(date +%s) - $time))
1726 summary | tee -a $LOGS/$pkg.log
1727 newline
1729 # We may want to install/update (outside aufs jail !).
1730 [ -s /aufs-umount.sh ] ||
1731 install_package
1733 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1734 # You want automation: use the Cooker Build Bot.
1735 rm -f $command ;;
1736 esac
1738 exit 0