cookutils view cook @ rev 1087

cook, cook.conf: move macro definition from CFLAGS and CXXFLAGS to CPPFLAGS
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Jul 28 15:31:35 2018 +0300 (2018-07-28)
parents f9a6a676a923
children 461c3da71257
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 --install -i $(_ 'cook and install the package.')
50 --getsrc -gs $(_ 'get the package source tarball.')
51 --block -b $(_ 'block a package so cook will skip it.')
52 --unblock -ub $(_ 'unblock a blocked package.')
53 --cdeps $(_ 'check dependencies of cooked package.')
54 --pack $(_ 'repack an already built package.')
55 --debug $(_ 'display debugging messages.')
56 --continue $(_ 'continue running compile_rules.')
57 cook new <pkg>
58 --interactive -x $(_ 'create a receipt interactively.')
59 cook setup
60 --wok $(_ 'clone the cooking wok from Hg repo.')
61 --stable $(_ 'clone the stable wok from Hg repo.')
62 --undigest $(_ 'clone the undigest wok from Hg repo.')
63 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
64 --forced $(_ 'force reinstall of chroot packages.')
65 cook pkgdb
66 --flavors $(_ 'create up-to-date flavors files.')
67 cook splitdb $(_ 'create up-to-date split.db file.')
69 EOT
70 exit 0
71 }
74 # We don't want these escapes in web interface.
76 clean_log() {
77 sed -i -e 's|\[70G\[ \[1;32m| |' \
78 -e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
79 }
82 # Be sure package exists in wok.
84 check_pkg_in_wok() {
85 [ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
86 }
89 # Find the package, return the receipt name where it was found
90 # for example, libpcreposix -> pcre
92 find_pkg_in_wok() {
93 awk -F$'\t' -vi="$1" '{
94 if (index(" " $2 " ", i)) {print $1; exit}
95 }' $cache/split.db
96 }
99 # Initialize files used in $CACHE
101 init_db_files() {
102 _ 'Creating directories structure in "%s"' "$SLITAZ"
103 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
104 _ 'Creating DB files in "%s"' "$CACHE"
105 touch $activity $command $broken $blocked $CACHE/webstat
106 chown www:www $cache/webstat
107 }
110 # Paths used in receipt and by cook itself.
112 set_paths() {
113 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
114 if [ -f "$WOK/linux/receipt" ]; then
115 kvers=$(. $WOK/linux/receipt; echo $VERSION)
116 kbasevers=$(echo $kvers | cut -d. -f1,2)
117 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
118 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
119 kbasevers=$(echo $kvers | cut -d. -f1,2)
120 fi
122 # Python version
123 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
124 # Perl version for some packages needed it
125 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
127 pkgdir="$WOK/$pkg"
128 . "$pkgdir/receipt"
129 basesrc="$pkgdir/source"
130 tmpsrc="$basesrc/tmp"
131 src="$basesrc/$PACKAGE-$VERSION"
132 taz="$pkgdir/taz"
133 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
134 fs="$pack/fs"
135 stuff="$pkgdir/stuff"
136 install="$pkgdir/install"
138 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
139 lzma_tarball="$pkgsrc.tar.lzma"
141 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
143 if [ -n "$WANTED" ]; then
144 basesrc="$WOK/$WANTED/source"
145 src="$basesrc/$WANTED-$VERSION"
146 install="$WOK/$WANTED/install"
147 wanted_stuff="$WOK/$WANTED/stuff"
148 fi
150 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
152 # Old way compatibility.
153 _pkg="$install"
154 }
157 # Create source tarball when URL is a SCM.
159 create_tarball() {
160 local tarball
161 tarball="$pkgsrc.tar.bz2"
162 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
163 _ 'Creating tarball "%s"' "$tarball"
164 if [ -n "$LZMA_SRC" ]; then
165 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
166 LZMA_SRC=''
167 else
168 tar -cjf $tarball $pkgsrc || exit 1
169 mv $tarball $SRC; rm -rf $pkgsrc
170 fi
171 TARBALL="$tarball"
172 }
175 # Get package source. For SCM we are in cache so clone here and create a
176 # tarball here.
178 get_source() {
179 local url
180 url=${WGET_URL#*|}
181 set_paths
182 pwd=$(pwd)
183 case "$WGET_URL" in
184 http://*|ftp://*|https://*)
185 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
186 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
187 wget -T 60 -c -O $SRC/$TARBALL $url ||
188 die 'ERROR: %s' "wget $WGET_URL"
189 ;;
191 hg*|mercurial*)
192 _ 'Getting source from %s...' 'Hg'
193 _ 'URL: %s' "$url"
194 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
195 if [ -n "$BRANCH" ]; then
196 _ 'Hg branch: %s' "$BRANCH"
197 hg clone $url --rev $BRANCH $pkgsrc ||
198 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
199 else
200 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
201 fi
202 rm -rf $pkgsrc/.hg
203 create_tarball
204 ;;
206 git*)
207 _ 'Getting source from %s...' 'Git'
208 _ 'URL: %s' "$url"
209 cd $SRC
210 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
211 if [ -n "$BRANCH" ]; then
212 _ 'Git branch: %s' "$BRANCH"
213 cd $pkgsrc; git checkout $BRANCH; cd ..
214 fi
215 cd $SRC
216 create_tarball
217 ;;
219 cvs*)
220 mod=$PACKAGE
221 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
222 _ 'Getting source from %s...' 'CVS'
223 _ 'URL: %s' "$url"
224 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
225 _ 'Cloning to "%s"' "$pwd/$mod"
226 cvs -d:$url co $mod && mv $mod $pkgsrc
227 create_tarball
228 ;;
230 svn*|subversion*)
231 _ 'Getting source from %s...' 'SVN'
232 _ 'URL: %s' "$url"
233 if [ -n "$BRANCH" ]; then
234 echo t | svn co $url -r $BRANCH $pkgsrc
235 else
236 echo t | svn co $url $pkgsrc
237 fi
238 create_tarball
239 ;;
241 bzr*)
242 _ 'Getting source from %s...' 'bazaar'
243 cd $SRC
244 pkgsrc=${url#*:}
245 if [ -n "$BRANCH" ]; then
246 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
247 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
248 else
249 echo "bzr -Ossl.cert_reqs=none branch $url"
250 bzr -Ossl.cert_reqs=none branch $url
251 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
252 _ "Don't forget to add to receipt:"
253 echo -e "BRANCH=\"$BRANCH\"\n"
254 fi
255 mv $pkgsrc $pkgsrc-$BRANCH
256 pkgsrc="$pkgsrc-$BRANCH"
257 create_tarball
258 ;;
260 *)
261 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
262 ;;
263 esac
264 }
267 # Extract source package.
269 extract_source() {
270 if [ ! -s "$SRC/$TARBALL" ]; then
271 local url
272 url="$MIRROR_URL/sources/packages"
273 url="$url/${TARBALL:0:1}/$TARBALL"
274 _ 'Getting source from %s...' 'mirror'
275 _ 'URL: %s' "$url"
276 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
277 fi
278 _ 'Extracting source archive "%s"' "$TARBALL"
279 case "$TARBALL" in
280 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
281 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
282 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
283 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
284 *.tar) tar -xf $SRC/$TARBALL ;;
285 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
286 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
287 tar -xf $SRC/$TARBALL 2>/dev/null;;
288 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
289 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
290 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
291 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
292 *) cp $SRC/$TARBALL $(pwd) ;;
293 esac
294 }
297 # Display time.
299 disp_time() {
300 local sec div min
301 sec="$1"
302 div=$(( ($1 + 30) / 60))
303 case $div in
304 0) min='';;
305 # L10n: 'm' is for minutes (approximate cooking time)
306 *) min=$(_n ' ~ %dm' "$div");;
307 esac
309 # L10n: 's' is for seconds (cooking time)
310 _ '%ds%s' "$sec" "$min"
311 }
314 # Display cooked package summary.
316 summary() {
317 local arch=''
318 case "$ARCH" in
319 arm*|x86_64) arch="-$ARCH" ;;
320 esac
322 set_paths
323 cd $WOK/$pkg
324 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
325 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
326 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
328 title 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION$arch"
330 # L10n: keep the same width of translations to get a consistent view
331 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
332 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
333 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
334 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
335 _ 'Cook time : %s' "$(disp_time "$time")"
336 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
337 _ 'Target arch : %s' "$ARCH"
339 separator -
340 _ ' # : Packed : Compressed : Files : Package name'
341 separator -
342 pkgi=1
343 for i in $(all_names); do
344 version=$(awk -F$'\t' -vpkg="$i" '{
345 if ($1 == pkg) {print $2; exit}
346 }' "$PKGS/packages.info")
347 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
348 pkgname="$i-$version$arch.tazpkg"
349 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
350 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
351 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
352 pkgi=$((pkgi + 1))
353 done
354 separator
355 }
358 # Display debugging error info.
360 debug_info() {
361 title 'Debug information'
362 # L10n: specify your format of date and time (to help: man date)
363 # L10n: not bad one is '+%x %R'
364 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
365 if [ -n "$time" ]; then
366 times="$(($(date +%s) - $time))"
367 _ 'Wasted time : %s' "$(disp_time "$times")"
368 fi
369 for error in \
370 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
371 'error:' 'fatal error:' 'undefined reference to' \
372 'Unable to connect to' 'link: cannot find the library' \
373 'CMake Error' ': No such file or directory' \
374 'Could not read symbols: File in wrong format'
375 do
376 # format "line number:line content"
377 fgrep -n "$error" $LOGS/$pkg.log
378 done > $LOGS/$pkg.log.debug_info 2>&1
379 # sort by line number, remove duplicates
380 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
381 rm -f $LOGS/$pkg.log.debug_info
382 footer
383 }
386 # A bit smarter function than the classic `cp` command
388 scopy() {
389 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
390 cp -a "$1" "$2" # copy generic files
391 else
392 cp -al "$1" "$2" # copy hardlinks
393 fi
394 }
397 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
398 # We use standard paths, so some packages need to copy these files with the
399 # receipt and genpkg_rules.
400 # This function executes inside the packaging process, before compressor call.
402 copy_generic_files() {
403 # Proceed only for "main" package (for v2), and for any packages (v1)
404 [ "$pkg" == "$PACKAGE" ] || return 0
406 # $LOCALE is set in cook.conf
407 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
408 if [ -d "$install/usr/share/locale" ]; then
409 mkdir -p "$fs/usr/share/locale"
410 for i in $LOCALE; do
411 if [ -d "$install/usr/share/locale/$i" ]; then
412 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
413 fi
414 done
415 fi
416 fi
418 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
419 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
420 if [ -d "$install/usr/share/pixmaps" ]; then
421 mkdir -p "$fs/usr/share/pixmaps"
422 for i in png xpm; do
423 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
424 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
425 done
426 fi
427 fi
429 # Desktop entry (.desktop).
430 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
431 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
432 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
433 mkdir -p "$fs/usr/share"
434 cp -r $install/usr/share/applications $fs/usr/share
435 fi
436 fi
437 }
440 # Copy pixmaps, desktop files and licenses from $stuff to $install.
441 # This function executes after the main compile_rules() is done.
443 copy_generic_stuff() {
444 # Custom or homemade PNG pixmap can be in stuff.
445 if [ -f "$stuff/$PACKAGE.png" ]; then
446 mkdir -p $install/usr/share/pixmaps
447 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
448 fi
450 # Homemade desktop file(s) can be in stuff.
451 if [ -d "$stuff/applications" ]; then
452 mkdir -p $install/usr/share
453 cp -r $stuff/applications $install/usr/share
454 fi
455 if [ -f "$stuff/$PACKAGE.desktop" ]; then
456 mkdir -p $install/usr/share/applications
457 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
458 fi
460 # Add custom licenses
461 if [ -d "$stuff/licenses" ]; then
462 mkdir -p $install/usr/share/licenses
463 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
464 fi
465 }
468 # Update installed.cook.diff
470 update_installed_cook_diff() {
471 # If a cook failed deps are removed.
472 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
473 cd $CACHE
474 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
475 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
476 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
477 }
480 # Remove installed deps.
482 remove_deps() {
483 # Now remove installed build deps.
484 diff='/tmp/installed.cook.diff'
485 [ -s "$diff" ] || return
487 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
488 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
489 newline
490 _n 'Build dependencies to remove:'; echo " $nb"
491 [ -n "$root" ] && echo "root=\"$root\""
492 {
493 _n 'Removing:'
494 for dep in $deps; do
495 echo -n " $dep"
496 # Do not waste time uninstalling the packages if we are inside
497 # aufs chroot - unmounting chroot will "uninstall" all packages.
498 [ -s /aufs-umount.sh ] ||
499 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
500 done
501 } | busybox fold -sw80
502 newline; newline
503 # Keep the last diff for debug and info.
504 mv -f $diff $CACHE/installed.diff
505 }
508 # Automatically patch the sources.
510 patchit() {
511 [ -f "$stuff/patches/series" ] || return
513 IFS=$'\n'
514 while read i; do
515 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
516 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
517 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
518 *) patchopts='-Np1';;
519 esac
520 [ -n "$patchname" ] || continue # allow empty lines
521 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
522 newline
523 _ 'Applying patch %s' "$patchname"
524 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
525 touch $src/done.$patchname
526 done < $stuff/patches/series
527 newline
528 unset IFS
529 }
532 # Check source tarball integrity.
534 check_integrity() {
535 for i in sha1 sha3 sha256 sha512 md5; do
536 I=$(echo $i | tr 'a-z' 'A-Z')
537 eval sum=\$TARBALL_$I
538 if [ -n "$sum" ]; then
539 newline
540 _ 'Checking %ssum of source tarball...' "$i"
541 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
542 fi
543 done
544 newline
545 }
548 # Misc fix functions
550 fix() {
551 case $1 in
552 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
553 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
554 ld)
555 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
556 ;;
557 libtool)
558 if [ -e 'libtool' ]; then
559 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
560 else
561 echo "fix libtool: warning: libtool absent, nothing to fix."
562 fi
563 ;;
564 math)
565 # fix C++ math issue introduced in Glibc 2.26:
566 # error: '__builtin_isnan' is not a member of 'std'
567 # if (std::isnan(N)) {
568 # ^
569 find $src -type f -exec sed -i '
570 s|std::signbit|__builtin_signbit|g;
571 s|std::isnan|__builtin_isnan|g;
572 s|std::isinf|__builtin_isinf_sign|g;
573 s|std::isfinite|__builtin_isfinite|g;
574 s|std::isnormal|__builtin_isnormal|g
575 ' '{}' \;
576 ;;
577 symlinks)
578 # make absolute symlinks relative
579 echo "fix symlinks"
580 local ifs="$IFS" link target
581 IFS=$'\n'
582 # step 1: fast job, prefix all the absolute symlinks with "$install"
583 for link in $(find $install -type l); do
584 target="$(readlink $link)"
585 case "$target" in
586 /*) ln -sfv "$install$target" "$link";;
587 esac
588 done
589 IFS="$ifs"
590 # step 2: fine tuning, make symlinks relative
591 tazpkg -gi --quiet --local --cookmode symlinks
592 symlinks -cr $install
593 ;;
594 esac
595 }
598 # Store timestamps, log jobs length
600 timestamp() {
601 local ts_file="$WOK/$pkg/.ts"
602 local curr_ts=$(date '+%s')
603 case $1 in
604 init)
605 rm $ts_file 2>/dev/null
606 echo $curr_ts > $prev_ts
607 ;;
608 job*)
609 # calculate time from the last timestamp
610 echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
611 echo $curr_ts > $prev_ts
612 ;;
613 sets)
614 echo "sets='$2'" >> $ts_file
615 ;;
616 esac
617 }
620 # Store time statsistics to the cache
622 store_timestats() {
623 # see doc/timestats.txt for file format
624 temp=$(mktemp)
625 {
626 for i in $(seq 1 30); do echo "job$i=0"; done
627 cat $WOK/$pkg/.ts
628 echo -n 'total=$(( 0'
629 for i in $(seq 1 30); do echo -n " + job$i"; done
630 echo ' ))'
631 } > $temp
632 . $temp
633 {
634 echo -n "$pkg $sets "
635 for i in $(seq 1 30); do echo -n "$((job$i)) "; done
636 echo "$total"
637 } >> /home/slitaz/cache/timestats
638 rm $temp $WOK/$pkg/.ts # clean
639 }
642 # Internal function to cook specified SET
644 cook_set() {
645 # Switch to the specified source set
646 set_paths
647 local suffix=''
648 [ -n "$SET" ] && suffix="-$SET"
649 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
650 export install="$WOK/$pkg/install$suffix"
651 export DESTDIR="$install"
653 if [ -n "$SETS" ]; then
654 if [ -n "$SET" ]; then
655 title "Switching to the set '$SET'"
656 else
657 title "Switching to the default set"
658 fi
659 echo "src : $src"
660 echo "install: $install"
661 fi
662 [ -d "$src" ] && cd $src # packages without sources exists
663 echo
665 [ -d "$install" ] && rm -r $install
666 #mkdir -p $install
668 compile_rules $@ || { broken; exit 1; }
670 # Stay compatible with _pkg
671 [ -d "$src/_pkg" ] && mv $src/_pkg $install
673 copy_generic_stuff
675 timestamp job$job_counter # compiling (set '$SET')
677 # Actions to do after compiling the package
678 # Skip all for split packages (already done in main package)
679 if [ -z "$WANTED" ]; then
680 footer
681 export COOKOPTS ARCH install
682 @@PREFIX@@/libexec/cookutils/compressor install
683 timestamp job$(($job_counter + 1)) # compressing (set '$SET')
684 fi
686 # Activate "instant-pack" mode
687 if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
688 echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
689 # determine the list of the packages belongs to the current SET...
690 echo -n $SPLIT \
691 | awk -vset="$SET" '
692 BEGIN { RS = " "; FS = ":"; }
693 { if ($2 == set) print $1; }' \
694 | while read SET_PKG; do
695 # ... and then pack them
696 packit $SET_PKG
697 done
698 fi
700 job_counter=$(($job_counter + 2))
701 }
704 # The main cook function.
706 cookit() {
707 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
708 _ 'ERROR: Broken setup. Abort.'
709 return
710 fi
712 title 'Cook: %s' "$PACKAGE $VERSION"
713 set_paths
714 timestamp init # the very start
716 # Handle cross-tools.
717 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
718 case "$ARCH" in
719 arm*|x86_64)
720 # CROSS_COMPILE is used by at least Busybox and the kernel to set
721 # the cross-tools prefix. Sysroot is the root of our target arch
722 sysroot="$CROSS_TREE/sysroot"
723 tools="$CROSS_TREE/tools"
724 # Set root path when cross compiling. ARM tested but not x86_64
725 # When cross compiling we must install build deps in $sysroot.
726 arch="-$ARCH"
727 root="$sysroot"
728 _ '%s sysroot: %s' "$ARCH" "$sysroot"
729 _ 'Adding "%s" to PATH' "$tools/bin"
730 export PATH="$PATH:$tools/bin"
731 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
732 export CROSS_COMPILE="$HOST_SYSTEM-"
733 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
734 if [ "$ARCH" == 'x86_64' ]; then
735 export CC="$HOST_SYSTEM-gcc -m64"
736 export CXX="$HOST_SYSTEM-g++ -m64"
737 else
738 export CC="$HOST_SYSTEM-gcc"
739 export CXX="$HOST_SYSTEM-g++"
740 fi
741 export AR="$HOST_SYSTEM-ar"
742 export AS="$HOST_SYSTEM-as"
743 export RANLIB="$HOST_SYSTEM-ranlib"
744 export LD="$HOST_SYSTEM-ld"
745 export STRIP="$HOST_SYSTEM-strip"
746 export LIBTOOL="$HOST_SYSTEM-libtool"
747 ;;
748 esac
750 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
752 cd $pkgdir
753 [ -z "$continue" ] && rm -rf source 2>/dev/null
754 rm -rf install taz 2>/dev/null
756 # Disable -pipe if less than 512 MB free RAM.
757 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
758 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
759 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
760 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
761 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
762 fi
763 unset free
765 # Export flags and path to be used by make and receipt.
766 DESTDIR="$pkgdir/install"
767 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
768 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
769 LDFLAGS
771 timestamp job1 # pre-checks
773 # BUILD_DEPENDS may vary depending on the ARCH
774 case "$ARCH" in
775 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
776 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
777 esac
779 # Check for build deps and handle implicit depends of *-dev packages
780 # (ex: libusb-dev :: libusb).
781 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
782 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
784 # Get the list of installed packages
785 cd $root$INSTALLED; ls > $CACHE/installed.list
787 for action in check install; do
788 for dep in $BUILD_DEPENDS; do
789 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
790 for i in $dep $implicit; do
791 # Skip if package already installed
792 [ -f "$root$INSTALLED/$i/receipt" ] && continue
794 case $action in
795 check)
796 # Search for local package or local provided-package
797 name=$(awk -F$'\t' -vpkg="$i" '{
798 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
799 }' "$PKGS/packages.info")
800 if [ -z "$name" ]; then
801 # Search for package in mirror
802 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
803 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
804 fi
805 ;;
806 install)
807 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
808 ;;
809 esac
810 done
811 done
812 done
814 update_installed_cook_diff
816 timestamp job2 # installing bdeps
818 # Get source tarball and make sure we have source dir named:
819 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
820 # tarball if it exists.
821 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
822 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
823 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
824 LZMA_SRC=''
825 else
826 get_source || { broken; exit 1; }
827 fi
828 fi
829 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
830 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
831 if ! extract_source ; then
832 get_source
833 extract_source || { broken; exit 1; }
834 fi
835 if [ -n "$LZMA_SRC" ]; then
836 cd $pkgdir/source
837 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
838 mv tmp tmp-1; mkdir tmp
839 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
840 fi
841 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
842 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
843 fi
844 fi
846 cd $pkgdir/source/tmp
847 # Some archives are not well done and don't extract to one dir (ex lzma).
848 files=$(ls | wc -l)
849 [ "$files" -eq 1 -a -d "$(ls)" ] &&
850 mv * ../$PACKAGE-$VERSION
851 [ "$files" -eq 1 -a -f "$(ls)" ] &&
852 mkdir -p ../$PACKAGE-$VERSION &&
853 mv * ../$PACKAGE-$VERSION/$TARBALL
854 [ "$files" -gt 1 ] &&
855 mkdir -p ../$PACKAGE-$VERSION &&
856 mv * ../$PACKAGE-$VERSION
857 cd ..; rm -rf tmp
858 fi
860 # Check md5sum (or similar) for sources tarball
861 check_integrity
863 # Libtool shared libs path hack.
864 case "$ARCH" in
865 arm*) cross libhack ;;
866 esac
868 timestamp job3 # get/unpack src tarball
870 # Compiling all the sets
871 if grep -q ^compile_rules $receipt; then
872 _ 'Executing: %s' 'compile_rules'
873 echo "CFLAGS : $CFLAGS"
874 echo "CXXLAGS : $CXXFLAGS"
875 echo "CPPFLAGS : $CPPFLAGS"
876 echo "LDFLAGS : $LDFLAGS"
877 [ -d "$src" ] && cd $src
878 patchit
880 timestamp job4 # patching
882 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
883 # Keep natural order of the sets, don't sort them alphabetically
884 SETS=$(echo -n $SPLIT \
885 | awk '
886 BEGIN { RS = " "; FS = ":"; }
887 {
888 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
889 }' \
890 | sed 's| $||')
891 # Prepare specified source sets using patched sources
892 [ -n "$SETS" -a -d "$src" ] &&
893 for set in $SETS; do
894 echo "Preparing set $set" # debug
895 cp -a $src $src-$set
896 done
898 timestamp job5 # preparing sets
899 timestamp sets "$SETS"
901 job_counter='6'
903 SET='' cook_set # first run for empty SET
905 # Allow to change SETS after the first run, follow the changes
906 SETS=$(. $receipt; echo -n $SPLIT \
907 | awk '
908 BEGIN { RS = " "; FS = ":"; }
909 {
910 if ($2 && ! set[$2]) { printf("%s ", $2); set[$2] = "1"; }
911 }' \
912 | sed 's| $||')
913 for SET in $SETS; do
914 cook_set
915 done
916 else
917 mkdir -p $install # allow receipts without `compile_rules()`
918 fi
919 footer
921 timestamp job # reset counter
923 # Execute testsuite.
924 if grep -q ^testsuite $receipt; then
925 title 'Running testsuite'
926 testsuite $@ || { broken; exit 1; }
927 footer
928 fi
930 timestamp job26 # test suite
932 update_installed_cook_diff force
933 }
936 # Cook quality assurance.
938 cookit_quality() {
939 while true; do
940 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
941 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
942 [ "$trials" == 'yes' ] || break
943 title "Interactive mode"
944 # TODO: allow commands:
945 # q - quit; v - edit receipt here using vi;
946 # s - search for package containing package;
947 # <package name> - install package; [Enter] - retry
948 _ 'You may install the packages here and/or edit the receipt there.'
949 newline
950 while true; do
951 _n 'Install the package? [name/N] '; read answer
952 [ -n "$answer" ] || break
953 tazpkg -gi $answer --root=$root --local --quiet --cookmode
954 done
955 newline
956 _n 'Try again? [Y/n] '; read answer
957 [ "$answer" == 'n' ] && break
958 # here you may append log if you want (">>" instead of last ">")
959 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
960 done
962 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
964 # ERROR can be echoed any time in cookit()
965 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
966 grep -Eq "(^ERROR|undefined reference to)" ; then
967 debug_info | tee -a $LOGS/$pkg.log
968 put_status $pkg Failed
969 rm -f $command
970 broken; exit 1
971 fi
972 }
975 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
976 # but it doesn't handle EXTRAVERSION.
978 packit() {
979 set_paths "$1"
980 PACKAGE="${1:-$PACKAGE}"
982 # Handle cross compilation
983 case "$ARCH" in
984 arm*|x86_64) arch="-$ARCH" ;;
985 esac
987 title 'Pack: %s' "$PACKAGE $VERSION$arch"
989 # Get set name for specified package from $SPLIT variable
990 local set=$(echo -n $SPLIT \
991 | awk -vpkg="$PACKAGE" '
992 BEGIN { RS = " "; FS = ":"; }
993 { if ($1 == pkg && $2 != "") { print "-" $2; exit; } }')
994 # Change set, make filelist and folderlist for new set
995 export src="$src$set"
996 export install="$install$set"
997 export DESTDIR="$install"
999 if grep -q ^genpkg_rules $receipt; then
1000 _ 'Executing: %s' 'genpkg_rules'
1001 set -e; cd $pkgdir; mkdir -p $fs
1002 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1003 $LOGS/$pkg.log
1004 else
1005 _ 'No packages rules: meta package'
1006 mkdir -p $fs
1007 fi
1009 # Check CONFIG_FILES
1010 if [ -n "$CONFIG_FILES" ]; then
1011 unset IFS
1012 for i in $CONFIG_FILES; do
1013 if [ ! -e $fs$i ]; then
1014 case $i in
1015 */) mkdir -p $fs$i ;;
1016 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
1017 esac
1018 fi
1019 done
1020 fi
1022 # First QA check to stop now if genpkg_rules failed.
1023 lerror=$(_n 'ERROR')
1024 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1025 broken; exit 1
1026 fi
1028 cd $taz
1029 action 'Copying "%s"...' 'receipt'
1030 export PACKAGE VERSION CATEGORY SHORT_DESC WEB_SITE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT CONFIG_FILES
1031 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
1032 chown 0.0 $pack/receipt; status
1034 unset desc
1035 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
1036 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
1037 if [ -n "$desc" ]; then
1038 action 'Copying "%s"...' "$(basename "$desc")"
1039 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
1040 fi
1042 copy_generic_files
1044 # Strip and stuff files.
1045 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
1047 # Create files.list with redirecting find output.
1048 action 'Creating the list of files...'
1049 cd $fs
1050 find . -type f -print > ../files.list
1051 find . -type l -print >> ../files.list
1052 cd ..; sed -i 's|^.||' files.list
1053 status
1055 # Md5sum of files.
1056 action 'Creating md5sum of files...'
1057 while read file; do
1058 [ -L "fs$file" ] && continue
1059 [ -f "fs$file" ] || continue
1060 case "$file" in
1061 /lib/modules/*/modules.*|*.pyc) continue ;;
1062 esac
1063 md5sum "fs$file" | sed 's| fs| |'
1064 done < files.list | sort -k2 > md5sum
1065 status
1067 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1068 2>/dev/null | awk 'END{ print $1 }')
1070 # Build cpio archive.
1071 action 'Compressing the FS...'
1072 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
1073 # find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
1074 find fs | cpio -o -H newc --quiet | /bin/lzma -qzeT0 >fs.cpio.lzma
1075 mv fs ../
1076 status
1078 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1079 2>/dev/null | awk 'END{ print $1 }')
1081 action 'Updating receipt sizes...'
1082 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
1083 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
1084 status
1086 # Set extra version.
1087 if [ -n "$EXTRAVERSION" ]; then
1088 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1089 sed -i '/^EXTRAVERSION=/d' receipt
1090 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
1091 status
1092 fi
1094 # Compress.
1095 action 'Creating full cpio archive...'
1096 find . -newer $receipt -exec touch -hr $receipt '{}' \;
1097 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1098 status
1100 # Restoring original package tree.
1101 mv ../fs .
1103 rm fs.cpio.lzma; cd ..
1105 # QA and give info.
1106 tazpkg=$(ls *.tazpkg)
1107 packit_quality
1108 footer "$(_ 'Package "%s" created' "$tazpkg")"
1112 # Verify package quality and consistency.
1114 packit_quality() {
1115 local arch=''
1116 case "$ARCH" in
1117 arm*|x86_64) arch="-$ARCH" ;;
1118 esac
1120 local rsum rsumold='' rsum_changed old_file
1121 local pi="$PKGS/packages.info" fl="$cache/files.list"
1122 local pkg_file="$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg"
1123 local rsum_file=$(mktemp) rsum_file_old=$(mktemp) tmpdir=$(mktemp -d)
1126 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1127 # Exit if any error found in log file.
1128 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1129 rm -f $command
1130 broken; exit 1
1131 fi
1132 fi
1135 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1137 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1138 action 'QA: checking for empty package...'
1139 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1140 broken
1141 rm -f $command
1142 false; status
1143 die 'ERROR: empty package'
1144 fi
1145 :; status
1146 fi
1149 # Calculate release checksum: usually it does not change on "just recook".
1150 # Release checksum is md5sum of file containing md5sums of:
1151 # a) all files, b) receipt, and c) description.txt.
1152 # Md5sum of the package file will change every time because of embedded timestamps;
1153 # release checksum based only on files content, and will change only when files change.
1154 # (Pitfall: ownership and permissions...)
1156 # Calculate rsum for new package
1157 cp $pack/md5sum $rsum_file
1158 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1159 [ -e "$pack/description.txt" ] &&
1160 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1161 rsum=$(md5sum $rsum_file | awk '{print $1}')
1163 # Calculate rsum for existing previous "old" package
1164 if [ -f "$pkg_file" ]; then
1165 # don't trust database entry, check the package file
1166 cd $tmpdir
1167 cpio -F "$pkg_file" -i md5sum receipt description.txt >/dev/null 2>&1
1168 cp ./md5sum $rsum_file_old
1169 md5sum ./receipt | sed 's| [^ ]*/| |' >> $rsum_file_old
1170 [ -e "./description.txt" ] &&
1171 md5sum ./description.txt | sed 's| [^ ]*/| |' >> $rsum_file_old
1172 rsumold=$(md5sum $rsum_file_old | awk '{print $1}')
1173 cd - >/dev/null
1174 fi
1176 # Clean
1177 rm $rsum_file $rsum_file_old
1178 rm -r $tmpdir
1181 touch $pi $broken
1184 # Find and remove old package only if "release checksum" has changed
1186 if [ "$rsum" != "$rsumold" ]; then
1187 old_file=$(awk -F$'\t' -vname="$PACKAGE" -varch="$arch" '{
1188 if ($1 == name) printf("%s-%s%s.tazpkg", $1, $2, arch);
1189 }' $pi) # <name>-<version><extra_version><-arch>.tazpkg
1190 if [ -f "$PKGS/$old_file" ]; then
1191 action 'Removing old package "%s"' "$old_file"
1192 rm -f "$PKGS/$old_file"
1193 status
1194 fi
1195 # package changed, substitute old package by new one
1196 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg $PKGS
1197 _ 'The release checksum has changed.'
1198 else
1199 # package not changed, remove new package
1200 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1201 _ 'The release checksum has not changed.'
1202 fi
1205 sed -i "/^${pkg}$/d" $broken
1208 # Update packages database every time after successful build
1210 # packages.info (unsorted, located near to packages)
1211 unset_receipt; . $pack/receipt
1212 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1213 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1214 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1215 cat >> $pi <<EOT
1216 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1217 EOT
1219 # files.list (uncompressed, unsorted, located in $cache)
1220 touch $fl
1221 sed -i "/^$PACKAGE: /d" $fl
1222 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1226 # Return all the names of packages bundled in this receipt
1228 all_names() {
1229 # Get package names from $SPLIT variable
1230 local split=$(echo -n $SPLIT \
1231 | awk '
1232 BEGIN { RS = " "; FS = ":"; }
1233 { print $1; }' \
1234 | tr '\n' ' ')
1235 local split_space=" $split "
1236 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1237 # For receipts v1: $SPLIT may present in the $WANTED package,
1238 # but split packages have their own receipts
1239 echo $PACKAGE
1240 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1241 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1242 # We should build packages in the order defined in the $SPLIT.
1243 echo $split
1244 else
1245 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1246 echo $PACKAGE $split
1247 fi
1251 # v2: pack all packages using compiled files
1253 packall() {
1254 set_paths
1255 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1256 for i in $(all_names); do
1257 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1258 packit $i
1259 done
1260 else
1261 packit
1262 fi
1266 # Reverse "cat" command: prints input lines in the reverse order
1268 tac() {
1269 sed '1!G;h;$!d' $1
1273 # Update chroot with freshly rebuilt package: keep env up-to-date.
1275 update_chroot() {
1276 local PACKAGE="$pkg"
1277 for i in $(all_names); do
1278 if [ -d "$root$INSTALLED/$i" ]; then
1279 . /etc/slitaz/cook.conf
1280 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1281 _ 'Updating %s chroot environment...' "$ARCH"
1282 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1283 cd $PKGS
1284 tazpkg -i "$PKGS/$i-$VERSION$EXTRAVERSION$arch.tazpkg" --forced --root=$root
1285 fi
1286 done
1290 # Install package on --inst or update the chroot.
1292 install_package() {
1293 set_paths
1294 case "$ARCH" in
1295 arm*)
1296 arch="-$ARCH"
1297 root="$CROSS_TREE/sysroot"
1298 ;;
1299 x86_64)
1300 arch="-$ARCH"
1301 ;;
1302 esac
1303 # Install package if requested but skip install if target host doesn't
1304 # match build system or it will break the build chroot.
1305 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1306 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1307 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" ]; then
1308 cd $PKGS
1309 tazpkg -i "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" --forced
1310 else
1311 broken
1312 die 'Unable to install package, build has failed.'
1313 fi
1314 fi
1316 update_chroot
1320 # remove chroot jail
1322 umount_aufs() {
1323 tac ${1}rw/aufs-umount.sh | sh
1324 rm -rf ${1}rw
1325 umount ${1}root
1326 rmdir ${1}r*
1330 # Launch the cook command into a chroot jail protected by aufs.
1331 # The current filesystems are used read-only and updates are
1332 # stored in a separate branch.
1334 try_aufs_chroot() {
1336 base="/dev/shm/aufsmnt$$"
1338 # Can we setup the chroot? Is it already done?
1339 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1340 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1341 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1342 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1343 mkdir ${base}root ${base}rw || return
1345 _ 'Setup aufs chroot...'
1347 # Sanity check
1348 for i in / /proc /sys /dev /dev/shm /home; do
1349 case " $AUFS_MOUNTS " in
1350 *\ $i\ *) ;;
1351 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1352 esac
1353 done
1354 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1355 mkdir -p ${base}root$mnt # for `mount -o bind`
1356 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1357 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1358 _ 'Aufs mount failure'
1359 umount ${base}root
1360 rm -rf ${base}r*
1361 return
1362 fi
1363 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1364 done
1365 trap "umount_aufs ${base}" INT
1367 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1368 status=$?
1370 _ 'Leaving aufs chroot...'
1371 umount_aufs $base
1372 # Install package outside the aufs jail
1373 install_package
1374 exit $status
1378 # Encode predefined XML entities
1380 xml_ent() {
1381 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1385 # Create a XML feed for freshly built packages.
1387 gen_rss() {
1388 pubdate=$(date '+%a, %d %b %Y %X')
1389 cat > $FEEDS/$pkg.xml <<EOT
1390 <item>
1391 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1392 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1393 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1394 <pubDate>$pubdate</pubDate>
1395 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1396 </item>
1397 EOT
1401 # Truncate stdout log file to $1 Mb.
1403 loglimit() {
1404 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1405 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1406 else
1407 tee /dev/stderr
1408 fi
1413 # Receipt functions to ease packaging
1416 get_dev_files() {
1417 action 'Getting standard devel files...'
1418 mkdir -p $fs/usr/lib
1419 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1420 cp -a $install/usr/lib/*a $fs/usr/lib
1421 cp -a $install/usr/include $fs/usr
1422 status
1426 # Function to use in compile_rules() to copy man page from $src to $install
1428 cook_pick_manpages() {
1429 local name section
1430 action 'Copying man pages...'
1432 for i in $@; do
1433 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1434 section=${name##*/}; section=${section##*.}
1435 mkdir -p $install/usr/share/man/man$section
1436 scopy $i $install/usr/share/man/man$section
1437 done
1438 status
1442 # Function to use in compile_rules() to copy documentation from $src to $install
1444 cook_pick_docs() {
1445 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1446 action 'Copying documentation...'
1447 mkdir -p $docdir
1448 cp -r $@ $docdir
1449 chmod -R a+r $docdir
1450 status
1454 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1456 cook_copy_files() {
1457 action 'Copying files...'
1458 cd $install
1459 local i j
1460 IFS=$'\n'
1461 for i in $@; do
1462 for j in $(find . -name $i ! -type d); do
1463 mkdir -p $fs$(dirname ${j#.})
1464 scopy $j $fs$(dirname ${j#.})
1465 done
1466 done
1467 cd - >/dev/null
1468 status
1472 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1474 cook_copy_folders() {
1475 action 'Copying folders...'
1476 cd $install
1477 local i j
1478 IFS=$'\n'
1479 for i in $@; do
1480 for j in $(find . -name $i -type d); do
1481 mkdir -p $fs$(dirname ${j#.})
1482 cp -a $j $fs$(dirname ${j#.})
1483 done
1484 done
1485 cd - >/dev/null
1486 status
1490 # Remove from current $fs files that are already packed (for receipts v2).
1491 # Note: the order in $SPLIT is very important.
1492 # Note 2: working in the current set.
1494 remove_already_packed() {
1495 local i j
1496 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1497 # $pkg may (or may not) be included in the $SPLIT
1498 neighbors=$(
1499 echo $pkg $SPLIT" " \
1500 | awk -F$'\t' -vpkg="$PACKAGE" '
1501 BEGIN { RS = " "; FS = ":"; }
1502 { set[$1] = $2; }
1503 END {
1504 current_set = set[pkg];
1505 for (i in set)
1506 { if (i != pkg && set[i] == current_set) print i; }
1508 ')
1509 IFS=$'\n'
1510 for neighbor in $neighbors; do
1511 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1512 [ -e "$i" ] || continue
1513 while read j; do
1514 [ -f $fs$j -o -h $fs$j ] || continue
1515 rm $fs$j
1516 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1517 done < $i
1518 done
1519 unset IFS
1523 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1524 # (default: 16 and 48) from $install to $fs
1526 cook_copy_icons() {
1527 local sizes=$@ i j ifs="$IFS"
1528 unset IFS
1529 action 'Copying hicolor icons...'
1530 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1531 mkdir -p $fs/usr/share/icons/hicolor
1532 for i in ${sizes:-16 48}; do
1533 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1534 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1535 scopy $install/usr/share/icons/hicolor/$j \
1536 $fs/usr/share/icons/hicolor
1537 done
1538 status
1539 IFS="$ifs"
1543 # Common function to copy files, folders and patterns
1545 copy() {
1546 action 'Copying folders and files...'
1547 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1549 IFS=$'\n'
1550 cd $install
1551 find ! -type d | sed 's|\.||' > $filelist
1552 find -type d | sed 's|\.||' > $folderlist
1554 for i in $@; do
1555 case $i in
1556 @std)
1557 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1558 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1559 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1560 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1561 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1562 /\/share\/devhelp\//d; /\/share\/locale\//d;
1563 /\/share\/bash-completion\//d; /\/etc\/bash_completion\.d\//d; /\/lib\/systemd\//d;
1564 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1565 /\/share\/appdata\//d; /\/share\/help\//d; /\/share\/metainfo\//d; /\/share\/mimelnk\//d;
1566 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1567 /\.so\.dbg$/d;
1568 ' $filelist
1569 ;;
1570 @dev)
1571 # Copy "developer files"
1572 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1573 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1574 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1575 /\.so\.dbg$/p;
1576 ' $filelist
1577 ;;
1578 @rm)
1579 # Quick alias
1580 remove_already_packed
1581 ;;
1582 @ico)
1583 # Quick alias
1584 cook_copy_icons >/dev/null
1585 ;;
1586 */)
1587 # Copy specified folders.
1588 i="${i%/}"
1589 find -type d -path "*/${i#/}" | sed 's|^.||'
1590 ;;
1591 *)
1592 # Copy specified files.
1593 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1594 ;;
1595 esac \
1596 | sort -u \
1597 | while read j; do
1598 mkdir -p $fs$(dirname "$j")
1599 if [ -d "$install$j" ]; then
1600 cp -a "$install$j" $fs$(dirname "$j")
1601 else
1602 scopy "$install$j" $fs$(dirname "$j")
1603 fi
1604 done
1605 # Copy empty directories
1606 case $i in
1607 @std)
1608 while read j; do
1609 case $j in
1610 # skip empty man & doc folders
1611 */man/*|*/doc/*) continue;;
1612 esac
1613 [ -z "$(ls -A "$install$j")" ] || continue
1614 # directory $j is empty
1615 k="$j"
1616 # make 'ladder' from directories, from root dir to $j
1617 # /a /a/b /a/b/c etc.
1618 while :; do
1619 [ -z "$k" ] && break
1620 echo "$k"
1621 k="${k%/*}"
1622 done \
1623 | tac \
1624 | while read k; do
1625 # make dir if it does not exist
1626 if [ ! -d "$fs$k" ]; then
1627 # It's like "copy the directory without its underlying content".
1628 # keep original ownership/permissions, access:
1629 keepIFS="$IFS"; unset IFS
1630 install -d $(stat -c'-o%u -g%g -m%a' "$install$k") "$fs$k"
1631 # keep last-modified date:
1632 touch -r "$install$k" "$fs$k"
1633 IFS="$keepIFS"; unset keepIFS
1634 fi
1635 done
1636 done < $folderlist
1637 ;;
1638 esac
1639 done
1640 cd - >/dev/null
1641 unset IFS
1642 rm $filelist $folderlist
1643 status
1647 # Update split.db once for receipt
1649 update_split_db() {
1650 local db="$cache/split.db"
1651 touch $db
1652 sed -i "/^$pkg\t/d" $db
1653 echo -e "$pkg\t$(all_names)" >> $db
1657 # Recreate whole split.db from scratch
1659 recreate_split_db() {
1660 # Clean
1661 local db="$cache/split.db"
1663 cd $WOK
1664 for pkg in *; do
1665 [ -f "$WOK/$pkg/receipt" ] || continue
1666 unset PACKAGE SPLIT
1667 . $WOK/$pkg/receipt
1668 echo -e "$PACKAGE\t$(all_names)"
1669 done > $db
1673 # Recreate whole maint.db from scratch
1675 recreate_maint_db() {
1676 # Clean
1677 local db="$cache/maint.db"
1679 cd $WOK
1680 for pkg in *; do
1681 [ -f "$WOK/$pkg/receipt" ] || continue
1682 unset PACKAGE MAINTAINER
1683 . $WOK/$pkg/receipt
1684 MAINTAINER=$(echo $MAINTAINER | sed 's|.*<||; s|>.*||')
1685 echo -e "$MAINTAINER\t$PACKAGE"
1686 done | sort > $db
1690 # Put the status to the activity log
1692 put_status() {
1693 # $1: package, $2: status, one of 'Done', 'Failed'
1694 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1695 if [ "$2" == 'Done' ]; then
1696 # overstrike all previous 'Failed' to indicate package is OK now
1697 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1698 fi
1705 # Commands
1708 # cook <package> --deps
1709 [ -n "$deps" ] && {
1710 @@PREFIX@@/libexec/cookutils/deps $1
1711 exit 0
1714 # cook <package> --clean
1715 # cook <package> -c
1716 [ -n "$clean" -o "$2" == '-c' ] && {
1717 action 'Cleaning "%s"' "$1"
1718 cd $WOK/$1; rm -rf install taz source
1719 status; newline
1720 touch $activity # update $activity -> something changed -> update webstat
1721 exit 0
1724 # cook <package> --getsrc
1725 # cook <package> -gs
1726 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1727 title 'Getting source for "%s"' "$1"
1728 receipt="$WOK/$pkg/receipt"
1729 check_pkg_in_wok
1730 unset_receipt
1731 . $receipt
1732 get_source
1733 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1734 exit 0
1737 # cook <package> --block
1738 # cook <package> -b
1739 [ -n "$block" -o "$2" == '-b' ] && {
1740 action 'Blocking package "%s"' "$1"
1741 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1742 status; newline
1743 touch $activity
1744 exit 0
1747 # cook <package> --unblock
1748 # cook <package> -ub
1749 [ -n "$unblock" -o "$2" == '-ub' ] && {
1750 action 'Unblocking package "%s"' "$1"
1751 sed -i "/^$1$/d" $blocked
1752 status; newline
1753 touch $activity
1754 exit 0
1760 case "$1" in
1761 usage|help|-u|-h)
1762 usage ;;
1764 list-wok)
1765 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1766 cd $WOK
1767 if [ "$ARCH" != 'i486' ]; then
1768 count=0
1769 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1770 do
1771 unset HOST_ARCH
1772 . ./$pkg
1773 count=$(($count + 1))
1774 colorize 34 "$PACKAGE"
1775 done
1776 else
1777 count=$(ls | wc -l)
1778 ls -1
1779 fi
1780 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1781 ;;
1783 activity)
1784 cat $activity ;;
1786 search)
1787 # Just a simple search function, we don't need more actually.
1788 query="$2"
1789 title 'Search results for "%s"' "$query"
1790 cd $WOK; ls -1 | grep "$query"
1791 footer ;;
1793 setup)
1794 # Setup a build environment
1795 check_root
1796 _ 'Cook: setup environment' | log
1797 title 'Setting up your environment'
1798 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1799 cd $SLITAZ
1800 init_db_files
1801 _ 'Checking for packages to install...'
1802 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1803 # ARCH-setup or 'cross check' should be used before: cook setup
1804 case "$ARCH" in
1805 arm*|x86_64)
1806 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1807 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1808 . /etc/slitaz/cross.conf ;;
1809 esac
1810 for pkg in $SETUP_PKGS; do
1811 if [ -n "$forced" ]; then
1812 tazpkg -gi $pkg --forced
1813 else
1814 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1815 fi
1816 done
1818 # Handle --options
1819 case "$2" in
1820 --wok) hg clone $WOK_URL wok || exit 1 ;;
1821 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1822 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1823 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1824 esac
1826 # SliTaz group and permissions
1827 if ! grep -q ^slitaz /etc/group; then
1828 _ 'Adding group "%s"' 'slitaz'
1829 addgroup slitaz
1830 fi
1831 _ 'Setting permissions for group "%s"...' 'slitaz'
1832 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1833 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1834 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1836 *-setup)
1837 # Setup for cross compiling.
1838 arch="${1%-setup}"
1839 check_root
1840 . /etc/slitaz/cook.conf
1841 for pkg in $CROSS_SETUP; do
1842 if [ -n "$forced" ]; then
1843 tazpkg -gi $pkg --forced
1844 else
1845 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1846 fi
1847 done
1849 _ 'Cook: setup %s cross environment' "$arch" | log
1850 title 'Setting up your %s cross environment' "$arch"
1851 init_db_files
1852 sed -i \
1853 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1854 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1855 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1856 /etc/slitaz/cook.conf
1857 case "$arch" in
1858 arm)
1859 flags='-O2 -march=armv6'
1860 host="$ARCH-slitaz-linux-gnueabi" ;;
1861 armv6hf)
1862 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1863 host="$ARCH-slitaz-linux-gnueabi" ;;
1864 armv7)
1865 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1866 host="$ARCH-slitaz-linux-gnueabi" ;;
1867 x86_64)
1868 flags='-O2 -mtune=generic -pipe'
1869 host="$ARCH-slitaz-linux" ;;
1870 esac
1871 sed -i \
1872 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1873 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1874 . /etc/slitaz/cook.conf
1875 sysroot="$CROSS_TREE/sysroot"
1876 tools="/cross/$arch/tools"
1877 root="$sysroot"
1878 # L10n: keep the same width of translations to get a consistent view
1879 _ 'Target arch : %s' "$ARCH"
1880 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1881 _ 'Build flags : %s' "$flags"
1882 _ 'Arch sysroot : %s' "$sysroot"
1883 _ 'Tools prefix : %s' "$tools/bin"
1884 # Tell the packages manager where to find packages.
1885 _ 'Packages DB : %s' "$root$DB"
1886 mkdir -p $root$INSTALLED
1887 cd $root$DB; rm -f *.bak
1888 for list in packages.list packages.desc packages.equiv packages.md5; do
1889 rm -f $list
1890 ln -s $SLITAZ/packages/$list $list
1891 done
1892 # We must have the cross compiled glibc-base installed or default
1893 # i486 package will be used as dep by tazpkg and then break the
1894 # cross environment
1895 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1896 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1897 fi
1898 # Show GCC version or warn if not yet compiled.
1899 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1900 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1901 else
1902 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1903 _ 'Run "%s" to cook a toolchain' 'cross compile'
1904 fi
1905 footer ;;
1907 test)
1908 # Test a cook environment.
1909 _ 'Cook test: testing the cook environment' | log
1910 [ ! -d "$WOK" ] && exit 1
1911 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1912 cook cooktest ;;
1914 new)
1915 # Create the package folder and an empty receipt.
1916 pkg="$2"
1917 [ -z "$pkg" ] && usage
1918 newline
1919 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1921 action 'Creating folder "%s"' "$WOK/$pkg"
1922 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1924 action 'Preparing the package receipt...'
1925 cp $DATA/receipt .
1926 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1927 status; newline
1929 # Interactive mode, asking and seding.
1930 case "$3" in
1931 --interactive|-x)
1932 _ 'Entering interactive mode...'
1933 separator
1934 _ 'Package : %s' "$pkg"
1936 _n 'Version : ' ; read answer
1937 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1939 _n 'Category : ' ; read answer
1940 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1942 # L10n: Short description
1943 _n 'Short desc : ' ; read answer
1944 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1946 _n 'Maintainer : ' ; read answer
1947 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1949 _n 'License : ' ; read answer
1950 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1952 _n 'Web site : ' ; read answer
1953 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1954 newline
1956 # Wget URL.
1957 _ 'Wget URL to download source tarball.'
1958 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1959 _n 'Wget url : ' ; read answer
1960 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1962 # Ask for a stuff dir.
1963 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1964 if [ "$?" -eq 0 ]; then
1965 action 'Creating the stuff directory...'
1966 mkdir $WOK/$pkg/stuff; status
1967 fi
1969 # Ask for a description file.
1970 confirm "$(_n 'Are you going to write a description? (y/N)')"
1971 if [ "$?" -eq 0 ]; then
1972 action 'Creating the "%s" file...' 'description.txt'
1973 touch $WOK/$pkg/description.txt; status
1974 fi
1976 footer "$(_ 'Receipt is ready to use.')" ;;
1977 esac ;;
1979 list)
1980 # Cook a list of packages (better use the Cooker since it will order
1981 # packages before executing cook).
1982 check_root
1983 [ -z "$2" ] && die 'No list in argument.'
1984 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1986 _ 'Starting cooking the list "%s"' "$2" | log
1988 while read pkg; do
1989 cook $pkg || broken
1990 done < $2
1991 ;;
1993 clean-wok)
1994 check_root
1995 newline; action 'Cleaning all packages files...'
1996 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1997 status; newline ;;
1999 clean-src)
2000 check_root
2001 newline; action 'Cleaning all packages sources...'
2002 rm -rf $WOK/*/source
2003 status; newline ;;
2005 uncook)
2006 cd $WOK
2007 count=0
2008 title 'Checking for uncooked packages'
2010 for i in *; do
2011 unset HOST_ARCH EXTRAVERSION
2012 [ ! -e $i/receipt ] && continue
2013 . ./$i/receipt
2014 # Source cooked pkg receipt to get EXTRAVERSION
2015 if [ -d "$WOK/$i/taz" ]; then
2016 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
2017 . ./receipt; cd $WOK
2018 fi
2019 case "$ARCH" in
2020 i486)
2021 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
2022 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
2023 count=$(($count + 1))
2024 colorize 34 "$i"
2025 fi ;;
2026 arm*)
2027 # Check only packages included in arch
2028 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
2029 # *.tazpkg
2030 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
2031 count=$(($count + 1))
2032 colorize 34 "$i"
2033 fi
2034 fi ;;
2035 esac
2036 done
2038 if [ "$count" -gt 0 ]; then
2039 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
2040 else
2041 _ 'All packages are cooked :-)'
2042 newline
2043 fi
2044 ;;
2046 pkgdb)
2047 # Create suitable packages list for TazPkg and only for built packages
2048 # as well as flavors files for TazLiTo. We don't need logs since we do it
2049 # manually to ensure everything is fine before syncing the mirror.
2050 recreate_split_db
2051 recreate_maint_db
2052 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
2053 ;;
2055 splitdb)
2056 # File split.db is useful for searching for split packages.
2057 recreate_split_db
2058 ;;
2060 maintdb)
2061 # File maint.db is useful for searching maintainer's packages.
2062 recreate_maint_db
2063 ;;
2065 *)
2066 # Just cook and generate a package.
2067 check_root
2068 time=$(date +%s)
2069 pkg="$1"
2070 [ -z "$pkg" ] && usage
2072 # Search last successful cook time in all logs from newer to older
2073 for i in '' $(seq 0 9 | sed 's|^|.|'); do
2074 [ -f "$LOGS/$pkg.log$i" ] || break
2075 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
2076 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
2077 [ -n "$lastcooktime" ] && break
2078 done
2080 receipt="$WOK/$pkg/receipt"
2081 check_pkg_in_wok
2082 newline
2084 unset inst
2085 unset_receipt
2086 . $receipt
2088 # Handle cross compilation.
2089 case "$ARCH" in
2090 arm*)
2091 if [ -z "$HOST_ARCH" ]; then
2092 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2093 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2094 _ 'cook: %s' "$error"
2095 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2096 _ 'Cook skip: %s' "$error" | log
2097 newline
2098 broken; exit 1
2099 fi ;;
2100 esac
2102 # Some packages are not included in some arch or fail to cross compile.
2103 : ${HOST_ARCH=$ARCH}
2104 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2105 # Handle arm{v6hf,v7,..}
2106 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2107 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2108 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2109 _ 'cook: %s' "error"
2110 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2111 _ 'Cook skip: %s' "$error" | log
2112 sed -i "/^${pkg}$/d" $broken
2113 newline
2114 exit 0
2115 fi
2117 # Skip blocked, 3 lines also for the Cooker.
2118 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
2119 die 'Package "%s" is blocked' "$pkg"
2121 try_aufs_chroot "$@"
2123 # Log and source receipt.
2124 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
2125 echo "cook:$pkg" > $command
2127 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2129 while read cmd duration start; do
2130 [ $(($start + $duration)) -lt $(date +%s) ] &&
2131 echo "sed -i '/^$cmd $duration/d' $cooktime"
2132 done < $cooktime | sh
2134 # Display and log info if cook process stopped.
2135 # FIXME: gettext not working (in single quotes) here!
2136 trap '_ "\n\nCook stopped: control-C\n\n" | \
2137 tee -a $LOGS/$pkg.log' INT
2139 update_split_db
2141 # Handle --options
2142 case "$2" in
2143 --install|-i)
2144 inst='yes' ;;
2146 --pack)
2147 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2148 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2149 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -f $LOGS/$pkg-pack.log
2150 sed -i '$ s|$| (packing)|' $activity
2151 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2152 clean_log "$pkg-pack"
2153 time=$(($(date +%s) - $time))
2154 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2155 put_status $pkg Done
2156 rm -f $command
2157 exit 0 ;;
2159 --trials|-t)
2160 trials='yes' ;;
2161 esac
2163 # Rotate log
2164 for i in $(seq 9 -1 1); do
2165 j=$(($i - 1))
2166 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2167 done
2168 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2170 # Check if wanted is built now so we have separate log files.
2171 for wanted in $WANTED ; do
2172 if grep -q "^$wanted$" $blocked; then
2173 broken
2174 rm -f $command
2175 die 'WANTED package "%s" is blocked' "$wanted"
2176 fi
2177 if grep -q "^$wanted$" $broken; then
2178 broken
2179 rm -f $command
2180 die 'WANTED package "%s" is broken' "$wanted"
2181 fi
2182 if [ ! -d "$WOK/$wanted/install" ]; then
2183 cook "$wanted" || { broken; exit 1; }
2184 fi
2185 done
2187 # Cook and pack or exit on error and log everything.
2188 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2189 rq=$? # the return code of `cookit $@` above command
2191 # Remove build dependencies both when `cookit` done or fail
2192 remove_deps | tee -a $LOGS/$pkg.log
2193 timestamp job27 # removing bdeps
2194 cookit_quality
2195 timestamp job28 # checking quality
2197 # Log and stop if `cookit` fails
2198 if [ $rq -eq 1 ]; then
2199 debug_info | tee -a $LOGS/$pkg.log
2200 put_status $pkg Failed
2201 rm -f $command
2202 broken; exit 1
2203 fi
2205 # Proceed only if `cookit` return code is zero-OK
2206 # If instant-pack if specified, then packages already packed in the cookit()
2207 [ "${COOKOPTS/instant-pack/}" == "$COOKOPTS" ] &&
2208 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2209 timestamp job29 # packing
2211 clean_log
2213 # Exit if any error in packing.
2214 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2215 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2216 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2217 debug_info | tee -a $LOGS/$pkg.log
2218 put_status $pkg Failed
2219 rm -f $command
2220 broken; exit 1
2221 fi
2223 # Create an XML feed
2224 gen_rss
2226 # Time and summary
2227 time=$(($(date +%s) - $time))
2228 summary | tee -a $LOGS/$pkg.log
2229 newline
2231 # We may want to install/update (outside aufs jail!).
2232 [ -s /aufs-umount.sh ] || install_package
2234 put_status $pkg Done
2236 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2237 # If you want automation, use the Cooker Build Bot.
2238 rm -f $command
2239 timestamp job30 # misc. final operations
2240 store_timestats
2242 sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
2243 | sed '/^Build/d; s|Removing: ||' \
2244 | tr ' ' '\n' \
2245 | sed '/^$/d' \
2246 > $WOK/$pkg/.bdeps
2248 ;;
2249 esac
2251 exit 0