cookutils view cook @ rev 1070
lighttpd/index.cgi: tiny edits (again)
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed Jun 06 13:39:19 2018 +0300 (2018-06-06) |
parents | 96366a824c1e |
children | 23700c523fdb |
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 version=$(awk -F$'\t' -vpkg="$i" '{
335 if ($1 == pkg) {print $2; exit}
336 }' "$PKGS/packages.info")
337 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
338 pkgname="$i-$version$EXTRAVERSION$arch.tazpkg"
339 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
340 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
341 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
342 pkgi=$((pkgi + 1))
343 done
344 separator
345 }
348 # Display debugging error info.
350 debug_info() {
351 title 'Debug information'
352 # L10n: specify your format of date and time (to help: man date)
353 # L10n: not bad one is '+%x %R'
354 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
355 if [ -n "$time" ]; then
356 times="$(($(date +%s) - $time))"
357 _ 'Wasted time : %s' "$(disp_time "$times")"
358 fi
359 for error in \
360 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
361 'error:' 'fatal error:' 'undefined reference to' \
362 'Unable to connect to' 'link: cannot find the library' \
363 'CMake Error' ': No such file or directory' \
364 'Could not read symbols: File in wrong format'
365 do
366 # format "line number:line content"
367 fgrep -n "$error" $LOGS/$pkg.log
368 done > $LOGS/$pkg.log.debug_info 2>&1
369 # sort by line number, remove duplicates
370 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
371 rm -f $LOGS/$pkg.log.debug_info
372 footer
373 }
376 # A bit smarter function than the classic `cp` command
378 scopy() {
379 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
380 cp -a "$1" "$2" # copy generic files
381 else
382 cp -al "$1" "$2" # copy hardlinks
383 fi
384 }
387 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
388 # We use standard paths, so some packages need to copy these files with the
389 # receipt and genpkg_rules.
390 # This function executes inside the packaging process, before compressor call.
392 copy_generic_files() {
393 # Proceed only for "main" package (for v2), and for any packages (v1)
394 [ "$pkg" == "$PACKAGE" ] || return 0
396 # $LOCALE is set in cook.conf
397 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
398 if [ -d "$install/usr/share/locale" ]; then
399 mkdir -p "$fs/usr/share/locale"
400 for i in $LOCALE; do
401 if [ -d "$install/usr/share/locale/$i" ]; then
402 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
403 fi
404 done
405 fi
406 fi
408 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
409 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
410 if [ -d "$install/usr/share/pixmaps" ]; then
411 mkdir -p "$fs/usr/share/pixmaps"
412 for i in png xpm; do
413 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
414 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
415 done
416 fi
417 fi
419 # Desktop entry (.desktop).
420 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
421 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
422 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
423 mkdir -p "$fs/usr/share"
424 cp -r $install/usr/share/applications $fs/usr/share
425 fi
426 fi
427 }
430 # Copy pixmaps, desktop files and licenses from $stuff to $install.
431 # This function executes after the main compile_rules() is done.
433 copy_generic_stuff() {
434 # Custom or homemade PNG pixmap can be in stuff.
435 if [ -f "$stuff/$PACKAGE.png" ]; then
436 mkdir -p $install/usr/share/pixmaps
437 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
438 fi
440 # Homemade desktop file(s) can be in stuff.
441 if [ -d "$stuff/applications" ]; then
442 mkdir -p $install/usr/share
443 cp -r $stuff/applications $install/usr/share
444 fi
445 if [ -f "$stuff/$PACKAGE.desktop" ]; then
446 mkdir -p $install/usr/share/applications
447 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
448 fi
450 # Add custom licenses
451 if [ -d "$stuff/licenses" ]; then
452 mkdir -p $install/usr/share/licenses
453 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
454 fi
455 }
458 # Update installed.cook.diff
460 update_installed_cook_diff() {
461 # If a cook failed deps are removed.
462 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
463 cd $CACHE
464 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
465 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
466 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
467 }
470 # Remove installed deps.
472 remove_deps() {
473 # Now remove installed build deps.
474 diff='/tmp/installed.cook.diff'
475 [ -s "$diff" ] || return
477 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
478 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
479 newline
480 _n 'Build dependencies to remove:'; echo " $nb"
481 [ -n "$root" ] && echo "root=\"$root\""
482 {
483 _n 'Removing:'
484 for dep in $deps; do
485 echo -n " $dep"
486 # Do not waste time uninstalling the packages if we are inside
487 # aufs chroot - unmounting chroot will "uninstall" all packages.
488 [ -s /aufs-umount.sh ] ||
489 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
490 done
491 } | busybox fold -sw80
492 newline; newline
493 # Keep the last diff for debug and info.
494 mv -f $diff $CACHE/installed.diff
495 }
498 # Automatically patch the sources.
500 patchit() {
501 [ -f "$stuff/patches/series" ] || return
503 IFS=$'\n'
504 while read i; do
505 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
506 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
507 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
508 *) patchopts='-Np1';;
509 esac
510 [ -n "$patchname" ] || continue # allow empty lines
511 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
512 newline
513 _ 'Applying patch %s' "$patchname"
514 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
515 touch $src/done.$patchname
516 done < $stuff/patches/series
517 newline
518 unset IFS
519 }
522 # Check source tarball integrity.
524 check_integrity() {
525 for i in sha1 sha3 sha256 sha512 md5; do
526 I=$(echo $i | tr 'a-z' 'A-Z')
527 eval sum=\$TARBALL_$I
528 if [ -n "$sum" ]; then
529 newline
530 _ 'Checking %ssum of source tarball...' "$i"
531 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
532 fi
533 done
534 newline
535 }
538 # Misc fix functions
540 fix() {
541 case $1 in
542 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
543 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
544 ld)
545 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
546 ;;
547 libtool)
548 if [ -e 'libtool' ]; then
549 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
550 else
551 echo "fix libtool: warning: libtool absent, nothing to fix."
552 fi
553 ;;
554 math)
555 # fix C++ math issue introduced in Glibc 2.26:
556 # error: '__builtin_isnan' is not a member of 'std'
557 # if (std::isnan(N)) {
558 # ^
559 find $src -type f -exec sed -i '
560 s|std::signbit|__builtin_signbit|g;
561 s|std::isnan|__builtin_isnan|g;
562 s|std::isinf|__builtin_isinf_sign|g;
563 s|std::isfinite|__builtin_isfinite|g;
564 s|std::isnormal|__builtin_isnormal|g
565 ' '{}' \;
566 ;;
567 symlinks)
568 # make absolute symlinks relative
569 echo "fix symlinks"
570 local ifs="$IFS" link target
571 IFS=$'\n'
572 # step 1: fast job, prefix all the absolute symlinks with "$install"
573 for link in $(find $install -type l); do
574 target="$(readlink $link)"
575 case "$target" in
576 /*) ln -sfv "$install$target" "$link";;
577 esac
578 done
579 IFS="$ifs"
580 # step 2: fine tuning, make symlinks relative
581 tazpkg -gi --quiet --local --cookmode symlinks
582 symlinks -cr $install
583 ;;
584 esac
585 }
588 # Store timestamps, log jobs length
590 timestamp() {
591 local ts_file="$WOK/$pkg/.ts"
592 local curr_ts=$(date '+%s')
593 case $1 in
594 init)
595 rm $ts_file 2>/dev/null
596 echo $curr_ts > $prev_ts
597 ;;
598 job*)
599 # calculate time from the last timestamp
600 echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
601 echo $curr_ts > $prev_ts
602 ;;
603 sets)
604 echo "sets='$2'" >> $ts_file
605 ;;
606 esac
607 }
610 # Store time statsistics to the cache
612 store_timestats() {
613 # see doc/timestats.txt for file format
614 temp=$(mktemp)
615 {
616 for i in $(seq 1 30); do echo "job$i=0"; done
617 cat $WOK/$pkg/.ts
618 echo -n 'total=$(( 0'
619 for i in $(seq 1 30); do echo -n " + job$i"; done
620 echo ' ))'
621 } > $temp
622 . $temp
623 {
624 echo -n "$pkg $sets "
625 for i in $(seq 1 30); do echo -n "$((job$i)) "; done
626 echo "$total"
627 } >> /home/slitaz/cache/timestats
628 rm $temp $WOK/$pkg/.ts # clean
629 }
632 # The main cook function.
634 cookit() {
635 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
636 _ 'ERROR: Broken setup. Abort.'
637 return
638 fi
640 title 'Cook: %s' "$PACKAGE $VERSION"
641 set_paths
642 timestamp init # the very start
644 # Handle cross-tools.
645 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
646 case "$ARCH" in
647 arm*|x86_64)
648 # CROSS_COMPILE is used by at least Busybox and the kernel to set
649 # the cross-tools prefix. Sysroot is the root of our target arch
650 sysroot="$CROSS_TREE/sysroot"
651 tools="$CROSS_TREE/tools"
652 # Set root path when cross compiling. ARM tested but not x86_64
653 # When cross compiling we must install build deps in $sysroot.
654 arch="-$ARCH"
655 root="$sysroot"
656 _ '%s sysroot: %s' "$ARCH" "$sysroot"
657 _ 'Adding "%s" to PATH' "$tools/bin"
658 export PATH="$PATH:$tools/bin"
659 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
660 export CROSS_COMPILE="$HOST_SYSTEM-"
661 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
662 if [ "$ARCH" == 'x86_64' ]; then
663 export CC="$HOST_SYSTEM-gcc -m64"
664 export CXX="$HOST_SYSTEM-g++ -m64"
665 else
666 export CC="$HOST_SYSTEM-gcc"
667 export CXX="$HOST_SYSTEM-g++"
668 fi
669 export AR="$HOST_SYSTEM-ar"
670 export AS="$HOST_SYSTEM-as"
671 export RANLIB="$HOST_SYSTEM-ranlib"
672 export LD="$HOST_SYSTEM-ld"
673 export STRIP="$HOST_SYSTEM-strip"
674 export LIBTOOL="$HOST_SYSTEM-libtool"
675 ;;
676 esac
678 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
680 cd $pkgdir
681 [ -z "$continue" ] && rm -rf source 2>/dev/null
682 rm -rf install taz 2>/dev/null
684 # Disable -pipe if less than 512 MB free RAM.
685 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
686 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
687 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
688 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
689 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
690 fi
691 unset free
693 # Export flags and path to be used by make and receipt.
694 DESTDIR="$pkgdir/install"
695 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
696 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
697 LDFLAGS
699 timestamp job1 # pre-checks
701 # BUILD_DEPENDS may vary depending on the ARCH
702 case "$ARCH" in
703 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
704 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
705 esac
707 # Check for build deps and handle implicit depends of *-dev packages
708 # (ex: libusb-dev :: libusb).
709 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
710 # touch $CACHE/installed.local $CACHE/installed.web
711 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
712 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
714 # Get the list of installed packages
715 cd $root$INSTALLED; ls > $CACHE/installed.list
717 for action in check install; do
718 for dep in $BUILD_DEPENDS; do
719 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
720 for i in $dep $implicit; do
721 # Skip if package already installed
722 [ -f "$root$INSTALLED/$i/receipt" ] && continue
724 case $action in
725 check)
726 # Search for local package or local provided-package
727 name=$(awk -F$'\t' -vpkg="$i" '{
728 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
729 }' "$PKGS/packages.info")
730 if [ -z "$name" ]; then
731 # Search for package in mirror
732 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
733 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
734 fi
735 ;;
736 install)
737 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
738 ;;
739 esac
740 done
741 done
742 done
744 # # Have we a missing build dep to cook?
745 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
746 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
747 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
748 # for i in $(uniq $CACHE/missing.dep); do
749 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
750 # tee -a $LOGS/$PACKAGE.log.$$
751 # # programmers: next two messages are exact copy from remove_deps()
752 # togrep1=$(_n 'Build dependencies to remove:')
753 # togrep2=$(_n 'Removing:')
754 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
755 # fgrep $togrep1 $LOGS/$i.log && \
756 # fgrep $togrep2 $LOGS/$i.log && newline) | \
757 # tee -a $LOGS/$PACKAGE.log.$$ && break
758 # done
759 # rm -f $CACHE/missing.dep
760 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
761 # fi
762 #
763 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
764 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
765 # # missing dep in cached file.
766 # lerror=$(_n 'ERROR')
767 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
768 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
769 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
770 # broken; exit 1
771 # fi
772 #
773 # # Install local packages: package-version$arch
774 # cd $PKGS
775 # for i in $(uniq $CACHE/installed.local); do
776 # # _ 'Installing dep (pkg/local): %s' "$i"
777 # tazpkg install $i --root=$root --local --quiet --cookmode
778 # done
779 #
780 # # Install web or cached packages (if mirror is set to $PKGS we only
781 # # use local packages).
782 # for i in $(uniq $CACHE/installed.web); do
783 # # _ 'Installing dep (web/cache): %s' "$i"
784 # tazpkg get-install $i --root=$root --local --quiet --cookmode
785 # done
787 update_installed_cook_diff
789 timestamp job2 # installing bdeps
791 # Get source tarball and make sure we have source dir named:
792 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
793 # tarball if it exists.
794 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
795 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
796 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
797 LZMA_SRC=''
798 else
799 get_source || { broken; exit 1; }
800 fi
801 fi
802 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
803 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
804 if ! extract_source ; then
805 get_source
806 extract_source || { broken; exit 1; }
807 fi
808 if [ -n "$LZMA_SRC" ]; then
809 cd $pkgdir/source
810 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
811 mv tmp tmp-1; mkdir tmp
812 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
813 fi
814 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
815 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
816 fi
817 fi
819 cd $pkgdir/source/tmp
820 # Some archives are not well done and don't extract to one dir (ex lzma).
821 files=$(ls | wc -l)
822 [ "$files" -eq 1 -a -d "$(ls)" ] &&
823 mv * ../$PACKAGE-$VERSION
824 [ "$files" -eq 1 -a -f "$(ls)" ] &&
825 mkdir -p ../$PACKAGE-$VERSION &&
826 mv * ../$PACKAGE-$VERSION/$TARBALL
827 [ "$files" -gt 1 ] &&
828 mkdir -p ../$PACKAGE-$VERSION &&
829 mv * ../$PACKAGE-$VERSION
830 cd ..; rm -rf tmp
831 fi
833 # Check md5sum (or similar) for sources tarball
834 check_integrity
836 # Libtool shared libs path hack.
837 case "$ARCH" in
838 arm*) cross libhack ;;
839 esac
841 timestamp job3 # get/unpack src tarball
843 # Compiling all the sets
844 if grep -q ^compile_rules $receipt; then
845 _ 'Executing: %s' 'compile_rules'
846 echo "CFLAGS : $CFLAGS"
847 echo "LDFLAGS : $LDFLAGS"
848 [ -d "$src" ] && cd $src
849 patchit
851 timestamp job4 # patching
853 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
854 SETS=$(echo $SPLIT \
855 | awk '
856 BEGIN { RS = " "; FS = ":"; }
857 { print $2; }' \
858 | sort -u \
859 | tr '\n' ' ')
860 SETS=${SETS% } # normalize space
861 # Prepare specified source sets using patched sources
862 [ -n "$SETS" ] &&
863 for set in $SETS; do
864 echo "Preparing set $set" # debug
865 cp -a $src $src-$set
866 done
868 timestamp job5 # preparing sets
869 timestamp sets "$SETS"
871 job_counter='6'
872 for SET in '' $SETS; do
873 # Switch to the specified source set
874 set_paths
875 local suffix=''
876 [ -n "$SET" ] && suffix="-$SET"
877 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
878 export install="$WOK/$pkg/install$suffix"
879 export DESTDIR="$install"
881 if [ -n "$SETS" ]; then
882 if [ -n "$SET" ]; then
883 title "Switching to the set '$SET'"
884 else
885 title "Switching to the default set"
886 fi
887 echo "src : $src"
888 echo "install: $install"
889 fi
890 [ -d "$src" ] && cd $src # packages without sources exists
891 echo
893 [ -d "$install" ] && rm -r $install
894 #mkdir -p $install
896 compile_rules $@ || { broken; exit 1; }
898 # Stay compatible with _pkg
899 [ -d "$src/_pkg" ] && mv $src/_pkg $install
901 copy_generic_stuff
903 timestamp job$job_counter # compiling (set '$SET')
905 # Actions to do after compiling the package
906 # Skip all for split packages (already done in main package)
907 if [ -z "$WANTED" ]; then
908 footer
909 export COOKOPTS ARCH install
910 @@PREFIX@@/libexec/cookutils/compressor install
911 timestamp job$(($job_counter + 1)) # compressing (set '$SET')
912 fi
914 job_counter=$(($job_counter + 2))
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 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")"
1109 }
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
1223 }
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 $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
1248 }
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
1263 }
1266 # Reverse "cat" command: prints input lines in the reverse order
1268 tac() {
1269 sed '1!G;h;$!d' $1
1270 }
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
1287 }
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
1317 }
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*
1327 }
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
1375 }
1378 # Encode predefined XML entities
1380 xml_ent() {
1381 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1382 }
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
1398 }
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
1409 }
1412 #
1413 # Receipt functions to ease packaging
1414 #
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
1423 }
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
1439 }
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
1451 }
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
1469 }
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
1487 }
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; }
1507 }
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
1520 }
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"
1540 }
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;
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
1644 }
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
1654 }
1657 # Recreate whole split.db from scratch
1659 recreate_split_db() {
1660 # Clean
1661 local db="$cache/split.db"
1662 touch $db
1663 > $db
1665 cd $WOK
1666 for pkg in *; do
1667 [ -f "$WOK/$pkg/receipt" ] || continue
1668 unset PACKAGE SPLIT
1669 . $WOK/$pkg/receipt
1670 echo -e "$PACKAGE\t$(all_names)" >> $db
1671 done
1672 }
1675 # Put the status to the activity log
1677 put_status() {
1678 # $1: package, $2: status, one of 'Done', 'Failed'
1679 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1680 if [ "$2" == 'Done' ]; then
1681 # overstrike all previous 'Failed' to indicate package is OK now
1682 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1683 fi
1684 }
1689 #
1690 # Commands
1691 #
1693 # cook <package> --deps
1694 [ -n "$deps" ] && {
1695 @@PREFIX@@/libexec/cookutils/deps $1
1696 exit 0
1697 }
1699 # cook <package> --clean
1700 # cook <package> -c
1701 [ -n "$clean" -o "$2" == '-c' ] && {
1702 action 'Cleaning "%s"' "$1"
1703 cd $WOK/$1; rm -rf install taz source
1704 status; newline
1705 touch $activity # update $activity -> something changed -> update webstat
1706 exit 0
1707 }
1709 # cook <package> --getsrc
1710 # cook <package> -gs
1711 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1712 title 'Getting source for "%s"' "$1"
1713 receipt="$WOK/$pkg/receipt"
1714 check_pkg_in_wok
1715 unset_receipt
1716 . $receipt
1717 get_source
1718 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1719 exit 0
1720 }
1722 # cook <package> --block
1723 # cook <package> -b
1724 [ -n "$block" -o "$2" == '-b' ] && {
1725 action 'Blocking package "%s"' "$1"
1726 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1727 status; newline
1728 touch $activity
1729 exit 0
1730 }
1732 # cook <package> --unblock
1733 # cook <package> -ub
1734 [ -n "$unblock" -o "$2" == '-ub' ] && {
1735 action 'Unblocking package "%s"' "$1"
1736 sed -i "/^$1$/d" $blocked
1737 status; newline
1738 touch $activity
1739 exit 0
1740 }
1745 case "$1" in
1746 usage|help|-u|-h)
1747 usage ;;
1749 list-wok)
1750 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1751 cd $WOK
1752 if [ "$ARCH" != 'i486' ]; then
1753 count=0
1754 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1755 do
1756 unset HOST_ARCH
1757 . ./$pkg
1758 count=$(($count + 1))
1759 colorize 34 "$PACKAGE"
1760 done
1761 else
1762 count=$(ls | wc -l)
1763 ls -1
1764 fi
1765 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1766 ;;
1768 activity)
1769 cat $activity ;;
1771 search)
1772 # Just a simple search function, we don't need more actually.
1773 query="$2"
1774 title 'Search results for "%s"' "$query"
1775 cd $WOK; ls -1 | grep "$query"
1776 footer ;;
1778 setup)
1779 # Setup a build environment
1780 check_root
1781 _ 'Cook: setup environment' | log
1782 title 'Setting up your environment'
1783 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1784 cd $SLITAZ
1785 init_db_files
1786 _ 'Checking for packages to install...'
1787 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1788 # ARCH-setup or 'cross check' should be used before: cook setup
1789 case "$ARCH" in
1790 arm*|x86_64)
1791 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1792 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1793 . /etc/slitaz/cross.conf ;;
1794 esac
1795 for pkg in $SETUP_PKGS; do
1796 if [ -n "$forced" ]; then
1797 tazpkg -gi $pkg --forced
1798 else
1799 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1800 fi
1801 done
1803 # Handle --options
1804 case "$2" in
1805 --wok) hg clone $WOK_URL wok || exit 1 ;;
1806 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1807 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1808 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1809 esac
1811 # SliTaz group and permissions
1812 if ! grep -q ^slitaz /etc/group; then
1813 _ 'Adding group "%s"' 'slitaz'
1814 addgroup slitaz
1815 fi
1816 _ 'Setting permissions for group "%s"...' 'slitaz'
1817 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1818 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1819 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1821 *-setup)
1822 # Setup for cross compiling.
1823 arch="${1%-setup}"
1824 check_root
1825 . /etc/slitaz/cook.conf
1826 for pkg in $CROSS_SETUP; do
1827 if [ -n "$forced" ]; then
1828 tazpkg -gi $pkg --forced
1829 else
1830 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1831 fi
1832 done
1834 _ 'Cook: setup %s cross environment' "$arch" | log
1835 title 'Setting up your %s cross environment' "$arch"
1836 init_db_files
1837 sed -i \
1838 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1839 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1840 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1841 /etc/slitaz/cook.conf
1842 case "$arch" in
1843 arm)
1844 flags='-O2 -march=armv6'
1845 host="$ARCH-slitaz-linux-gnueabi" ;;
1846 armv6hf)
1847 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1848 host="$ARCH-slitaz-linux-gnueabi" ;;
1849 armv7)
1850 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1851 host="$ARCH-slitaz-linux-gnueabi" ;;
1852 x86_64)
1853 flags='-O2 -mtune=generic -pipe'
1854 host="$ARCH-slitaz-linux" ;;
1855 esac
1856 sed -i \
1857 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1858 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1859 . /etc/slitaz/cook.conf
1860 sysroot="$CROSS_TREE/sysroot"
1861 tools="/cross/$arch/tools"
1862 root="$sysroot"
1863 # L10n: keep the same width of translations to get a consistent view
1864 _ 'Target arch : %s' "$ARCH"
1865 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1866 _ 'Build flags : %s' "$flags"
1867 _ 'Arch sysroot : %s' "$sysroot"
1868 _ 'Tools prefix : %s' "$tools/bin"
1869 # Tell the packages manager where to find packages.
1870 _ 'Packages DB : %s' "$root$DB"
1871 mkdir -p $root$INSTALLED
1872 cd $root$DB; rm -f *.bak
1873 for list in packages.list packages.desc packages.equiv packages.md5; do
1874 rm -f $list
1875 ln -s $SLITAZ/packages/$list $list
1876 done
1877 # We must have the cross compiled glibc-base installed or default
1878 # i486 package will be used as dep by tazpkg and then break the
1879 # cross environment
1880 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1881 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1882 fi
1883 # Show GCC version or warn if not yet compiled.
1884 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1885 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1886 else
1887 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1888 _ 'Run "%s" to cook a toolchain' 'cross compile'
1889 fi
1890 footer ;;
1892 test)
1893 # Test a cook environment.
1894 _ 'Cook test: testing the cook environment' | log
1895 [ ! -d "$WOK" ] && exit 1
1896 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1897 cook cooktest ;;
1899 new)
1900 # Create the package folder and an empty receipt.
1901 pkg="$2"
1902 [ -z "$pkg" ] && usage
1903 newline
1904 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1906 action 'Creating folder "%s"' "$WOK/$pkg"
1907 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1909 action 'Preparing the package receipt...'
1910 cp $DATA/receipt .
1911 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1912 status; newline
1914 # Interactive mode, asking and seding.
1915 case "$3" in
1916 --interactive|-x)
1917 _ 'Entering interactive mode...'
1918 separator
1919 _ 'Package : %s' "$pkg"
1921 _n 'Version : ' ; read answer
1922 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1924 _n 'Category : ' ; read answer
1925 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1927 # L10n: Short description
1928 _n 'Short desc : ' ; read answer
1929 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1931 _n 'Maintainer : ' ; read answer
1932 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1934 _n 'License : ' ; read answer
1935 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1937 _n 'Web site : ' ; read answer
1938 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1939 newline
1941 # Wget URL.
1942 _ 'Wget URL to download source tarball.'
1943 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1944 _n 'Wget url : ' ; read answer
1945 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1947 # Ask for a stuff dir.
1948 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1949 if [ "$?" -eq 0 ]; then
1950 action 'Creating the stuff directory...'
1951 mkdir $WOK/$pkg/stuff; status
1952 fi
1954 # Ask for a description file.
1955 confirm "$(_n 'Are you going to write a description? (y/N)')"
1956 if [ "$?" -eq 0 ]; then
1957 action 'Creating the "%s" file...' 'description.txt'
1958 touch $WOK/$pkg/description.txt; status
1959 fi
1961 footer "$(_ 'Receipt is ready to use.')" ;;
1962 esac ;;
1964 list)
1965 # Cook a list of packages (better use the Cooker since it will order
1966 # packages before executing cook).
1967 check_root
1968 [ -z "$2" ] && die 'No list in argument.'
1969 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1971 _ 'Starting cooking the list "%s"' "$2" | log
1973 while read pkg; do
1974 cook $pkg || broken
1975 done < $2
1976 ;;
1978 clean-wok)
1979 check_root
1980 newline; action 'Cleaning all packages files...'
1981 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1982 status; newline ;;
1984 clean-src)
1985 check_root
1986 newline; action 'Cleaning all packages sources...'
1987 rm -rf $WOK/*/source
1988 status; newline ;;
1990 uncook)
1991 cd $WOK
1992 count=0
1993 title 'Checking for uncooked packages'
1995 for i in *; do
1996 unset HOST_ARCH EXTRAVERSION
1997 [ ! -e $i/receipt ] && continue
1998 . ./$i/receipt
1999 # Source cooked pkg receipt to get EXTRAVERSION
2000 if [ -d "$WOK/$i/taz" ]; then
2001 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
2002 . ./receipt; cd $WOK
2003 fi
2004 case "$ARCH" in
2005 i486)
2006 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
2007 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
2008 count=$(($count + 1))
2009 colorize 34 "$i"
2010 fi ;;
2011 arm*)
2012 # Check only packages included in arch
2013 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
2014 # *.tazpkg
2015 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
2016 count=$(($count + 1))
2017 colorize 34 "$i"
2018 fi
2019 fi ;;
2020 esac
2021 done
2023 if [ "$count" -gt 0 ]; then
2024 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
2025 else
2026 _ 'All packages are cooked :-)'
2027 newline
2028 fi
2029 ;;
2031 pkgdb)
2032 # Create suitable packages list for TazPkg and only for built packages
2033 # as well as flavors files for TazLiTo. We don't need logs since we do it
2034 # manually to ensure everything is fine before syncing the mirror.
2035 recreate_split_db
2036 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
2037 ;;
2039 splitdb)
2040 # File split.db is useful for searching for split packages.
2041 recreate_split_db
2042 ;;
2044 *)
2045 # Just cook and generate a package.
2046 check_root
2047 time=$(date +%s)
2048 pkg="$1"
2049 [ -z "$pkg" ] && usage
2051 # Search last successful cook time in all logs from newer to older
2052 for i in '' $(seq 0 9 | sed 's|^|.|'); do
2053 [ -f "$LOGS/$pkg.log$i" ] || break
2054 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
2055 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
2056 [ -n "$lastcooktime" ] && break
2057 done
2059 receipt="$WOK/$pkg/receipt"
2060 check_pkg_in_wok
2061 newline
2063 unset inst
2064 unset_receipt
2065 . $receipt
2067 # Handle cross compilation.
2068 case "$ARCH" in
2069 arm*)
2070 if [ -z "$HOST_ARCH" ]; then
2071 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2072 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2073 _ 'cook: %s' "$error"
2074 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2075 _ 'Cook skip: %s' "$error" | log
2076 newline
2077 broken; exit 1
2078 fi ;;
2079 esac
2081 # Some packages are not included in some arch or fail to cross compile.
2082 : ${HOST_ARCH=$ARCH}
2083 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2084 # Handle arm{v6hf,v7,..}
2085 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2086 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2087 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2088 _ 'cook: %s' "error"
2089 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2090 _ 'Cook skip: %s' "$error" | log
2091 sed -i "/^${pkg}$/d" $broken
2092 newline
2093 exit 0
2094 fi
2096 # Skip blocked, 3 lines also for the Cooker.
2097 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
2098 die 'Package "%s" is blocked' "$pkg"
2100 try_aufs_chroot "$@"
2102 # Log and source receipt.
2103 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
2104 echo "cook:$pkg" > $command
2106 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2108 while read cmd duration start; do
2109 [ $(($start + $duration)) -lt $(date +%s) ] &&
2110 echo "sed -i '/^$cmd $duration/d' $cooktime"
2111 done < $cooktime | sh
2113 # Display and log info if cook process stopped.
2114 # FIXME: gettext not working (in single quotes) here!
2115 trap '_ "\n\nCook stopped: control-C\n\n" | \
2116 tee -a $LOGS/$pkg.log' INT
2118 update_split_db
2120 # Handle --options
2121 case "$2" in
2122 --install|-i)
2123 inst='yes' ;;
2125 --pack)
2126 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2127 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2128 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2129 sed -i '$ s|$| (packing)|' $activity
2130 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2131 clean_log "$pkg-pack"
2132 time=$(($(date +%s) - $time))
2133 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2134 put_status $pkg Done
2135 rm -f $command
2136 exit 0 ;;
2138 --trials|-t)
2139 trials='yes' ;;
2140 esac
2142 # Rotate log
2143 for i in $(seq 9 -1 1); do
2144 j=$(($i - 1))
2145 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2146 done
2147 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2149 # Check if wanted is built now so we have separate log files.
2150 for wanted in $WANTED ; do
2151 if grep -q "^$wanted$" $blocked; then
2152 broken
2153 rm -f $command
2154 die 'WANTED package "%s" is blocked' "$wanted"
2155 fi
2156 if grep -q "^$wanted$" $broken; then
2157 broken
2158 rm -f $command
2159 die 'WANTED package "%s" is broken' "$wanted"
2160 fi
2161 if [ ! -d "$WOK/$wanted/install" ]; then
2162 cook "$wanted" || { broken; exit 1; }
2163 fi
2164 done
2166 # Cook and pack or exit on error and log everything.
2167 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2168 rq=$? # the return code of `cookit $@` above command
2170 # Remove build dependencies both when `cookit` done or fail
2171 remove_deps | tee -a $LOGS/$pkg.log
2172 timestamp job27 # removing bdeps
2173 cookit_quality
2174 timestamp job28 # checking quality
2176 # Log and stop if `cookit` fails
2177 if [ $rq -eq 1 ]; then
2178 debug_info | tee -a $LOGS/$pkg.log
2179 put_status $pkg Failed
2180 rm -f $command
2181 broken; exit 1
2182 fi
2184 # Proceed only if `cookit` return code is zero-OK
2185 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2186 timestamp job29 # packing
2188 clean_log
2190 # Exit if any error in packing.
2191 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2192 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2193 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2194 debug_info | tee -a $LOGS/$pkg.log
2195 put_status $pkg Failed
2196 rm -f $command
2197 broken; exit 1
2198 fi
2200 # Create an XML feed
2201 gen_rss
2203 # Time and summary
2204 time=$(($(date +%s) - $time))
2205 summary | tee -a $LOGS/$pkg.log
2206 newline
2208 # We may want to install/update (outside aufs jail!).
2209 [ -s /aufs-umount.sh ] || install_package
2211 put_status $pkg Done
2213 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2214 # If you want automation, use the Cooker Build Bot.
2215 rm -f $command
2216 timestamp job30 # misc. final operations
2217 store_timestats
2219 sed -n '/^Build dependencies to remove:/,/^$/p' $LOGS/$pkg.log \
2220 | sed '/^Build/d; s|Removing: ||' \
2221 | tr ' ' '\n' \
2222 | sed '/^$/d' \
2223 > $WOK/$pkg/.bdeps
2225 ;;
2226 esac
2228 exit 0