cookutils view cook @ rev 1129

cook: patchit(): allow external patches and patches checksum
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Jan 04 17:23:46 2019 +0200 (2019-01-04)
parents f77e48e58ac0
children b6def327b90a
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
14 prev_ts="/home/slitaz/cache/prev_ts"; touch $prev_ts
17 # Internationalization.
19 export TEXTDOMAIN='cook'
22 #
23 # Functions
24 #
26 usage() {
27 cat <<EOT
29 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
31 $(boldify "$(_ 'Commands:')")
32 usage|help $(_ 'Display this short usage.')
33 setup $(_ 'Setup your build environment.')
34 *-setup $(_ 'Setup a cross environment.')
35 * = {arm|armv6hf|armv7|x86_64}
36 test $(_ 'Test environment and cook a package.')
37 list-wok $(_ 'List packages in the wok.')
38 search $(_ 'Simple packages search function.')
39 new $(_ 'Create a new package with a receipt.')
40 list $(_ 'Cook a list of packages.')
41 clean-wok $(_ 'Clean-up all packages files.')
42 clean-src $(_ 'Clean-up all packages sources.')
43 uncook $(_ 'Check for uncooked packages')
44 pkgdb $(_ 'Create packages DB lists and flavors.')
46 $(boldify "$(_ 'Options:')")
47 cook <pkg>
48 --clean -c $(_ 'clean the package in the wok.')
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 # Find the package, return the receipt name where it was found
89 # for example, libpcreposix -> pcre
91 find_pkg_in_wok() {
92 awk -F$'\t' -vi=" $1 " '{
93 if (index(" " $2 " ", i)) {print $1; exit}
94 }' $cache/split.db
95 }
98 # Initialize files used in $CACHE
100 init_db_files() {
101 _ 'Creating directories structure in "%s"' "$SLITAZ"
102 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
103 _ 'Creating DB files in "%s"' "$CACHE"
104 touch $activity $command $broken $blocked $CACHE/webstat
105 chown www:www $cache/webstat
106 }
109 # Paths used in receipt and by cook itself.
111 set_paths() {
112 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
113 if [ -f "$WOK/linux/receipt" ]; then
114 kvers=$(. $WOK/linux/receipt; echo $VERSION)
115 kbasevers=$(echo $kvers | cut -d. -f1,2)
116 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
117 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
118 kbasevers=$(echo $kvers | cut -d. -f1,2)
119 fi
121 # Python version
122 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
123 # Perl version for some packages needed it
124 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
126 pkgdir="$WOK/$pkg"
127 . "$pkgdir/receipt"
128 basesrc="$pkgdir/source"
129 tmpsrc="$basesrc/tmp"
130 src="$basesrc/$PACKAGE-$VERSION"
131 taz="$pkgdir/taz"
132 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
133 fs="$pack/fs"
134 stuff="$pkgdir/stuff"
135 install="$pkgdir/install"
137 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
138 lzma_tarball="$pkgsrc.tar.lzma"
140 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
142 if [ -n "$WANTED" ]; then
143 basesrc="$WOK/$WANTED/source"
144 src="$basesrc/$WANTED-$VERSION"
145 install="$WOK/$WANTED/install"
146 wanted_stuff="$WOK/$WANTED/stuff"
147 fi
149 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
151 # Old way compatibility.
152 _pkg="$install"
153 }
156 # Create source tarball when URL is a SCM.
158 create_tarball() {
159 local tarball
160 tarball="$pkgsrc.tar.bz2"
161 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
162 _ 'Creating tarball "%s"' "$tarball"
163 if [ -n "$LZMA_SRC" ]; then
164 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
165 LZMA_SRC=''
166 else
167 tar -cjf $tarball $pkgsrc || exit 1
168 mv $tarball $SRC; rm -rf $pkgsrc
169 fi
170 TARBALL="$tarball"
171 }
174 # Get package source. For SCM we are in cache so clone here and create a
175 # tarball here.
177 get_source() {
178 local url
179 url=${WGET_URL#*|}
180 set_paths
181 pwd=$(pwd)
182 case "$WGET_URL" in
183 http://*|ftp://*|https://*)
184 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
185 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
186 wget -T 60 -c -O $SRC/$TARBALL $url ||
187 die 'ERROR: %s' "wget $WGET_URL"
188 ;;
190 hg*|mercurial*)
191 _ 'Getting source from %s...' 'Hg'
192 _ 'URL: %s' "$url"
193 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
194 if [ -n "$BRANCH" ]; then
195 _ 'Hg branch: %s' "$BRANCH"
196 hg clone $url --rev $BRANCH $pkgsrc ||
197 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
198 else
199 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
200 fi
201 rm -rf $pkgsrc/.hg
202 create_tarball
203 ;;
205 git*)
206 _ 'Getting source from %s...' 'Git'
207 _ 'URL: %s' "$url"
208 cd $SRC
209 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
210 if [ -n "$BRANCH" ]; then
211 _ 'Git branch: %s' "$BRANCH"
212 cd $pkgsrc; git checkout $BRANCH; cd ..
213 fi
214 cd $SRC
215 create_tarball
216 ;;
218 cvs*)
219 mod=$PACKAGE
220 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
221 _ 'Getting source from %s...' 'CVS'
222 _ 'URL: %s' "$url"
223 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
224 _ 'Cloning to "%s"' "$pwd/$mod"
225 cvs -d:$url co $mod && mv $mod $pkgsrc
226 create_tarball
227 ;;
229 svn*|subversion*)
230 _ 'Getting source from %s...' 'SVN'
231 _ 'URL: %s' "$url"
232 if [ -n "$BRANCH" ]; then
233 echo t | svn co $url -r $BRANCH $pkgsrc
234 else
235 echo t | svn co $url $pkgsrc
236 fi
237 create_tarball
238 ;;
240 bzr*)
241 _ 'Getting source from %s...' 'bazaar'
242 cd $SRC
243 pkgsrc=${url#*:}
244 if [ -n "$BRANCH" ]; then
245 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
246 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
247 else
248 echo "bzr -Ossl.cert_reqs=none branch $url"
249 bzr -Ossl.cert_reqs=none branch $url
250 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
251 _ "Don't forget to add to receipt:"
252 echo -e "BRANCH=\"$BRANCH\"\n"
253 fi
254 mv $pkgsrc $pkgsrc-$BRANCH
255 pkgsrc="$pkgsrc-$BRANCH"
256 create_tarball
257 ;;
259 *)
260 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
261 ;;
262 esac
263 }
266 # Extract source package.
268 extract_source() {
269 if [ ! -s "$SRC/$TARBALL" ]; then
270 local url
271 url="$MIRROR_URL/sources/packages"
272 url="$url/${TARBALL:0:1}/$TARBALL"
273 _ 'Getting source from %s...' 'mirror'
274 _ 'URL: %s' "$url"
275 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
276 fi
277 _ 'Extracting source archive "%s"' "$TARBALL"
278 case "$TARBALL" in
279 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
280 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
281 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
282 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
283 *.tar) tar -xf $SRC/$TARBALL ;;
284 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
285 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
286 tar -xf $SRC/$TARBALL 2>/dev/null;;
287 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
288 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
289 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
290 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
291 *) cp $SRC/$TARBALL $(pwd) ;;
292 esac
293 }
296 # Display time.
298 disp_time_old() {
299 local sec div min
300 sec="$1"
301 div=$(( ($1 + 30) / 60))
302 case $div in
303 0) min='';;
304 # L10n: 'm' is for minutes (approximate cooking time)
305 *) min=$(_n ' ~ %dm' "$div");;
306 esac
308 # L10n: 's' is for seconds (cooking time)
309 _ '%ds%s' "$sec" "$min"
310 }
313 # Display time.
315 disp_time() {
316 local sec="$1" day hour min out=''
318 day=$(( sec / 86400 )); sec=$(( sec % 86400 ))
319 hour=$(( sec / 3600 )); sec=$(( sec % 3600 ))
320 min=$(( sec / 60 )); sec=$(( sec % 60 ))
322 [ $day -gt 0 ] && out="${day}d "
323 [ -n "$out" -o $hour -gt 0 ] && out="$out$(printf '%02dh ' $hour)"
324 [ -n "$out" -o $min -gt 0 ] && out="$out$(printf '%02dm ' $min)"
325 [ -n "$out" ] && out=" ~ $out$(printf '%02ds' $sec)"
327 echo "${1}s$out"
328 }
331 # Display cooked package summary.
333 summary() {
334 # local arch=''
335 # case "$ARCH" in
336 # arm*|x86_64) arch="-$ARCH" ;;
337 # esac
339 set_paths
340 cd $WOK/$pkg
341 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
342 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
343 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
345 title 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION"
347 # L10n: keep the same width of translations to get a consistent view
348 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
349 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
350 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
351 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
352 _ 'Cook time : %s' "$(disp_time "$time")"
353 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
354 _ 'Target arch : %s' "$(cut -d$'\t' -f2 $pkgdir/.arch | sort -u | tr '\n' ' ' | sed 's| $||; s| |, |g')"
356 separator -
357 _ ' # : Packed : Compressed : Files : Package name'
358 separator -
359 pkgi=1
360 for i in $(all_names); do
361 version=$(awk -F$'\t' -vpkg="$i" '{
362 if ($1 == pkg) {print $2; exit}
363 }' "$PKGS/packages-$ARCH.info")
364 [ -n "$version" ] || continue
365 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
366 arch=$(awk -F$'\t' -vi="$i" '{if ($1 == i) print $2}' $pkgdir/.arch)
367 pkgname="$i-$version-$arch.tazpkg"
368 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
369 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
370 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
371 pkgi=$((pkgi + 1))
372 done
373 separator
374 }
377 # Display debugging error info.
379 debug_info() {
380 title 'Debug information %s.' "$1"
381 # L10n: specify your format of date and time (to help: man date)
382 # L10n: not bad one is '+%x %R'
383 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
384 if [ -n "$time" ]; then
385 times="$(($(date +%s) - $time))"
386 _ 'Wasted time : %s' "$(disp_time "$times")"
387 fi
388 for error in \
389 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
390 'error:' 'fatal error:' 'undefined reference to' \
391 'Unable to connect to' 'link: cannot find the library' \
392 'CMake Error' ': No such file or directory' \
393 'Could not read symbols: File in wrong format'
394 do
395 # format "line number:line content"
396 fgrep -n "$error" $LOGS/$pkg.log
397 done > $LOGS/$pkg.log.debug_info 2>&1
398 # sort by line number, remove duplicates
399 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
400 rm -f $LOGS/$pkg.log.debug_info
401 footer
402 }
405 # A bit smarter function than the classic `cp` command
407 scopy() {
408 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
409 cp -a "$1" "$2" # copy generic files
410 else
411 cp -al "$1" "$2" # copy hardlinks
412 fi
413 }
416 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
417 # We use standard paths, so some packages need to copy these files with the
418 # receipt and genpkg_rules.
419 # This function executes inside the packaging process, before compressor call.
421 copy_generic_files() {
422 # Proceed only for "main" package (for v2), and for any packages (v1)
423 [ "$pkg" == "$PACKAGE" ] || return 0
425 # $LOCALE is set in cook.conf
426 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
427 if [ -d "$install/usr/share/locale" ]; then
428 mkdir -p "$fs/usr/share/locale"
429 for i in $LOCALE; do
430 if [ -d "$install/usr/share/locale/$i" ]; then
431 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
432 fi
433 done
434 fi
435 fi
437 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
438 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
439 if [ -d "$install/usr/share/pixmaps" ]; then
440 mkdir -p "$fs/usr/share/pixmaps"
441 for i in png xpm; do
442 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
443 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
444 done
445 fi
446 fi
448 # Desktop entry (.desktop).
449 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
450 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
451 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
452 mkdir -p "$fs/usr/share"
453 cp -r $install/usr/share/applications $fs/usr/share
454 fi
455 fi
456 }
459 # Copy pixmaps, desktop files and licenses from $stuff to $install.
460 # This function executes after the main compile_rules() is done.
462 copy_generic_stuff() {
463 # Custom or homemade PNG pixmap can be in stuff.
464 if [ -f "$stuff/$PACKAGE.png" ]; then
465 mkdir -p $install/usr/share/pixmaps
466 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
467 fi
469 # Homemade desktop file(s) can be in stuff.
470 if [ -d "$stuff/applications" ]; then
471 mkdir -p $install/usr/share
472 cp -r $stuff/applications $install/usr/share
473 fi
474 if [ -f "$stuff/$PACKAGE.desktop" ]; then
475 mkdir -p $install/usr/share/applications
476 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
477 fi
479 # Add custom licenses
480 if [ -d "$stuff/licenses" ]; then
481 mkdir -p $install/usr/share/licenses
482 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
483 fi
484 }
487 # Update installed.cook.diff
489 update_installed_cook_diff() {
490 # If a cook failed deps are removed.
491 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
492 cd $CACHE
493 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
494 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
495 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
496 }
499 # Remove installed deps.
501 remove_deps() {
502 # Now remove installed build deps.
503 diff='/tmp/installed.cook.diff'
504 [ -s "$diff" ] || return
506 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
507 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
508 newline
509 _n 'Build dependencies to remove:'; echo " $nb"
510 [ -n "$root" ] && echo "root=\"$root\""
512 _n 'Removing:'
513 for dep in $deps; do
514 echo -n " $dep"
515 # Do not waste time uninstalling the packages if we are inside
516 # aufs chroot - unmounting chroot will "uninstall" all packages.
517 [ -s /aufs-umount.sh ] ||
518 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
519 done
521 newline; newline
522 # Keep the last diff for debug and info.
523 mv -f $diff $CACHE/installed.diff
524 }
527 # Automatically patch the sources.
529 patchit() {
530 [ -f "$stuff/patches/series" ] || return
531 # Empty lines and comments (started with "#") are ignored
532 # Up to three fields (no spaces inside allowed) separated by "|":
533 # 1. patch options like "-p0" (optional);
534 # 2. patch file name or URL (mandatory);
535 # 3. patch checksum in form "sha1=..." or other *sum (optional).
537 local done="$pkgdir/.patch.done" var1 var2 var3
538 local patchname patchopts patchfile patchsum patchsum_type patchsum_sum
539 IFS=$'\n'
540 while read i; do
541 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
542 [ -n "$patchname" ] || continue # skip empty lines
544 var1=$(echo "$patchname||" | cut -d'|' -f1) # options or name
545 var2=$(echo "$patchname||" | cut -d'|' -f2) # name or checksum or empty
546 var3=$(echo "$patchname||" | cut -d'|' -f3) # checksum or empty
548 if [ -n "$var3" ]; then
549 patchopts="$var1"; patchname="$var2"; patchsum="$var3"
550 elif [ -n "$var2" ]; then
551 case $var2 in
552 *=*) patchopts='-Np1'; patchname="$var1"; patchsum="$var2";;
553 *) patchopts="$var1"; patchname="$var2"; patchsum='';;
554 esac
555 else
556 patchopts='-Np1'; patchname="$var1"; patchsum=''
557 fi
559 case $patchname in
560 ftp://*|http://*|https://*)
561 patchfile="$SRC/$(basename $patchname)"
562 [ -e "$patchfile" ] || wget -q -T 60 -O $patchfile $patchname ||
563 die 'ERROR: %s' "can't get $patchname"
564 ;;
565 *)
566 patchfile="$stuff/patches/$patchname"
567 ;;
568 esac
570 if [ -n "$patchsum" ]; then
571 patchsum_type=${patchsum%=*}
572 patchsum_sum=${patchsum#*=}
573 echo "$patchsum_sum $patchfile" | ${patchsum_type}sum -cs ||
574 die 'ERROR: %s' "wrong ${patchsum_type}sum for $patchfile"
575 fi
577 touch $done
578 grep -q "^${patchname}$" $done && continue # already applied (useful with `cook --continue`)
580 newline
581 _ 'Applying patch %s' "$patchname"
582 patch $patchopts -i $patchfile | sed 's|^| |'
584 echo $patchname >> $done
585 done < $stuff/patches/series
586 newline
587 unset IFS
588 }
591 # Check source tarball integrity.
593 check_integrity() {
594 for i in sha1 sha3 sha256 sha512 md5; do
595 I=$(echo $i | tr 'a-z' 'A-Z')
596 eval sum=\$TARBALL_$I
597 if [ -n "$sum" ]; then
598 newline
599 _ 'Checking %ssum of source tarball...' "$i"
600 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
601 fi
602 done
603 newline
604 }
607 # Misc fix functions
609 fix() {
610 case $1 in
611 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
612 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
613 ld)
614 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
615 ;;
616 libtool)
617 if [ -e 'libtool' ]; then
618 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
619 echo "fix.libtool" >> $pkgdir/.patch.done
620 else
621 echo "fix libtool: warning: libtool absent, nothing to fix."
622 fi
623 ;;
624 math)
625 # fix C++ math issue introduced in Glibc 2.26:
626 # error: '__builtin_isnan' is not a member of 'std'
627 # if (std::isnan(N)) {
628 # ^
629 find $src -type f -exec sed -i '
630 s|std::signbit|__builtin_signbit|g;
631 s|std::isnan|__builtin_isnan|g;
632 s|std::isinf|__builtin_isinf_sign|g;
633 s|std::isfinite|__builtin_isfinite|g;
634 s|std::isnormal|__builtin_isnormal|g
635 ' '{}' \;
636 ;;
637 symlinks)
638 # make absolute symlinks relative
639 echo "fix symlinks"
640 local ifs="$IFS" link target
641 IFS=$'\n'
642 # step 1: fast job, prefix all the absolute symlinks with "$install"
643 for link in $(find $install -type l); do
644 target="$(readlink $link)"
645 case "$target" in
646 /*) ln -sfv "$install$target" "$link";;
647 esac
648 done
649 IFS="$ifs"
650 # step 2: fine tuning, make symlinks relative
651 tazpkg -gi --quiet --local --cookmode symlinks
652 symlinks -cr $install
653 ;;
654 gem)
655 # some useful operations while Ruby gems cooking
656 _gems="$(ruby -e'puts Gem.default_dir')"
658 # remove unwanted empty folders
659 rmdir --ignore-fail-on-non-empty \
660 $install/$_gems/build_info/ \
661 $install/$_gems/cache/ \
662 $install/$_gems/doc/ \
663 $install/$_gems/extensions/
665 # move files to docdir
666 docdir=$install/usr/share/doc/$PACKAGE-$VERSION
667 for i in $(ls -ap $install/$_gems/gems/${PACKAGE#*-}-$VERSION/ | sed '
668 /\/$/d; /^\./d; /gemspec$/d; /Rakefile*/d; /Gemfile*/d; /Makefile/d;
669 /\.c$/d; /\.h$/d; /\.o$/d; /\.rb$/d; /\.so$/d; /\.yml$/d;
670 /Manifest/d; /\.inc$/d; /depend/d;
671 '); do
672 mkdir -p $docdir # docdir will not be created when nothing to move
673 mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/$i $docdir
674 done
675 if [ -d $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ ]; then
676 mkdir -p $docdir
677 mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ $docdir
678 fi
680 if [ -d $docdir ]; then
681 # move man pages
682 unset man_to_copy
683 for i in $(seq 1 8); do
684 for j in $(find $docdir -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
685 man_to_copy="$man_to_copy $j"
686 done
687 done
688 if [ -n "$man_to_copy" ]; then
689 cook_pick_manpages $man_to_copy
690 rm $man_to_copy
691 fi
693 # convert rdoc to markdown (thanks https://gist.github.com/teeparham/8a99e308884e1c32735a)
694 for i in $(find $docdir -type f -name '*.rdoc'); do
695 fix utf-8
696 LC_ALL=en_US.UTF-8 ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert File.read(ARGV[0] || "'$i'")' >$i.md && rm $i || rm $i.md
697 done
698 fi
700 # move man pages (from the different place)
701 rubyman=$install/$_gems/gems/${PACKAGE#*-}-$VERSION/man
702 if [ -d $rubyman ]; then
703 unset man_to_copy
704 for i in $(seq 1 8); do
705 for j in $(find $rubyman -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
706 man_to_copy="$man_to_copy $j"
707 done
708 done
709 if [ -n "$man_to_copy" ]; then
710 cook_pick_manpages $man_to_copy
711 fi
712 rm -r $rubyman
713 fi
714 ;;
715 utf-8)
716 # Install UTF-8 locale
717 tazpkg -gi --quiet --local --cookmode locale-en-base
718 mkdir -p /usr/lib/locale
719 localedef -i 'en_US' -c -f 'UTF-8' /usr/lib/locale/en_US.UTF-8
720 ;;
721 esac
722 }
725 # Typical function used in compile_rules() to make perl modules packages
727 cook_perl() {
728 if [ -e "Makefile.PL" ]; then
729 # Up to 3 optional parameters supported
730 PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor $1 &&
731 make $2 &&
732 make $3 PERL_MM_USE_DEFAULT=1 DESTDIR=$install install &&
733 chmod -R u+w $install
734 elif [ -e "Build.PL" ]; then
735 echo "Not implemented yet"
736 return 1
737 else
738 echo "Unable to cook Perl module"
739 return 1
740 fi
741 }
744 # Store timestamps, log jobs length
746 timestamp() {
747 local ts_file="$WOK/$pkg/.ts"
748 local curr_ts=$(date '+%s')
749 case $1 in
750 init)
751 rm $ts_file 2>/dev/null
752 echo $curr_ts > $prev_ts
753 ;;
754 job*)
755 # calculate time from the last timestamp
756 echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
757 echo $curr_ts > $prev_ts
758 ;;
759 sets)
760 echo "sets='$2'" >> $ts_file
761 ;;
762 esac
763 }
766 # Store time statsistics to the cache
768 store_timestats() {
769 # see doc/timestats.txt for file format
770 temp=$(mktemp)
771 {
772 for i in $(seq 1 30); do echo "job$i=0"; done
773 cat $WOK/$pkg/.ts
774 echo -n 'total=$(( 0'
775 for i in $(seq 1 30); do echo -n " + job$i"; done
776 echo ' ))'
777 } > $temp
778 . $temp
779 {
780 echo -n "$pkg $sets "
781 for i in $(seq 1 30); do echo -n "$((job$i)) "; done
782 echo "$total"
783 } >> /home/slitaz/cache/timestats
784 rm $temp $WOK/$pkg/.ts # clean
785 }
788 # Internal function to cook specified SET
790 cook_set() {
791 # Switch to the specified source set
792 set_paths
793 local suffix=''
794 [ -n "$SET" ] && suffix="-$SET"
795 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
796 export install="$WOK/$pkg/install$suffix"
797 export DESTDIR="$install"
799 if [ -n "$SETS" ]; then
800 if [ -n "$SET" ]; then
801 title "Switching to the set '$SET'"
802 else
803 title "Switching to the default set"
804 fi
805 echo "src : $src"
806 echo "install: $install"
807 fi
808 [ -d "$src" ] && cd $src # packages without sources exists
809 echo
811 [ -d "$install" ] && rm -r $install
812 #mkdir -p $install
814 compile_rules $@ || { broken; exit 1; }
816 # Stay compatible with _pkg
817 [ -d "$src/_pkg" ] && mv $src/_pkg $install
819 copy_generic_stuff
821 timestamp job$job_counter # compiling (set '$SET')
823 # Actions to do after compiling the package
824 # Skip all for split packages (already done in main package)
825 if [ -z "$WANTED" ]; then
826 footer
827 export COOKOPTS ARCH install
828 @@PREFIX@@/libexec/cookutils/compressor install
829 timestamp job$(($job_counter + 1)) # compressing (set '$SET')
830 fi
832 # Activate "instant-pack" mode
833 if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
834 echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
835 export PACKAGE
836 # determine the list of the packages belongs to the current SET...
837 echo -n $SPLIT \
838 | awk -vset="$SET" '
839 BEGIN { RS = " "; FS = ":"; }
840 { if ($2 == set) print $1; }' \
841 | xargs -n1 @@PREFIX@@/libexec/cookutils/pack # ... and then pack them
842 fi
844 job_counter=$(($job_counter + 2))
845 }
848 # The main cook function.
850 cookit() {
851 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
852 _ 'ERROR: Broken setup. Abort.'
853 return
854 fi
856 title 'Cook: %s' "$PACKAGE $VERSION"
857 set_paths
858 timestamp init # the very start
860 # Handle cross-tools.
861 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
862 case "$ARCH" in
863 arm*|x86_64)
864 # CROSS_COMPILE is used by at least Busybox and the kernel to set
865 # the cross-tools prefix. Sysroot is the root of our target arch
866 sysroot="$CROSS_TREE/sysroot"
867 tools="$CROSS_TREE/tools"
868 # Set root path when cross compiling. ARM tested but not x86_64
869 # When cross compiling we must install build deps in $sysroot.
870 arch="-$ARCH"
871 root="$sysroot"
872 _ '%s sysroot: %s' "$ARCH" "$sysroot"
873 _ 'Adding "%s" to PATH' "$tools/bin"
874 export PATH="$PATH:$tools/bin"
875 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
876 export CROSS_COMPILE="$HOST_SYSTEM-"
877 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
878 if [ "$ARCH" == 'x86_64' ]; then
879 export CC="$HOST_SYSTEM-gcc -m64"
880 export CXX="$HOST_SYSTEM-g++ -m64"
881 else
882 export CC="$HOST_SYSTEM-gcc"
883 export CXX="$HOST_SYSTEM-g++"
884 fi
885 export AR="$HOST_SYSTEM-ar"
886 export AS="$HOST_SYSTEM-as"
887 export RANLIB="$HOST_SYSTEM-ranlib"
888 export LD="$HOST_SYSTEM-ld"
889 export STRIP="$HOST_SYSTEM-strip"
890 export LIBTOOL="$HOST_SYSTEM-libtool"
891 ;;
892 esac
894 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
896 cd $pkgdir
897 if [ -z "$continue" ]; then
898 rm -rf source 2>/dev/null
899 rm .patch.done 2>/dev/null
900 fi
901 rm -rf install taz 2>/dev/null
903 # Disable -pipe if less than 512 MB free RAM.
904 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
905 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
906 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
907 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
908 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
909 fi
910 unset free
912 # Export flags and path to be used by make and receipt.
913 DESTDIR="$pkgdir/install"
914 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
915 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
916 LDFLAGS
918 timestamp job1 # pre-checks
920 # BUILD_DEPENDS may vary depending on the ARCH
921 case "$ARCH" in
922 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
923 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
924 esac
926 # Check for build deps and handle implicit depends of *-dev packages
927 # (ex: libusb-dev :: libusb).
928 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
929 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
931 # Get the list of installed packages
932 cd $root$INSTALLED; ls > $CACHE/installed.list
934 for action in check install; do
935 for dep in $BUILD_DEPENDS; do
936 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
937 for i in $dep $implicit; do
938 # Skip if package already installed
939 [ -f "$root$INSTALLED/$i/receipt" ] && continue
941 case $action in
942 check)
943 # Search for local package or local provided-package
944 name=$(awk -F$'\t' -vpkg="$i" '{
945 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
946 }' "$PKGS/packages-$ARCH.info")
947 if [ -z "$name" ]; then
948 # Search for package in mirror
949 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
950 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
951 fi
952 ;;
953 install)
954 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
955 ;;
956 esac
957 done
958 done
959 done
961 update_installed_cook_diff
963 timestamp job2 # installing bdeps
965 # Get source tarball and make sure we have source dir named:
966 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
967 # tarball if it exists.
968 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
969 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
970 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
971 LZMA_SRC=''
972 else
973 get_source || { broken; exit 1; }
974 fi
975 fi
976 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
977 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
978 if ! extract_source ; then
979 get_source
980 extract_source || { broken; exit 1; }
981 fi
982 if [ -n "$LZMA_SRC" ]; then
983 cd $pkgdir/source
984 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
985 mv tmp tmp-1; mkdir tmp
986 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
987 fi
988 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
989 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
990 fi
991 fi
993 cd $pkgdir/source/tmp
994 # Some archives are not well done and don't extract to one dir (ex lzma).
995 files=$(ls | wc -l)
996 [ "$files" -eq 1 -a -d "$(ls)" ] &&
997 mv * ../$PACKAGE-$VERSION
998 [ "$files" -eq 1 -a -f "$(ls)" ] &&
999 mkdir -p ../$PACKAGE-$VERSION &&
1000 mv * ../$PACKAGE-$VERSION/$TARBALL
1001 [ "$files" -gt 1 ] &&
1002 mkdir -p ../$PACKAGE-$VERSION &&
1003 mv * ../$PACKAGE-$VERSION
1004 cd ..; rm -rf tmp
1005 fi
1007 # Check md5sum (or similar) for sources tarball
1008 check_integrity
1010 # Libtool shared libs path hack.
1011 case "$ARCH" in
1012 arm*) cross libhack ;;
1013 esac
1015 timestamp job3 # get/unpack src tarball
1017 # Compiling all the sets
1018 if grep -q ^compile_rules $receipt; then
1019 _ 'Executing: %s' 'compile_rules'
1020 echo "CFLAGS : $CFLAGS"
1021 echo "CXXLAGS : $CXXFLAGS"
1022 echo "CPPFLAGS : $CPPFLAGS"
1023 echo "LDFLAGS : $LDFLAGS"
1024 [ -d "$src" ] && cd $src
1025 patchit
1027 timestamp job4 # patching
1029 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
1030 # Keep natural order of the sets, don't sort them alphabetically
1031 SETS=$(echo -n $SPLIT \
1032 | awk '
1033 BEGIN { RS = " "; FS = ":"; }
1035 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
1036 }' \
1037 | sed 's| $||')
1038 # Prepare specified source sets using patched sources
1039 [ -n "$SETS" -a -d "$src" ] &&
1040 for set in $SETS; do
1041 echo "Preparing set $set" # debug
1042 cp -a $src $src-$set
1043 done
1045 timestamp job5 # preparing sets
1046 timestamp sets "$SETS"
1048 job_counter='6'
1050 SET='' cook_set # first run for empty SET
1052 # Allow to change SETS after the first run, follow the changes
1053 SETS=$(. $receipt; echo -n $SPLIT \
1054 | awk '
1055 BEGIN { RS = " "; FS = ":"; }
1057 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
1058 }' \
1059 | sed 's| $||')
1060 for SET in $SETS; do
1061 cook_set
1062 done
1063 else
1064 mkdir -p $install # allow receipts without `compile_rules()`
1065 fi
1066 footer
1068 timestamp job # reset counter
1070 # Execute testsuite.
1071 if grep -q ^testsuite $receipt; then
1072 title 'Running testsuite'
1073 testsuite $@ || { broken; exit 1; }
1074 footer
1075 fi
1077 timestamp job26 # test suite
1079 update_installed_cook_diff force
1083 # Cook quality assurance.
1085 cookit_quality() {
1086 while true; do
1087 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
1088 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
1089 [ "$trials" == 'yes' ] || break
1090 title "Interactive mode"
1091 # TODO: allow commands:
1092 # q - quit; v - edit receipt here using vi;
1093 # s - search for package containing package;
1094 # <package name> - install package; [Enter] - retry
1095 _ 'You may install the packages here and/or edit the receipt there.'
1096 newline
1097 while true; do
1098 _n 'Install the package? [name/N] '; read answer
1099 [ -n "$answer" ] || break
1100 tazpkg -gi $answer --root=$root --local --quiet --cookmode
1101 done
1102 newline
1103 _n 'Try again? [Y/n] '; read answer
1104 [ "$answer" == 'n' ] && break
1105 # here you may append log if you want (">>" instead of last ">")
1106 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1107 done
1109 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
1111 # ERROR can be echoed any time in cookit()
1112 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
1113 grep -Eq "(^ERROR|undefined reference to)" ; then
1114 debug_info "cookit_quality" | tee -a $LOGS/$pkg.log
1115 put_status $pkg Failed
1116 # rm -f $command
1117 # broken; exit 1
1118 fi
1122 # Return all the names of packages bundled in this receipt
1124 all_names() {
1125 # Get package names from $SPLIT variable
1126 local split=$(echo -n $SPLIT \
1127 | awk '
1128 BEGIN { RS = " "; FS = ":"; }
1129 { print $1; }' \
1130 | tr '\n' ' ')
1131 local split_space=" $split "
1132 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1133 # For receipts v1: $SPLIT may present in the $WANTED package,
1134 # but split packages have their own receipts
1135 echo $PACKAGE
1136 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1137 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1138 # We should build packages in the order defined in the $SPLIT.
1139 echo $split
1140 else
1141 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1142 echo $PACKAGE $split
1143 fi
1147 # v2: pack all packages using compiled files
1149 packall() {
1150 set_paths
1151 [ -e $pkgdir/.arch ] && rm $pkgdir/.arch
1153 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1154 for i in $(all_names); do
1155 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1156 export PACKAGE; @@PREFIX@@/libexec/cookutils/pack $i
1157 done
1158 else
1159 export PACKAGE; @@PREFIX@@/libexec/cookutils/pack $PACKAGE
1160 fi
1164 # Reverse "cat" command: prints input lines in the reverse order
1166 tac() {
1167 sed '1!G;h;$!d' $1
1171 # Install package: update the chroot with freshly rebuilt package: keep env up-to-date.
1173 install_package() {
1174 set_paths
1175 case "$ARCH" in
1176 arm*) root="$CROSS_TREE/sysroot";;
1177 esac
1179 # Process all the package names built by this receipt (defined in $SPLIT)
1180 for i in $(PACKAGE="$pkg" all_names); do
1181 if [ -d "$root$INSTALLED/$i" ]; then
1182 pkg_file=$(awk -F$'\t' -vpkg="$i" -varch="$ARCH" '{
1183 if ($1 == pkg) {
1184 pkgarch = ($11 == "0") ? "any" : arch;
1185 printf("%s-%s-%s.tazpkg", $1, $2, pkgarch);
1186 exit
1188 }' $PKGS/packages-$ARCH.info)
1189 if [ -e "$PKGS/$pkg_file" ]; then
1190 _ 'Updating %s chroot environment...' "$ARCH"
1191 _ 'Updating chroot: %s' "${pkg_file%.tazpkg}" | log
1192 tazpkg -i "$PKGS/$pkg_file" --forced --root=$root
1193 fi
1194 fi
1195 done
1199 # remove chroot jail
1201 umount_aufs() {
1202 tac ${1}rw/aufs-umount.sh | sh
1203 rm -rf ${1}rw
1204 umount ${1}root
1205 rmdir ${1}r*
1209 # Launch the cook command into a chroot jail protected by aufs.
1210 # The current filesystems are used read-only and updates are
1211 # stored in a separate branch.
1213 try_aufs_chroot() {
1215 base="/dev/shm/aufsmnt$$"
1217 # Can we setup the chroot? Is it already done?
1218 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1219 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1220 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1221 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1222 mkdir ${base}root ${base}rw || return
1224 _ 'Setup aufs chroot...'
1226 # Sanity check
1227 for i in / /proc /sys /dev /dev/shm /home; do
1228 case " $AUFS_MOUNTS " in
1229 *\ $i\ *) ;;
1230 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1231 esac
1232 done
1233 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1234 mkdir -p ${base}root$mnt # for `mount -o bind`
1235 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1236 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1237 _ 'Aufs mount failure'
1238 umount ${base}root
1239 rm -rf ${base}r*
1240 return
1241 fi
1242 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1243 done
1244 trap "umount_aufs ${base}" INT
1246 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1247 status=$?
1249 _ 'Leaving aufs chroot...'
1250 umount_aufs $base
1251 # Install package outside the aufs jail
1252 install_package
1253 exit $status
1257 # Encode predefined XML entities
1259 xml_ent() {
1260 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1264 # Create a XML feed for freshly built packages.
1266 gen_rss() {
1267 if [ -e "$WOK/$PACKAGE/.icon.png" ]; then
1268 icon="$COOKER_URL$PACKAGE/browse/.icon.png"
1269 else
1270 icon="http://cook.slitaz.org/tazpkg.png"
1271 fi
1273 cat > $FEEDS/$pkg.xml <<EOT
1274 <item>
1275 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1276 <link>$COOKER_URL${PACKAGE//+/%2B}</link>
1277 <guid isPermaLink="false">$PACKAGE-$VERSION$EXTRAVERSION</guid>
1278 <pubDate>$(date '+%a, %d %b %Y %X GMT')</pubDate>
1279 <description><![CDATA[
1280 <table>
1281 <tr>
1282 <td vertical-align="top"><img src="$icon" alt=""/></td>
1283 <td>$(echo -n "$SHORT_DESC" | xml_ent)</td>
1284 </tr>
1285 </table>
1286 ]]></description>
1287 </item>
1288 EOT
1292 # Truncate stdout log file to $1 Mb.
1294 loglimit() {
1295 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1296 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1297 else
1298 tee /dev/stderr
1299 fi
1304 # Receipt functions to ease packaging
1307 get_dev_files() {
1308 action 'Getting standard devel files...'
1309 mkdir -p $fs/usr/lib
1310 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1311 cp -a $install/usr/lib/*a $fs/usr/lib
1312 cp -a $install/usr/include $fs/usr
1313 status
1317 # Function to use in compile_rules() to copy man page from $src to $install
1319 cook_pick_manpages() {
1320 local name section
1321 action 'Copying man pages...'
1323 for i in $@; do
1324 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1325 section=${name##*/}; section=${section##*.}
1326 mkdir -p $install/usr/share/man/man$section
1327 scopy $i $install/usr/share/man/man$section
1328 done
1329 status
1333 # Function to use in compile_rules() to copy documentation from $src to $install
1335 cook_pick_docs() {
1336 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1337 action 'Copying documentation...'
1338 mkdir -p $docdir
1339 cp -r $@ $docdir
1340 chmod -R a+r $docdir
1341 status
1345 # Update split.db once for receipt
1347 update_split_db() {
1348 local db="$cache/split.db"
1349 touch $db
1350 sed -i "/^$pkg\t/d" $db
1351 echo -e "$pkg\t$(all_names)" >> $db
1355 # Recreate whole split.db from scratch
1357 recreate_split_db() {
1358 # Clean
1359 local db="$cache/split.db"
1361 cd $WOK
1362 for pkg in *; do
1363 [ -f "$WOK/$pkg/receipt" ] || continue
1364 unset PACKAGE SPLIT
1365 . $WOK/$pkg/receipt
1366 echo -e "$PACKAGE\t$(all_names)"
1367 done > $db
1371 # Recreate whole maint.db from scratch
1373 recreate_maint_db() {
1374 # Clean
1375 local db="$cache/maint.db"
1377 cd $WOK
1378 for pkg in *; do
1379 [ -f "$WOK/$pkg/receipt" ] || continue
1380 unset PACKAGE MAINTAINER
1381 . $WOK/$pkg/receipt
1382 MAINTAINER=$(echo $MAINTAINER | sed 's|.*<||; s|>.*||')
1383 echo -e "$MAINTAINER\t$PACKAGE"
1384 done | sort > $db
1388 # Put the status to the activity log
1390 put_status() {
1391 # $1: package, $2: status, one of 'Done', 'Failed'
1392 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1393 if [ "$2" == 'Done' ]; then
1394 # overstrike all previous 'Failed' to indicate package is OK now
1395 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1396 fi
1403 # Commands
1406 # cook <package> --deps
1407 [ -n "$deps" ] && {
1408 @@PREFIX@@/libexec/cookutils/deps $1
1409 exit 0
1412 # cook <package> --clean
1413 # cook <package> -c
1414 [ -n "$clean" -o "$2" == '-c' ] && {
1415 action 'Cleaning "%s"' "$1"
1416 cd $WOK/$1; rm -rf install taz source
1417 status; newline
1418 touch $activity # update $activity -> something changed -> update webstat
1419 exit 0
1422 # cook <package> --getsrc
1423 # cook <package> -gs
1424 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1425 pkg="$1"
1426 title 'Getting source for "%s"' "$pkg"
1427 receipt="$WOK/$pkg/receipt"
1428 check_pkg_in_wok
1429 unset_receipt
1430 . $receipt
1431 get_source
1432 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1433 exit 0
1436 # cook <package> --block
1437 # cook <package> -b
1438 [ -n "$block" -o "$2" == '-b' ] && {
1439 action 'Blocking package "%s"' "$1"
1440 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1441 status; newline
1442 touch $activity
1443 exit 0
1446 # cook <package> --unblock
1447 # cook <package> -ub
1448 [ -n "$unblock" -o "$2" == '-ub' ] && {
1449 action 'Unblocking package "%s"' "$1"
1450 sed -i "/^$1$/d" $blocked
1451 status; newline
1452 touch $activity
1453 exit 0
1459 case "$1" in
1460 usage|help|-u|-h)
1461 usage ;;
1463 list-wok)
1464 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1465 cd $WOK
1466 if [ "$ARCH" != 'i486' ]; then
1467 count=0
1468 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1469 do
1470 unset HOST_ARCH
1471 . ./$pkg
1472 count=$(($count + 1))
1473 colorize 34 "$PACKAGE"
1474 done
1475 else
1476 count=$(ls | wc -l)
1477 ls -1
1478 fi
1479 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1480 ;;
1482 activity)
1483 cat $activity ;;
1485 search)
1486 # Just a simple search function, we don't need more actually.
1487 query="$2"
1488 title 'Search results for "%s"' "$query"
1489 cd $WOK; ls -1 | grep "$query"
1490 footer ;;
1492 setup)
1493 # Setup a build environment
1494 check_root
1495 _ 'Cook: setup environment' | log
1496 title 'Setting up your environment'
1497 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1498 cd $SLITAZ
1499 init_db_files
1500 _ 'Checking for packages to install...'
1501 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1502 # ARCH-setup or 'cross check' should be used before: cook setup
1503 case "$ARCH" in
1504 arm*|x86_64)
1505 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1506 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1507 . /etc/slitaz/cross.conf ;;
1508 esac
1509 for pkg in $SETUP_PKGS; do
1510 if [ -n "$forced" ]; then
1511 tazpkg -gi $pkg --forced
1512 else
1513 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1514 fi
1515 done
1517 # Handle --options
1518 case "$2" in
1519 --wok) hg clone $WOK_URL wok || exit 1 ;;
1520 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1521 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1522 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1523 esac
1525 # SliTaz group and permissions
1526 if ! grep -q ^slitaz /etc/group; then
1527 _ 'Adding group "%s"' 'slitaz'
1528 addgroup slitaz
1529 fi
1530 _ 'Setting permissions for group "%s"...' 'slitaz'
1531 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1532 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1533 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1535 *-setup)
1536 # Setup for cross compiling.
1537 arch="${1%-setup}"
1538 check_root
1539 . /etc/slitaz/cook.conf
1540 for pkg in $CROSS_SETUP; do
1541 if [ -n "$forced" ]; then
1542 tazpkg -gi $pkg --forced
1543 else
1544 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1545 fi
1546 done
1548 _ 'Cook: setup %s cross environment' "$arch" | log
1549 title 'Setting up your %s cross environment' "$arch"
1550 init_db_files
1551 sed -i \
1552 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1553 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1554 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1555 /etc/slitaz/cook.conf
1556 case "$arch" in
1557 arm)
1558 flags='-O2 -march=armv6'
1559 host="$ARCH-slitaz-linux-gnueabi" ;;
1560 armv6hf)
1561 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1562 host="$ARCH-slitaz-linux-gnueabi" ;;
1563 armv7)
1564 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1565 host="$ARCH-slitaz-linux-gnueabi" ;;
1566 x86_64)
1567 flags='-O2 -mtune=generic -pipe'
1568 host="$ARCH-slitaz-linux" ;;
1569 esac
1570 sed -i \
1571 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1572 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1573 . /etc/slitaz/cook.conf
1574 sysroot="$CROSS_TREE/sysroot"
1575 tools="/cross/$arch/tools"
1576 root="$sysroot"
1577 # L10n: keep the same width of translations to get a consistent view
1578 _ 'Target arch : %s' "$ARCH"
1579 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1580 _ 'Build flags : %s' "$flags"
1581 _ 'Arch sysroot : %s' "$sysroot"
1582 _ 'Tools prefix : %s' "$tools/bin"
1583 # Tell the packages manager where to find packages.
1584 _ 'Packages DB : %s' "$root$DB"
1585 mkdir -p $root$INSTALLED
1586 cd $root$DB; rm -f *.bak
1587 for list in packages.list packages.desc packages.equiv packages.md5; do
1588 rm -f $list
1589 ln -s $SLITAZ/packages/$list $list
1590 done
1591 # We must have the cross compiled glibc-base installed or default
1592 # i486 package will be used as dep by tazpkg and then break the
1593 # cross environment
1594 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1595 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1596 fi
1597 # Show GCC version or warn if not yet compiled.
1598 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1599 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1600 else
1601 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1602 _ 'Run "%s" to cook a toolchain' 'cross compile'
1603 fi
1604 footer ;;
1606 test)
1607 # Test a cook environment.
1608 _ 'Cook test: testing the cook environment' | log
1609 [ ! -d "$WOK" ] && exit 1
1610 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1611 cook cooktest ;;
1613 new)
1614 # Create the package folder and an empty receipt.
1615 pkg="$2"
1616 [ -z "$pkg" ] && usage
1617 newline
1618 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1620 action 'Creating folder "%s"' "$WOK/$pkg"
1621 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1623 action 'Preparing the package receipt...'
1624 cp $DATA/receipt .
1625 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1626 status; newline
1628 # Interactive mode, asking and seding.
1629 case "$3" in
1630 --interactive|-x)
1631 _ 'Entering interactive mode...'
1632 separator
1633 _ 'Package : %s' "$pkg"
1635 _n 'Version : ' ; read answer
1636 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1638 _n 'Category : ' ; read answer
1639 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1641 # L10n: Short description
1642 _n 'Short desc : ' ; read answer
1643 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1645 _n 'Maintainer : ' ; read answer
1646 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1648 _n 'License : ' ; read answer
1649 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1651 _n 'Web site : ' ; read answer
1652 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1653 newline
1655 # Wget URL.
1656 _ 'Wget URL to download source tarball.'
1657 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1658 _n 'Wget url : ' ; read answer
1659 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1661 # Ask for a stuff dir.
1662 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1663 if [ "$?" -eq 0 ]; then
1664 action 'Creating the stuff directory...'
1665 mkdir $WOK/$pkg/stuff; status
1666 fi
1668 # Ask for a description file.
1669 confirm "$(_n 'Are you going to write a description? (y/N)')"
1670 if [ "$?" -eq 0 ]; then
1671 action 'Creating the "%s" file...' 'description.txt'
1672 touch $WOK/$pkg/description.txt; status
1673 fi
1675 footer "$(_ 'Receipt is ready to use.')" ;;
1676 esac ;;
1678 list)
1679 # Cook a list of packages (better use the Cooker since it will order
1680 # packages before executing cook).
1681 check_root
1682 [ -z "$2" ] && die 'No list in argument.'
1683 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1685 _ 'Starting cooking the list "%s"' "$2" | log
1687 while read pkg; do
1688 cook $pkg || broken
1689 done < $2
1690 ;;
1692 clean-wok)
1693 check_root
1694 newline; action 'Cleaning all packages files...'
1695 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1696 status; newline ;;
1698 clean-src)
1699 check_root
1700 newline; action 'Cleaning all packages sources...'
1701 rm -rf $WOK/*/source
1702 status; newline ;;
1704 uncook)
1705 cd $WOK
1706 count=0
1707 title 'Checking for uncooked packages'
1709 for i in *; do
1710 unset HOST_ARCH EXTRAVERSION
1711 [ ! -e $i/receipt ] && continue
1712 . ./$i/receipt
1713 # Source cooked pkg receipt to get EXTRAVERSION
1714 if [ -d "$WOK/$i/taz" ]; then
1715 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1716 . ./receipt; cd $WOK
1717 fi
1718 case "$ARCH" in
1719 i486)
1720 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1721 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1722 count=$(($count + 1))
1723 colorize 34 "$i"
1724 fi ;;
1725 arm*)
1726 # Check only packages included in arch
1727 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1728 # *.tazpkg
1729 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1730 count=$(($count + 1))
1731 colorize 34 "$i"
1732 fi
1733 fi ;;
1734 esac
1735 done
1737 if [ "$count" -gt 0 ]; then
1738 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1739 else
1740 _ 'All packages are cooked :-)'
1741 newline
1742 fi
1743 ;;
1745 pkgdb)
1746 # Create suitable packages list for TazPkg and only for built packages
1747 # as well as flavors files for TazLiTo. We don't need logs since we do it
1748 # manually to ensure everything is fine before syncing the mirror.
1749 recreate_split_db
1750 recreate_maint_db
1751 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1752 ;;
1754 splitdb)
1755 # File split.db is useful for searching for split packages.
1756 recreate_split_db
1757 ;;
1759 maintdb)
1760 # File maint.db is useful for searching maintainer's packages.
1761 recreate_maint_db
1762 ;;
1764 *)
1765 # Just cook and generate a package.
1766 check_root
1767 time=$(date +%s)
1768 pkg="$1"
1769 [ -z "$pkg" ] && usage
1771 # Search last successful cook time in all logs from newer to older
1772 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1773 [ -f "$LOGS/$pkg.log$i" ] || break
1774 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1775 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1776 [ -n "$lastcooktime" ] && break
1777 done
1779 receipt="$WOK/$pkg/receipt"
1780 check_pkg_in_wok
1781 newline
1783 unset inst
1784 unset_receipt
1785 . $receipt
1787 # Handle cross compilation.
1788 case "$ARCH" in
1789 arm*)
1790 if [ -z "$HOST_ARCH" ]; then
1791 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1792 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1793 _ 'cook: %s' "$error"
1794 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1795 _ 'Cook skip: %s' "$error" | log
1796 newline
1797 broken; exit 1
1798 fi ;;
1799 esac
1801 # Some packages are not included in some arch or fail to cross compile.
1802 : ${HOST_ARCH=$ARCH}
1803 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1804 # Handle arm{v6hf,v7,..}
1805 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1806 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1807 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1808 _ 'cook: %s' "error"
1809 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1810 _ 'Cook skip: %s' "$error" | log
1811 sed -i "/^${pkg}$/d" $broken
1812 newline
1813 exit 0
1814 fi
1816 # Remove package from broken list before cooking
1817 sed -i "/^${pkg}$/d" $broken
1819 # Skip blocked, 3 lines also for the Cooker.
1820 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1821 die 'Package "%s" is blocked' "$pkg"
1823 try_aufs_chroot "$@"
1825 # Log and source receipt.
1826 echo "cook:$pkg" > $command
1828 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1830 while read cmd duration start; do
1831 [ $(($start + $duration)) -lt $(date +%s) ] &&
1832 echo "sed -i '/^$cmd $duration/d' $cooktime"
1833 done < $cooktime | sh
1835 # Display and log info if cook process stopped.
1836 # FIXME: gettext not working (in single quotes) here!
1837 trap '_ "\n\nCook stopped: control-C\n\n" | \
1838 tee -a $LOGS/$pkg.log' INT
1840 update_split_db
1842 # Handle --options
1843 case "$2" in
1844 --pack)
1845 _ 'Packing %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1846 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1847 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1848 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -f $LOGS/$pkg-pack.log
1849 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1850 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1851 clean_log "$pkg-pack"
1852 time=$(($(date +%s) - $time))
1853 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1854 gen_rss
1855 put_status $pkg Done
1856 rm -f $command
1857 exit 0 ;;
1859 --trials|-t)
1860 trials='yes' ;;
1861 esac
1863 _ 'Making %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1865 # Rotate log
1866 for i in $(seq 9 -1 1); do
1867 j=$(($i - 1))
1868 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1869 done
1870 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1872 # Check if wanted is built now so we have separate log files.
1873 for wanted in $WANTED ; do
1874 if grep -q "^$wanted$" $blocked; then
1875 broken
1876 rm -f $command
1877 die 'WANTED package "%s" is blocked' "$wanted"
1878 fi
1879 if grep -q "^$wanted$" $broken; then
1880 broken
1881 rm -f $command
1882 die 'WANTED package "%s" is broken' "$wanted"
1883 fi
1884 if [ ! -d "$WOK/$wanted/install" ]; then
1885 cook "$wanted" || { broken; exit 1; }
1886 fi
1887 done
1889 # Cook and pack or exit on error and log everything.
1890 ( ( ( (cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq) )
1891 rq=$? # the return code of `cookit $@` above command
1893 if [ $rq -eq 1 ]; then
1894 broken
1895 fi
1897 # Remove build dependencies both when `cookit` done or fail
1898 remove_deps | tee -a $LOGS/$pkg.log
1899 timestamp job27 # removing bdeps
1900 # cookit_quality
1901 timestamp job28 # checking quality
1903 # Log and stop if `cookit` fails
1904 if [ $rq -eq 1 ]; then
1905 debug_info "ret1" | tee -a $LOGS/$pkg.log
1906 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1907 put_status $pkg Failed
1908 rm -f $command
1909 broken
1910 exit 1
1911 fi
1913 # Proceed only if `cookit` return code is zero-OK
1914 # If instant-pack if specified, then packages already packed in the cookit()
1915 [ "${COOKOPTS/instant-pack/}" == "$COOKOPTS" ] &&
1916 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1917 timestamp job29 # packing
1919 @@PREFIX@@/libexec/cookutils/postcheck $pkg | tee -a $LOGS/$pkg.log
1921 clean_log
1923 # Exit if any error in packing.
1924 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
1925 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1926 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1927 debug_info "packerr" | tee -a $LOGS/$pkg.log
1928 put_status $pkg Failed
1929 rm -f $command
1930 broken; exit 1
1931 fi
1933 # Create an XML feed
1934 gen_rss
1936 # Time and summary
1937 time=$(($(date +%s) - $time))
1938 summary | tee -a $LOGS/$pkg.log
1939 newline
1941 # We may want to install/update (outside aufs jail!).
1942 [ -s /aufs-umount.sh ] || install_package
1944 put_status $pkg Done
1946 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1947 # If you want automation, use the Cooker Build Bot.
1948 rm -f $command
1949 timestamp job30 # misc. final operations
1950 store_timestats
1952 sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
1953 | sed '/^Build/d; s|Removing: ||' \
1954 | tr ' ' '\n' \
1955 | sed '/^$/d' \
1956 > $WOK/$pkg/.bdeps
1958 ;;
1959 esac
1961 exit 0