cookutils view cook @ rev 1039

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