cookutils view cook @ rev 1024

cook, lighttpd/index.cgi, modules/compressor, modules/mk_pkg_receipt, modules/pkgdb: patch for the x86_64 native architecture support, fix empty depends, etc.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Jan 24 12:14:38 2018 +0200 (2018-01-24)
parents 713fecc03454
children 6943f5f9845a
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 esac
551 }
554 # The main cook function.
556 cookit() {
557 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
558 _ 'ERROR: Broken setup. Abort.'
559 return
560 fi
562 title 'Cook: %s' "$PACKAGE $VERSION"
563 set_paths
565 # Handle cross-tools.
566 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
567 case "$ARCH" in
568 arm*|x86_64)
569 # CROSS_COMPILE is used by at least Busybox and the kernel to set
570 # the cross-tools prefix. Sysroot is the root of our target arch
571 sysroot="$CROSS_TREE/sysroot"
572 tools="$CROSS_TREE/tools"
573 # Set root path when cross compiling. ARM tested but not x86_64
574 # When cross compiling we must install build deps in $sysroot.
575 arch="-$ARCH"
576 root="$sysroot"
577 _ '%s sysroot: %s' "$ARCH" "$sysroot"
578 _ 'Adding "%s" to PATH' "$tools/bin"
579 export PATH="$PATH:$tools/bin"
580 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
581 export CROSS_COMPILE="$HOST_SYSTEM-"
582 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
583 if [ "$ARCH" == 'x86_64' ]; then
584 export CC="$HOST_SYSTEM-gcc -m64"
585 export CXX="$HOST_SYSTEM-g++ -m64"
586 else
587 export CC="$HOST_SYSTEM-gcc"
588 export CXX="$HOST_SYSTEM-g++"
589 fi
590 export AR="$HOST_SYSTEM-ar"
591 export AS="$HOST_SYSTEM-as"
592 export RANLIB="$HOST_SYSTEM-ranlib"
593 export LD="$HOST_SYSTEM-ld"
594 export STRIP="$HOST_SYSTEM-strip"
595 export LIBTOOL="$HOST_SYSTEM-libtool"
596 ;;
597 esac
599 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
601 cd $pkgdir
602 [ -z "$continue" ] && rm -rf source 2>/dev/null
603 rm -rf install taz 2>/dev/null
605 # Disable -pipe if less than 512 MB free RAM.
606 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
607 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
608 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
609 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
610 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
611 fi
612 unset free
614 # Export flags and path to be used by make and receipt.
615 DESTDIR="$pkgdir/install"
616 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
617 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
618 #LDFLAGS
620 # BUILD_DEPENDS may vary depending on the ARCH
621 case "$ARCH" in
622 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
623 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
624 esac
626 # Check for build deps and handle implicit depends of *-dev packages
627 # (ex: libusb-dev :: libusb).
628 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
629 # touch $CACHE/installed.local $CACHE/installed.web
630 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
631 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
633 # Get the list of installed packages
634 cd $root$INSTALLED; ls > $CACHE/installed.list
636 for action in check install; do
637 for dep in $BUILD_DEPENDS; do
638 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
639 for i in $dep $implicit; do
640 # Skip if package already installed
641 [ -f "$root$INSTALLED/$i/receipt" ] && continue
643 case $action in
644 check)
645 # Search for local package or local provided-package
646 name=$(awk -F$'\t' -vpkg="$i" '{
647 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
648 }' "$PKGS/packages.info")
649 if [ -z "$name" ]; then
650 # Search for package in mirror
651 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
652 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
653 fi
654 ;;
655 install)
656 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
657 ;;
658 esac
659 done
660 done
661 done
663 # # Have we a missing build dep to cook?
664 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
665 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
666 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
667 # for i in $(uniq $CACHE/missing.dep); do
668 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
669 # tee -a $LOGS/$PACKAGE.log.$$
670 # # programmers: next two messages are exact copy from remove_deps()
671 # togrep1=$(_n 'Build dependencies to remove:')
672 # togrep2=$(_n 'Removing:')
673 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
674 # fgrep $togrep1 $LOGS/$i.log && \
675 # fgrep $togrep2 $LOGS/$i.log && newline) | \
676 # tee -a $LOGS/$PACKAGE.log.$$ && break
677 # done
678 # rm -f $CACHE/missing.dep
679 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
680 # fi
681 #
682 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
683 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
684 # # missing dep in cached file.
685 # lerror=$(_n 'ERROR')
686 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
687 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
688 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
689 # broken; exit 1
690 # fi
691 #
692 # # Install local packages: package-version$arch
693 # cd $PKGS
694 # for i in $(uniq $CACHE/installed.local); do
695 # # _ 'Installing dep (pkg/local): %s' "$i"
696 # tazpkg install $i --root=$root --local --quiet --cookmode
697 # done
698 #
699 # # Install web or cached packages (if mirror is set to $PKGS we only
700 # # use local packages).
701 # for i in $(uniq $CACHE/installed.web); do
702 # # _ 'Installing dep (web/cache): %s' "$i"
703 # tazpkg get-install $i --root=$root --local --quiet --cookmode
704 # done
706 update_installed_cook_diff
708 # Get source tarball and make sure we have source dir named:
709 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
710 # tarball if it exists.
711 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
712 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
713 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
714 LZMA_SRC=''
715 else
716 get_source || { broken; exit 1; }
717 fi
718 fi
719 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
720 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
721 if ! extract_source ; then
722 get_source
723 extract_source || { broken; exit 1; }
724 fi
725 if [ -n "$LZMA_SRC" ]; then
726 cd $pkgdir/source
727 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
728 mv tmp tmp-1; mkdir tmp
729 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
730 fi
731 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
732 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
733 fi
734 fi
736 cd $pkgdir/source/tmp
737 # Some archives are not well done and don't extract to one dir (ex lzma).
738 files=$(ls | wc -l)
739 [ "$files" -eq 1 -a -d "$(ls)" ] &&
740 mv * ../$PACKAGE-$VERSION
741 [ "$files" -eq 1 -a -f "$(ls)" ] &&
742 mkdir -p ../$PACKAGE-$VERSION &&
743 mv * ../$PACKAGE-$VERSION/$TARBALL
744 [ "$files" -gt 1 ] &&
745 mkdir -p ../$PACKAGE-$VERSION &&
746 mv * ../$PACKAGE-$VERSION
747 cd ..; rm -rf tmp
748 fi
750 # Check md5sum (or similar) for sources tarball
751 check_integrity
753 # Libtool shared libs path hack.
754 case "$ARCH" in
755 arm*) cross libhack ;;
756 esac
758 # Compiling all the sets
759 if grep -q ^compile_rules $receipt; then
760 _ 'Executing: %s' 'compile_rules'
761 echo "CFLAGS : $CFLAGS"
762 #echo "LDFLAGS : $LDFLAGS"
763 [ -d "$src" ] && cd $src
764 patchit
766 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
767 SETS=$(echo $SPLIT \
768 | awk '
769 BEGIN { RS = " "; FS = ":"; }
770 { print $2; }' \
771 | sort -u \
772 | tr '\n' ' ')
773 SETS=${SETS% } # normalize space
774 # Prepare specified source sets using patched sources
775 [ -n "$SETS" ] &&
776 for set in $SETS; do
777 echo "Preparing set $set" # debug
778 cp -a $src $src-$set
779 done
781 for SET in '' $SETS; do
782 # Switch to the specified source set
783 set_paths
784 local suffix=''
785 [ -n "$SET" ] && suffix="-$SET"
786 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
787 export install="$WOK/$pkg/install$suffix"
788 export DESTDIR="$install"
790 if [ -n "$SETS" ]; then
791 if [ -n "$SET" ]; then
792 title "Switching to the set '$SET'"
793 else
794 title "Switching to the default set"
795 fi
796 echo "src : $src"
797 echo "install: $install"
798 fi
799 [ -d "$src" ] && cd $src # packages without sources exists
800 echo
802 [ -d "$install" ] && rm -r $install
803 #mkdir -p $install
805 compile_rules $@ || { broken; exit 1; }
807 # Stay compatible with _pkg
808 [ -d "$src/_pkg" ] && mv $src/_pkg $install
810 copy_generic_stuff
812 # Actions to do after compiling the package
813 # Skip all for split packages (already done in main package)
814 if [ -z "$WANTED" ]; then
815 footer
816 export COOKOPTS ARCH install
817 @@PREFIX@@/libexec/cookutils/compressor install
818 fi
819 done
820 else
821 mkdir -p $install # allow receipts without `compile_rules()`
822 fi
823 footer
825 # Execute testsuite.
826 if grep -q ^testsuite $receipt; then
827 title 'Running testsuite'
828 testsuite $@ || { broken; exit 1; }
829 footer
830 fi
832 update_installed_cook_diff force
833 }
836 # Cook quality assurance.
838 cookit_quality() {
839 while true; do
840 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
841 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
842 [ "$trials" == 'yes' ] || break
843 title "Interactive mode"
844 # TODO: allow commands:
845 # q - quit; v - edit receipt here using vi;
846 # s - search for package containing package;
847 # <package name> - install package; [Enter] - retry
848 _ 'You may install the packages here and/or edit the receipt there.'
849 newline
850 while true; do
851 _n 'Install the package? [name/N] '; read answer
852 [ -n "$answer" ] || break
853 tazpkg -gi $answer --root=$root --local --quiet --cookmode
854 done
855 newline
856 _n 'Try again? [Y/n] '; read answer
857 [ "$answer" == 'n' ] && break
858 # here you may append log if you want (">>" instead of last ">")
859 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
860 done
862 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
864 # ERROR can be echoed any time in cookit()
865 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
866 grep -Eq "(^ERROR|undefined reference to)" ; then
867 debug_info | tee -a $LOGS/$pkg.log
868 put_status $pkg Failed
869 rm -f $command
870 broken; exit 1
871 fi
872 }
875 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
876 # but it doesn't handle EXTRAVERSION.
878 packit() {
879 set_paths "$1"
880 PACKAGE="${1:-$PACKAGE}"
882 # Handle cross compilation
883 case "$ARCH" in
884 arm*|x86_64) arch="-$ARCH" ;;
885 esac
887 title 'Pack: %s' "$PACKAGE $VERSION$arch"
889 # Get set name for specified package from $SPLIT variable
890 local set=$(echo -n $SPLIT \
891 | awk -vpkg="$PACKAGE" '
892 BEGIN { RS = " "; FS = ":"; }
893 { if ($1 == pkg && $2 != "") { print "-" $2; exit; } }')
894 # Change set, make filelist and folderlist for new set
895 export src="$src$set"
896 export install="$install$set"
897 export DESTDIR="$install"
899 if grep -q ^genpkg_rules $receipt; then
900 _ 'Executing: %s' 'genpkg_rules'
901 set -e; cd $pkgdir; mkdir -p $fs
902 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
903 $LOGS/$pkg.log
904 else
905 _ 'No packages rules: meta package'
906 mkdir -p $fs
907 fi
909 # Check CONFIG_FILES
910 if [ -n "$CONFIG_FILES" ]; then
911 unset IFS
912 for i in $CONFIG_FILES; do
913 if [ ! -e $fs$i ]; then
914 case $i in
915 */) mkdir -p $fs$i ;;
916 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
917 esac
918 fi
919 done
920 fi
922 # First QA check to stop now if genpkg_rules failed.
923 lerror=$(_n 'ERROR')
924 if fgrep -q ^$lerror $LOGS/$pkg.log; then
925 broken; exit 1
926 fi
928 cd $taz
929 action 'Copying "%s"...' 'receipt'
930 export PACKAGE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT
931 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
932 chown 0.0 $pack/receipt; status
934 unset desc
935 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
936 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
937 if [ -n "$desc" ]; then
938 action 'Copying "%s"...' "$(basename "$desc")"
939 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
940 fi
942 copy_generic_files
944 # Strip and stuff files.
945 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
947 # Create files.list with redirecting find output.
948 action 'Creating the list of files...'
949 cd $fs
950 find . -type f -print > ../files.list
951 find . -type l -print >> ../files.list
952 cd ..; sed -i 's|^.||' files.list
953 status
955 # Md5sum of files.
956 action 'Creating md5sum of files...'
957 while read file; do
958 [ -L "fs$file" ] && continue
959 [ -f "fs$file" ] || continue
960 case "$file" in
961 /lib/modules/*/modules.*|*.pyc) continue ;;
962 esac
963 md5sum "fs$file" | sed 's| fs| |'
964 done < files.list | sort -k2 > md5sum
965 status
967 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
968 2>/dev/null | awk 'END{ print $1 }')
970 # Build cpio archive.
971 action 'Compressing the FS...'
972 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
973 # find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
974 find fs | cpio -o -H newc --quiet | /bin/lzma -qzeT0 >fs.cpio.lzma
975 mv fs ../
976 status
978 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
979 2>/dev/null | awk 'END{ print $1 }')
981 action 'Updating receipt sizes...'
982 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
983 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
984 status
986 # Set extra version.
987 if [ -n "$EXTRAVERSION" ]; then
988 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
989 sed -i '/^EXTRAVERSION=/d' receipt
990 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
991 status
992 fi
994 # Compress.
995 action 'Creating full cpio archive...'
996 find . -newer $receipt -exec touch -hr $receipt '{}' \;
997 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
998 status
1000 # Restoring original package tree.
1001 mv ../fs .
1003 rm fs.cpio.lzma; cd ..
1005 # QA and give info.
1006 tazpkg=$(ls *.tazpkg)
1007 packit_quality
1008 footer "$(_ 'Package "%s" created' "$tazpkg")"
1012 # Verify package quality and consistency.
1014 packit_quality() {
1015 local arch=''
1016 case "$ARCH" in
1017 arm*|x86_64) arch="-$ARCH" ;;
1018 esac
1020 local rsum rsumold='' rsum_changed old_file
1021 local pi="$PKGS/packages.info" fl="$cache/files.list"
1022 local pkg_file="$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg"
1023 local rsum_file=$(mktemp) rsum_file_old=$(mktemp) tmpdir=$(mktemp -d)
1026 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1027 # Exit if any error found in log file.
1028 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1029 rm -f $command
1030 broken; exit 1
1031 fi
1032 fi
1035 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1037 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1038 action 'QA: checking for empty package...'
1039 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1040 broken
1041 rm -f $command
1042 false; status
1043 die 'ERROR: empty package'
1044 fi
1045 :; status
1046 fi
1049 # Calculate release checksum: usually it does not change on "just recook".
1050 # Release checksum is md5sum of file containing md5sums of:
1051 # a) all files, b) receipt, and c) description.txt.
1052 # Md5sum of the package file will change every time because of embedded timestamps;
1053 # release checksum based only on files content, and will change only when files change.
1054 # (Pitfall: ownership and permissions...)
1056 # Calculate rsum for new package
1057 cp $pack/md5sum $rsum_file
1058 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1059 [ -e "$pack/description.txt" ] &&
1060 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1061 rsum=$(md5sum $rsum_file | awk '{print $1}')
1063 # Calculate rsum for existing previous "old" package
1064 if [ -f "$pkg_file" ]; then
1065 # don't trust database entry, check the package file
1066 cd $tmpdir
1067 cpio -F "$pkg_file" -i md5sum receipt description.txt >/dev/null 2>&1
1068 cp ./md5sum $rsum_file_old
1069 md5sum ./receipt | sed 's| [^ ]*/| |' >> $rsum_file_old
1070 [ -e "./description.txt" ] &&
1071 md5sum ./description.txt | sed 's| [^ ]*/| |' >> $rsum_file_old
1072 rsumold=$(md5sum $rsum_file_old | awk '{print $1}')
1073 cd - >/dev/null
1074 fi
1076 # Clean
1077 rm $rsum_file $rsum_file_old
1078 rm -r $tmpdir
1081 touch $pi $broken
1084 # Find and remove old package only if "release checksum" has changed
1086 if [ "$rsum" != "$rsumold" ]; then
1087 old_file=$(awk -F$'\t' -vname="$PACKAGE" '{
1088 if ($1 == name) printf("%s-%s.tazpkg", $1, $2);
1089 }' $pi) # <name>-<version><extra_version>.tazpkg
1090 if [ -f "$PKGS/$old_file" ]; then
1091 action 'Removing old package "%s"' "$old_file"
1092 rm -f "$PKGS/$old_file"
1093 status
1094 fi
1095 # package changed, substitute old package by new one
1096 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg $PKGS
1097 _ 'The release checksum has changed.'
1098 else
1099 # package not changed, remove new package
1100 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1101 _ 'The release checksum has not changed.'
1102 fi
1105 sed -i "/^${pkg}$/d" $broken
1108 # Update packages database every time after successful build
1110 # packages.info (unsorted, located near to packages)
1111 unset_receipt; . $pack/receipt
1112 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1113 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1114 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1115 cat >> $pi <<EOT
1116 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1117 EOT
1119 # files.list (uncompressed, unsorted, located in $cache)
1120 touch $fl
1121 sed -i "/^$PACKAGE: /d" $fl
1122 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1126 # Return all the names of packages bundled in this receipt
1128 all_names() {
1129 # Get package names from $SPLIT variable
1130 local split=$(echo $SPLIT \
1131 | awk '
1132 BEGIN { RS = " "; FS = ":"; }
1133 { print $1; }' \
1134 | tr '\n' ' ')
1135 local split_space=" $split "
1136 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1137 # For receipts v1: $SPLIT may present in the $WANTED package,
1138 # but split packages have their own receipts
1139 echo $PACKAGE
1140 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1141 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1142 # We should build packages in the order defined in the $SPLIT.
1143 echo $split
1144 else
1145 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1146 echo $PACKAGE $split
1147 fi
1151 # v2: pack all packages using compiled files
1153 packall() {
1154 set_paths
1155 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1156 for i in $(all_names); do
1157 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1158 packit $i
1159 done
1160 else
1161 packit
1162 fi
1166 # Reverse "cat" command: prints input lines in the reverse order
1168 tac() {
1169 sed '1!G;h;$!d' $1
1173 # Update chroot with freshly rebuilt package: keep env up-to-date.
1175 update_chroot() {
1176 local PACKAGE="$pkg"
1177 for i in $(all_names); do
1178 if [ -d "$root$INSTALLED/$i" ]; then
1179 . /etc/slitaz/cook.conf
1180 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1181 _ 'Updating %s chroot environment...' "$ARCH"
1182 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1183 cd $PKGS
1184 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1185 fi
1186 done
1190 # Install package on --inst or update the chroot.
1192 install_package() {
1193 set_paths
1194 case "$ARCH" in
1195 arm*|x86_64)
1196 arch="-$ARCH"
1197 root="$CROSS_TREE/sysroot" ;;
1198 esac
1199 # Install package if requested but skip install if target host doesn't
1200 # match build system or it will break the build chroot.
1201 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1202 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1203 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1204 cd $PKGS
1205 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1206 else
1207 broken
1208 die 'Unable to install package, build has failed.'
1209 fi
1210 fi
1212 update_chroot
1216 # remove chroot jail
1218 umount_aufs() {
1219 tac ${1}rw/aufs-umount.sh | sh
1220 rm -rf ${1}rw
1221 umount ${1}root
1222 rmdir ${1}r*
1226 # Launch the cook command into a chroot jail protected by aufs.
1227 # The current filesystems are used read-only and updates are
1228 # stored in a separate branch.
1230 try_aufs_chroot() {
1232 base="/dev/shm/aufsmnt$$"
1234 # Can we setup the chroot? Is it already done?
1235 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1236 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1237 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1238 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1239 mkdir ${base}root ${base}rw || return
1241 _ 'Setup aufs chroot...'
1243 # Sanity check
1244 for i in / /proc /sys /dev/shm /home ; do
1245 case " $AUFS_MOUNTS " in
1246 *\ $i\ *) ;;
1247 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1248 esac
1249 done
1250 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1251 mount --bind $mnt ${base}root$mnt
1252 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1253 _ 'Aufs mount failure'
1254 umount ${base}root
1255 rm -rf ${base}r*
1256 return
1257 fi
1258 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1259 done
1260 trap "umount_aufs ${base}" INT
1262 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1263 status=$?
1265 _ 'Leaving aufs chroot...'
1266 umount_aufs $base
1267 # Install package outside the aufs jail
1268 install_package
1269 exit $status
1273 # Encode predefined XML entities
1275 xml_ent() {
1276 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1280 # Create a XML feed for freshly built packages.
1282 gen_rss() {
1283 pubdate=$(date '+%a, %d %b %Y %X')
1284 cat > $FEEDS/$pkg.xml <<EOT
1285 <item>
1286 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1287 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1288 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1289 <pubDate>$pubdate</pubDate>
1290 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1291 </item>
1292 EOT
1296 # Truncate stdout log file to $1 Mb.
1298 loglimit() {
1299 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1300 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1301 else
1302 tee /dev/stderr
1303 fi
1308 # Receipt functions to ease packaging
1311 get_dev_files() {
1312 action 'Getting standard devel files...'
1313 mkdir -p $fs/usr/lib
1314 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1315 cp -a $install/usr/lib/*a $fs/usr/lib
1316 cp -a $install/usr/include $fs/usr
1317 status
1321 # Function to use in compile_rules() to copy man page from $src to $install
1323 cook_pick_manpages() {
1324 local name section
1325 action 'Copying man pages...'
1327 for i in $@; do
1328 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1329 section=${name##*/}; section=${section##*.}
1330 mkdir -p $install/usr/share/man/man$section
1331 scopy $i $install/usr/share/man/man$section
1332 done
1333 status
1337 # Function to use in compile_rules() to copy documentation from $src to $install
1339 cook_pick_docs() {
1340 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1341 action 'Copying documentation...'
1342 mkdir -p $docdir
1343 cp -r $@ $docdir
1344 chmod -R a+r $docdir
1345 status
1349 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1351 cook_copy_files() {
1352 action 'Copying files...'
1353 cd $install
1354 local i j
1355 IFS=$'\n'
1356 for i in $@; do
1357 for j in $(find . -name $i ! -type d); do
1358 mkdir -p $fs$(dirname ${j#.})
1359 scopy $j $fs$(dirname ${j#.})
1360 done
1361 done
1362 cd - >/dev/null
1363 status
1367 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1369 cook_copy_folders() {
1370 action 'Copying folders...'
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 cp -a $j $fs$(dirname ${j#.})
1378 done
1379 done
1380 cd - >/dev/null
1381 status
1385 # Remove from current $fs files that are already packed (for receipts v2).
1386 # Note: the order in $SPLIT is very important.
1387 # Note 2: working in the current set.
1389 remove_already_packed() {
1390 local i j
1391 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1392 # $pkg may (or may not) be included in the $SPLIT
1393 neighbors=$(
1394 echo $pkg $SPLIT" " \
1395 | awk -F$'\t' -vpkg="$PACKAGE" '
1396 BEGIN { RS = " "; FS = ":"; }
1397 { set[$1] = $2; }
1398 END {
1399 current_set = set[pkg];
1400 for (i in set)
1401 { if (i != pkg && set[i] == current_set) print i; }
1403 ')
1404 IFS=$'\n'
1405 for neighbor in $neighbors; do
1406 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1407 [ -e "$i" ] || continue
1408 while read j; do
1409 [ -f $fs$j -o -h $fs$j ] || continue
1410 rm $fs$j
1411 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1412 done < $i
1413 done
1414 unset IFS
1418 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1419 # (default: 16 and 48) from $install to $fs
1421 cook_copy_icons() {
1422 local sizes=$@ i j ifs="$IFS"
1423 unset IFS
1424 action 'Copying hicolor icons...'
1425 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1426 mkdir -p $fs/usr/share/icons/hicolor
1427 for i in ${sizes:-16 48}; do
1428 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1429 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1430 scopy $install/usr/share/icons/hicolor/$j \
1431 $fs/usr/share/icons/hicolor
1432 done
1433 status
1434 IFS="$ifs"
1438 # Common function to copy files, folders and patterns
1440 copy() {
1441 action 'Copying folders and files...'
1442 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1444 IFS=$'\n'
1445 cd $install
1446 find ! -type d | sed 's|\.||' > $filelist
1447 find -type d | sed 's|\.||' > $folderlist
1449 for i in $@; do
1450 case $i in
1451 @std)
1452 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1453 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1454 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1455 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1456 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1457 /\/share\/devhelp\//d; /\/share\/locale\//d;
1458 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1459 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1460 /\/share\/appdata\//d; /\/share\/help\//d;
1461 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1462 ' $filelist
1463 ;;
1464 @dev)
1465 # Copy "developer files"
1466 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1467 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1468 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1469 ' $filelist
1470 ;;
1471 @rm)
1472 # Quick alias
1473 remove_already_packed
1474 ;;
1475 @ico)
1476 # Quick alias
1477 cook_copy_icons >/dev/null
1478 ;;
1479 */)
1480 # Copy specified folders.
1481 i="${i%/}"
1482 find -type d -path "*/${i#/}" | sed 's|^.||'
1483 ;;
1484 *)
1485 # Copy specified files.
1486 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1487 ;;
1488 esac \
1489 | sort -u \
1490 | while read j; do
1491 mkdir -p $fs$(dirname "$j")
1492 if [ -d "$install$j" ]; then
1493 cp -a "$install$j" $fs$(dirname "$j")
1494 else
1495 scopy "$install$j" $fs$(dirname "$j")
1496 fi
1497 done
1498 # Copy empty directories
1499 case $i in
1500 @std)
1501 while read j; do
1502 case $j in
1503 # always skip empty man & doc folders, because this will end up
1504 # copying all the man pages and docs to the package
1505 */man/*|*/doc/*) continue;;
1506 esac
1507 [ -z "$(ls -A "$install$j")" ] || continue
1508 # directory $j is empty
1509 k="$j"
1510 # make 'ladder' from directories, from root dir to $j
1511 # /a /a/b /a/b/c etc.
1512 while :; do
1513 [ -z "$k" ] && break
1514 echo "$k"
1515 k="${k%/*}"
1516 done \
1517 | tac \
1518 | while read k; do
1519 # copy dir with its original ownership/permissions if it does not exist
1520 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1521 done
1522 done < $folderlist
1523 ;;
1524 esac
1525 done
1526 cd - >/dev/null
1527 unset IFS
1528 rm $filelist $folderlist
1529 status
1533 # Update split.db once for receipt
1535 update_split_db() {
1536 local db="$cache/split.db"
1537 touch $db
1538 sed -i "/^$pkg\t/d" $db
1539 echo -e "$pkg\t$(all_names)" >> $db
1543 # Recreate whole split.db from scratch
1545 recreate_split_db() {
1546 # Clean
1547 local db="$cache/split.db"
1548 touch $db
1549 > $db
1551 cd $WOK
1552 for pkg in *; do
1553 [ -f "$WOK/$pkg/receipt" ] || continue
1554 unset PACKAGE SPLIT
1555 . $WOK/$pkg/receipt
1556 echo -e "$PACKAGE\t$(all_names)" >> $db
1557 done
1561 # Put the status to the activity log
1563 put_status() {
1564 # $1: package, $2: status, one of 'Done', 'Failed'
1565 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1572 # Commands
1575 # cook <package> --deps
1576 [ -n "$deps" ] && {
1577 @@PREFIX@@/libexec/cookutils/deps $1
1578 exit 0
1581 # cook <package> --clean
1582 # cook <package> -c
1583 [ -n "$clean" -o "$2" == '-c' ] && {
1584 action 'Cleaning "%s"' "$1"
1585 cd $WOK/$1; rm -rf install taz source
1586 status; newline
1587 touch $activity # update $activity -> something changed -> update webstat
1588 exit 0
1591 # cook <package> --getsrc
1592 # cook <package> -gs
1593 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1594 title 'Getting source for "%s"' "$1"
1595 receipt="$WOK/$pkg/receipt"
1596 check_pkg_in_wok
1597 unset_receipt
1598 . $receipt
1599 get_source
1600 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1601 exit 0
1604 # cook <package> --block
1605 # cook <package> -b
1606 [ -n "$block" -o "$2" == '-b' ] && {
1607 action 'Blocking package "%s"' "$1"
1608 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1609 status; newline
1610 touch $activity
1611 exit 0
1614 # cook <package> --unblock
1615 # cook <package> -ub
1616 [ -n "$unblock" -o "$2" == '-ub' ] && {
1617 action 'Unblocking package "%s"' "$1"
1618 sed -i "/^$1$/d" $blocked
1619 status; newline
1620 touch $activity
1621 exit 0
1627 case "$1" in
1628 usage|help|-u|-h)
1629 usage ;;
1631 list-wok)
1632 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1633 cd $WOK
1634 if [ "$ARCH" != 'i486' ]; then
1635 count=0
1636 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1637 do
1638 unset HOST_ARCH
1639 . ./$pkg
1640 count=$(($count + 1))
1641 colorize 34 "$PACKAGE"
1642 done
1643 else
1644 count=$(ls | wc -l)
1645 ls -1
1646 fi
1647 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1648 ;;
1650 activity)
1651 cat $activity ;;
1653 search)
1654 # Just a simple search function, we don't need more actually.
1655 query="$2"
1656 title 'Search results for "%s"' "$query"
1657 cd $WOK; ls -1 | grep "$query"
1658 footer ;;
1660 setup)
1661 # Setup a build environment
1662 check_root
1663 _ 'Cook: setup environment' | log
1664 title 'Setting up your environment'
1665 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1666 cd $SLITAZ
1667 init_db_files
1668 _ 'Checking for packages to install...'
1669 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1670 # ARCH-setup or 'cross check' should be used before: cook setup
1671 case "$ARCH" in
1672 arm*|x86_64)
1673 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1674 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1675 . /etc/slitaz/cross.conf ;;
1676 esac
1677 for pkg in $SETUP_PKGS; do
1678 if [ -n "$forced" ]; then
1679 tazpkg -gi $pkg --forced
1680 else
1681 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1682 fi
1683 done
1685 # Handle --options
1686 case "$2" in
1687 --wok) hg clone $WOK_URL wok || exit 1 ;;
1688 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1689 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1690 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1691 esac
1693 # SliTaz group and permissions
1694 if ! grep -q ^slitaz /etc/group; then
1695 _ 'Adding group "%s"' 'slitaz'
1696 addgroup slitaz
1697 fi
1698 _ 'Setting permissions for group "%s"...' 'slitaz'
1699 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1700 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1701 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1703 *-setup)
1704 # Setup for cross compiling.
1705 arch="${1%-setup}"
1706 check_root
1707 . /etc/slitaz/cook.conf
1708 for pkg in $CROSS_SETUP; do
1709 if [ -n "$forced" ]; then
1710 tazpkg -gi $pkg --forced
1711 else
1712 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1713 fi
1714 done
1716 _ 'Cook: setup %s cross environment' "$arch" | log
1717 title 'Setting up your %s cross environment' "$arch"
1718 init_db_files
1719 sed -i \
1720 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1721 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1722 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1723 /etc/slitaz/cook.conf
1724 case "$arch" in
1725 arm)
1726 flags='-O2 -march=armv6'
1727 host="$ARCH-slitaz-linux-gnueabi" ;;
1728 armv6hf)
1729 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1730 host="$ARCH-slitaz-linux-gnueabi" ;;
1731 armv7)
1732 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1733 host="$ARCH-slitaz-linux-gnueabi" ;;
1734 x86_64)
1735 flags='-O2 -mtune=generic -pipe'
1736 host="$ARCH-slitaz-linux" ;;
1737 esac
1738 sed -i \
1739 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1740 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1741 . /etc/slitaz/cook.conf
1742 sysroot="$CROSS_TREE/sysroot"
1743 tools="/cross/$arch/tools"
1744 root="$sysroot"
1745 # L10n: keep the same width of translations to get a consistent view
1746 _ 'Target arch : %s' "$ARCH"
1747 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1748 _ 'Build flags : %s' "$flags"
1749 _ 'Arch sysroot : %s' "$sysroot"
1750 _ 'Tools prefix : %s' "$tools/bin"
1751 # Tell the packages manager where to find packages.
1752 _ 'Packages DB : %s' "$root$DB"
1753 mkdir -p $root$INSTALLED
1754 cd $root$DB; rm -f *.bak
1755 for list in packages.list packages.desc packages.equiv packages.md5; do
1756 rm -f $list
1757 ln -s $SLITAZ/packages/$list $list
1758 done
1759 # We must have the cross compiled glibc-base installed or default
1760 # i486 package will be used as dep by tazpkg and then break the
1761 # cross environment
1762 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1763 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1764 fi
1765 # Show GCC version or warn if not yet compiled.
1766 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1767 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1768 else
1769 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1770 _ 'Run "%s" to cook a toolchain' 'cross compile'
1771 fi
1772 footer ;;
1774 test)
1775 # Test a cook environment.
1776 _ 'Cook test: testing the cook environment' | log
1777 [ ! -d "$WOK" ] && exit 1
1778 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1779 cook cooktest ;;
1781 new)
1782 # Create the package folder and an empty receipt.
1783 pkg="$2"
1784 [ -z "$pkg" ] && usage
1785 newline
1786 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1788 action 'Creating folder "%s"' "$WOK/$pkg"
1789 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1791 action 'Preparing the package receipt...'
1792 cp $DATA/receipt .
1793 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1794 status; newline
1796 # Interactive mode, asking and seding.
1797 case "$3" in
1798 --interactive|-x)
1799 _ 'Entering interactive mode...'
1800 separator
1801 _ 'Package : %s' "$pkg"
1803 _n 'Version : ' ; read answer
1804 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1806 _n 'Category : ' ; read answer
1807 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1809 # L10n: Short description
1810 _n 'Short desc : ' ; read answer
1811 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1813 _n 'Maintainer : ' ; read answer
1814 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1816 _n 'License : ' ; read answer
1817 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1819 _n 'Web site : ' ; read answer
1820 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1821 newline
1823 # Wget URL.
1824 _ 'Wget URL to download source tarball.'
1825 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1826 _n 'Wget url : ' ; read answer
1827 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1829 # Ask for a stuff dir.
1830 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1831 if [ "$?" -eq 0 ]; then
1832 action 'Creating the stuff directory...'
1833 mkdir $WOK/$pkg/stuff; status
1834 fi
1836 # Ask for a description file.
1837 confirm "$(_n 'Are you going to write a description? (y/N)')"
1838 if [ "$?" -eq 0 ]; then
1839 action 'Creating the "%s" file...' 'description.txt'
1840 touch $WOK/$pkg/description.txt; status
1841 fi
1843 footer "$(_ 'Receipt is ready to use.')" ;;
1844 esac ;;
1846 list)
1847 # Cook a list of packages (better use the Cooker since it will order
1848 # packages before executing cook).
1849 check_root
1850 [ -z "$2" ] && die 'No list in argument.'
1851 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1853 _ 'Starting cooking the list "%s"' "$2" | log
1855 while read pkg; do
1856 cook $pkg || broken
1857 done < $2
1858 ;;
1860 clean-wok)
1861 check_root
1862 newline; action 'Cleaning all packages files...'
1863 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1864 status; newline ;;
1866 clean-src)
1867 check_root
1868 newline; action 'Cleaning all packages sources...'
1869 rm -rf $WOK/*/source
1870 status; newline ;;
1872 uncook)
1873 cd $WOK
1874 count=0
1875 title 'Checking for uncooked packages'
1877 for i in *; do
1878 unset HOST_ARCH EXTRAVERSION
1879 [ ! -e $i/receipt ] && continue
1880 . ./$i/receipt
1881 # Source cooked pkg receipt to get EXTRAVERSION
1882 if [ -d "$WOK/$i/taz" ]; then
1883 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1884 . ./receipt; cd $WOK
1885 fi
1886 case "$ARCH" in
1887 i486)
1888 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1889 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1890 count=$(($count + 1))
1891 colorize 34 "$i"
1892 fi ;;
1893 arm*)
1894 # Check only packages included in arch
1895 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1896 # *.tazpkg
1897 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1898 count=$(($count + 1))
1899 colorize 34 "$i"
1900 fi
1901 fi ;;
1902 esac
1903 done
1905 if [ "$count" -gt 0 ]; then
1906 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1907 else
1908 _ 'All packages are cooked :-)'
1909 newline
1910 fi
1911 ;;
1913 pkgdb)
1914 # Create suitable packages list for TazPkg and only for built packages
1915 # as well as flavors files for TazLiTo. We don't need logs since we do it
1916 # manually to ensure everything is fine before syncing the mirror.
1917 recreate_split_db
1918 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1919 ;;
1921 splitdb)
1922 # File split.db is useful for searching for split packages.
1923 recreate_split_db
1924 ;;
1926 *)
1927 # Just cook and generate a package.
1928 check_root
1929 time=$(date +%s)
1930 pkg="$1"
1931 [ -z "$pkg" ] && usage
1933 # Search last successful cook time in all logs from newer to older
1934 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1935 [ -f "$LOGS/$pkg.log$i" ] || break
1936 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1937 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1938 [ -n "$lastcooktime" ] && break
1939 done
1941 receipt="$WOK/$pkg/receipt"
1942 check_pkg_in_wok
1943 newline
1945 unset inst
1946 unset_receipt
1947 . $receipt
1949 # Handle cross compilation.
1950 case "$ARCH" in
1951 arm*)
1952 if [ -z "$HOST_ARCH" ]; then
1953 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1954 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1955 _ 'cook: %s' "$error"
1956 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1957 _ 'Cook skip: %s' "$error" | log
1958 newline
1959 broken; exit 1
1960 fi ;;
1961 esac
1963 # Some packages are not included in some arch or fail to cross compile.
1964 : ${HOST_ARCH=$ARCH}
1965 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1966 # Handle arm{v6hf,v7,..}
1967 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1968 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1969 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1970 _ 'cook: %s' "error"
1971 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1972 _ 'Cook skip: %s' "$error" | log
1973 sed -i "/^${pkg}$/d" $broken
1974 newline
1975 exit 0
1976 fi
1978 # Skip blocked, 3 lines also for the Cooker.
1979 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1980 die 'Package "%s" is blocked' "$pkg"
1982 try_aufs_chroot "$@"
1984 # Log and source receipt.
1985 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1986 echo "cook:$pkg" > $command
1988 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1990 while read cmd duration start; do
1991 [ $(($start + $duration)) -lt $(date +%s) ] &&
1992 echo "sed -i '/^$cmd $duration/d' $cooktime"
1993 done < $cooktime | sh
1995 # Display and log info if cook process stopped.
1996 # FIXME: gettext not working (in single quotes) here!
1997 trap '_ "\n\nCook stopped: control-C\n\n" | \
1998 tee -a $LOGS/$pkg.log' INT
2000 update_split_db
2002 # Handle --options
2003 case "$2" in
2004 --install|-i)
2005 inst='yes' ;;
2007 --pack)
2008 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2009 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2010 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2011 sed -i '$ s|$| (packing)|' $activity
2012 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2013 clean_log "$pkg-pack"
2014 time=$(($(date +%s) - $time))
2015 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2016 put_status $pkg Done
2017 rm -f $command
2018 exit 0 ;;
2020 --trials|-t)
2021 trials='yes' ;;
2022 esac
2024 # Rotate log
2025 for i in $(seq 9 -1 1); do
2026 j=$(($i - 1))
2027 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2028 done
2029 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2031 # Check if wanted is built now so we have separate log files.
2032 for wanted in $WANTED ; do
2033 if grep -q "^$wanted$" $blocked; then
2034 broken
2035 rm -f $command
2036 die 'WANTED package "%s" is blocked' "$wanted"
2037 fi
2038 if grep -q "^$wanted$" $broken; then
2039 broken
2040 rm -f $command
2041 die 'WANTED package "%s" is broken' "$wanted"
2042 fi
2043 if [ ! -d "$WOK/$wanted/install" ]; then
2044 cook "$wanted" || { broken; exit 1; }
2045 fi
2046 done
2048 # Cook and pack or exit on error and log everything.
2049 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2050 rq=$? # the return code of `cookit $@` above command
2052 # Remove build dependencies both when `cookit` done or fail
2053 remove_deps | tee -a $LOGS/$pkg.log
2054 cookit_quality
2056 # Log and stop if `cookit` fails
2057 if [ $rq -eq 1 ]; then
2058 debug_info | tee -a $LOGS/$pkg.log
2059 put_status $pkg Failed
2060 rm -f $command
2061 broken; exit 1
2062 fi
2064 # Proceed only if `cookit` return code is zero-OK
2065 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2067 clean_log
2069 # Exit if any error in packing.
2070 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2071 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2072 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2073 debug_info | tee -a $LOGS/$pkg.log
2074 put_status $pkg Failed
2075 rm -f $command
2076 broken; exit 1
2077 fi
2079 # Create an XML feed
2080 gen_rss
2082 # Time and summary
2083 time=$(($(date +%s) - $time))
2084 summary | tee -a $LOGS/$pkg.log
2085 newline
2087 # We may want to install/update (outside aufs jail!).
2088 [ -s /aufs-umount.sh ] || install_package
2090 put_status $pkg Done
2092 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2093 # If you want automation, use the Cooker Build Bot.
2094 rm -f $command
2095 ;;
2096 esac
2098 exit 0