cookutils view cook @ rev 1019

cook: add fix() to use '--as-needed' linker flag in compile_rules(); cookit(): make QA fail on empty vars / bad values; remove_already_packed(): fix bug when $PACKAGE not listed in $SPLIT and we use this function for the default set. lighttpd/index.cgi: sort orphans. modules/precheck: separate error message by empty lines.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Thu Dec 07 14:31:28 2017 +0200 (2017-12-07)
parents 6907a43402f6
children dc7238a11470
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.')
66 cook splitdb $(_ 'create up-to-date split.db file.')
68 EOT
69 exit 0
70 }
73 # We don't want these escapes in web interface.
75 clean_log() {
76 sed -i -e 's|\[70G\[ \[1;32m| |' \
77 -e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
78 }
81 # Be sure package exists in wok.
83 check_pkg_in_wok() {
84 [ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
85 }
88 # Initialize files used in $CACHE
90 init_db_files() {
91 _ 'Creating directories structure in "%s"' "$SLITAZ"
92 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
93 _ 'Creating DB files in "%s"' "$CACHE"
94 touch $activity $command $broken $blocked $CACHE/webstat
95 chown www:www $cache/webstat
96 }
99 # Paths used in receipt and by cook itself.
101 set_paths() {
102 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
103 if [ -f "$WOK/linux/receipt" ]; then
104 kvers=$(. $WOK/linux/receipt; echo $VERSION)
105 kbasevers=$(echo $kvers | cut -d. -f1,2)
106 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
107 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
108 kbasevers=$(echo $kvers | cut -d. -f1,2)
109 fi
111 # Python version
112 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
113 # Perl version for some packages needed it
114 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
116 pkgdir="$WOK/$pkg"
117 . "$pkgdir/receipt"
118 basesrc="$pkgdir/source"
119 tmpsrc="$basesrc/tmp"
120 src="$basesrc/$PACKAGE-$VERSION"
121 taz="$pkgdir/taz"
122 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
123 fs="$pack/fs"
124 stuff="$pkgdir/stuff"
125 install="$pkgdir/install"
127 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
128 lzma_tarball="$pkgsrc.tar.lzma"
130 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
132 if [ -n "$WANTED" ]; then
133 basesrc="$WOK/$WANTED/source"
134 src="$basesrc/$WANTED-$VERSION"
135 install="$WOK/$WANTED/install"
136 wanted_stuff="$WOK/$WANTED/stuff"
137 fi
139 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
141 # Old way compatibility.
142 _pkg="$install"
143 }
146 # Create source tarball when URL is a SCM.
148 create_tarball() {
149 local tarball
150 tarball="$pkgsrc.tar.bz2"
151 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
152 _ 'Creating tarball "%s"' "$tarball"
153 if [ -n "$LZMA_SRC" ]; then
154 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
155 LZMA_SRC=''
156 else
157 tar -cjf $tarball $pkgsrc || exit 1
158 mv $tarball $SRC; rm -rf $pkgsrc
159 fi
160 TARBALL="$tarball"
161 }
164 # Get package source. For SCM we are in cache so clone here and create a
165 # tarball here.
167 get_source() {
168 local url
169 url=${WGET_URL#*|}
170 set_paths
171 pwd=$(pwd)
172 case "$WGET_URL" in
173 http://*|ftp://*|https://*)
174 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
175 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
176 wget -T 60 -c -O $SRC/$TARBALL $url ||
177 die 'ERROR: %s' "wget $WGET_URL"
178 ;;
180 hg*|mercurial*)
181 _ 'Getting source from %s...' 'Hg'
182 _ 'URL: %s' "$url"
183 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
184 if [ -n "$BRANCH" ]; then
185 _ 'Hg branch: %s' "$BRANCH"
186 hg clone $url --rev $BRANCH $pkgsrc ||
187 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
188 else
189 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
190 fi
191 rm -rf $pkgsrc/.hg
192 create_tarball
193 ;;
195 git*)
196 _ 'Getting source from %s...' 'Git'
197 _ 'URL: %s' "$url"
198 cd $SRC
199 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
200 if [ -n "$BRANCH" ]; then
201 _ 'Git branch: %s' "$BRANCH"
202 cd $pkgsrc; git checkout $BRANCH; cd ..
203 fi
204 cd $SRC
205 create_tarball
206 ;;
208 cvs*)
209 mod=$PACKAGE
210 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
211 _ 'Getting source from %s...' 'CVS'
212 _ 'URL: %s' "$url"
213 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
214 _ 'Cloning to "%s"' "$pwd/$mod"
215 cvs -d:$url co $mod && mv $mod $pkgsrc
216 create_tarball
217 ;;
219 svn*|subversion*)
220 _ 'Getting source from %s...' 'SVN'
221 _ 'URL: %s' "$url"
222 if [ -n "$BRANCH" ]; then
223 echo t | svn co $url -r $BRANCH $pkgsrc
224 else
225 echo t | svn co $url $pkgsrc
226 fi
227 create_tarball
228 ;;
230 bzr*)
231 _ 'Getting source from %s...' 'bazaar'
232 cd $SRC
233 pkgsrc=${url#*:}
234 if [ -n "$BRANCH" ]; then
235 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
236 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
237 else
238 echo "bzr -Ossl.cert_reqs=none branch $url"
239 bzr -Ossl.cert_reqs=none branch $url
240 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
241 _ "Don't forget to add to receipt:"
242 echo -e "BRANCH=\"$BRANCH\"\n"
243 fi
244 mv $pkgsrc $pkgsrc-$BRANCH
245 pkgsrc="$pkgsrc-$BRANCH"
246 create_tarball
247 ;;
249 *)
250 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
251 ;;
252 esac
253 }
256 # Extract source package.
258 extract_source() {
259 if [ ! -s "$SRC/$TARBALL" ]; then
260 local url
261 url="$MIRROR_URL/sources/packages"
262 url="$url/${TARBALL:0:1}/$TARBALL"
263 _ 'Getting source from %s...' 'mirror'
264 _ 'URL: %s' "$url"
265 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
266 fi
267 _ 'Extracting source archive "%s"' "$TARBALL"
268 case "$TARBALL" in
269 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
270 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
271 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
272 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
273 *.tar) tar -xf $SRC/$TARBALL ;;
274 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
275 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
276 tar -xf $SRC/$TARBALL 2>/dev/null;;
277 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
278 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
279 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
280 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
281 *) cp $SRC/$TARBALL $(pwd) ;;
282 esac
283 }
286 # Display time.
288 disp_time() {
289 local sec div min
290 sec="$1"
291 div=$(( ($1 + 30) / 60))
292 case $div in
293 0) min='';;
294 # L10n: 'm' is for minutes (approximate cooking time)
295 *) min=$(_n ' ~ %dm' "$div");;
296 esac
298 # L10n: 's' is for seconds (cooking time)
299 _ '%ds%s' "$sec" "$min"
300 }
303 # Display cooked package summary.
305 summary() {
306 set_paths
307 cd $WOK/$pkg
308 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
309 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
310 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
312 _ 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION"
313 separator
315 # L10n: keep the same width of translations to get a consistent view
316 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
317 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
318 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
319 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
320 _ 'Cook time : %s' "$(disp_time "$time")"
321 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
322 _ 'Host arch : %s' "$ARCH"
324 separator -
325 _ ' # : Packed : Compressed : Files : Package name'
326 separator -
327 pkgi=1
328 for i in $(all_names); do
329 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
330 pkgname="$i-$VERSION$EXTRAVERSION.tazpkg"
331 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
332 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
333 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
334 pkgi=$((pkgi + 1))
335 done
336 separator
337 }
340 # Display debugging error info.
342 debug_info() {
343 title 'Debug information'
344 # L10n: specify your format of date and time (to help: man date)
345 # L10n: not bad one is '+%x %R'
346 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
347 if [ -n "$time" ]; then
348 times="$(($(date +%s) - $time))"
349 _ 'Wasted time : %s' "$(disp_time "$times")"
350 fi
351 for error in \
352 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
353 'error:' 'fatal error:' 'undefined reference to' \
354 'Unable to connect to' 'link: cannot find the library' \
355 'CMake Error' ': No such file or directory' \
356 'Could not read symbols: File in wrong format'
357 do
358 # format "line number:line content"
359 fgrep -n "$error" $LOGS/$pkg.log
360 done > $LOGS/$pkg.log.debug_info 2>&1
361 # sort by line number, remove duplicates
362 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
363 rm -f $LOGS/$pkg.log.debug_info
364 footer
365 }
368 # A bit smarter function than the classic `cp` command
370 scopy() {
371 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
372 cp -a "$1" "$2" # copy generic files
373 else
374 cp -al "$1" "$2" # copy hardlinks
375 fi
376 }
379 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
380 # We use standard paths, so some packages need to copy these files with the
381 # receipt and genpkg_rules.
382 # This function executes inside the packaging process, before compressor call.
384 copy_generic_files() {
385 # Proceed only for "main" package (for v2), and for any packages (v1)
386 [ "$pkg" == "$PACKAGE" ] || return 0
388 # $LOCALE is set in cook.conf
389 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
390 if [ -d "$install/usr/share/locale" ]; then
391 mkdir -p "$fs/usr/share/locale"
392 for i in $LOCALE; do
393 if [ -d "$install/usr/share/locale/$i" ]; then
394 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
395 fi
396 done
397 fi
398 fi
400 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
401 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
402 if [ -d "$install/usr/share/pixmaps" ]; then
403 mkdir -p "$fs/usr/share/pixmaps"
404 for i in png xpm; do
405 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
406 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
407 done
408 fi
409 fi
411 # Desktop entry (.desktop).
412 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
413 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
414 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
415 mkdir -p "$fs/usr/share"
416 cp -r $install/usr/share/applications $fs/usr/share
417 fi
418 fi
419 }
422 # Copy pixmaps, desktop files and licenses from $stuff to $install.
423 # This function executes after the main compile_rules() is done.
425 copy_generic_stuff() {
426 # Custom or homemade PNG pixmap can be in stuff.
427 if [ -f "$stuff/$PACKAGE.png" ]; then
428 mkdir -p $install/usr/share/pixmaps
429 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
430 fi
432 # Homemade desktop file(s) can be in stuff.
433 if [ -d "$stuff/applications" ]; then
434 mkdir -p $install/usr/share
435 cp -r $stuff/applications $install/usr/share
436 fi
437 if [ -f "$stuff/$PACKAGE.desktop" ]; then
438 mkdir -p $install/usr/share/applications
439 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
440 fi
442 # Add custom licenses
443 if [ -d "$stuff/licenses" ]; then
444 mkdir -p $install/usr/share/licenses
445 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
446 fi
447 }
450 # Update installed.cook.diff
452 update_installed_cook_diff() {
453 # If a cook failed deps are removed.
454 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
455 cd $CACHE
456 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
457 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
458 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
459 }
462 # Remove installed deps.
464 remove_deps() {
465 # Now remove installed build deps.
466 diff='/tmp/installed.cook.diff'
467 [ -s "$diff" ] || return
469 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
470 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
471 newline
472 _n 'Build dependencies to remove:'; echo " $nb"
473 [ -n "$root" ] && echo "root=\"$root\""
474 {
475 _n 'Removing:'
476 for dep in $deps; do
477 echo -n " $dep"
478 # Do not waste time uninstalling the packages if we are inside
479 # aufs chroot - unmounting chroot will "uninstall" all packages.
480 [ -s /aufs-umount.sh ] ||
481 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
482 done
483 } | busybox fold -sw80
484 newline; newline
485 # Keep the last diff for debug and info.
486 mv -f $diff $CACHE/installed.diff
487 }
490 # Automatically patch the sources.
492 patchit() {
493 [ -f "$stuff/patches/series" ] || return
495 IFS=$'\n'
496 while read i; do
497 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
498 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
499 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
500 *) patchopts='-Np1';;
501 esac
502 [ -n "$patchname" ] || continue # allow empty lines
503 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
504 newline
505 _ 'Applying patch %s' "$patchname"
506 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
507 touch $src/done.$patchname
508 done < $stuff/patches/series
509 newline
510 unset IFS
511 }
514 # Check source tarball integrity.
516 check_integrity() {
517 for i in sha1 sha3 sha256 sha512 md5; do
518 I=$(echo $i | tr 'a-z' 'A-Z')
519 eval sum=\$TARBALL_$I
520 if [ -n "$sum" ]; then
521 newline
522 _ 'Checking %ssum of source tarball...' "$i"
523 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
524 fi
525 done
526 newline
527 }
530 # Misc fix functions
532 fix() {
533 case $1 in
534 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
535 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
536 ld)
537 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
538 ;;
539 libtool)
540 if [ -e 'libtool' ]; then
541 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
542 else
543 echo "fix libtool: warning: libtool absent, nothing to fix."
544 fi
545 ;;
546 esac
547 }
550 # The main cook function.
552 cookit() {
553 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
554 _ 'ERROR: Broken setup. Abort.'
555 return
556 fi
558 title 'Cook: %s' "$PACKAGE $VERSION"
559 set_paths
561 # Handle cross-tools.
562 case "$ARCH" in
563 arm*|x86_64)
564 # CROSS_COMPILE is used by at least Busybox and the kernel to set
565 # the cross-tools prefix. Sysroot is the root of our target arch
566 sysroot="$CROSS_TREE/sysroot"
567 tools="$CROSS_TREE/tools"
568 # Set root path when cross compiling. ARM tested but not x86_64
569 # When cross compiling we must install build deps in $sysroot.
570 arch="-$ARCH"
571 root="$sysroot"
572 _ '%s sysroot: %s' "$ARCH" "$sysroot"
573 _ 'Adding "%s" to PATH' "$tools/bin"
574 export PATH="$PATH:$tools/bin"
575 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
576 export CROSS_COMPILE="$HOST_SYSTEM-"
577 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
578 if [ "$ARCH" == 'x86_64' ]; then
579 export CC="$HOST_SYSTEM-gcc -m64"
580 export CXX="$HOST_SYSTEM-g++ -m64"
581 else
582 export CC="$HOST_SYSTEM-gcc"
583 export CXX="$HOST_SYSTEM-g++"
584 fi
585 export AR="$HOST_SYSTEM-ar"
586 export AS="$HOST_SYSTEM-as"
587 export RANLIB="$HOST_SYSTEM-ranlib"
588 export LD="$HOST_SYSTEM-ld"
589 export STRIP="$HOST_SYSTEM-strip"
590 export LIBTOOL="$HOST_SYSTEM-libtool"
591 ;;
592 esac
594 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
596 cd $pkgdir
597 [ -z "$continue" ] && rm -rf source 2>/dev/null
598 rm -rf install taz 2>/dev/null
600 # Disable -pipe if less than 512 MB free RAM.
601 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
602 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
603 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
604 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
605 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
606 fi
607 unset free
609 # Export flags and path to be used by make and receipt.
610 DESTDIR="$pkgdir/install"
611 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
612 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
613 #LDFLAGS
615 # BUILD_DEPENDS may vary depending on the ARCH
616 case "$ARCH" in
617 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
618 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
619 esac
621 # Check for build deps and handle implicit depends of *-dev packages
622 # (ex: libusb-dev :: libusb).
623 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
624 # touch $CACHE/installed.local $CACHE/installed.web
625 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
626 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
628 # Get the list of installed packages
629 cd $root$INSTALLED; ls > $CACHE/installed.list
631 for action in check install; do
632 for dep in $BUILD_DEPENDS; do
633 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
634 for i in $dep $implicit; do
635 # Skip if package already installed
636 [ -f "$root$INSTALLED/$i/receipt" ] && continue
638 case $action in
639 check)
640 # Search for local package or local provided-package
641 name=$(awk -F$'\t' -vpkg="$i" '{
642 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
643 }' "$PKGS/packages.info")
644 if [ -z "$name" ]; then
645 # Search for package in mirror
646 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
647 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
648 fi
649 ;;
650 install)
651 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
652 ;;
653 esac
654 done
655 done
656 done
658 # # Have we a missing build dep to cook?
659 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
660 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
661 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
662 # for i in $(uniq $CACHE/missing.dep); do
663 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
664 # tee -a $LOGS/$PACKAGE.log.$$
665 # # programmers: next two messages are exact copy from remove_deps()
666 # togrep1=$(_n 'Build dependencies to remove:')
667 # togrep2=$(_n 'Removing:')
668 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
669 # fgrep $togrep1 $LOGS/$i.log && \
670 # fgrep $togrep2 $LOGS/$i.log && newline) | \
671 # tee -a $LOGS/$PACKAGE.log.$$ && break
672 # done
673 # rm -f $CACHE/missing.dep
674 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
675 # fi
676 #
677 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
678 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
679 # # missing dep in cached file.
680 # lerror=$(_n 'ERROR')
681 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
682 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
683 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
684 # broken; exit 1
685 # fi
686 #
687 # # Install local packages: package-version$arch
688 # cd $PKGS
689 # for i in $(uniq $CACHE/installed.local); do
690 # # _ 'Installing dep (pkg/local): %s' "$i"
691 # tazpkg install $i --root=$root --local --quiet --cookmode
692 # done
693 #
694 # # Install web or cached packages (if mirror is set to $PKGS we only
695 # # use local packages).
696 # for i in $(uniq $CACHE/installed.web); do
697 # # _ 'Installing dep (web/cache): %s' "$i"
698 # tazpkg get-install $i --root=$root --local --quiet --cookmode
699 # done
701 update_installed_cook_diff
703 # Get source tarball and make sure we have source dir named:
704 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
705 # tarball if it exists.
706 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
707 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
708 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
709 LZMA_SRC=''
710 else
711 get_source || { broken; exit 1; }
712 fi
713 fi
714 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
715 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
716 if ! extract_source ; then
717 get_source
718 extract_source || { broken; exit 1; }
719 fi
720 if [ -n "$LZMA_SRC" ]; then
721 cd $pkgdir/source
722 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
723 mv tmp tmp-1; mkdir tmp
724 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
725 fi
726 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
727 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
728 fi
729 fi
731 cd $pkgdir/source/tmp
732 # Some archives are not well done and don't extract to one dir (ex lzma).
733 files=$(ls | wc -l)
734 [ "$files" -eq 1 -a -d "$(ls)" ] &&
735 mv * ../$PACKAGE-$VERSION
736 [ "$files" -eq 1 -a -f "$(ls)" ] &&
737 mkdir -p ../$PACKAGE-$VERSION &&
738 mv * ../$PACKAGE-$VERSION/$TARBALL
739 [ "$files" -gt 1 ] &&
740 mkdir -p ../$PACKAGE-$VERSION &&
741 mv * ../$PACKAGE-$VERSION
742 cd ..; rm -rf tmp
743 fi
745 # Check md5sum (or similar) for sources tarball
746 check_integrity
748 # Libtool shared libs path hack.
749 case "$ARCH" in
750 arm*) cross libhack ;;
751 esac
753 # Compiling all the sets
754 if grep -q ^compile_rules $receipt; then
755 _ 'Executing: %s' 'compile_rules'
756 echo "CFLAGS : $CFLAGS"
757 #echo "LDFLAGS : $LDFLAGS"
758 [ -d "$src" ] && cd $src
759 patchit
761 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
762 SETS=$(echo $SPLIT \
763 | awk '
764 BEGIN { RS = " "; FS = ":"; }
765 { print $2; }' \
766 | sort -u \
767 | tr '\n' ' ')
768 SETS=${SETS% } # normalize space
769 # Prepare specified source sets using patched sources
770 [ -n "$SETS" ] &&
771 for set in $SETS; do
772 echo "Preparing set $set" # debug
773 cp -a $src $src-$set
774 done
776 for SET in '' $SETS; do
777 # Switch to the specified source set
778 set_paths
779 local suffix=''
780 [ -n "$SET" ] && suffix="-$SET"
781 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
782 export install="$WOK/$pkg/install$suffix"
783 export DESTDIR="$install"
785 if [ -n "$SETS" ]; then
786 if [ -n "$SET" ]; then
787 title "Switching to the set '$SET'"
788 else
789 title "Switching to the default set"
790 fi
791 echo "src : $src"
792 echo "install: $install"
793 fi
794 [ -d "$src" ] && cd $src # packages without sources exists
795 echo
797 [ -d "$install" ] && rm -r $install
798 #mkdir -p $install
800 compile_rules $@ || { broken; exit 1; }
802 # Stay compatible with _pkg
803 [ -d "$src/_pkg" ] && mv $src/_pkg $install
805 copy_generic_stuff
807 # Actions to do after compiling the package
808 # Skip all for split packages (already done in main package)
809 if [ -z "$WANTED" ]; then
810 footer
811 export COOKOPTS ARCH install
812 @@PREFIX@@/libexec/cookutils/compressor install
813 fi
814 done
815 else
816 mkdir -p $install # allow receipts without `compile_rules()`
817 fi
818 footer
820 # Execute testsuite.
821 if grep -q ^testsuite $receipt; then
822 title 'Running testsuite'
823 testsuite $@ || { broken; exit 1; }
824 footer
825 fi
827 update_installed_cook_diff force
828 }
831 # Cook quality assurance.
833 cookit_quality() {
834 while true; do
835 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
836 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
837 [ "$trials" == 'yes' ] || break
838 title "Interactive mode"
839 # TODO: allow commands:
840 # q - quit; v - edit receipt here using vi;
841 # s - search for package containing package;
842 # <package name> - install package; [Enter] - retry
843 _ 'You may install the packages here and/or edit the receipt there.'
844 newline
845 while true; do
846 _n 'Install the package? [name/N] '; read answer
847 [ -n "$answer" ] || break
848 tazpkg -gi $answer --root=$root --local --quiet --cookmode
849 done
850 newline
851 _n 'Try again? [Y/n] '; read answer
852 [ "$answer" == 'n' ] && break
853 # here you may append log if you want (">>" instead of last ">")
854 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
855 done
857 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
859 # ERROR can be echoed any time in cookit()
860 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
861 grep -Eq "(^ERROR|undefined reference to)" ; then
862 debug_info | tee -a $LOGS/$pkg.log
863 put_status $pkg Failed
864 rm -f $command
865 broken; exit 1
866 fi
867 }
870 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
871 # but it doesn't handle EXTRAVERSION.
873 packit() {
874 set_paths "$1"
875 PACKAGE="${1:-$PACKAGE}"
877 # Handle cross compilation
878 case "$ARCH" in
879 arm*|x86_64) arch="-$ARCH" ;;
880 esac
882 title 'Pack: %s' "$PACKAGE $VERSION$arch"
884 if grep -q ^genpkg_rules $receipt; then
885 _ 'Executing: %s' 'genpkg_rules'
886 set -e; cd $pkgdir; mkdir -p $fs
887 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
888 $LOGS/$pkg.log
889 else
890 _ 'No packages rules: meta package'
891 mkdir -p $fs
892 fi
894 # Check CONFIG_FILES
895 if [ -n "$CONFIG_FILES" ]; then
896 unset IFS
897 for i in $CONFIG_FILES; do
898 if [ ! -e $fs$i ]; then
899 case $i in
900 */) mkdir -p $fs$i ;;
901 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
902 esac
903 fi
904 done
905 fi
907 # First QA check to stop now if genpkg_rules failed.
908 lerror=$(_n 'ERROR')
909 if fgrep -q ^$lerror $LOGS/$pkg.log; then
910 broken; exit 1
911 fi
913 cd $taz
914 action 'Copying "%s"...' 'receipt'
915 export PACKAGE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT
916 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
917 chown 0.0 $pack/receipt; status
919 unset desc
920 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
921 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
922 if [ -n "$desc" ]; then
923 action 'Copying "%s"...' "$(basename "$desc")"
924 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
925 fi
927 copy_generic_files
929 # Strip and stuff files.
930 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
932 # Create files.list with redirecting find output.
933 action 'Creating the list of files...'
934 cd $fs
935 find . -type f -print > ../files.list
936 find . -type l -print >> ../files.list
937 cd ..; sed -i 's|^.||' files.list
938 status
940 # Md5sum of files.
941 action 'Creating md5sum of files...'
942 while read file; do
943 [ -L "fs$file" ] && continue
944 [ -f "fs$file" ] || continue
945 case "$file" in
946 /lib/modules/*/modules.*|*.pyc) continue ;;
947 esac
948 md5sum "fs$file" | sed 's| fs| |'
949 done < files.list | sort -k2 > md5sum
950 status
952 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
953 2>/dev/null | awk 'END{ print $1 }')
955 # Build cpio archive.
956 action 'Compressing the FS...'
957 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
958 find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
959 # find fs | cpio -o -H newc --quiet | /bin/lzma -zeT0 -vv >fs.cpio.lzma
960 mv fs ../
961 status
963 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
964 2>/dev/null | awk 'END{ print $1 }')
966 action 'Updating receipt sizes...'
967 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
968 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
969 status
971 # Set extra version.
972 if [ -n "$EXTRAVERSION" ]; then
973 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
974 sed -i '/^EXTRAVERSION=/d' receipt
975 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
976 status
977 fi
979 # Compress.
980 action 'Creating full cpio archive...'
981 find . -newer $receipt -exec touch -hr $receipt '{}' \;
982 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
983 status
985 # Restoring original package tree.
986 mv ../fs .
988 rm fs.cpio.lzma; cd ..
990 # QA and give info.
991 tazpkg=$(ls *.tazpkg)
992 packit_quality
993 footer "$(_ 'Package "%s" created' "$tazpkg")"
994 update_packages_db
995 }
998 # Calculate release checksum: usually it does not change on "just recook".
999 # Release checksum is md5sum of file containing md5sums of:
1000 # a) all files, b) receipt, and c) description.txt.
1001 # Md5sum of the package file will change every time because of embedded timestamps;
1002 # release checksum based only on files content, and will change only when files change.
1003 # (Pitfall: ownership and permissions...)
1005 release_checksum() {
1006 local pack=$1
1007 local rsum_file=$(mktemp)
1009 cp $pack/md5sum $rsum_file
1010 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1011 [ -e "$pack/description.txt" ] &&
1012 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1014 local rsum=$(md5sum $rsum_file | awk '{print $1}')
1015 rm $rsum_file
1016 local rsumold=$(awk -F$'\t' -vpkg="$PACKAGE" '
1017 {if ($1 == pkg) { print $9; exit; }}' $PKGS/packages.info)
1019 [ "$rsum" == "$rsumold" ] && rsum=''
1021 echo $rsum
1025 # Verify package quality and consistency.
1027 packit_quality() {
1028 #action 'QA: checking for broken link...'
1029 #link=$(find $fs/usr -type l -follow)
1030 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1031 #status
1033 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1034 # Exit if any error found in log file.
1035 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1036 rm -f $command
1037 broken; exit 1
1038 fi
1039 fi
1041 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1043 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1044 action 'QA: checking for empty package...'
1045 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1046 broken
1047 rm -f $command
1048 false; status
1049 die 'ERROR: empty package'
1050 fi
1051 :; status
1052 fi
1055 # Find and remove old package(s) only if "release checksum" has changed
1056 rsum=$(release_checksum $pack)
1057 if [ -n "$rsum" ]; then
1058 old_file=$(awk -F$'\t' -vname="$PACKAGE" '{
1059 if ($1 == name) printf("%s-%s.tazpkg", $1, $2);
1060 }' $PKGS/packages.info)
1061 if [ -f "$PKGS/$old_file" ]; then
1062 action 'Removing old package "%s"' "$old_file"
1063 rm -f "$PKGS/$old_file"
1064 status
1065 fi
1066 # package changed, substitute old package by new
1067 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
1068 else
1069 # package not changed, remove new package
1070 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg
1071 fi
1073 sed -i "/^${pkg}$/d" $broken
1074 #action 'Removing source tree...'
1075 #rm -f $WOK/$pkg/source; status
1079 # Return all the names of packages bundled in this receipt
1081 all_names() {
1082 # Get package names from $SPLIT variable
1083 local split=$(echo $SPLIT \
1084 | awk '
1085 BEGIN { RS = " "; FS = ":"; }
1086 { print $1; }' \
1087 | tr '\n' ' ')
1088 local split_space=" $split "
1089 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1090 # For receipts v1: $SPLIT may present in the $WANTED package,
1091 # but split packages have their own receipts
1092 echo $PACKAGE
1093 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1094 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1095 # We should build packages in the order defined in the $SPLIT.
1096 echo $split
1097 else
1098 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1099 echo $PACKAGE $split
1100 fi
1104 # v2: pack all packages using compiled files
1106 packall() {
1107 set_paths
1108 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1109 for i in $(all_names); do
1110 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1111 packit $i
1112 done
1113 else
1114 packit
1115 fi
1119 # Reverse "cat" command: prints input lines in the reverse order
1121 tac() {
1122 sed '1!G;h;$!d' $1
1126 # Update chroot with freshly rebuilt package: keep env up-to-date.
1128 update_chroot() {
1129 local PACKAGE="$pkg"
1130 for i in $(all_names); do
1131 if [ -d "$root$INSTALLED/$i" ]; then
1132 . /etc/slitaz/cook.conf
1133 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1134 _ 'Updating %s chroot environment...' "$ARCH"
1135 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1136 cd $PKGS
1137 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1138 fi
1139 done
1143 # Install package on --inst or update the chroot.
1145 install_package() {
1146 set_paths
1147 case "$ARCH" in
1148 arm*|x86_64)
1149 arch="-$ARCH"
1150 root="$CROSS_TREE/sysroot" ;;
1151 esac
1152 # Install package if requested but skip install if target host doesn't
1153 # match build system or it will break the build chroot.
1154 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1155 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1156 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1157 cd $PKGS
1158 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1159 else
1160 broken
1161 die 'Unable to install package, build has failed.'
1162 fi
1163 fi
1165 update_chroot
1169 # remove chroot jail
1171 umount_aufs() {
1172 tac ${1}rw/aufs-umount.sh | sh
1173 rm -rf ${1}rw
1174 umount ${1}root
1175 rmdir ${1}r*
1179 # Launch the cook command into a chroot jail protected by aufs.
1180 # The current filesystems are used read-only and updates are
1181 # stored in a separate branch.
1183 try_aufs_chroot() {
1185 base="/dev/shm/aufsmnt$$"
1187 # Can we setup the chroot? Is it already done?
1188 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1189 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1190 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1191 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1192 mkdir ${base}root ${base}rw || return
1194 _ 'Setup aufs chroot...'
1196 # Sanity check
1197 for i in / /proc /sys /dev/shm /home ; do
1198 case " $AUFS_MOUNTS " in
1199 *\ $i\ *) ;;
1200 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1201 esac
1202 done
1203 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1204 mount --bind $mnt ${base}root$mnt
1205 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1206 _ 'Aufs mount failure'
1207 umount ${base}root
1208 rm -rf ${base}r*
1209 return
1210 fi
1211 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1212 done
1213 trap "umount_aufs ${base}" INT
1215 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1216 status=$?
1218 _ 'Leaving aufs chroot...'
1219 umount_aufs $base
1220 # Install package outside the aufs jail
1221 install_package
1222 exit $status
1226 # Encode predefined XML entities
1228 xml_ent() {
1229 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1233 # Create a XML feed for freshly built packages.
1235 gen_rss() {
1236 pubdate=$(date '+%a, %d %b %Y %X')
1237 cat > $FEEDS/$pkg.xml <<EOT
1238 <item>
1239 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1240 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1241 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1242 <pubDate>$pubdate</pubDate>
1243 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1244 </item>
1245 EOT
1249 # Truncate stdout log file to $1 Mb.
1251 loglimit() {
1252 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1253 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1254 else
1255 tee /dev/stderr
1256 fi
1261 # Receipt functions to ease packaging
1264 get_dev_files() {
1265 action 'Getting standard devel files...'
1266 mkdir -p $fs/usr/lib
1267 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1268 cp -a $install/usr/lib/*a $fs/usr/lib
1269 cp -a $install/usr/include $fs/usr
1270 status
1274 # Function to use in compile_rules() to copy man page from $src to $install
1276 cook_pick_manpages() {
1277 local name section
1278 action 'Copying man pages...'
1280 for i in $@; do
1281 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1282 section=${name##*/}; section=${section##*.}
1283 mkdir -p $install/usr/share/man/man$section
1284 scopy $i $install/usr/share/man/man$section
1285 done
1286 status
1290 # Function to use in compile_rules() to copy documentation from $src to $install
1292 cook_pick_docs() {
1293 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1294 action 'Copying documentation...'
1295 mkdir -p $docdir
1296 cp -r $@ $docdir
1297 chmod -R a+r $docdir
1298 status
1302 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1304 cook_copy_files() {
1305 action 'Copying files...'
1306 cd $install
1307 local i j
1308 IFS=$'\n'
1309 for i in $@; do
1310 for j in $(find . -name $i ! -type d); do
1311 mkdir -p $fs$(dirname ${j#.})
1312 scopy $j $fs$(dirname ${j#.})
1313 done
1314 done
1315 cd - >/dev/null
1316 status
1320 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1322 cook_copy_folders() {
1323 action 'Copying folders...'
1324 cd $install
1325 local i j
1326 IFS=$'\n'
1327 for i in $@; do
1328 for j in $(find . -name $i -type d); do
1329 mkdir -p $fs$(dirname ${j#.})
1330 cp -a $j $fs$(dirname ${j#.})
1331 done
1332 done
1333 cd - >/dev/null
1334 status
1338 # Remove from current $fs files that are already packed (for receipts v2).
1339 # Note: the order in $SPLIT is very important.
1340 # Note 2: working in the current set.
1342 remove_already_packed() {
1343 local i j
1344 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1345 # $pkg may (or may not) be included in the $SPLIT
1346 neighbors=$(
1347 echo $pkg $SPLIT" " \
1348 | awk -F$'\t' -vpkg="$PACKAGE" '
1349 BEGIN { RS = " "; FS = ":"; }
1350 { set[$1] = $2; }
1351 END {
1352 current_set = set[pkg];
1353 for (i in set)
1354 { if (i != pkg && set[i] == current_set) print i; }
1356 ')
1357 IFS=$'\n'
1358 for neighbor in $neighbors; do
1359 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1360 [ -e "$i" ] || continue
1361 while read j; do
1362 [ -f $fs$j -o -h $fs$j ] || continue
1363 rm $fs$j
1364 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1365 done < $i
1366 done
1367 unset IFS
1371 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1372 # (default: 16 and 48) from $install to $fs
1374 cook_copy_icons() {
1375 local sizes=$@ i j ifs="$IFS"
1376 unset IFS
1377 action 'Copying hicolor icons...'
1378 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1379 mkdir -p $fs/usr/share/icons/hicolor
1380 for i in ${sizes:-16 48}; do
1381 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1382 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1383 scopy $install/usr/share/icons/hicolor/$j \
1384 $fs/usr/share/icons/hicolor
1385 done
1386 status
1387 IFS="$ifs"
1391 # Common function to copy files, folders and patterns
1393 copy() {
1394 action 'Copying folders and files...'
1395 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1397 # Get set name for specified package from $SPLIT variable
1398 local set=$(echo $SPLIT \
1399 | awk -vpkg="$PACKAGE" '
1400 BEGIN { RS = " "; FS = ":"; }
1401 { if ($1 == pkg && $2) { print "-" $2; exit; } }')
1402 # Change set, make filelist and folderlist for new set
1403 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$set"
1404 export install="$WOK/$pkg/install$set"
1405 export DESTDIR="$install"
1406 IFS=$'\n'
1407 cd $install
1408 find ! -type d | sed 's|\.||' > $filelist
1409 find -type d | sed 's|\.||' > $folderlist
1411 for i in $@; do
1412 case $i in
1413 @std)
1414 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1415 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1416 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1417 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1418 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1419 /\/share\/devhelp\//d; /\/share\/locale\//d;
1420 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1421 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1422 /\/share\/appdata\//d; /\/share\/help\//d;
1423 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1424 ' $filelist
1425 ;;
1426 @dev)
1427 # Copy "developer files"
1428 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1429 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1430 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1431 ' $filelist
1432 ;;
1433 @rm)
1434 # Quick alias
1435 remove_already_packed
1436 ;;
1437 @ico)
1438 # Quick alias
1439 cook_copy_icons >/dev/null
1440 ;;
1441 */)
1442 # Copy specified folders.
1443 i="${i%/}"
1444 find -type d -path "*/${i#/}" | sed 's|^.||'
1445 ;;
1446 *)
1447 # Copy specified files.
1448 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1449 ;;
1450 esac \
1451 | sort -u \
1452 | while read j; do
1453 mkdir -p $fs$(dirname "$j")
1454 if [ -d "$install$j" ]; then
1455 cp -a "$install$j" $fs$(dirname "$j")
1456 else
1457 scopy "$install$j" $fs$(dirname "$j")
1458 fi
1459 done
1460 # Copy empty directories
1461 case $i in
1462 @std)
1463 while read j; do
1464 case $j in
1465 # always skip empty man & doc folders, because this will end up
1466 # copying all the man pages and docs to the package
1467 */man/*|*/doc/*) continue;;
1468 esac
1469 [ -z "$(ls -A "$install$j")" ] || continue
1470 # directory $j is empty
1471 k="$j"
1472 # make 'ladder' from directories, from root dir to $j
1473 # /a /a/b /a/b/c etc.
1474 while :; do
1475 [ -z "$k" ] && break
1476 echo "$k"
1477 k="${k%/*}"
1478 done \
1479 | tac \
1480 | while read k; do
1481 # copy dir with its original ownership/permissions if it does not exist
1482 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1483 done
1484 done < $folderlist
1485 ;;
1486 esac
1487 done
1488 cd - >/dev/null
1489 unset IFS
1490 rm $filelist $folderlist
1491 status
1495 # Update packages database every time after successful build
1497 update_packages_db() {
1498 # packages.info (unsorted, located near to packages)
1499 local pi="$PKGS/packages.info"
1500 unset_receipt; . $pack/receipt
1501 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1503 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1505 rsum=$(release_checksum $pack)
1506 if [ -n "$rsum" ]; then
1507 _ 'The release checksum has changed.\n'
1509 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1510 cat >> $pi <<EOT
1511 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1512 EOT
1514 # files.list (uncompressed, unsorted, located in $cache)
1515 local fl="$cache/files.list"
1516 touch $fl
1517 sed -i "/^$PACKAGE: /d" $fl
1518 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1519 else
1520 _ 'The release checksum has not changed.\n'
1521 fi
1525 # Update split.db once for receipt
1527 update_split_db() {
1528 local db="$cache/split.db"
1529 touch $db
1530 sed -i "/^$pkg\t/d" $db
1531 echo -e "$pkg\t$(all_names)" >> $db
1535 # Recreate whole split.db from scratch
1537 recreate_split_db() {
1538 # Clean
1539 local db="$cache/split.db"
1540 touch $db
1541 > $db
1543 cd $WOK
1544 for pkg in *; do
1545 [ -f "$WOK/$pkg/receipt" ] || continue
1546 unset PACKAGE SPLIT
1547 . $WOK/$pkg/receipt
1548 echo -e "$PACKAGE\t$(all_names)" >> $db
1549 done
1553 # Put the status to the activity log
1555 put_status() {
1556 # $1: package, $2: status, one of 'Done', 'Failed'
1557 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1564 # Commands
1567 # cook <package> --deps
1568 [ -n "$deps" ] && {
1569 @@PREFIX@@/libexec/cookutils/deps $1
1570 exit 0
1573 # cook <package> --clean
1574 # cook <package> -c
1575 [ -n "$clean" -o "$2" == '-c' ] && {
1576 action 'Cleaning "%s"' "$1"
1577 cd $WOK/$1; rm -rf install taz source
1578 status; newline
1579 touch $activity # update $activity -> something changed -> update webstat
1580 exit 0
1583 # cook <package> --getsrc
1584 # cook <package> -gs
1585 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1586 title 'Getting source for "%s"' "$1"
1587 receipt="$WOK/$pkg/receipt"
1588 check_pkg_in_wok
1589 unset_receipt
1590 . $receipt
1591 get_source
1592 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1593 exit 0
1596 # cook <package> --block
1597 # cook <package> -b
1598 [ -n "$block" -o "$2" == '-b' ] && {
1599 action 'Blocking package "%s"' "$1"
1600 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1601 status; newline
1602 touch $activity
1603 exit 0
1606 # cook <package> --unblock
1607 # cook <package> -ub
1608 [ -n "$unblock" -o "$2" == '-ub' ] && {
1609 action 'Unblocking package "%s"' "$1"
1610 sed -i "/^$1$/d" $blocked
1611 status; newline
1612 touch $activity
1613 exit 0
1619 case "$1" in
1620 usage|help|-u|-h)
1621 usage ;;
1623 list-wok)
1624 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1625 cd $WOK
1626 if [ "$ARCH" != 'i486' ]; then
1627 count=0
1628 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1629 do
1630 unset HOST_ARCH
1631 . ./$pkg
1632 count=$(($count + 1))
1633 colorize 34 "$PACKAGE"
1634 done
1635 else
1636 count=$(ls | wc -l)
1637 ls -1
1638 fi
1639 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1640 ;;
1642 activity)
1643 cat $activity ;;
1645 search)
1646 # Just a simple search function, we don't need more actually.
1647 query="$2"
1648 title 'Search results for "%s"' "$query"
1649 cd $WOK; ls -1 | grep "$query"
1650 footer ;;
1652 setup)
1653 # Setup a build environment
1654 check_root
1655 _ 'Cook: setup environment' | log
1656 title 'Setting up your environment'
1657 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1658 cd $SLITAZ
1659 init_db_files
1660 _ 'Checking for packages to install...'
1661 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1662 # ARCH-setup or 'cross check' should be used before: cook setup
1663 case "$ARCH" in
1664 arm*|x86_64)
1665 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1666 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1667 . /etc/slitaz/cross.conf ;;
1668 esac
1669 for pkg in $SETUP_PKGS; do
1670 if [ -n "$forced" ]; then
1671 tazpkg -gi $pkg --forced
1672 else
1673 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1674 fi
1675 done
1677 # Handle --options
1678 case "$2" in
1679 --wok) hg clone $WOK_URL wok || exit 1 ;;
1680 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1681 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1682 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1683 esac
1685 # SliTaz group and permissions
1686 if ! grep -q ^slitaz /etc/group; then
1687 _ 'Adding group "%s"' 'slitaz'
1688 addgroup slitaz
1689 fi
1690 _ 'Setting permissions for group "%s"...' 'slitaz'
1691 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1692 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1693 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1695 *-setup)
1696 # Setup for cross compiling.
1697 arch="${1%-setup}"
1698 check_root
1699 . /etc/slitaz/cook.conf
1700 for pkg in $CROSS_SETUP; do
1701 if [ -n "$forced" ]; then
1702 tazpkg -gi $pkg --forced
1703 else
1704 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1705 fi
1706 done
1708 _ 'Cook: setup %s cross environment' "$arch" | log
1709 title 'Setting up your %s cross environment' "$arch"
1710 init_db_files
1711 sed -i \
1712 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1713 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1714 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1715 /etc/slitaz/cook.conf
1716 case "$arch" in
1717 arm)
1718 flags='-O2 -march=armv6'
1719 host="$ARCH-slitaz-linux-gnueabi" ;;
1720 armv6hf)
1721 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1722 host="$ARCH-slitaz-linux-gnueabi" ;;
1723 armv7)
1724 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1725 host="$ARCH-slitaz-linux-gnueabi" ;;
1726 x86_64)
1727 flags='-O2 -mtune=generic -pipe'
1728 host="$ARCH-slitaz-linux" ;;
1729 esac
1730 sed -i \
1731 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1732 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1733 . /etc/slitaz/cook.conf
1734 sysroot="$CROSS_TREE/sysroot"
1735 tools="/cross/$arch/tools"
1736 root="$sysroot"
1737 # L10n: keep the same width of translations to get a consistent view
1738 _ 'Target arch : %s' "$ARCH"
1739 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1740 _ 'Build flags : %s' "$flags"
1741 _ 'Arch sysroot : %s' "$sysroot"
1742 _ 'Tools prefix : %s' "$tools/bin"
1743 # Tell the packages manager where to find packages.
1744 _ 'Packages DB : %s' "$root$DB"
1745 mkdir -p $root$INSTALLED
1746 cd $root$DB; rm -f *.bak
1747 for list in packages.list packages.desc packages.equiv packages.md5; do
1748 rm -f $list
1749 ln -s $SLITAZ/packages/$list $list
1750 done
1751 # We must have the cross compiled glibc-base installed or default
1752 # i486 package will be used as dep by tazpkg and then break the
1753 # cross environment
1754 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1755 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1756 fi
1757 # Show GCC version or warn if not yet compiled.
1758 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1759 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1760 else
1761 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1762 _ 'Run "%s" to cook a toolchain' 'cross compile'
1763 fi
1764 footer ;;
1766 test)
1767 # Test a cook environment.
1768 _ 'Cook test: testing the cook environment' | log
1769 [ ! -d "$WOK" ] && exit 1
1770 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1771 cook cooktest ;;
1773 new)
1774 # Create the package folder and an empty receipt.
1775 pkg="$2"
1776 [ -z "$pkg" ] && usage
1777 newline
1778 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1780 action 'Creating folder "%s"' "$WOK/$pkg"
1781 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1783 action 'Preparing the package receipt...'
1784 cp $DATA/receipt .
1785 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1786 status; newline
1788 # Interactive mode, asking and seding.
1789 case "$3" in
1790 --interactive|-x)
1791 _ 'Entering interactive mode...'
1792 separator
1793 _ 'Package : %s' "$pkg"
1795 _n 'Version : ' ; read answer
1796 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1798 _n 'Category : ' ; read answer
1799 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1801 # L10n: Short description
1802 _n 'Short desc : ' ; read answer
1803 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1805 _n 'Maintainer : ' ; read answer
1806 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1808 _n 'License : ' ; read answer
1809 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1811 _n 'Web site : ' ; read answer
1812 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1813 newline
1815 # Wget URL.
1816 _ 'Wget URL to download source tarball.'
1817 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1818 _n 'Wget url : ' ; read answer
1819 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1821 # Ask for a stuff dir.
1822 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1823 if [ "$?" -eq 0 ]; then
1824 action 'Creating the stuff directory...'
1825 mkdir $WOK/$pkg/stuff; status
1826 fi
1828 # Ask for a description file.
1829 confirm "$(_n 'Are you going to write a description? (y/N)')"
1830 if [ "$?" -eq 0 ]; then
1831 action 'Creating the "%s" file...' 'description.txt'
1832 touch $WOK/$pkg/description.txt; status
1833 fi
1835 footer "$(_ 'Receipt is ready to use.')" ;;
1836 esac ;;
1838 list)
1839 # Cook a list of packages (better use the Cooker since it will order
1840 # packages before executing cook).
1841 check_root
1842 [ -z "$2" ] && die 'No list in argument.'
1843 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1845 _ 'Starting cooking the list "%s"' "$2" | log
1847 while read pkg; do
1848 cook $pkg || broken
1849 done < $2
1850 ;;
1852 clean-wok)
1853 check_root
1854 newline; action 'Cleaning all packages files...'
1855 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1856 status; newline ;;
1858 clean-src)
1859 check_root
1860 newline; action 'Cleaning all packages sources...'
1861 rm -rf $WOK/*/source
1862 status; newline ;;
1864 uncook)
1865 cd $WOK
1866 count=0
1867 title 'Checking for uncooked packages'
1869 for i in *; do
1870 unset HOST_ARCH EXTRAVERSION
1871 [ ! -e $i/receipt ] && continue
1872 . ./$i/receipt
1873 # Source cooked pkg receipt to get EXTRAVERSION
1874 if [ -d "$WOK/$i/taz" ]; then
1875 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1876 . ./receipt; cd $WOK
1877 fi
1878 case "$ARCH" in
1879 i486)
1880 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1881 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1882 count=$(($count + 1))
1883 colorize 34 "$i"
1884 fi ;;
1885 arm*)
1886 # Check only packages included in arch
1887 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1888 # *.tazpkg
1889 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1890 count=$(($count + 1))
1891 colorize 34 "$i"
1892 fi
1893 fi ;;
1894 esac
1895 done
1897 if [ "$count" -gt 0 ]; then
1898 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1899 else
1900 _ 'All packages are cooked :-)'
1901 newline
1902 fi
1903 ;;
1905 pkgdb)
1906 # Create suitable packages list for TazPkg and only for built packages
1907 # as well as flavors files for TazLiTo. We don't need logs since we do it
1908 # manually to ensure everything is fine before syncing the mirror.
1909 recreate_split_db
1910 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1911 ;;
1913 splitdb)
1914 # File split.db is useful for searching for split packages.
1915 recreate_split_db
1916 ;;
1918 *)
1919 # Just cook and generate a package.
1920 check_root
1921 time=$(date +%s)
1922 pkg="$1"
1923 [ -z "$pkg" ] && usage
1925 # Search last successful cook time in all logs from newer to older
1926 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1927 [ -f "$LOGS/$pkg.log$i" ] || break
1928 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1929 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1930 [ -n "$lastcooktime" ] && break
1931 done
1933 receipt="$WOK/$pkg/receipt"
1934 check_pkg_in_wok
1935 newline
1937 unset inst
1938 unset_receipt
1939 . $receipt
1941 # Handle cross compilation.
1942 case "$ARCH" in
1943 arm*)
1944 if [ -z "$HOST_ARCH" ]; then
1945 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1946 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1947 _ 'cook: %s' "$error"
1948 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1949 _ 'Cook skip: %s' "$error" | log
1950 newline
1951 broken; exit 1
1952 fi ;;
1953 esac
1955 # Some packages are not included in some arch or fail to cross compile.
1956 : ${HOST_ARCH=i486}
1957 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1958 # Handle arm{v6hf,v7,..}
1959 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1960 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1961 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1962 _ 'cook: %s' "error"
1963 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1964 _ 'Cook skip: %s' "$error" | log
1965 sed -i "/^${pkg}$/d" $broken
1966 newline
1967 exit 0
1968 fi
1970 # Skip blocked, 3 lines also for the Cooker.
1971 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1972 die 'Package "%s" is blocked' "$pkg"
1974 try_aufs_chroot "$@"
1976 # Log and source receipt.
1977 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1978 echo "cook:$pkg" > $command
1980 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1982 while read cmd duration start; do
1983 [ $(($start + $duration)) -lt $(date +%s) ] &&
1984 echo "sed -i '/^$cmd $duration/d' $cooktime"
1985 done < $cooktime | sh
1987 # Display and log info if cook process stopped.
1988 # FIXME: gettext not working (in single quotes) here!
1989 trap '_ "\n\nCook stopped: control-C\n\n" | \
1990 tee -a $LOGS/$pkg.log' INT
1992 update_split_db
1994 # Handle --options
1995 case "$2" in
1996 --install|-i)
1997 inst='yes' ;;
1999 --pack)
2000 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2001 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2002 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2003 sed -i '$ s|$| (packing)|' $activity
2004 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2005 clean_log "$pkg-pack"
2006 time=$(($(date +%s) - $time))
2007 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2008 put_status $pkg Done
2009 rm -f $command
2010 exit 0 ;;
2012 --trials|-t)
2013 trials='yes' ;;
2014 esac
2016 # Rotate log
2017 for i in $(seq 9 -1 1); do
2018 j=$(($i - 1))
2019 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2020 done
2021 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2023 # Check if wanted is built now so we have separate log files.
2024 for wanted in $WANTED ; do
2025 if grep -q "^$wanted$" $blocked; then
2026 broken
2027 rm -f $command
2028 die 'WANTED package "%s" is blocked' "$wanted"
2029 fi
2030 if grep -q "^$wanted$" $broken; then
2031 broken
2032 rm -f $command
2033 die 'WANTED package "%s" is broken' "$wanted"
2034 fi
2035 if [ ! -d "$WOK/$wanted/install" ]; then
2036 cook "$wanted" || { broken; exit 1; }
2037 fi
2038 done
2040 # Cook and pack or exit on error and log everything.
2041 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2042 rq=$? # the return code of `cookit $@` above command
2044 # Remove build dependencies both when `cookit` done or fail
2045 remove_deps | tee -a $LOGS/$pkg.log
2046 cookit_quality
2048 # Log and stop if `cookit` fails
2049 if [ $rq -eq 1 ]; then
2050 debug_info | tee -a $LOGS/$pkg.log
2051 put_status $pkg Failed
2052 rm -f $command
2053 broken; exit 1
2054 fi
2056 # Proceed only if `cookit` return code is zero-OK
2057 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2059 clean_log
2061 # Exit if any error in packing.
2062 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2063 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2064 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2065 debug_info | tee -a $LOGS/$pkg.log
2066 put_status $pkg Failed
2067 rm -f $command
2068 broken; exit 1
2069 fi
2071 # Create an XML feed
2072 gen_rss
2074 # Time and summary
2075 time=$(($(date +%s) - $time))
2076 summary | tee -a $LOGS/$pkg.log
2077 newline
2079 # We may want to install/update (outside aufs jail!).
2080 [ -s /aufs-umount.sh ] || install_package
2082 put_status $pkg Done
2084 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2085 # If you want automation, use the Cooker Build Bot.
2086 rm -f $command
2087 ;;
2088 esac
2090 exit 0