cookutils view cook @ rev 1031

cook: change chroot mount options to "-o bind", add /dev here; mark "*.so.dbg" as @dev files
author Aleksej Bobylev <al.bobylev@gmail.com>
date Wed Feb 21 12:55:19 2018 +0200 (2018-02-21)
parents 7d37b282b4fb
children 5a63ab7642f2
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 CONFIG_FILES
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" -varch="$arch" '{
1088 if ($1 == name) printf("%s-%s%s.tazpkg", $1, $2, arch);
1089 }' $pi) # <name>-<version><extra_version><-arch>.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 -i "$PKGS/$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*)
1196 arch="-$ARCH"
1197 root="$CROSS_TREE/sysroot"
1198 ;;
1199 x86_64)
1200 arch="-$ARCH"
1201 ;;
1202 esac
1203 # Install package if requested but skip install if target host doesn't
1204 # match build system or it will break the build chroot.
1205 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1206 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1207 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" ]; then
1208 cd $PKGS
1209 tazpkg -i "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" --forced
1210 else
1211 broken
1212 die 'Unable to install package, build has failed.'
1213 fi
1214 fi
1216 update_chroot
1220 # remove chroot jail
1222 umount_aufs() {
1223 tac ${1}rw/aufs-umount.sh | sh
1224 rm -rf ${1}rw
1225 umount ${1}root
1226 rmdir ${1}r*
1230 # Launch the cook command into a chroot jail protected by aufs.
1231 # The current filesystems are used read-only and updates are
1232 # stored in a separate branch.
1234 try_aufs_chroot() {
1236 base="/dev/shm/aufsmnt$$"
1238 # Can we setup the chroot? Is it already done?
1239 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1240 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1241 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1242 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1243 mkdir ${base}root ${base}rw || return
1245 _ 'Setup aufs chroot...'
1247 # Sanity check
1248 for i in / /proc /sys /dev /dev/shm /home; do
1249 case " $AUFS_MOUNTS " in
1250 *\ $i\ *) ;;
1251 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1252 esac
1253 done
1254 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1255 mkdir -p ${base}root$mnt # for `mount -o bind`
1256 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1257 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1258 _ 'Aufs mount failure'
1259 umount ${base}root
1260 rm -rf ${base}r*
1261 return
1262 fi
1263 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1264 done
1265 trap "umount_aufs ${base}" INT
1267 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1268 status=$?
1270 _ 'Leaving aufs chroot...'
1271 umount_aufs $base
1272 # Install package outside the aufs jail
1273 install_package
1274 exit $status
1278 # Encode predefined XML entities
1280 xml_ent() {
1281 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1285 # Create a XML feed for freshly built packages.
1287 gen_rss() {
1288 pubdate=$(date '+%a, %d %b %Y %X')
1289 cat > $FEEDS/$pkg.xml <<EOT
1290 <item>
1291 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1292 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1293 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1294 <pubDate>$pubdate</pubDate>
1295 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1296 </item>
1297 EOT
1301 # Truncate stdout log file to $1 Mb.
1303 loglimit() {
1304 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1305 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1306 else
1307 tee /dev/stderr
1308 fi
1313 # Receipt functions to ease packaging
1316 get_dev_files() {
1317 action 'Getting standard devel files...'
1318 mkdir -p $fs/usr/lib
1319 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1320 cp -a $install/usr/lib/*a $fs/usr/lib
1321 cp -a $install/usr/include $fs/usr
1322 status
1326 # Function to use in compile_rules() to copy man page from $src to $install
1328 cook_pick_manpages() {
1329 local name section
1330 action 'Copying man pages...'
1332 for i in $@; do
1333 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1334 section=${name##*/}; section=${section##*.}
1335 mkdir -p $install/usr/share/man/man$section
1336 scopy $i $install/usr/share/man/man$section
1337 done
1338 status
1342 # Function to use in compile_rules() to copy documentation from $src to $install
1344 cook_pick_docs() {
1345 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1346 action 'Copying documentation...'
1347 mkdir -p $docdir
1348 cp -r $@ $docdir
1349 chmod -R a+r $docdir
1350 status
1354 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1356 cook_copy_files() {
1357 action 'Copying files...'
1358 cd $install
1359 local i j
1360 IFS=$'\n'
1361 for i in $@; do
1362 for j in $(find . -name $i ! -type d); do
1363 mkdir -p $fs$(dirname ${j#.})
1364 scopy $j $fs$(dirname ${j#.})
1365 done
1366 done
1367 cd - >/dev/null
1368 status
1372 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1374 cook_copy_folders() {
1375 action 'Copying folders...'
1376 cd $install
1377 local i j
1378 IFS=$'\n'
1379 for i in $@; do
1380 for j in $(find . -name $i -type d); do
1381 mkdir -p $fs$(dirname ${j#.})
1382 cp -a $j $fs$(dirname ${j#.})
1383 done
1384 done
1385 cd - >/dev/null
1386 status
1390 # Remove from current $fs files that are already packed (for receipts v2).
1391 # Note: the order in $SPLIT is very important.
1392 # Note 2: working in the current set.
1394 remove_already_packed() {
1395 local i j
1396 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1397 # $pkg may (or may not) be included in the $SPLIT
1398 neighbors=$(
1399 echo $pkg $SPLIT" " \
1400 | awk -F$'\t' -vpkg="$PACKAGE" '
1401 BEGIN { RS = " "; FS = ":"; }
1402 { set[$1] = $2; }
1403 END {
1404 current_set = set[pkg];
1405 for (i in set)
1406 { if (i != pkg && set[i] == current_set) print i; }
1408 ')
1409 IFS=$'\n'
1410 for neighbor in $neighbors; do
1411 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1412 [ -e "$i" ] || continue
1413 while read j; do
1414 [ -f $fs$j -o -h $fs$j ] || continue
1415 rm $fs$j
1416 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1417 done < $i
1418 done
1419 unset IFS
1423 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1424 # (default: 16 and 48) from $install to $fs
1426 cook_copy_icons() {
1427 local sizes=$@ i j ifs="$IFS"
1428 unset IFS
1429 action 'Copying hicolor icons...'
1430 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1431 mkdir -p $fs/usr/share/icons/hicolor
1432 for i in ${sizes:-16 48}; do
1433 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1434 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1435 scopy $install/usr/share/icons/hicolor/$j \
1436 $fs/usr/share/icons/hicolor
1437 done
1438 status
1439 IFS="$ifs"
1443 # Common function to copy files, folders and patterns
1445 copy() {
1446 action 'Copying folders and files...'
1447 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1449 IFS=$'\n'
1450 cd $install
1451 find ! -type d | sed 's|\.||' > $filelist
1452 find -type d | sed 's|\.||' > $folderlist
1454 for i in $@; do
1455 case $i in
1456 @std)
1457 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1458 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1459 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1460 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1461 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1462 /\/share\/devhelp\//d; /\/share\/locale\//d;
1463 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1464 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1465 /\/share\/appdata\//d; /\/share\/help\//d;
1466 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1467 /\.so\.dbg$/d;
1468 ' $filelist
1469 ;;
1470 @dev)
1471 # Copy "developer files"
1472 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1473 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1474 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1475 /\.so\.dbg$/p;
1476 ' $filelist
1477 ;;
1478 @rm)
1479 # Quick alias
1480 remove_already_packed
1481 ;;
1482 @ico)
1483 # Quick alias
1484 cook_copy_icons >/dev/null
1485 ;;
1486 */)
1487 # Copy specified folders.
1488 i="${i%/}"
1489 find -type d -path "*/${i#/}" | sed 's|^.||'
1490 ;;
1491 *)
1492 # Copy specified files.
1493 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1494 ;;
1495 esac \
1496 | sort -u \
1497 | while read j; do
1498 mkdir -p $fs$(dirname "$j")
1499 if [ -d "$install$j" ]; then
1500 cp -a "$install$j" $fs$(dirname "$j")
1501 else
1502 scopy "$install$j" $fs$(dirname "$j")
1503 fi
1504 done
1505 # Copy empty directories
1506 case $i in
1507 @std)
1508 while read j; do
1509 case $j in
1510 # always skip empty man & doc folders, because this will end up
1511 # copying all the man pages and docs to the package
1512 */man/*|*/doc/*) continue;;
1513 esac
1514 [ -z "$(ls -A "$install$j")" ] || continue
1515 # directory $j is empty
1516 k="$j"
1517 # make 'ladder' from directories, from root dir to $j
1518 # /a /a/b /a/b/c etc.
1519 while :; do
1520 [ -z "$k" ] && break
1521 echo "$k"
1522 k="${k%/*}"
1523 done \
1524 | tac \
1525 | while read k; do
1526 # copy dir with its original ownership/permissions if it does not exist
1527 [ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
1528 done
1529 done < $folderlist
1530 ;;
1531 esac
1532 done
1533 cd - >/dev/null
1534 unset IFS
1535 rm $filelist $folderlist
1536 status
1540 # Update split.db once for receipt
1542 update_split_db() {
1543 local db="$cache/split.db"
1544 touch $db
1545 sed -i "/^$pkg\t/d" $db
1546 echo -e "$pkg\t$(all_names)" >> $db
1550 # Recreate whole split.db from scratch
1552 recreate_split_db() {
1553 # Clean
1554 local db="$cache/split.db"
1555 touch $db
1556 > $db
1558 cd $WOK
1559 for pkg in *; do
1560 [ -f "$WOK/$pkg/receipt" ] || continue
1561 unset PACKAGE SPLIT
1562 . $WOK/$pkg/receipt
1563 echo -e "$PACKAGE\t$(all_names)" >> $db
1564 done
1568 # Put the status to the activity log
1570 put_status() {
1571 # $1: package, $2: status, one of 'Done', 'Failed'
1572 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1573 if [ "$2" == 'Done' ]; then
1574 # overstrike all previous 'Failed' to indicate package is OK now
1575 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1576 fi
1583 # Commands
1586 # cook <package> --deps
1587 [ -n "$deps" ] && {
1588 @@PREFIX@@/libexec/cookutils/deps $1
1589 exit 0
1592 # cook <package> --clean
1593 # cook <package> -c
1594 [ -n "$clean" -o "$2" == '-c' ] && {
1595 action 'Cleaning "%s"' "$1"
1596 cd $WOK/$1; rm -rf install taz source
1597 status; newline
1598 touch $activity # update $activity -> something changed -> update webstat
1599 exit 0
1602 # cook <package> --getsrc
1603 # cook <package> -gs
1604 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1605 title 'Getting source for "%s"' "$1"
1606 receipt="$WOK/$pkg/receipt"
1607 check_pkg_in_wok
1608 unset_receipt
1609 . $receipt
1610 get_source
1611 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1612 exit 0
1615 # cook <package> --block
1616 # cook <package> -b
1617 [ -n "$block" -o "$2" == '-b' ] && {
1618 action 'Blocking package "%s"' "$1"
1619 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1620 status; newline
1621 touch $activity
1622 exit 0
1625 # cook <package> --unblock
1626 # cook <package> -ub
1627 [ -n "$unblock" -o "$2" == '-ub' ] && {
1628 action 'Unblocking package "%s"' "$1"
1629 sed -i "/^$1$/d" $blocked
1630 status; newline
1631 touch $activity
1632 exit 0
1638 case "$1" in
1639 usage|help|-u|-h)
1640 usage ;;
1642 list-wok)
1643 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1644 cd $WOK
1645 if [ "$ARCH" != 'i486' ]; then
1646 count=0
1647 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1648 do
1649 unset HOST_ARCH
1650 . ./$pkg
1651 count=$(($count + 1))
1652 colorize 34 "$PACKAGE"
1653 done
1654 else
1655 count=$(ls | wc -l)
1656 ls -1
1657 fi
1658 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1659 ;;
1661 activity)
1662 cat $activity ;;
1664 search)
1665 # Just a simple search function, we don't need more actually.
1666 query="$2"
1667 title 'Search results for "%s"' "$query"
1668 cd $WOK; ls -1 | grep "$query"
1669 footer ;;
1671 setup)
1672 # Setup a build environment
1673 check_root
1674 _ 'Cook: setup environment' | log
1675 title 'Setting up your environment'
1676 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1677 cd $SLITAZ
1678 init_db_files
1679 _ 'Checking for packages to install...'
1680 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1681 # ARCH-setup or 'cross check' should be used before: cook setup
1682 case "$ARCH" in
1683 arm*|x86_64)
1684 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1685 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1686 . /etc/slitaz/cross.conf ;;
1687 esac
1688 for pkg in $SETUP_PKGS; do
1689 if [ -n "$forced" ]; then
1690 tazpkg -gi $pkg --forced
1691 else
1692 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1693 fi
1694 done
1696 # Handle --options
1697 case "$2" in
1698 --wok) hg clone $WOK_URL wok || exit 1 ;;
1699 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1700 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1701 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1702 esac
1704 # SliTaz group and permissions
1705 if ! grep -q ^slitaz /etc/group; then
1706 _ 'Adding group "%s"' 'slitaz'
1707 addgroup slitaz
1708 fi
1709 _ 'Setting permissions for group "%s"...' 'slitaz'
1710 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1711 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1712 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1714 *-setup)
1715 # Setup for cross compiling.
1716 arch="${1%-setup}"
1717 check_root
1718 . /etc/slitaz/cook.conf
1719 for pkg in $CROSS_SETUP; do
1720 if [ -n "$forced" ]; then
1721 tazpkg -gi $pkg --forced
1722 else
1723 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1724 fi
1725 done
1727 _ 'Cook: setup %s cross environment' "$arch" | log
1728 title 'Setting up your %s cross environment' "$arch"
1729 init_db_files
1730 sed -i \
1731 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1732 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1733 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1734 /etc/slitaz/cook.conf
1735 case "$arch" in
1736 arm)
1737 flags='-O2 -march=armv6'
1738 host="$ARCH-slitaz-linux-gnueabi" ;;
1739 armv6hf)
1740 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1741 host="$ARCH-slitaz-linux-gnueabi" ;;
1742 armv7)
1743 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1744 host="$ARCH-slitaz-linux-gnueabi" ;;
1745 x86_64)
1746 flags='-O2 -mtune=generic -pipe'
1747 host="$ARCH-slitaz-linux" ;;
1748 esac
1749 sed -i \
1750 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1751 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1752 . /etc/slitaz/cook.conf
1753 sysroot="$CROSS_TREE/sysroot"
1754 tools="/cross/$arch/tools"
1755 root="$sysroot"
1756 # L10n: keep the same width of translations to get a consistent view
1757 _ 'Target arch : %s' "$ARCH"
1758 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1759 _ 'Build flags : %s' "$flags"
1760 _ 'Arch sysroot : %s' "$sysroot"
1761 _ 'Tools prefix : %s' "$tools/bin"
1762 # Tell the packages manager where to find packages.
1763 _ 'Packages DB : %s' "$root$DB"
1764 mkdir -p $root$INSTALLED
1765 cd $root$DB; rm -f *.bak
1766 for list in packages.list packages.desc packages.equiv packages.md5; do
1767 rm -f $list
1768 ln -s $SLITAZ/packages/$list $list
1769 done
1770 # We must have the cross compiled glibc-base installed or default
1771 # i486 package will be used as dep by tazpkg and then break the
1772 # cross environment
1773 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1774 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1775 fi
1776 # Show GCC version or warn if not yet compiled.
1777 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1778 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1779 else
1780 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1781 _ 'Run "%s" to cook a toolchain' 'cross compile'
1782 fi
1783 footer ;;
1785 test)
1786 # Test a cook environment.
1787 _ 'Cook test: testing the cook environment' | log
1788 [ ! -d "$WOK" ] && exit 1
1789 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1790 cook cooktest ;;
1792 new)
1793 # Create the package folder and an empty receipt.
1794 pkg="$2"
1795 [ -z "$pkg" ] && usage
1796 newline
1797 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1799 action 'Creating folder "%s"' "$WOK/$pkg"
1800 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1802 action 'Preparing the package receipt...'
1803 cp $DATA/receipt .
1804 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1805 status; newline
1807 # Interactive mode, asking and seding.
1808 case "$3" in
1809 --interactive|-x)
1810 _ 'Entering interactive mode...'
1811 separator
1812 _ 'Package : %s' "$pkg"
1814 _n 'Version : ' ; read answer
1815 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1817 _n 'Category : ' ; read answer
1818 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1820 # L10n: Short description
1821 _n 'Short desc : ' ; read answer
1822 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1824 _n 'Maintainer : ' ; read answer
1825 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1827 _n 'License : ' ; read answer
1828 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1830 _n 'Web site : ' ; read answer
1831 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1832 newline
1834 # Wget URL.
1835 _ 'Wget URL to download source tarball.'
1836 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1837 _n 'Wget url : ' ; read answer
1838 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1840 # Ask for a stuff dir.
1841 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1842 if [ "$?" -eq 0 ]; then
1843 action 'Creating the stuff directory...'
1844 mkdir $WOK/$pkg/stuff; status
1845 fi
1847 # Ask for a description file.
1848 confirm "$(_n 'Are you going to write a description? (y/N)')"
1849 if [ "$?" -eq 0 ]; then
1850 action 'Creating the "%s" file...' 'description.txt'
1851 touch $WOK/$pkg/description.txt; status
1852 fi
1854 footer "$(_ 'Receipt is ready to use.')" ;;
1855 esac ;;
1857 list)
1858 # Cook a list of packages (better use the Cooker since it will order
1859 # packages before executing cook).
1860 check_root
1861 [ -z "$2" ] && die 'No list in argument.'
1862 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1864 _ 'Starting cooking the list "%s"' "$2" | log
1866 while read pkg; do
1867 cook $pkg || broken
1868 done < $2
1869 ;;
1871 clean-wok)
1872 check_root
1873 newline; action 'Cleaning all packages files...'
1874 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1875 status; newline ;;
1877 clean-src)
1878 check_root
1879 newline; action 'Cleaning all packages sources...'
1880 rm -rf $WOK/*/source
1881 status; newline ;;
1883 uncook)
1884 cd $WOK
1885 count=0
1886 title 'Checking for uncooked packages'
1888 for i in *; do
1889 unset HOST_ARCH EXTRAVERSION
1890 [ ! -e $i/receipt ] && continue
1891 . ./$i/receipt
1892 # Source cooked pkg receipt to get EXTRAVERSION
1893 if [ -d "$WOK/$i/taz" ]; then
1894 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1895 . ./receipt; cd $WOK
1896 fi
1897 case "$ARCH" in
1898 i486)
1899 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1900 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1901 count=$(($count + 1))
1902 colorize 34 "$i"
1903 fi ;;
1904 arm*)
1905 # Check only packages included in arch
1906 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1907 # *.tazpkg
1908 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1909 count=$(($count + 1))
1910 colorize 34 "$i"
1911 fi
1912 fi ;;
1913 esac
1914 done
1916 if [ "$count" -gt 0 ]; then
1917 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1918 else
1919 _ 'All packages are cooked :-)'
1920 newline
1921 fi
1922 ;;
1924 pkgdb)
1925 # Create suitable packages list for TazPkg and only for built packages
1926 # as well as flavors files for TazLiTo. We don't need logs since we do it
1927 # manually to ensure everything is fine before syncing the mirror.
1928 recreate_split_db
1929 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1930 ;;
1932 splitdb)
1933 # File split.db is useful for searching for split packages.
1934 recreate_split_db
1935 ;;
1937 *)
1938 # Just cook and generate a package.
1939 check_root
1940 time=$(date +%s)
1941 pkg="$1"
1942 [ -z "$pkg" ] && usage
1944 # Search last successful cook time in all logs from newer to older
1945 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1946 [ -f "$LOGS/$pkg.log$i" ] || break
1947 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1948 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1949 [ -n "$lastcooktime" ] && break
1950 done
1952 receipt="$WOK/$pkg/receipt"
1953 check_pkg_in_wok
1954 newline
1956 unset inst
1957 unset_receipt
1958 . $receipt
1960 # Handle cross compilation.
1961 case "$ARCH" in
1962 arm*)
1963 if [ -z "$HOST_ARCH" ]; then
1964 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1965 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1966 _ 'cook: %s' "$error"
1967 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1968 _ 'Cook skip: %s' "$error" | log
1969 newline
1970 broken; exit 1
1971 fi ;;
1972 esac
1974 # Some packages are not included in some arch or fail to cross compile.
1975 : ${HOST_ARCH=$ARCH}
1976 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1977 # Handle arm{v6hf,v7,..}
1978 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1979 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1980 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1981 _ 'cook: %s' "error"
1982 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1983 _ 'Cook skip: %s' "$error" | log
1984 sed -i "/^${pkg}$/d" $broken
1985 newline
1986 exit 0
1987 fi
1989 # Skip blocked, 3 lines also for the Cooker.
1990 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1991 die 'Package "%s" is blocked' "$pkg"
1993 try_aufs_chroot "$@"
1995 # Log and source receipt.
1996 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1997 echo "cook:$pkg" > $command
1999 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2001 while read cmd duration start; do
2002 [ $(($start + $duration)) -lt $(date +%s) ] &&
2003 echo "sed -i '/^$cmd $duration/d' $cooktime"
2004 done < $cooktime | sh
2006 # Display and log info if cook process stopped.
2007 # FIXME: gettext not working (in single quotes) here!
2008 trap '_ "\n\nCook stopped: control-C\n\n" | \
2009 tee -a $LOGS/$pkg.log' INT
2011 update_split_db
2013 # Handle --options
2014 case "$2" in
2015 --install|-i)
2016 inst='yes' ;;
2018 --pack)
2019 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2020 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2021 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2022 sed -i '$ s|$| (packing)|' $activity
2023 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2024 clean_log "$pkg-pack"
2025 time=$(($(date +%s) - $time))
2026 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2027 put_status $pkg Done
2028 rm -f $command
2029 exit 0 ;;
2031 --trials|-t)
2032 trials='yes' ;;
2033 esac
2035 # Rotate log
2036 for i in $(seq 9 -1 1); do
2037 j=$(($i - 1))
2038 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2039 done
2040 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2042 # Check if wanted is built now so we have separate log files.
2043 for wanted in $WANTED ; do
2044 if grep -q "^$wanted$" $blocked; then
2045 broken
2046 rm -f $command
2047 die 'WANTED package "%s" is blocked' "$wanted"
2048 fi
2049 if grep -q "^$wanted$" $broken; then
2050 broken
2051 rm -f $command
2052 die 'WANTED package "%s" is broken' "$wanted"
2053 fi
2054 if [ ! -d "$WOK/$wanted/install" ]; then
2055 cook "$wanted" || { broken; exit 1; }
2056 fi
2057 done
2059 # Cook and pack or exit on error and log everything.
2060 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2061 rq=$? # the return code of `cookit $@` above command
2063 # Remove build dependencies both when `cookit` done or fail
2064 remove_deps | tee -a $LOGS/$pkg.log
2065 cookit_quality
2067 # Log and stop if `cookit` fails
2068 if [ $rq -eq 1 ]; then
2069 debug_info | tee -a $LOGS/$pkg.log
2070 put_status $pkg Failed
2071 rm -f $command
2072 broken; exit 1
2073 fi
2075 # Proceed only if `cookit` return code is zero-OK
2076 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2078 clean_log
2080 # Exit if any error in packing.
2081 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2082 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2083 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2084 debug_info | tee -a $LOGS/$pkg.log
2085 put_status $pkg Failed
2086 rm -f $command
2087 broken; exit 1
2088 fi
2090 # Create an XML feed
2091 gen_rss
2093 # Time and summary
2094 time=$(($(date +%s) - $time))
2095 summary | tee -a $LOGS/$pkg.log
2096 newline
2098 # We may want to install/update (outside aufs jail!).
2099 [ -s /aufs-umount.sh ] || install_package
2101 put_status $pkg Done
2103 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2104 # If you want automation, use the Cooker Build Bot.
2105 rm -f $command
2106 ;;
2107 esac
2109 exit 0