cookutils view cook @ rev 952

cook: do not replace package in $PKGS if release checksum has not changed -> mirror package will not change if nothing was changed after rebuilding.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Jul 29 14:50:36 2017 +0300 (2017-07-29)
parents 4e8c86306ce2
children 160d8c595c75
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 # QA: check a receipt consistency before building.
101 receipt_quality() {
102 _ 'QA: checking package receipt...'
104 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
105 unset value
106 value="$(. $receipt; eval echo \$$var)"
107 # L10n: QA is quality assurance
108 [ -n "$value" ] || die 'QA: empty variable: %s' "$var=\"\""
110 case "$var" in
111 CATEGORY)
112 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
113 if ! echo " $valid " | grep -q " $value "; then
114 _ 'QA: unknown category "%s"' "$value"
115 die 'Please, use one of: %s' "$valid"
116 fi
117 ;;
118 WEB_SITE)
119 # We don't check WGET_URL since if dl is needed it will fail.
120 # Break also if we're not online. Here error is not fatal.
121 if ifconfig | grep -A1 '^[a-z]*[0-9]' | fgrep -q 'addr:' && \
122 ! busybox wget -T 12 --spider $value 2>/dev/null; then
123 _ 'QA: unable to reach "%s"' "$value"
124 fi
125 ;;
126 esac
127 done
128 }
131 # Paths used in receipt and by cook itself.
133 set_paths() {
134 pkgdir="$WOK/$pkg"
135 . "$pkgdir/receipt"
136 basesrc="$pkgdir/source"
137 tmpsrc="$basesrc/tmp"
138 src="$basesrc/$PACKAGE-$VERSION"
139 taz="$pkgdir/taz"
140 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
141 fs="$pack/fs"
142 stuff="$pkgdir/stuff"
143 install="$pkgdir/install"
145 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
146 lzma_tarball="$pkgsrc.tar.lzma"
148 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
150 if [ -n "$WANTED" ]; then
151 basesrc="$WOK/$WANTED/source"
152 src="$basesrc/$WANTED-$VERSION"
153 install="$WOK/$WANTED/install"
154 wanted_stuff="$WOK/$WANTED/stuff"
155 fi
157 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
159 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
160 if [ -f "$WOK/linux/receipt" ]; then
161 kvers=$(. $WOK/linux/receipt; echo $VERSION)
162 kbasevers=$(echo $kvers | cut -d. -f1,2)
163 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
164 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
165 kbasevers=$(echo $kvers | cut -d. -f1,2)
166 fi
168 # Python version
169 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
170 # Perl version for some packages needed it
171 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
173 # Old way compatibility.
174 _pkg="$install"
175 }
178 # Create source tarball when URL is a SCM.
180 create_tarball() {
181 local tarball
182 tarball="$pkgsrc.tar.bz2"
183 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
184 _ 'Creating tarball "%s"' "$tarball"
185 if [ -n "$LZMA_SRC" ]; then
186 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
187 LZMA_SRC=''
188 else
189 tar -cjf $tarball $pkgsrc || exit 1
190 mv $tarball $SRC; rm -rf $pkgsrc
191 fi
192 TARBALL="$tarball"
193 }
196 # Get package source. For SCM we are in cache so clone here and create a
197 # tarball here.
199 get_source() {
200 local url
201 url=${WGET_URL#*|}
202 set_paths
203 pwd=$(pwd)
204 case "$WGET_URL" in
205 http://*|ftp://*|https://*)
206 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
207 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
208 wget -T 60 -c -O $SRC/$TARBALL $url ||
209 die 'ERROR: %s' "wget $WGET_URL"
210 ;;
212 hg*|mercurial*)
213 _ 'Getting source from %s...' 'Hg'
214 _ 'URL: %s' "$url"
215 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
216 if [ -n "$BRANCH" ]; then
217 _ 'Hg branch: %s' "$BRANCH"
218 hg clone $url --rev $BRANCH $pkgsrc ||
219 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
220 else
221 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
222 fi
223 rm -rf $pkgsrc/.hg
224 create_tarball
225 ;;
227 git*)
228 _ 'Getting source from %s...' 'Git'
229 _ 'URL: %s' "$url"
230 cd $SRC
231 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
232 if [ -n "$BRANCH" ]; then
233 _ 'Git branch: %s' "$BRANCH"
234 cd $pkgsrc; git checkout $BRANCH; cd ..
235 fi
236 cd $SRC
237 create_tarball
238 ;;
240 cvs*)
241 mod=$PACKAGE
242 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
243 _ 'Getting source from %s...' 'CVS'
244 _ 'URL: %s' "$url"
245 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
246 _ 'Cloning to "%s"' "$pwd/$mod"
247 cvs -d:$url co $mod && mv $mod $pkgsrc
248 create_tarball
249 ;;
251 svn*|subversion*)
252 _ 'Getting source from %s...' 'SVN'
253 _ 'URL: %s' "$url"
254 if [ -n "$BRANCH" ]; then
255 echo t | svn co $url -r $BRANCH $pkgsrc
256 else
257 echo t | svn co $url $pkgsrc
258 fi
259 create_tarball
260 ;;
262 bzr*)
263 _ 'Getting source from %s...' 'bazaar'
264 cd $SRC
265 pkgsrc=${url#*:}
266 if [ -n "$BRANCH" ]; then
267 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
268 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
269 else
270 echo "bzr -Ossl.cert_reqs=none branch $url"
271 bzr -Ossl.cert_reqs=none branch $url
272 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
273 _ "Don't forget to add to receipt:"
274 echo -e "BRANCH=\"$BRANCH\"\n"
275 fi
276 mv $pkgsrc $pkgsrc-$BRANCH
277 pkgsrc="$pkgsrc-$BRANCH"
278 create_tarball
279 ;;
281 *)
282 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
283 ;;
284 esac
285 }
288 # Extract source package.
290 extract_source() {
291 if [ ! -s "$SRC/$TARBALL" ]; then
292 local url
293 url="$MIRROR_URL/sources/packages"
294 url="$url/${TARBALL:0:1}/$TARBALL"
295 _ 'Getting source from %s...' 'mirror'
296 _ 'URL: %s' "$url"
297 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
298 fi
299 _ 'Extracting source archive "%s"' "$TARBALL"
300 case "$TARBALL" in
301 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
302 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
303 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
304 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
305 *.tar) tar -xf $SRC/$TARBALL ;;
306 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
307 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
308 tar -xf $SRC/$TARBALL 2>/dev/null;;
309 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
310 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
311 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
312 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
313 *) cp $SRC/$TARBALL $(pwd) ;;
314 esac
315 }
318 # Display time.
320 disp_time() {
321 local sec div min
322 sec="$1"
323 div=$(( ($1 + 30) / 60))
324 case $div in
325 0) min='';;
326 # L10n: 'm' is for minutes (approximate cooking time)
327 *) min=$(_n ' ~ %dm' "$div");;
328 esac
330 # L10n: 's' is for seconds (cooking time)
331 _ '%ds%s' "$sec" "$min"
332 }
335 # Display cooked package summary.
337 summary() {
338 set_paths
339 cd $WOK/$pkg
340 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
341 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
342 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
344 _ 'Summary for: %s' "$PACKAGE $VERSION"
345 separator
347 # L10n: keep the same width of translations to get a consistent view
348 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
349 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
350 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
351 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
352 _ 'Cook time : %s' "$(disp_time "$time")"
353 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
354 _ 'Host arch : %s' "$ARCH"
356 separator -
357 _ ' # : Packed : Compressed : Files : Package name'
358 separator -
359 pkgi=1
360 for i in $(all_names); do
361 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION | awk '{print $1}')
362 pkgname="$i-$VERSION.tazpkg"
363 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
364 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION/files.list)
365 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
366 pkgi=$((pkgi + 1))
367 done
368 separator
369 }
372 # Display debugging error info.
374 debug_info() {
375 title 'Debug information'
376 # L10n: specify your format of date and time (to help: man date)
377 # L10n: not bad one is '+%x %R'
378 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
379 if [ -n "$time" ]; then
380 times="$(($(date +%s) - $time))"
381 _ 'Wasted time : %s' "$(disp_time "$times")"
382 fi
383 for error in \
384 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
385 'error:' 'fatal error:' 'undefined reference to' \
386 'Unable to connect to' 'link: cannot find the library' \
387 'CMake Error' ': No such file or directory' \
388 'Could not read symbols: File in wrong format'
389 do
390 # format "line number:line content"
391 fgrep -n "$error" $LOGS/$pkg.log
392 done > $LOGS/$pkg.log.debug_info 2>&1
393 # sort by line number, remove duplicates
394 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
395 rm -f $LOGS/$pkg.log.debug_info
396 footer
397 }
400 # A bit smarter function than the classic `cp` command
402 scopy() {
403 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
404 cp -a "$1" "$2" # copy generic files
405 else
406 cp -al "$1" "$2" # copy hardlinks
407 fi
408 }
411 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
412 # We use standard paths, so some packages need to copy these files with the
413 # receipt and genpkg_rules.
414 # This function executes inside the packaging process, before compressor call.
416 copy_generic_files() {
417 # Proceed only for "main" package (for v2), and for any packages (v1)
418 [ "$pkg" == "$PACKAGE" ] || return 0
420 # $LOCALE is set in cook.conf
421 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
422 if [ -d "$install/usr/share/locale" ]; then
423 mkdir -p "$fs/usr/share/locale"
424 for i in $LOCALE; do
425 if [ -d "$install/usr/share/locale/$i" ]; then
426 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
427 fi
428 done
429 fi
430 fi
432 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
433 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
434 if [ -d "$install/usr/share/pixmaps" ]; then
435 mkdir -p "$fs/usr/share/pixmaps"
436 for i in png xpm; do
437 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
438 cp -a $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
439 done
440 fi
441 fi
443 # Desktop entry (.desktop).
444 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
445 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
446 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
447 mkdir -p "$fs/usr/share"
448 cp -a $install/usr/share/applications $fs/usr/share
449 fi
450 fi
451 }
454 # Copy pixmaps, desktop files and licenses from $stuff to $install.
455 # This function executes after the main compile_rules() is done.
457 copy_generic_stuff() {
458 # Custom or homemade PNG pixmap can be in stuff.
459 if [ -f "$stuff/$PACKAGE.png" ]; then
460 mkdir -p $install/usr/share/pixmaps
461 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
462 fi
464 # Homemade desktop file(s) can be in stuff.
465 if [ -d "$stuff/applications" ]; then
466 mkdir -p $install/usr/share
467 cp -a $stuff/applications $install/usr/share
468 fi
469 if [ -f "$stuff/$PACKAGE.desktop" ]; then
470 mkdir -p $install/usr/share/applications
471 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
472 fi
474 # Add custom licenses
475 if [ -d "$stuff/licenses" ]; then
476 mkdir -p $install/usr/share/licenses
477 cp -a $stuff/licenses $install/usr/share/licenses/$PACKAGE
478 fi
479 }
482 # Remove files provided by split packages
483 # For example:
484 # 1. Package "pkg-main":
485 # SPLIT="pkg-1 pkg-2 pkg-extra"
486 # 2. Package="pkg-extra":
487 # WANTED="pkg-main"
488 # BUILD_DEPENDS="pkg-1 pkg-2"
489 # cook_copy_folders usr
490 # cook_split_rm $BUILD_DEPENDS
492 cook_split_rm() {
493 for i in $@; do
494 action 'Remove files provided by split package %s...' "$i"
495 while read j; do
496 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
497 rmdir "$(dirname "$fs$j")" 2>/dev/null
498 done < $WOK/$i/taz/$i-$VERSION/files.list
499 :; status
500 done
501 }
504 # Update installed.cook.diff
506 update_installed_cook_diff() {
507 # If a cook failed deps are removed.
508 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
509 cd $CACHE
510 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
511 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
512 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
513 }
516 # Remove installed deps.
518 remove_deps() {
519 # Now remove installed build deps.
520 diff='/tmp/installed.cook.diff'
521 [ -s "$diff" ] || return
523 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
524 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
525 newline
526 _n 'Build dependencies to remove:'; echo " $nb"
527 [ -n "$root" ] && echo "root=\"$root\""
528 {
529 _n 'Removing:'
530 for dep in $deps; do
531 echo -n " $dep"
532 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
533 done
534 newline; newline
535 # Keep the last diff for debug and info.
536 mv -f $diff $CACHE/installed.diff
537 } | busybox fold -sw80
538 }
541 # Automatically patch the sources.
543 patchit() {
544 [ -f "$stuff/patches/series" ] || return
546 IFS=$'\n'
547 while read i; do
548 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
549 [ -n "$patchname" ] || continue # allow empty lines
550 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
551 newline
552 _ 'Applying patch %s' "$patchname"
553 patch -Np1 -i $stuff/patches/$patchname | sed 's|^| |'
554 touch $src/done.$patchname
555 done < $stuff/patches/series
556 newline
557 unset IFS
558 }
561 # Check source tarball integrity.
563 check_integrity() {
564 for i in sha1 sha3 sha256 sha512 md5; do
565 I=$(echo $i | tr 'a-z' 'A-Z')
566 eval sum=\$TARBALL_$I
567 if [ -n "$sum" ]; then
568 newline
569 _ 'Checking %ssum of source tarball...' "$i"
570 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
571 fi
572 done
573 newline
574 }
577 # The main cook function.
579 cookit() {
580 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
581 _ 'ERROR: Broken setup. Abort.'
582 return
583 fi
585 title 'Cook: %s' "$PACKAGE $VERSION"
586 set_paths
588 # Handle cross-tools.
589 case "$ARCH" in
590 arm*|x86_64)
591 # CROSS_COMPILE is used by at least Busybox and the kernel to set
592 # the cross-tools prefix. Sysroot is the root of our target arch
593 sysroot="$CROSS_TREE/sysroot"
594 tools="$CROSS_TREE/tools"
595 # Set root path when cross compiling. ARM tested but not x86_64
596 # When cross compiling we must install build deps in $sysroot.
597 arch="-$ARCH"
598 root="$sysroot"
599 _ '%s sysroot: %s' "$ARCH" "$sysroot"
600 _ 'Adding "%s" to PATH' "$tools/bin"
601 export PATH="$PATH:$tools/bin"
602 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
603 export CROSS_COMPILE="$HOST_SYSTEM-"
604 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
605 if [ "$ARCH" == 'x86_64' ]; then
606 export CC="$HOST_SYSTEM-gcc -m64"
607 export CXX="$HOST_SYSTEM-g++ -m64"
608 else
609 export CC="$HOST_SYSTEM-gcc"
610 export CXX="$HOST_SYSTEM-g++"
611 fi
612 export AR="$HOST_SYSTEM-ar"
613 export AS="$HOST_SYSTEM-as"
614 export RANLIB="$HOST_SYSTEM-ranlib"
615 export LD="$HOST_SYSTEM-ld"
616 export STRIP="$HOST_SYSTEM-strip"
617 export LIBTOOL="$HOST_SYSTEM-libtool"
618 ;;
619 esac
621 [ -n "$QA" ] && receipt_quality
623 cd $pkgdir
624 [ -z "$continue" ] && rm -rf source 2>/dev/null
625 rm -rf install taz 2>/dev/null
627 # Disable -pipe if less than 512 MB free RAM.
628 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
629 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
630 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
631 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
632 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
633 fi
634 unset free
636 # Export flags and path to be used by make and receipt.
637 DESTDIR="$pkgdir/install"
638 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
639 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
640 #LDFLAGS
642 # BUILD_DEPENDS may vary depending on the ARCH
643 case "$ARCH" in
644 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
645 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
646 esac
648 # Check for build deps and handle implicit depends of *-dev packages
649 # (ex: libusb-dev :: libusb).
650 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
651 # touch $CACHE/installed.local $CACHE/installed.web
652 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
653 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
655 # Get the list of installed packages
656 cd $root$INSTALLED; ls > $CACHE/installed.list
658 for action in check install; do
659 for dep in $BUILD_DEPENDS; do
660 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
661 for i in $dep $implicit; do
662 # Skip if package already installed
663 [ -f "$root$INSTALLED/$i/receipt" ] && continue
665 case $action in
666 check)
667 # Search for local package or local provided-package
668 name=$(awk -F$'\t' -vpkg="$i" '{
669 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
670 }' "$PKGS/packages.info")
671 if [ -z "$name" ]; then
672 # Search for package in mirror
673 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
674 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
675 fi
676 ;;
677 install)
678 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
679 ;;
680 esac
681 done
682 done
683 done
685 # # Have we a missing build dep to cook?
686 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
687 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
688 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
689 # for i in $(uniq $CACHE/missing.dep); do
690 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
691 # tee -a $LOGS/$PACKAGE.log.$$
692 # # programmers: next two messages are exact copy from remove_deps()
693 # togrep1=$(_n 'Build dependencies to remove:')
694 # togrep2=$(_n 'Removing:')
695 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
696 # fgrep $togrep1 $LOGS/$i.log && \
697 # fgrep $togrep2 $LOGS/$i.log && newline) | \
698 # tee -a $LOGS/$PACKAGE.log.$$ && break
699 # done
700 # rm -f $CACHE/missing.dep
701 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
702 # fi
703 #
704 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
705 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
706 # # missing dep in cached file.
707 # lerror=$(_n 'ERROR')
708 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
709 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
710 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
711 # broken; exit 1
712 # fi
713 #
714 # # Install local packages: package-version$arch
715 # cd $PKGS
716 # for i in $(uniq $CACHE/installed.local); do
717 # # _ 'Installing dep (pkg/local): %s' "$i"
718 # tazpkg install $i --root=$root --local --quiet --cookmode
719 # done
720 #
721 # # Install web or cached packages (if mirror is set to $PKGS we only
722 # # use local packages).
723 # for i in $(uniq $CACHE/installed.web); do
724 # # _ 'Installing dep (web/cache): %s' "$i"
725 # tazpkg get-install $i --root=$root --local --quiet --cookmode
726 # done
728 update_installed_cook_diff
730 # Get source tarball and make sure we have source dir named:
731 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
732 # tarball if it exists.
733 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
734 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
735 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
736 LZMA_SRC=''
737 else
738 get_source || { broken; exit 1; }
739 fi
740 fi
741 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
742 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
743 if ! extract_source ; then
744 get_source
745 extract_source || { broken; exit 1; }
746 fi
747 if [ -n "$LZMA_SRC" ]; then
748 cd $pkgdir/source
749 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
750 mv tmp tmp-1; mkdir tmp
751 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
752 fi
753 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
754 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
755 fi
756 fi
757 cd $pkgdir/source/tmp
758 # Some archives are not well done and don't extract to one dir (ex lzma).
759 files=$(ls | wc -l)
760 [ "$files" -eq 1 -a -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
761 [ "$files" -eq 1 -a -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
762 mv * ../$PACKAGE-$VERSION/$TARBALL
763 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
764 mv * ../$PACKAGE-$VERSION
765 cd ..; rm -rf tmp
766 fi
768 check_integrity
770 # Libtool shared libs path hack.
771 case "$ARCH" in
772 arm*) cross libhack ;;
773 esac
775 # Execute receipt rules.
776 if grep -q ^compile_rules $receipt; then
777 _ 'Executing: %s' 'compile_rules'
778 echo "CFLAGS : $CFLAGS"
779 #echo "LDFLAGS : $LDFLAGS"
780 [ -d "$src" ] && cd $src
781 patchit
782 compile_rules $@ || { broken; exit 1; }
783 # Stay compatible with _pkg
784 [ -d "$src/_pkg" ] && mv $src/_pkg $install
785 # QA: compile_rules success so valid.
786 mkdir -p $install
787 else
788 # QA: no compile_rules so no error, valid.
789 mkdir -p $install
790 fi
792 copy_generic_stuff
794 # Actions to do after compiling the package
795 # Skip all for split packages (already done in main package)
796 if [ -z "$WANTED" ]; then
797 footer
798 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
799 fi
800 footer
802 # Execute testsuite.
803 if grep -q ^testsuite $receipt; then
804 title 'Running testsuite'
805 testsuite $@ || { broken; exit 1; }
806 footer
807 fi
809 update_installed_cook_diff force
810 }
813 # Cook quality assurance.
815 cookit_quality() {
816 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
817 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
818 fi
819 # ERROR can be echoed any time in cookit()
820 lerror=$(_n 'ERROR')
821 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
822 grep -Eq "(^$lerror|undefined reference to)" ; then
823 debug_info | tee -a $LOGS/$pkg.log
824 sed -i '$ s|$| [ Failed ]|' $activity
825 rm -f $command
826 broken; exit 1
827 fi
828 }
831 # Receipt used for cooking the package is redundant to be included into package.
832 # This script will strip the original receipt to bare minimum: variables,
833 # {pre,post}_{install,remove} functions.
835 mk_pkg_receipt() {
836 orig_receipt="$1"
838 # Receipt's signature is important, although some receipts may miss it
839 signature=$(head -n1 "$orig_receipt")
840 [ "${signature:0:1}" == '#' ] || signature='# SliTaz package receipt.'
842 save_PACKAGE="$PACKAGE"; save_DEPENDS="$DEPENDS"; save_PROVIDE="$PROVIDE"
843 save_SUGGESTED="$SUGGESTED"; save_TAZPANEL_DAEMON="$TAZPANEL_DAEMON"
844 save_TAGS="$TAGS"
845 unset_receipt
846 . "$orig_receipt"
847 PACKAGE="$save_PACKAGE"; DEPENDS="$save_DEPENDS"; PROVIDE="$save_PROVIDE"
848 SUGGESTED="$save_SUGGESTED"; TAZPANEL_DAEMON="$save_TAZPANEL_DAEMON"
849 TAGS="$save_TAGS"
851 # Manage split packages
852 SPLIT=" $SPLIT "
853 if [ "$SPLIT" != ' ' -a "${SPLIT/ $PACKAGE /}" != "$SPLIT" ]; then
854 # For packages with empty $DEPENDS
855 if [ -z "$DEPENDS" ]; then
856 case $PACKAGE in
857 *-dev)
858 # main package and all the split packages but this *-dev itself
859 DEPENDS=$(echo "$pkg $SPLIT " | sed "s| $PACKAGE | |; s| *$||") ;;
860 *)
861 # main package
862 DEPENDS="$pkg" ;;
863 esac
864 fi
866 # Default $CAT
867 [ -z "$CAT" ] &&
868 case $PACKAGE in
869 *-dev) CAT="development|development files" ;;
870 esac
871 fi
873 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
874 if [ -n "$CAT" ]; then
875 CATEGORY="${CAT%|*}"
876 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
877 fi
879 # escape quotes for receipt
880 SHORT_DESC="${SHORT_DESC//\"/\\\"}"
882 # Mandatory variables
883 cat <<EOF
884 $signature
886 PACKAGE="$PACKAGE"
887 VERSION="$VERSION"
888 CATEGORY="$CATEGORY"
889 SHORT_DESC="$SHORT_DESC"
890 MAINTAINER="$MAINTAINER"
891 LICENSE="$LICENSE"
892 WEB_SITE="$WEB_SITE"
893 EOF
895 # Optional variables
896 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\"" | tr -ds '\t' ' '
897 [ -n "${DEPENDS# }" ] && echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' '
898 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\"" | tr -ds '\t' ' '
899 [ -n "$CONFIG_FILES" ] && echo "CONFIG_FILES=\"$CONFIG_FILES\"" | tr -ds '\t' ' '
900 [ -n "$SUGGESTED" ] && echo "SUGGESTED=\"$SUGGESTED\"" | tr -ds '\t' ' '
901 [ -n "$DATABASE_FILES" ] && echo "DATABASE_FILES=\"$DATABASE_FILES\""
902 [ -n "$TAZPANEL_DAEMON" ] && echo "TAZPANEL_DAEMON=\"$TAZPANEL_DAEMON\""
904 # Extract {pre,post}_{install,remove} functions;
905 # post_install() will be copied for both main and all the split packages
906 # post_install_gtk_() will be copied as post_install() for gtk+ package only
907 #
908 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
909 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
910 for i in pre post; do
911 for j in install remove; do
912 sed "/^${i}_${j}()/,/^}/!d" "$orig_receipt"
913 sed "/^${i}_${j}_$rname()/,/^}/!d" "$orig_receipt" | \
914 sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
915 done
916 done
917 }
920 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
921 # but it doesn't handle EXTRAVERSION.
923 packit() {
924 set_paths "$1"
925 PACKAGE="${1:-$PACKAGE}"
927 # Handle cross compilation
928 case "$ARCH" in
929 arm*|x86_64) arch="-$ARCH" ;;
930 esac
932 title 'Pack: %s' "$PACKAGE $VERSION$arch"
934 if grep -q ^genpkg_rules $receipt; then
935 _ 'Executing: %s' 'genpkg_rules'
936 set -e; cd $pkgdir; mkdir -p $fs
937 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
938 $LOGS/$pkg.log
939 else
940 _ 'No packages rules: meta package'
941 mkdir -p $fs
942 fi
944 # Check CONFIG_FILES
945 if [ -n "$CONFIG_FILES" ]; then
946 unset IFS
947 for i in $CONFIG_FILES; do
948 if [ ! -e $fs$i ]; then
949 case $i in
950 */) mkdir -p $fs$i ;;
951 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
952 esac
953 fi
954 done
955 fi
957 # First QA check to stop now if genpkg_rules failed.
958 lerror=$(_n 'ERROR')
959 if fgrep -q ^$lerror $LOGS/$pkg.log; then
960 broken; exit 1
961 fi
963 cd $taz
964 action 'Copying "%s"...' 'receipt'
965 mk_pkg_receipt ../receipt > $pack/receipt
966 chown 0.0 $pack/receipt; status
968 unset desc
969 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
970 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
971 if [ -n "$desc" ]; then
972 action 'Copying "%s"...' "$(basename "$desc")"
973 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
974 fi
976 copy_generic_files
978 # Strip and stuff files.
979 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
981 # Create files.list with redirecting find output.
982 action 'Creating the list of files...'
983 cd $fs
984 find . -type f -print > ../files.list
985 find . -type l -print >> ../files.list
986 cd ..; sed -i 's|^.||' files.list
987 status
989 # Md5sum of files.
990 action 'Creating md5sum of files...'
991 while read file; do
992 [ -L "fs$file" ] && continue
993 [ -f "fs$file" ] || continue
994 case "$file" in
995 /lib/modules/*/modules.*|*.pyc) continue ;;
996 esac
997 md5sum "fs$file" | sed 's| fs| |'
998 done < files.list > md5sum
999 status
1001 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1002 2>/dev/null | awk 'END{ print $1 }')
1004 # Build cpio archive.
1005 action 'Compressing the FS...'
1006 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
1007 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1008 mv fs ../
1009 status
1011 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1012 2>/dev/null | awk 'END{ print $1 }')
1014 action 'Updating receipt sizes...'
1015 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
1016 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
1017 status
1019 # Set extra version.
1020 if [ -n "$EXTRAVERSION" ]; then
1021 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1022 sed -i '/^EXTRAVERSION=/d' receipt
1023 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
1024 status
1025 fi
1027 # Compress.
1028 action 'Creating full cpio archive...'
1029 find . -newer $receipt -exec touch -hr $receipt '{}' \;
1030 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1031 status
1033 action 'Restoring original package tree...'
1034 mv ../fs .
1035 status
1037 rm fs.cpio.lzma; cd ..
1039 # QA and give info.
1040 tazpkg=$(ls *.tazpkg)
1041 packit_quality
1042 footer "$(_ 'Package "%s" created' "$tazpkg")"
1043 update_packages_db
1047 # Calculate release checksum: usually it does not change on "just recook".
1048 # Release checksum is md5sum of file containing md5sums of:
1049 # a) all files, b) receipt, and c) description.txt.
1050 # Md5sum of the package file will change every time because of embedded timestamps;
1051 # release checksum based only on files content, and will change only when files change.
1052 # (Pitfall: ownership and permissions...)
1054 release_checksum() {
1055 local pack=$1
1056 local rsum_file=$(mktemp)
1058 cp $pack/md5sum $rsum_file
1059 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1060 [ -e "$pack/description.txt" ] &&
1061 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1063 local rsum=$(md5sum $rsum_file | awk '{print $1}')
1064 rm $rsum_file
1065 local rsumold=$(awk -F$'\t' -vpkg="$PACKAGE" '
1066 {if ($1 == pkg) { print $9; exit; }}' $PKGS/packages.info)
1068 [ "$rsum" == "$rsumold" ] && rsum=''
1070 echo $rsum
1074 # Verify package quality and consistency.
1076 packit_quality() {
1077 #action 'QA: checking for broken link...'
1078 #link=$(find $fs/usr -type l -follow)
1079 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1080 #status
1082 # Exit if any error found in log file.
1083 lerror=$(_n 'ERROR')
1084 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1085 rm -f $command
1086 broken; exit 1
1087 fi
1089 action 'QA: checking for empty package...'
1090 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1091 broken
1092 rm -f $command
1093 die 'ERROR: empty package'
1094 fi
1096 :; status
1098 # Find and remove old package(s) only if "release checksum" has changed
1099 rsum=$(release_checksum $pack)
1100 if [ -n "$rsum" ]; then
1101 old_file=$(awk -F$'\t' -vname="$PACKAGE" '{
1102 if ($1 == name) printf("%s-%s.tazpkg", $1, $2);
1103 }' $PKGS/packages.info)
1104 if [ -f "$PKGS/$old_file" ]; then
1105 action 'Removing old package "%s"' "$old_file"
1106 rm -f "$PKGS/$old_file"
1107 status
1108 fi
1109 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
1110 fi
1112 sed -i "/^${pkg}$/d" $broken
1113 #action 'Removing source tree...'
1114 #rm -f $WOK/$pkg/source; status
1118 # Return all the names of packages bundled in this receipt
1120 all_names() {
1121 local split=" $SPLIT "
1122 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1123 # For receipts v1: $SPLIT may present in the $WANTED package,
1124 # but split packages have their own receipts
1125 echo $PACKAGE
1126 elif [ "${split/ $PACKAGE /}" != "$split" ]; then
1127 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1128 # We should build packages in the order defined in the $SPLIT.
1129 echo $SPLIT
1130 else
1131 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1132 echo $PACKAGE $SPLIT
1133 fi
1137 # v2: pack all packages using compiled files
1139 packall() {
1140 set_paths
1141 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1142 for i in $(all_names); do
1143 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1144 packit $i
1145 done
1146 else
1147 packit
1148 fi
1152 # Reverse "cat" command: prints input lines in the reverse order
1154 tac() {
1155 sed '1!G;h;$!d' $1
1159 # Update chroot with freshly rebuilt package: keep env up-to-date.
1161 update_chroot() {
1162 local PACKAGE="$pkg"
1163 for i in $(all_names); do
1164 if [ -d "$root$INSTALLED/$i" ]; then
1165 . /etc/slitaz/cook.conf
1166 . $WOK/$pkg/taz/$i-$VERSION/receipt
1167 _ 'Updating %s chroot environment...' "$ARCH"
1168 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1169 cd $PKGS
1170 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1171 fi
1172 done
1176 # Install package on --inst or update the chroot.
1178 install_package() {
1179 case "$ARCH" in
1180 arm*|x86_64)
1181 arch="-$ARCH"
1182 root="$CROSS_TREE/sysroot" ;;
1183 esac
1184 # Install package if requested but skip install if target host doesn't
1185 # match build system or it will break the build chroot.
1186 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1187 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1188 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1189 cd $PKGS
1190 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1191 else
1192 broken
1193 die 'Unable to install package, build has failed.'
1194 fi
1195 fi
1197 update_chroot
1201 # remove chroot jail
1203 umount_aufs() {
1204 tac ${1}rw/aufs-umount.sh | sh
1205 rm -rf ${1}rw
1206 umount ${1}root
1207 rmdir ${1}r*
1211 # Launch the cook command into a chroot jail protected by aufs.
1212 # The current filesystems are used read-only and updates are
1213 # stored in a separate branch.
1215 try_aufs_chroot() {
1217 base="/dev/shm/aufsmnt$$"
1219 # Can we setup the chroot? Is it already done?
1220 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1221 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1222 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1223 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1224 mkdir ${base}root ${base}rw || return
1226 _ 'Setup aufs chroot...'
1228 # Sanity check
1229 for i in / /proc /sys /dev/shm /home ; do
1230 case " $AUFS_MOUNTS " in
1231 *\ $i\ *) ;;
1232 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1233 esac
1234 done
1235 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1236 mount --bind $mnt ${base}root$mnt
1237 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1238 _ 'Aufs mount failure'
1239 umount ${base}root
1240 rm -rf ${base}r*
1241 return
1242 fi
1243 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1244 done
1245 trap "umount_aufs ${base}" INT
1247 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1248 status=$?
1250 _ 'Leaving aufs chroot...'
1251 umount_aufs $base
1252 # Install package outside the aufs jail
1253 install_package
1254 exit $status
1258 # Encode predefined XML entities
1260 xml_ent() {
1261 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1265 # Create a XML feed for freshly built packages.
1267 gen_rss() {
1268 pubdate=$(date '+%a, %d %b %Y %X')
1269 cat > $FEEDS/$pkg.xml <<EOT
1270 <item>
1271 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1272 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1273 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1274 <pubDate>$pubdate</pubDate>
1275 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1276 </item>
1277 EOT
1281 # Truncate stdout log file to $1 Mb.
1283 loglimit() {
1284 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1285 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1286 else
1287 tee /dev/stderr
1288 fi
1293 # Receipt functions to ease packaging
1296 get_dev_files() {
1297 action 'Getting standard devel files...'
1298 mkdir -p $fs/usr/lib
1299 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1300 cp -a $install/usr/lib/*a $fs/usr/lib
1301 cp -a $install/usr/include $fs/usr
1302 status
1306 # Function to use in compile_rules() to copy man page from $src to $install
1308 cook_pick_manpages() {
1309 local name section
1310 action 'Copying man pages...'
1312 for i in $@; do
1313 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1314 section=${name##*/}; section=${section##*.}
1315 mkdir -p $install/usr/share/man/man$section
1316 scopy $i $install/usr/share/man/man$section
1317 done
1318 status
1322 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1324 cook_copy_files() {
1325 action 'Copying files...'
1326 cd $install
1327 local i j
1328 IFS=$'\n'
1329 for i in $@; do
1330 for j in $(find . -name $i ! -type d); do
1331 mkdir -p $fs$(dirname ${j#.})
1332 scopy $j $fs$(dirname ${j#.})
1333 done
1334 done
1335 cd - >/dev/null
1336 status
1340 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1342 cook_copy_folders() {
1343 action 'Copying folders...'
1344 cd $install
1345 local i j
1346 IFS=$'\n'
1347 for i in $@; do
1348 for j in $(find . -name $i -type d); do
1349 mkdir -p $fs$(dirname ${j#.})
1350 cp -a $j $fs$(dirname ${j#.})
1351 done
1352 done
1353 cd - >/dev/null
1354 status
1358 # Common function to copy files, folders and patterns
1360 copy() {
1361 action 'Copying folders and files...'
1362 local i j filelist=$(mktemp)
1363 IFS=$'\n'
1364 cd $install; find ! -type d | sed 's|\.||' > $filelist
1365 for i in $@; do
1366 case $i in
1367 @std)
1368 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1369 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /bin\/.*-config$/d;
1370 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1371 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1372 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1373 /\/share\/devhelp\//d; /\/share\/locale\//d;
1374 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1375 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1376 ' $filelist
1377 ;;
1378 @dev)
1379 # Copy "developer files"
1380 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /bin\/.*-config$/p;
1381 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1382 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1383 ' $filelist
1384 ;;
1385 */)
1386 # Copy specified folders.
1387 i="${i%/}"
1388 find -type d -path "*/${i#/}" | sed 's|^.||'
1389 ;;
1390 *)
1391 # Copy specified files.
1392 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1393 ;;
1394 esac | sort -u | \
1395 while read j; do
1396 mkdir -p $fs$(dirname "$j")
1397 if [ -d "$install$j" ]; then
1398 cp -a "$install$j" $fs$(dirname "$j")
1399 else
1400 scopy "$install$j" $fs$(dirname "$j")
1401 fi
1402 done
1403 done
1404 cd - >/dev/null
1405 unset IFS
1406 rm $filelist
1407 status
1411 # Remove from current $fs files that already packed (for receipts v2).
1412 # Note: the order in $SPLIT is very important.
1414 remove_already_packed() {
1415 local i j
1416 IFS=$'\n'
1417 for i in $taz/*/files.list; do
1418 while read j; do
1419 [ -f $fs$j -o -h $fs$j ] || continue
1420 rm $fs$j
1421 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1422 done < $i
1423 done
1424 unset IFS
1428 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1429 # (default: 16 and 48) from $install to $fs
1431 cook_copy_icons() {
1432 local sizes=$@
1433 action 'Copying hicolor icons...'
1434 mkdir -p $fs/usr/share/icons/hicolor
1435 for i in ${sizes:-16 48}; do
1436 [ ! -e "$install/usr/share/icons/hicolor/${i}x$i" ] ||
1437 scopy $install/usr/share/icons/hicolor/${i}x$i \
1438 $fs/usr/share/icons/hicolor
1439 done
1440 status
1444 # Update packages database every time after successful build
1446 update_packages_db() {
1447 # packages.info (unsorted, located near to packages)
1448 local pi="$PKGS/packages.info"
1449 unset_receipt; . $pack/receipt
1450 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1452 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1454 rsum=$(release_checksum $pack)
1455 if [ -n "$rsum" ]; then
1456 _ 'The release checksum has changed.\n'
1458 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1459 cat >> $pi <<EOT
1460 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1461 EOT
1463 # files.list (uncompressed, unsorted, located in $cache)
1464 local fl="$cache/files.list"
1465 touch $fl
1466 sed -i "/^$PACKAGE: /d" $fl
1467 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1468 else
1469 _ 'The release checksum has not changed.\n'
1470 fi
1474 # Update split.db once for receipt
1476 update_split_db() {
1477 local db="$cache/split.db"
1478 touch $db
1479 sed -i "/^$pkg\t/d" $db
1480 echo -e "$pkg\t$(all_names)" >> $db
1484 # Recreate whole split.db from scratch
1486 recreate_split_db() {
1487 # Clean
1488 local db="$cache/split.db"
1489 touch $db
1490 > $db
1492 cd $WOK
1493 for pkg in *; do
1494 [ -f "$WOK/$pkg/receipt" ] || continue
1495 unset PACKAGE SPLIT
1496 . $WOK/$pkg/receipt
1497 echo -e "$PACKAGE\t$(all_names)" >> $db
1498 done
1505 # Commands
1508 # cook <package> --deps
1509 [ -n "$deps" ] && {
1510 @@PREFIX@@/libexec/cookutils/deps $1
1511 exit 0
1514 # cook <package> --clean
1515 # cook <package> -c
1516 [ -n "$clean" -o "$2" == '-c' ] && {
1517 action 'Cleaning "%s"' "$1"
1518 cd $WOK/$1; rm -rf install taz source
1519 status; newline
1520 touch $activity # update $activity -> something changed -> update webstat
1521 exit 0
1524 # cook <package> --getsrc
1525 # cook <package> -gs
1526 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1527 title 'Getting source for "%s"' "$1"
1528 receipt="$WOK/$pkg/receipt"
1529 check_pkg_in_wok
1530 unset_receipt
1531 . $receipt
1532 get_source
1533 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1534 exit 0
1537 # cook <package> --block
1538 # cook <package> -b
1539 [ -n "$block" -o "$2" == '-b' ] && {
1540 action 'Blocking package "%s"' "$1"
1541 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1542 status; newline
1543 touch $activity
1544 exit 0
1547 # cook <package> --unblock
1548 # cook <package> -ub
1549 [ -n "$unblock" -o "$2" == '-ub' ] && {
1550 action 'Unblocking package "%s"' "$1"
1551 sed -i "/^$1$/d" $blocked
1552 status; newline
1553 touch $activity
1554 exit 0
1560 case "$1" in
1561 usage|help|-u|-h)
1562 usage ;;
1564 list-wok)
1565 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1566 cd $WOK
1567 if [ "$ARCH" != 'i486' ]; then
1568 count=0
1569 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1570 do
1571 unset HOST_ARCH
1572 . ./$pkg
1573 count=$(($count + 1))
1574 colorize 34 "$PACKAGE"
1575 done
1576 else
1577 count=$(ls | wc -l)
1578 ls -1
1579 fi
1580 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1581 ;;
1583 activity)
1584 cat $activity ;;
1586 search)
1587 # Just a simple search function, we don't need more actually.
1588 query="$2"
1589 title 'Search results for "%s"' "$query"
1590 cd $WOK; ls -1 | grep "$query"
1591 footer ;;
1593 setup)
1594 # Setup a build environment
1595 check_root
1596 _ 'Cook: setup environment' | log
1597 title 'Setting up your environment'
1598 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1599 cd $SLITAZ
1600 init_db_files
1601 _ 'Checking for packages to install...'
1602 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1603 # ARCH-setup or 'cross check' should be used before: cook setup
1604 case "$ARCH" in
1605 arm*|x86_64)
1606 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1607 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1608 . /etc/slitaz/cross.conf ;;
1609 esac
1610 for pkg in $SETUP_PKGS; do
1611 if [ -n "$forced" ]; then
1612 tazpkg -gi $pkg --forced
1613 else
1614 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1615 fi
1616 done
1618 # Handle --options
1619 case "$2" in
1620 --wok) hg clone $WOK_URL wok || exit 1 ;;
1621 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1622 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1623 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1624 esac
1626 # SliTaz group and permissions
1627 if ! grep -q ^slitaz /etc/group; then
1628 _ 'Adding group "%s"' 'slitaz'
1629 addgroup slitaz
1630 fi
1631 _ 'Setting permissions for group "%s"...' 'slitaz'
1632 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1633 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1634 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1636 *-setup)
1637 # Setup for cross compiling.
1638 arch="${1%-setup}"
1639 check_root
1640 . /etc/slitaz/cook.conf
1641 for pkg in $CROSS_SETUP; do
1642 if [ -n "$forced" ]; then
1643 tazpkg -gi $pkg --forced
1644 else
1645 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1646 fi
1647 done
1649 _ 'Cook: setup %s cross environment' "$arch" | log
1650 title 'Setting up your %s cross environment' "$arch"
1651 init_db_files
1652 sed -i \
1653 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1654 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1655 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1656 /etc/slitaz/cook.conf
1657 case "$arch" in
1658 arm)
1659 flags='-O2 -march=armv6'
1660 host="$ARCH-slitaz-linux-gnueabi" ;;
1661 armv6hf)
1662 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1663 host="$ARCH-slitaz-linux-gnueabi" ;;
1664 armv7)
1665 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1666 host="$ARCH-slitaz-linux-gnueabi" ;;
1667 x86_64)
1668 flags='-O2 -mtune=generic -pipe'
1669 host="$ARCH-slitaz-linux" ;;
1670 esac
1671 sed -i \
1672 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1673 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1674 . /etc/slitaz/cook.conf
1675 sysroot="$CROSS_TREE/sysroot"
1676 tools="/cross/$arch/tools"
1677 root="$sysroot"
1678 # L10n: keep the same width of translations to get a consistent view
1679 _ 'Target arch : %s' "$ARCH"
1680 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1681 _ 'Build flags : %s' "$flags"
1682 _ 'Arch sysroot : %s' "$sysroot"
1683 _ 'Tools prefix : %s' "$tools/bin"
1684 # Tell the packages manager where to find packages.
1685 _ 'Packages DB : %s' "$root$DB"
1686 mkdir -p $root$INSTALLED
1687 cd $root$DB; rm -f *.bak
1688 for list in packages.list packages.desc packages.equiv packages.md5; do
1689 rm -f $list
1690 ln -s $SLITAZ/packages/$list $list
1691 done
1692 # We must have the cross compiled glibc-base installed or default
1693 # i486 package will be used as dep by tazpkg and then break the
1694 # cross environment
1695 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1696 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1697 fi
1698 # Show GCC version or warn if not yet compiled.
1699 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1700 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1701 else
1702 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1703 _ 'Run "%s" to cook a toolchain' 'cross compile'
1704 fi
1705 footer ;;
1707 test)
1708 # Test a cook environment.
1709 _ 'Cook test: testing the cook environment' | log
1710 [ ! -d "$WOK" ] && exit 1
1711 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1712 cook cooktest ;;
1714 new)
1715 # Create the package folder and an empty receipt.
1716 pkg="$2"
1717 [ -z "$pkg" ] && usage
1718 newline
1719 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1721 action 'Creating folder "%s"' "$WOK/$pkg"
1722 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1724 action 'Preparing the package receipt...'
1725 cp $DATA/receipt .
1726 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1727 status; newline
1729 # Interactive mode, asking and seding.
1730 case "$3" in
1731 --interactive|-x)
1732 _ 'Entering interactive mode...'
1733 separator
1734 _ 'Package : %s' "$pkg"
1736 _n 'Version : ' ; read answer
1737 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1739 _n 'Category : ' ; read answer
1740 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1742 # L10n: Short description
1743 _n 'Short desc : ' ; read answer
1744 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1746 _n 'Maintainer : ' ; read answer
1747 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1749 _n 'License : ' ; read answer
1750 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1752 _n 'Web site : ' ; read answer
1753 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1754 newline
1756 # Wget URL.
1757 _ 'Wget URL to download source tarball.'
1758 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1759 _n 'Wget url : ' ; read answer
1760 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1762 # Ask for a stuff dir.
1763 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1764 if [ "$?" -eq 0 ]; then
1765 action 'Creating the stuff directory...'
1766 mkdir $WOK/$pkg/stuff; status
1767 fi
1769 # Ask for a description file.
1770 confirm "$(_n 'Are you going to write a description? (y/N)')"
1771 if [ "$?" -eq 0 ]; then
1772 action 'Creating the "%s" file...' 'description.txt'
1773 touch $WOK/$pkg/description.txt; status
1774 fi
1776 footer "$(_ 'Receipt is ready to use.')" ;;
1777 esac ;;
1779 list)
1780 # Cook a list of packages (better use the Cooker since it will order
1781 # packages before executing cook).
1782 check_root
1783 [ -z "$2" ] && die 'No list in argument.'
1784 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1786 _ 'Starting cooking the list "%s"' "$2" | log
1788 while read pkg; do
1789 cook $pkg || broken
1790 done < $2
1791 ;;
1793 clean-wok)
1794 check_root
1795 newline; action 'Cleaning all packages files...'
1796 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1797 status; newline ;;
1799 clean-src)
1800 check_root
1801 newline; action 'Cleaning all packages sources...'
1802 rm -rf $WOK/*/source
1803 status; newline ;;
1805 uncook)
1806 cd $WOK
1807 count=0
1808 title 'Checking for uncooked packages'
1810 for i in *; do
1811 unset HOST_ARCH EXTRAVERSION
1812 [ ! -e $i/receipt ] && continue
1813 . ./$i/receipt
1814 # Source cooked pkg receipt to get EXTRAVERSION
1815 if [ -d "$WOK/$i/taz" ]; then
1816 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1817 . ./receipt; cd $WOK
1818 fi
1819 case "$ARCH" in
1820 i486)
1821 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1822 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1823 count=$(($count + 1))
1824 colorize 34 "$i"
1825 fi ;;
1826 arm*)
1827 # Check only packages included in arch
1828 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1829 # *.tazpkg
1830 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1831 count=$(($count + 1))
1832 colorize 34 "$i"
1833 fi
1834 fi ;;
1835 esac
1836 done
1838 if [ "$count" -gt 0 ]; then
1839 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1840 else
1841 _ 'All packages are cooked :-)'
1842 newline
1843 fi
1844 ;;
1846 pkgdb)
1847 # Create suitable packages list for TazPkg and only for built packages
1848 # as well as flavors files for TazLiTo. We don't need logs since we do it
1849 # manually to ensure everything is fine before syncing the mirror.
1850 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1851 ;;
1853 splitdb)
1854 # File split.db is useful for searching for split packages.
1855 recreate_split_db
1856 ;;
1858 *)
1859 # Just cook and generate a package.
1860 check_root
1861 time=$(date +%s)
1862 pkg="$1"
1863 [ -z "$pkg" ] && usage
1865 # Search last successful cook time in all logs from newer to older
1866 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1867 [ -f "$LOGS/$pkg.log$i" ] || break
1868 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1869 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1870 [ -n "$lastcooktime" ] && break
1871 done
1873 receipt="$WOK/$pkg/receipt"
1874 check_pkg_in_wok
1875 newline
1877 unset inst
1878 unset_receipt
1879 . $receipt
1881 # Handle cross compilation.
1882 case "$ARCH" in
1883 arm*)
1884 if [ -z "$HOST_ARCH" ]; then
1885 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1886 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1887 _ 'cook: %s' "$error"
1888 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1889 _ 'Cook skip: %s' "$error" | log
1890 newline
1891 broken; exit 1
1892 fi ;;
1893 esac
1895 # Some packages are not included in some arch or fail to cross compile.
1896 : ${HOST_ARCH=i486}
1897 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1898 # Handle arm{v6hf,v7,..}
1899 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1900 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1901 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1902 _ 'cook: %s' "error"
1903 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1904 _ 'Cook skip: %s' "$error" | log
1905 sed -i "/^${pkg}$/d" $broken
1906 newline
1907 exit 0
1908 fi
1910 # Skip blocked, 3 lines also for the Cooker.
1911 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1912 die 'Package "%s" is blocked' "$pkg"
1914 try_aufs_chroot "$@"
1916 # Log and source receipt.
1917 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1918 echo "cook:$pkg" > $command
1920 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1922 while read cmd duration start; do
1923 [ $(($start + $duration)) -lt $(date +%s) ] &&
1924 echo "sed -i '/^$cmd $duration/d' $cooktime"
1925 done < $cooktime | sh
1927 # Display and log info if cook process stopped.
1928 # FIXME: gettext not working (in single quotes) here!
1929 trap '_ "\n\nCook stopped: control-C\n\n" | \
1930 tee -a $LOGS/$pkg.log' INT
1932 update_split_db
1934 # Handle --options
1935 case "$2" in
1936 --install|-i)
1937 inst='yes' ;;
1939 --pack)
1940 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
1941 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
1942 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
1943 sed -i '$ s|$| (packing)|' $activity
1944 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
1945 clean_log "$pkg-pack"
1946 time=$(($(date +%s) - $time))
1947 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
1948 sed -i '$ s|$| [ Done ]|' $activity
1949 rm -f $command
1950 exit 0 ;;
1951 esac
1953 # Rotate log
1954 for i in $(seq 9 -1 1); do
1955 j=$(($i - 1))
1956 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1957 done
1958 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1960 # Check if wanted is built now so we have separate log files.
1961 for wanted in $WANTED ; do
1962 if grep -q "^$wanted$" $blocked; then
1963 broken
1964 rm -f $command
1965 die 'WANTED package "%s" is blocked' "$wanted"
1966 fi
1967 if grep -q "^$wanted$" $broken; then
1968 broken
1969 rm -f $command
1970 die 'WANTED package "%s" is broken' "$wanted"
1971 fi
1972 if [ ! -d "$WOK/$wanted/install" ]; then
1973 cook "$wanted" || { broken; exit 1; }
1974 fi
1975 done
1977 # Cook and pack or exit on error and log everything.
1978 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1979 remove_deps | tee -a $LOGS/$pkg.log
1980 cookit_quality
1981 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1982 clean_log
1984 # Exit if any error in packing.
1985 lerror=$(_n 'ERROR')
1986 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1987 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1988 debug_info | tee -a $LOGS/$pkg.log
1989 sed -i '$ s|$| [ Failed ]|' $activity
1990 rm -f $command
1991 broken; exit 1
1992 fi
1994 # Create an XML feed
1995 gen_rss
1997 # Time and summary
1998 time=$(($(date +%s) - $time))
1999 summary | tee -a $LOGS/$pkg.log
2000 newline
2002 # We may want to install/update (outside aufs jail!).
2003 [ -s /aufs-umount.sh ] || install_package
2005 sed -i '$ s|$| [ Done ]|' $activity
2007 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2008 # If you want automation, use the Cooker Build Bot.
2009 rm -f $command
2010 ;;
2011 esac
2013 exit 0