cookutils view cook @ rev 1051

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