cookutils view cook @ rev 752

cook: catch more errors
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Sep 21 11:14:29 2015 +0200 (2015-09-21)
parents 08ad52d1ff04
children aea93b5ceac8
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"
15 # Internationalization.
17 export TEXTDOMAIN='cook'
18 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
19 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
20 _p() {
21 local S="$1" P="$2" N="$3"; shift; shift; shift;
22 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
25 #
26 # Functions
27 #
29 usage() {
30 cat <<EOT
32 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
34 $(boldify "$(_ 'Commands:')")
35 usage|help $(_ 'Display this short usage.')
36 setup $(_ 'Setup your build environment.')
37 *-setup $(_ 'Setup a cross environment.')
38 * = {arm|armv6hf|armv7|x86_64}
39 test $(_ 'Test environment and cook a package.')
40 list-wok $(_ 'List packages in the wok.')
41 search $(_ 'Simple packages search function.')
42 new $(_ 'Create a new package with a receipt.')
43 list $(_ 'Cook a list of packages.')
44 clean-wok $(_ 'Clean-up all packages files.')
45 clean-src $(_ 'Clean-up all packages sources.')
46 uncook $(_ 'Check for uncooked packages')
47 pkgdb $(_ 'Create packages DB lists and flavors.')
49 $(boldify "$(_ 'Options:')")
50 cook <pkg>
51 --clean -c $(_ 'clean the package in the wok.')
52 --install -i $(_ 'cook and install the package.')
53 --getsrc -gs $(_ 'get the package source tarball.')
54 --block -b $(_ 'block a package so cook will skip it.')
55 --unblock -ub $(_ 'unblock a blocked package.')
56 --cdeps $(_ 'check dependencies of cooked package.')
57 --pack $(_ 'repack an already built package.')
58 --debug $(_ 'display debugging messages.')
59 --continue $(_ 'continue running compile_rules.')
60 cook new <pkg>
61 --interactive -x $(_ 'create a receipt interactively.')
62 cook setup
63 --wok $(_ 'clone the cooking wok from Hg repo.')
64 --stable $(_ 'clone the stable wok from Hg repo.')
65 --undigest $(_ 'clone the undigest wok from Hg repo.')
66 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
67 --forced $(_ 'force reinstall of chroot packages.')
68 cook pkgdb
69 --flavors $(_ 'create up-to-date flavors files.')
71 EOT
72 exit 0
73 }
76 # We don't want these escapes in web interface.
78 clean_log() {
79 sed -i -e s'|\[70G\[ \[1;32m| |' \
80 -e s'|\[0;39m \]||' $LOGS/$pkg.log
81 }
84 # Be sure package exists in wok.
86 check_pkg_in_wok() {
87 if [ ! -d "$WOK/$pkg" ]; then
88 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
89 exit 1
90 fi
91 }
94 if_empty_value() {
95 if [ -z "$value" ]; then
96 # L10n: QA is quality assurance
97 _ 'QA: empty variable: %s' "$var=\"\""; newline
98 exit 1
99 fi
100 }
103 # Initialize files used in $CACHE
105 init_db_files() {
106 _ 'Creating directories structure in "%s"' "$SLITAZ"
107 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
108 _ 'Creating DB files in "%s"' "$CACHE"
109 for f in $activity $command $broken $blocked; do
110 touch $f
111 done
112 }
115 # QA: check a receipt consistency before building.
117 receipt_quality() {
118 _ 'QA: checking package receipt...'
119 unset online
120 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
121 online='online'
122 fi
123 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
124 unset value
125 value="$(. $receipt; eval echo \$$var)"
126 case "$var" in
127 PACKAGE|VERSION|SHORT_DESC)
128 if_empty_value ;;
129 CATEGORY)
130 value="${value:-empty}"
131 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
132 if ! echo " $valid " | grep -q " $value "; then
133 _ 'QA: unknown category "%s"' "$value"
134 longline "$(_ 'Please, use one of: %s' "$valid")"
135 newline
136 exit 1
137 fi ;;
138 WEB_SITE)
139 # We don't check WGET_URL since if dl is needed it will fail.
140 # Break also if we're not online. Here error is not fatal.
141 if_empty_value
142 [ -z "$online" ] && break
143 if ! busybox wget -T 12 -s $value 2>/dev/null; then
144 _ 'QA: unable to reach "%s"' "$value"
145 fi ;;
146 esac
147 done
148 }
151 # Paths used in receipt and by cook itself.
153 set_paths() {
154 pkgdir="$WOK/$PACKAGE"
155 basesrc="$pkgdir/source"
156 tmpsrc="$basesrc/tmp"
157 src="$basesrc/$PACKAGE-$VERSION"
158 taz="$pkgdir/taz"
159 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
160 fs="$pack/fs"
161 stuff="$pkgdir/stuff"
162 install="$pkgdir/install"
163 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
164 lzma_tarball="$pkgsrc.tar.lzma"
165 if [ -n "$PATCH" ]; then
166 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
167 fi
168 if [ -n "$WANTED" ]; then
169 basesrc="$WOK/$WANTED/source"
170 src="$basesrc/$WANTED-$VERSION"
171 install="$WOK/$WANTED/install"
172 wanted_stuff="$WOK/$WANTED/stuff"
173 fi
174 if [ -n "$SOURCE" ]; then
175 source_stuff="$WOK/$SOURCE/stuff"
176 fi
177 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
178 if [ -f "$WOK/linux/receipt" ]; then
179 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
180 kbasevers=${kvers:0:3}
181 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
182 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
183 kbasevers=${kvers:0:3}
184 fi
185 # Python version
186 if [ -f "$WOK/python/receipt" ]; then
187 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
188 fi
189 # Perl version for some packages needed it
190 if [ -f "$WOK/perl/receipt" ]; then
191 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
192 fi
193 # Old way compatibility.
194 _pkg="$install"
195 }
198 # Create source tarball when URL is a SCM.
200 create_tarball() {
201 local tarball
202 tarball="$pkgsrc.tar.bz2"
203 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
204 _ 'Creating tarball "%s"' "$tarball"
205 if [ -n "$LZMA_SRC" ]; then
206 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
207 LZMA_SRC=''
208 else
209 tar -cjf $tarball $pkgsrc || exit 1
210 mv $tarball $SRC; rm -rf $pkgsrc
211 fi
212 TARBALL="$tarball"
213 }
216 # Get package source. For SCM we are in cache so clone here and create a
217 # tarball here.
219 get_source() {
220 local url
221 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
222 set_paths
223 pwd=$(pwd)
224 case "$WGET_URL" in
225 http://*|ftp://*)
226 # Busybox Wget is better!
227 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
228 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
229 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
231 https://*)
232 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
233 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
234 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
236 hg*|mercurial*)
237 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
238 url=${WGET_URL#hg|}
239 else
240 url=${WGET_URL#mercurial|}
241 fi
242 _ 'Getting source from %s...' 'Hg'
243 _ 'URL: %s' "$url"
244 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
245 if [ -n "$BRANCH" ]; then
246 _ 'Hg branch: %s' "$BRANCH"
247 hg clone $url --rev $BRANCH $pkgsrc || \
248 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
249 else
250 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
251 fi
252 rm -rf $pkgsrc/.hg
253 create_tarball ;;
255 git*)
256 url=${WGET_URL#git|}
257 _ 'Getting source from %s...' 'Git'
258 _ 'URL: %s' "$url"
259 cd $SRC
260 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
261 if [ -n "$BRANCH" ]; then
262 _ 'Git branch: %s' "$BRANCH"
263 cd $pkgsrc; git checkout $BRANCH; cd ..
264 fi
265 cd $SRC
266 create_tarball ;;
268 cvs*)
269 url=${WGET_URL#cvs|}
270 mod=$PACKAGE
271 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
272 _ 'Getting source from %s...' 'CVS'
273 _ 'URL: %s' "$url"
274 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
275 _ 'Cloning to "%s"' "$pwd/$mod"
276 cvs -d:$url co $mod && mv $mod $pkgsrc
277 create_tarball ;;
279 svn*|subversion*)
280 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
281 url=${WGET_URL#svn|}
282 else
283 url=${WGET_URL#subversion|}
284 fi
285 _ 'Getting source from %s...' 'SVN'
286 _ 'URL: %s' "$url"
287 if [ -n "$BRANCH" ]; then
288 echo t | svn co $url -r $BRANCH $pkgsrc
289 else
290 echo t | svn co $url $pkgsrc
291 fi
292 create_tarball ;;
294 bzr*)
295 url=${WGET_URL#bzr|}
296 _ 'Getting source from %s...' 'bazaar'
297 cd $SRC
298 pkgsrc=${url#*:}
299 if [ -n "$BRANCH" ]; then
300 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
301 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
302 else
303 echo "bzr -Ossl.cert_reqs=none branch $url"
304 bzr -Ossl.cert_reqs=none branch $url
305 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
306 _ "Don't forget to add to receipt:"
307 echo -e "BRANCH=\"$BRANCH\"\n"
308 fi
309 mv $pkgsrc $pkgsrc-$BRANCH
310 pkgsrc="$pkgsrc-$BRANCH"
311 create_tarball ;;
313 *)
314 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
315 tee -a $LOGS/$PACKAGE.log
316 exit 1 ;;
317 esac
318 }
321 # Extract source package.
323 extract_source() {
324 if [ ! -s "$SRC/$TARBALL" ]; then
325 local url
326 url="$MIRROR_URL/sources/packages"
327 url="$url/${TARBALL:0:1}/$TARBALL"
328 _ 'Getting source from %s...' 'mirror'
329 _ 'URL: %s' "$url"
330 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
331 fi
332 _ 'Extracting source archive "%s"' "$TARBALL"
333 case "$TARBALL" in
334 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
335 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
336 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
337 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
338 *.tar) tar -xf $SRC/$TARBALL ;;
339 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
340 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
341 tar -xf $SRC/$TARBALL 2>/dev/null;;
342 *.7z) 7zr x $SRC/$TARBALL ;;
343 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
344 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
345 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
346 *) cp $SRC/$TARBALL $(pwd) ;;
347 esac
348 }
351 # Display cooked package summary.
353 summary() {
354 cd $WOK/$pkg
355 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
356 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
357 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
358 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
359 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
360 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
362 sec="$time"
363 div=$(( ($time + 30) / 60))
364 case $div in
365 0) min='';;
366 # L10n: 'm' is for minutes (approximate cooking time)
367 *) min=$(_n '~ %dm' "$div");;
368 esac
370 _ 'Summary for: %s' "$PACKAGE $VERSION"
371 separator
373 # L10n: keep the same width of translations to get a consistent view
374 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
375 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
376 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
377 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
378 _ 'Packed : %s' "$fs"
379 _ 'Compressed : %s' "$size"
380 _ 'Files : %s' "$files"
381 # L10n: 's' is for seconds (cooking time)
382 _ 'Cook time : %ds %s' "$sec" "$min"
383 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
384 _ 'Host arch : %s' "$ARCH"
385 separator
386 }
389 # Display debugging error info.
391 debug_info() {
392 newline; _ 'Debug information'; separator
393 # L10n: specify your format of date and time (to help: man date)
394 # L10n: not bad one is '+%x %R'
395 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
396 # L10n: Please, translate all messages beginning with ERROR in a same way
397 lerror=$(_n 'ERROR')
398 for error in \
399 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
400 'error:' 'fatal error:' 'undefined reference to' \
401 'Unable to connect to' 'link: cannot find the library' \
402 'CMake Error' ': No such file or directory'
403 do
404 fgrep "$error" $LOGS/$pkg.log
405 done > $LOGS/$pkg.log.debug_info 2>&1
406 cat $LOGS/$pkg.log.debug_info
407 rm -f $LOGS/$pkg.log.debug_info
408 separator; newline
409 }
412 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
413 # so some packages need to copy these files with the receipt and genpkg_rules.
415 copy_generic_files() {
416 # $LOCALE is set in cook.conf
417 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
418 if [ -d "$install/usr/share/locale" ]; then
419 mkdir -p $fs/usr/share/locale
420 for i in $LOCALE; do
421 if [ -d "$install/usr/share/locale/$i" ]; then
422 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
423 fi
424 done
425 fi
426 fi
428 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
429 if [ "$GENERIC_PIXMAPS" != 'no' ]; then
430 if [ -d "$install/usr/share/pixmaps" ]; then
431 mkdir -p $fs/usr/share/pixmaps
432 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
433 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
434 $fs/usr/share/pixmaps
435 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
436 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
437 $fs/usr/share/pixmaps
438 fi
439 fi
441 # Custom or homemade PNG pixmap can be in stuff.
442 if [ -f "$stuff/$PACKAGE.png" ]; then
443 mkdir -p $fs/usr/share/pixmaps
444 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
445 fi
446 fi
448 # Desktop entry (.desktop).
449 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
450 if [ "$GENERIC_MENUS" != 'no' ]; then
451 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
452 mkdir -p $fs/usr/share
453 cp -a $install/usr/share/applications $fs/usr/share
454 fi
455 fi
457 # Homemade desktop file(s) can be in stuff.
458 if [ -d "$stuff/applications" ]; then
459 mkdir -p $fs/usr/share
460 cp -a $stuff/applications $fs/usr/share
461 fi
462 if [ -f "$stuff/$PACKAGE.desktop" ]; then
463 mkdir -p $fs/usr/share/applications
464 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
465 fi
467 # Add custom licenses
468 if [ -d "$stuff/licenses" ]; then
469 mkdir -p $fs/usr/share/licenses
470 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
471 fi
472 }
475 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
476 # as removing unneeded files like in Python packages. Cross compiled binaries
477 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
479 strip_package() {
480 case "$ARCH" in
481 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
482 *) export STRIP='strip' ;;
483 esac
484 _n 'Executing strip on all files...'
485 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
486 if [ -d "$dir" ]; then
487 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
488 fi
489 done
490 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
491 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
492 status
494 # Remove Python .pyc and .pyo from packages.
495 #_n 'Removing Python compiled files...'
496 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
497 #status
499 # Remove Perl perllocal.pod and .packlist from packages.
500 #_n 'Removing Perl compiled files...'
501 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
502 #status
503 }
506 # Remove installed deps.
508 remove_deps() {
509 # Now remove installed build deps.
510 diff='/tmp/installed.cook.diff'
511 if [ -s $diff ]; then
512 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
513 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
514 _n 'Build dependencies to remove:'; echo " $nb"
515 [ -n "$root" ] && echo "root=\"$root\""
516 _n 'Removing:'
517 for dep in $deps; do
518 echo -n " $dep"
519 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
520 done
521 newline; newline
522 # Keep the last diff for debug and info.
523 mv -f $diff $CACHE/installed.diff
524 fi
525 }
528 # The main cook function.
530 cookit() {
531 _ 'Cook: %s' "$PACKAGE $VERSION"; separator
532 set_paths
534 # Handle cross-tools.
535 case "$ARCH" in
536 arm*|x86_64)
537 # CROSS_COMPILE is used by at least Busybox and the kernel to set
538 # the cross-tools prefix. Sysroot is the root of our target arch
539 sysroot="$CROSS_TREE/sysroot"
540 tools="$CROSS_TREE/tools"
541 # Set root path when cross compiling. ARM tested but not x86_64
542 # When cross compiling we must install build deps in $sysroot.
543 arch="-$ARCH"
544 root="$sysroot"
545 _ '%s sysroot: %s' "$ARCH" "$sysroot"
546 _ 'Adding "%s" to PATH' "$tools/bin"
547 export PATH="$PATH:$tools/bin"
548 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
549 export CROSS_COMPILE="$HOST_SYSTEM-"
550 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
551 if [ "$ARCH" == 'x86_64' ]; then
552 export CC="$HOST_SYSTEM-gcc -m64"
553 export CXX="$HOST_SYSTEM-g++ -m64"
554 else
555 export CC="$HOST_SYSTEM-gcc"
556 export CXX="$HOST_SYSTEM-g++"
557 fi
558 export AR="$HOST_SYSTEM-ar"
559 export AS="$HOST_SYSTEM-as"
560 export RANLIB="$HOST_SYSTEM-ranlib"
561 export LD="$HOST_SYSTEM-ld"
562 export STRIP="$HOST_SYSTEM-strip"
563 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
564 esac
566 [ -n "$QA" ] && receipt_quality
567 cd $pkgdir
568 [ -z "$continue" ] && rm -rf source 2>/dev/null
569 rm -rf install taz 2>/dev/null
571 # Disable -pipe if less than 512Mb free RAM.
572 free=$(free | awk '/buffers:/{print $4}')
573 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
574 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
575 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
576 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
577 fi
578 unset free
580 # Export flags and path to be used by make and receipt.
581 DESTDIR="$pkgdir/install"
582 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
583 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
584 #LDFLAGS
586 # Check for build deps and handle implicit depends of *-dev packages
587 # (ex: libusb-dev :: libusb).
588 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
589 touch $CACHE/installed.local $CACHE/installed.web
590 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
591 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
592 for dep in $BUILD_DEPENDS; do
593 implicit="${dep%-dev}"
594 for i in $dep $implicit; do
595 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
596 # Try local package first. In some cases implicit doesn't exist, ex:
597 # libboost-dev exists but not libboost, so check if we got vers.
598 unset vers
599 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
600 # We may have a local package.
601 if [ -z "$vers" ]; then
602 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info)
603 fi
604 debug "bdep: $i version: $vers"
605 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
606 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
607 else
608 # Priority to package version in wok (maybe more up-to-date)
609 # than the mirrored one.
610 if [ -n "$vers" ]; then
611 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
612 echo $i >> $CACHE/installed.web
613 else
614 # So package exists in wok but not available.
615 _ 'Missing dep (wok/pkg): %s' "$i $vers"
616 echo $i >> $CACHE/missing.dep
617 fi
618 else
619 # Package is not in wok but may be in online repo.
620 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
621 echo $i >> $CACHE/installed.web
622 else
623 _ 'ERROR: unknown dep "%s"' "$i"
624 exit 1
625 fi
626 fi
627 fi
628 fi
629 done
630 done
632 # Get the list of installed packages
633 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
635 # Have we a missing build dep to cook?
636 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
637 _ 'Auto cook config is set: %s' "$AUTO_COOK"
638 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
639 for i in $(uniq $CACHE/missing.dep); do
640 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
641 tee -a $LOGS/$PACKAGE.log.$$
642 # programmers: next two messages are exact copy from remove_deps()
643 togrep1=$(_n 'Build dependencies to remove:')
644 togrep2=$(_n 'Removing:')
645 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
646 fgrep $togrep1 $LOGS/$i.log && \
647 fgrep $togrep2 $LOGS/$i.log && newline) | \
648 tee -a $LOGS/$PACKAGE.log.$$ && break
649 done
650 rm -f $CACHE/missing.dep
651 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
652 fi
654 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
655 # is enabled and cook fails we have ERROR in log, if no auto cook we have
656 # missing dep in cached file.
657 lerror=$(_n 'ERROR')
658 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
659 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
660 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
661 exit 1
662 fi
664 # Install local packages: package-version$arch
665 cd $PKGS
666 for i in $(uniq $CACHE/installed.local); do
667 _ 'Installing dep (pkg/local): %s' "$i"
668 tazpkg install $i --root=$root >/dev/null
669 done
671 # Install web or cached packages (if mirror is set to $PKGS we only
672 # use local packages).
673 for i in $(uniq $CACHE/installed.web); do
674 _ 'Installing dep (web/cache): %s' "$i"
675 tazpkg get-install $i --root=$root >/dev/null
676 done
678 # If a cook failed deps are removed.
679 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
680 cd $CACHE
681 [ ! -s '/tmp/installed.cook.diff' ] && \
682 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
683 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
685 # Get source tarball and make sure we have source dir named:
686 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
687 # tarball if it exists.
688 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
689 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
690 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
691 LZMA_SRC=''
692 else
693 get_source || exit 1
694 fi
695 fi
696 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
697 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
698 if ! extract_source ; then
699 get_source
700 extract_source || exit 1
701 fi
702 if [ -n "$LZMA_SRC" ]; then
703 cd $pkgdir/source
704 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
705 mv tmp tmp-1; mkdir tmp
706 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
707 fi
708 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
709 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
710 fi
711 fi
712 cd $pkgdir/source/tmp
713 # Some archives are not well done and don't extract to one dir (ex lzma).
714 files=$(ls | wc -l)
715 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
716 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
717 mv * ../$PACKAGE-$VERSION/$TARBALL
718 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
719 mv * ../$PACKAGE-$VERSION
720 cd ..; rm -rf tmp
721 fi
723 # Libtool shared libs path hack.
724 case "$ARCH" in
725 arm*) cross libhack ;;
726 esac
728 # Execute receipt rules.
729 if grep -q ^compile_rules $receipt; then
730 _ 'Executing: %s' 'compile_rules'
731 echo "CFLAGS : $CFLAGS"
732 #echo "LDFLAGS : $LDFLAGS"
733 [ -d "$src" ] && cd $src
734 compile_rules $@ || exit 1
735 # Stay compatible with _pkg
736 [ -d "$src/_pkg" ] && mv $src/_pkg $install
737 # QA: compile_rules success so valid.
738 mkdir -p $install
739 else
740 # QA: no compile_rules so no error, valid.
741 mkdir -p $install
742 fi
743 separator; newline
745 # Execute testsuite.
746 if grep -q ^testsuite $receipt; then
747 _ 'Running testsuite'; separator
748 testsuite $@ || exit 1
749 separator; newline
750 fi
751 }
754 # Cook quality assurance.
756 cookit_quality() {
757 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
758 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
759 fi
760 # ERROR can be echoed any time in cookit()
761 lerror=$(_n 'ERROR')
762 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
763 grep -Eq "(^$lerror|undefined reference to)" ; then
764 debug_info | tee -a $LOGS/$pkg.log
765 rm -f $command
766 exit 1
767 fi
768 }
771 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
772 # but it doesn't handle EXTRAVERSION.
774 packit() {
775 set_paths
777 # Handle cross compilation
778 case "$ARCH" in
779 arm*|x86_64) arch="-$ARCH" ;;
780 esac
782 _ 'Pack: %s' "$PACKAGE $VERSION$arch"; separator
784 if grep -q ^genpkg_rules $receipt; then
785 _ 'Executing: %s' 'genpkg_rules'
786 set -e; cd $pkgdir; mkdir -p $fs
787 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
788 $LOGS/$pkg.log
789 else
790 _ 'No packages rules: meta package'
791 mkdir -p $fs
792 fi
794 # First QA check to stop now if genpkg_rules failed.
795 lerror=$(_n 'ERROR')
796 if fgrep -q ^$lerror $LOGS/$pkg.log; then
797 exit 1
798 fi
800 cd $taz
801 for file in receipt description.txt; do
802 [ ! -f "../$file" ] && continue
803 _n 'Copying "%s"...' "$file"
804 cp -f ../$file $pack; chown 0.0 $pack/$file; status
805 done
806 copy_generic_files
808 # Strip and stuff files.
809 strip_package
811 # Create files.list with redirecting find output.
812 _n 'Creating the list of files...'
813 cd $fs
814 find . -type f -print > ../files.list
815 find . -type l -print >> ../files.list
816 cd ..; sed -i s/'^.'/''/ files.list
817 status
819 # Md5sum of files.
820 _n 'Creating md5sum of files...'
821 while read file; do
822 [ -L "fs$file" ] && continue
823 [ -f "fs$file" ] || continue
824 case "$file" in
825 /lib/modules/*/modules.*|*.pyc) continue ;;
826 esac
827 md5sum "fs$file" | sed 's/ fs/ /'
828 done < files.list > md5sum
829 status
831 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
832 2>/dev/null | awk 'END{ print $1 }')
834 # Build cpio archives.
835 _n 'Compressing the FS...'
836 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
837 rm -rf fs
838 status
840 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
841 2>/dev/null | awk 'END{ print $1 }')
843 _n 'Updating receipt sizes...'
844 sed -i s/^PACKED_SIZE.*$// receipt
845 sed -i s/^UNPACKED_SIZE.*$// receipt
846 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
847 status
849 # Set extra version.
850 if [ -n "$EXTRAVERSION" ]; then
851 _n 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
852 sed -i s/^EXTRAVERSION.*$// receipt
853 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
854 status
855 fi
857 # Compress.
858 _n 'Creating full cpio archive...'
859 find . -print | cpio -o -H newc --quiet > \
860 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
861 status
863 _n 'Restoring original package tree...'
864 unlzma -c fs.cpio.lzma | cpio -idm --quiet
865 status
867 rm fs.cpio.lzma; cd ..
869 # QA and give info.
870 tazpkg=$(ls *.tazpkg)
871 packit_quality
872 separator; _ 'Package "%s" created' "$tazpkg"; newline
873 }
876 # Verify package quality and consistency.
878 packit_quality() {
879 #gettext "QA: checking for broken link..."
880 #link=$(find $fs/usr -type l -follow)
881 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
882 #status
884 # Exit if any error found in log file.
885 lerror=$(_n 'ERROR')
886 if fgrep -q ^$lerror $LOGS/$pkg.log; then
887 rm -f $command
888 exit 1
889 fi
891 _n 'QA: checking for empty package...'
892 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
893 if [ "$files" == 0 ] && [ "$CATEGORY" != 'meta' ]; then
894 newline; _ 'ERROR: empty package'
895 rm -f $command
896 exit 1
897 else
898 # Ls sort by name so the first file is the one we want.
899 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n1)
900 status
901 if [ -f "$old" ]; then
902 _n 'Removing old package "%s"' "$(basename $old)"
903 rm -f $old; status
904 fi
905 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
906 sed -i /^${pkg}$/d $broken
907 #gettext "Removing source tree..."
908 #rm -f $WOK/$pkg/source && status
909 fi
910 }
913 # Reverse "cat" command: prints input lines in the reverse order
915 tac() {
916 sed '1!G;h;$!d' $1
917 }
920 # Install package on --install or update the chroot.
922 install_package() {
923 case "$ARCH" in
924 arm*|x86_64)
925 arch="-$ARCH"
926 root="$CROSS_TREE/sysroot" ;;
927 esac
928 # Install package if requested but skip install if target host doesn't
929 # match build system or it will break the build chroot.
930 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
931 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
932 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
933 cd $PKGS
934 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
935 else
936 _ 'Unable to install package, build has failed.'; newline
937 exit 1
938 fi
939 fi
941 # Install package if part of the chroot to keep env up-to-date.
942 if [ -d "$root$INSTALLED/$pkg" ]; then
943 . /etc/slitaz/cook.conf
944 . $WOK/$pkg/taz/$pkg-*/receipt
945 _ 'Updating %s chroot environment...' "$ARCH"
946 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
947 cd $PKGS
948 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
949 fi
950 }
953 # remove chroot jail
955 umount_aufs() {
956 tac ${1}rw/aufs-umount.sh | sh
957 rm -rf ${1}rw
958 umount ${1}root
959 rmdir ${1}r*
960 }
963 # Launch the cook command into a chroot jail protected by aufs.
964 # The current filesystems are used read-only and updates are
965 # stored in a separate branch.
967 try_aufs_chroot() {
969 base="/dev/shm/aufsmnt$$"
971 # Can we setup the chroot? Is it already done?
972 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
973 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
974 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
975 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
976 mkdir ${base}root ${base}rw || return
978 _ 'Setup aufs chroot...'
980 # Sanity check
981 for i in / /proc /sys /dev/shm /home ; do
982 case " $AUFS_MOUNTS " in
983 *\ $i\ *) ;;
984 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
985 esac
986 done
987 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
988 mount --bind $mnt ${base}root$mnt
989 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
990 _ 'Aufs mount failure'
991 umount ${base}root
992 rm -rf ${base}r*
993 return
994 fi
995 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
996 done
997 trap "umount_aufs ${base}" INT
999 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1000 status=$?
1002 _ 'Leaving aufs chroot...'
1003 umount_aufs $base
1004 # Install package outside the aufs jail
1005 install_package
1006 exit $status
1010 # Encode predefined XML entities
1012 xml_ent() {
1013 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1017 # Create a XML feed for freshly built packages.
1019 gen_rss() {
1020 pubdate=$(date '+%a, %d %b %Y %X')
1021 cat > $FEEDS/$pkg.xml <<EOT
1022 <item>
1023 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1024 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1025 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1026 <pubDate>$pubdate</pubDate>
1027 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1028 </item>
1029 EOT
1033 # Truncate stdout log file to $1 Mb.
1035 loglimit() {
1036 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1037 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1038 else
1039 tee /dev/stderr
1040 fi
1044 # Search file in mirrored packages
1046 search_file_mirror() {
1047 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1051 # Search file in local wok packages
1053 search_file_local() {
1054 # existing packages have precedence over the package/taz folder
1055 srch=$1
1056 { for package in $(find $PKGS -name '*.tazpkg'); do
1057 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1058 grep /$srch\$)" ]; then
1059 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1060 fi
1061 done } | sort -u
1065 # Ask in multiple choice
1067 ask_multiple() {
1068 local multiples first my_choice
1069 multiples="$1"
1070 first=$(echo "$multiples" | head -n1)
1071 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1072 _ 'Select one [%s]: ' "$first"; read my_choice
1073 found="${my_choice:-$first}"
1077 # Search file in local cache (fast), local wok packages, mirrored packages
1079 search_file() {
1080 local srch cache missing
1081 srch="$1"
1082 cache='/var/cache/ldsearch.cache'
1083 missing='/var/cache/missing.file'
1084 touch $cache $missing
1085 found=$(grep $srch $cache | cut -d$'\t' -f2)
1086 if [ -z "$found" ]; then
1087 found=$(search_file_local $srch)
1088 if [ -n "$found" ]; then
1089 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1090 ask_multiple "$found"
1091 fi
1092 echo -e "$srch\t$found" >> $cache
1093 else
1094 found=$(search_file_mirror $srch)
1095 if [ -n "$found" ]; then
1096 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1097 ask_multiple "$found"
1098 fi
1099 echo -e "$srch\t$found" >> $cache
1100 else
1101 echo "$srch" >> $missing
1102 fi
1103 fi
1104 fi
1108 # Return size of file in human readible format
1109 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1110 filesize() {
1111 busybox ls -lh "$1" | awk '{print $5 "B"}'
1116 # Receipt functions to ease packaging
1119 get_dev_files() {
1120 _n 'Getting standard devel files...'
1121 mkdir -p $fs/usr/lib
1122 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1123 cp -a $install/usr/lib/*a $fs/usr/lib
1124 cp -a $install/usr/include $fs/usr
1125 status
1128 dblog() { tee -a $LOGS/pkgdb.log; }
1134 # Commands
1137 case "$1" in
1138 usage|help|-u|-h)
1139 usage ;;
1141 list-wok)
1142 newline; _ 'List of %s packages in "%s"' "$ARCH" "$WOK"; separator
1143 cd $WOK
1144 if [ "$ARCH" != 'i486' ]; then
1145 count=0
1146 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1147 do
1148 unset HOST_ARCH
1149 . $pkg
1150 count=$(($count + 1))
1151 colorize 34 "$PACKAGE"
1152 done
1153 else
1154 count=$(ls | wc -l)
1155 ls -1
1156 fi
1157 separator
1158 _p '%s package' '%s packages' "$count" "$(colorize 32 "$count")"
1159 newline ;;
1161 activity)
1162 cat $activity ;;
1164 search)
1165 # Just a simple search function, we dont need more actually.
1166 query="$2"
1167 newline; _ 'Search results for "%s"' "$query"; separator
1168 cd $WOK; ls -1 | grep "$query"
1169 separator; newline ;;
1171 setup)
1172 # Setup a build environment
1173 check_root
1174 _ 'Cook: setup environment' | log
1175 newline; _ 'Setting up your environment'; separator
1176 cd $SLITAZ
1177 init_db_files
1178 _ 'Checking for packages to install...'
1179 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1180 # ARCH-setup or 'cross check' should be used before: cook setup
1181 case "$ARCH" in
1182 arm*|x86_64)
1183 if [ ! -x '/usr/bin/cross' ]; then
1184 _ 'ERROR: %s is not installed' 'cross'
1185 exit 1
1186 fi
1187 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1188 . /etc/slitaz/cross.conf ;;
1189 esac
1190 for pkg in $SETUP_PKGS; do
1191 if [ -n "$forced" ]; then
1192 tazpkg -gi $pkg --forced
1193 else
1194 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1195 fi
1196 done
1198 # Handle --options
1199 case "$2" in
1200 --wok) hg clone $WOK_URL wok || exit 1 ;;
1201 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1202 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1203 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1204 esac
1206 # SliTaz group and permissions
1207 if ! grep -q ^slitaz /etc/group; then
1208 _ 'Adding group "%s"' 'slitaz'
1209 addgroup slitaz
1210 fi
1211 _ 'Setting permissions for group "%s"...' 'slitaz'
1212 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1213 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1214 separator; _ 'All done, ready to cook packages :-)'; newline ;;
1216 *-setup)
1217 # Setup for cross compiling.
1218 arch="${1%-setup}"
1219 check_root
1220 . /etc/slitaz/cook.conf
1221 for pkg in $CROSS_SETUP; do
1222 if [ -n "$forced" ]; then
1223 tazpkg -gi $pkg --forced
1224 else
1225 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1226 fi
1227 done
1229 _ 'Cook: setup %s cross environment' "$arch" | log
1230 newline; boldify $(_n 'Setting up your %s cross environment' "$arch"); separator
1231 init_db_files
1232 sed -i \
1233 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1234 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1235 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1236 /etc/slitaz/cook.conf
1237 case "$arch" in
1238 arm)
1239 flags='-O2 -march=armv6'
1240 host="$ARCH-slitaz-linux-gnueabi" ;;
1241 armv6hf)
1242 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1243 host="$ARCH-slitaz-linux-gnueabi" ;;
1244 armv7)
1245 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1246 host="$ARCH-slitaz-linux-gnueabi" ;;
1247 x86_64)
1248 flags='-O2 -mtune=generic -pipe'
1249 host="$ARCH-slitaz-linux" ;;
1250 esac
1251 sed -i \
1252 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1253 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1254 . /etc/slitaz/cook.conf
1255 sysroot="$CROSS_TREE/sysroot"
1256 tools="/cross/$arch/tools"
1257 root="$sysroot"
1258 # L10n: keep the same width of translations to get a consistent view
1259 _ 'Target arch : %s' "$ARCH"
1260 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1261 _ 'Build flags : %s' "$flags"
1262 _ 'Arch sysroot : %s' "$sysroot"
1263 _ 'Tools prefix : %s' "$tools/bin"
1264 # Tell the packages manager where to find packages.
1265 _ 'Packages DB : %s' "$root$DB"
1266 mkdir -p $root$INSTALLED
1267 cd $root$DB; rm -f *.bak
1268 for list in packages.list packages.desc packages.equiv packages.md5; do
1269 rm -f $list
1270 ln -s $SLITAZ/packages/$list $list
1271 done
1272 # We must have the cross compiled glibc-base installed or default
1273 # i486 package will be used as dep by tazpkg and then break the
1274 # cross environment
1275 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1276 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1277 fi
1278 # Show GCC version or warn if not yet compiled.
1279 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1280 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1281 else
1282 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1283 _ 'Run "%s" to cook a toolchain' 'cross compile'
1284 fi
1285 separator; newline ;;
1287 test)
1288 # Test a cook environment.
1289 _ 'Cook test: testing the cook environment' | log
1290 [ ! -d "$WOK" ] && exit 1
1291 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1292 cook cooktest ;;
1294 new)
1295 # Create the package folder and an empty receipt.
1296 pkg="$2"
1297 [ -z "$pkg" ] && usage
1298 newline
1299 if [ -d "$WOK/$pkg" ]; then
1300 _ 'Package "%s" already exists.' "$pkg"
1301 exit 1
1302 fi
1304 _n 'Creating folder "%s"' "$WOK/$pkg"
1305 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1307 _n 'Preparing the package receipt...'
1308 cp $DATA/receipt .
1309 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1310 status; newline
1312 # Interactive mode, asking and seding.
1313 case "$3" in
1314 --interactive|-x)
1315 _ 'Entering interactive mode...'
1316 separator
1317 _ 'Package : %s' "$pkg"
1319 _n 'Version : ' ; read answer
1320 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1322 _n 'Category : ' ; read answer
1323 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1325 # L10n: Short description
1326 _n 'Short desc : ' ; read answer
1327 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1329 _n 'Maintainer : ' ; read answer
1330 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1332 _n 'License : ' ; read answer
1333 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1335 _n 'Web site : ' ; read answer
1336 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1337 newline
1339 # Wget URL.
1340 _ 'Wget URL to download source tarball.'
1341 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1342 _n 'Wget url : ' ; read answer
1343 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1345 # Ask for a stuff dir.
1346 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1347 if [ "$?" == 0 ]; then
1348 _n 'Creating the stuff directory...'
1349 mkdir $WOK/$pkg/stuff; status
1350 fi
1352 # Ask for a description file.
1353 confirm "$(_n 'Are you going to write a description? (y/N)')"
1354 if [ "$?" == 0 ]; then
1355 _n 'Creating the "%s" file...' 'description.txt'
1356 touch $WOK/$pkg/description.txt; status
1357 fi
1359 separator; _ 'Receipt is ready to use.'; newline ;;
1360 esac ;;
1362 list)
1363 # Cook a list of packages (better use the Cooker since it will order
1364 # packages before executing cook).
1365 check_root
1366 if [ -z "$2" ]; then
1367 newline; _ 'No list in argument.'; newline
1368 exit 1
1369 fi
1370 if [ ! -f "$2" ]; then
1371 newline; _ 'List "%s" not found.' "$2"; newline
1372 exit 1
1373 fi
1375 _ 'Starting cooking the list "%s"' "$2" | log
1377 for pkg in $(cat $2); do
1378 cook $pkg || broken
1379 done ;;
1381 clean-wok)
1382 check_root
1383 newline; _n 'Cleaning all packages files...'
1384 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1385 status; newline ;;
1387 clean-src)
1388 check_root
1389 newline; _n 'Cleaning all packages sources...'
1390 rm -rf $WOK/*/source
1391 status; newline ;;
1393 uncook)
1394 cd $WOK
1395 count=0
1396 newline; _ 'Checking for uncooked packages'; separator
1398 for pkg in *; do
1399 unset HOST_ARCH EXTRAVERSION
1400 [ ! -e $pkg/receipt ] && continue
1401 . $pkg/receipt
1402 # Source cooked pkg receipt to get EXTRAVERSION
1403 if [ -d "$WOK/$pkg/taz" ]; then
1404 cd $WOK/$pkg/taz/$pkg-*
1405 . receipt; cd $WOK
1406 fi
1407 case "$ARCH" in
1408 i486)
1409 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1410 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1411 count=$(($count + 1))
1412 colorize 34 "$pkg"
1413 fi ;;
1414 arm*)
1415 # Check only packages included in arch
1416 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1417 # *.tazpkg
1418 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1419 count=$(($count + 1))
1420 colorize 34 "$pkg"
1421 fi
1422 fi ;;
1423 esac
1424 done
1426 if [ "$count" -gt "0" ]; then
1427 separator
1428 _p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")"
1429 else
1430 _ 'All packages are cooked :-)'
1431 fi
1432 newline ;;
1434 pkgdb)
1435 # Create suitable packages list for TazPKG and only for built packages
1436 # as well as flavors files for TazLiTo. We dont need logs since we do it
1437 # manually to ensure everything is fine before syncing the mirror.
1439 rm $LOGS/pkgdb.log 2>/dev/null
1441 case "$2" in
1442 --flavors|--rmpkg) ;;
1443 *)
1444 [ -n "$2" ] && PKGS="$2"
1445 if [ ! -d "$PKGS" ]; then
1446 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1447 exit 1
1448 fi ;;
1449 esac
1451 time=$(date +%s)
1452 flavors="$SLITAZ/flavors"
1453 live="$SLITAZ/live"
1455 echo 'cook:pkgdb' > $command
1456 _ 'Cook pkgdb: Creating all packages lists' | log
1457 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1459 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1461 cd $PKGS
1462 rm -f packages.* extra.list
1463 touch packages.equiv
1465 _n 'Creating file "%s"' 'packages.list' | dblog
1466 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1467 echo " ($(filesize $PKGS/packages.list))" | dblog
1469 _n 'Creating file "%s"' 'packages.md5' | dblog
1470 md5sum *.tazpkg > $PKGS/packages.md5
1471 echo " ($(filesize $PKGS/packages.md5))" | dblog
1472 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1474 md5sum packages.md5 | cut -d' ' -f1 > ID
1475 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1477 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1478 rm $PKGS/descriptions.txt 2>/dev/null
1479 for i in $(ls $WOK | sort); do
1480 if [ -e "$WOK/$i/description.txt" ]; then
1481 echo "$i" >> descriptions.txt
1482 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1483 echo >> descriptions.txt
1484 fi
1485 done
1486 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1489 _ 'Creating lists from "%s"' "$WOK" | dblog
1490 cd $WOK
1491 for pkg in *; do
1492 unset_receipt
1493 . $pkg/receipt
1494 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1495 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1497 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1498 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1500 # packages.desc lets us search easily in DB
1501 cat >> $PKGS/packages.desc <<EOT
1502 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1503 EOT
1505 # packages.txt used by tazpkg and tazpkg-web also to provide
1506 # a human readable package list with version and description.
1507 cat >> $PKGS/packages.txt <<EOT
1508 $PACKAGE
1509 $VERSION$EXTRAVERSION
1510 $SHORT_DESC
1511 $PACKED_SIZE ($UNPACKED_SIZE installed)
1513 EOT
1515 # packages.info combines TazPkg separate files
1516 # and will substitute them all
1517 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1518 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1519 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1520 cat >> $PKGS/packages.info <<EOT
1521 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1522 EOT
1524 # packages.equiv is used by tazpkg install to check depends.
1525 for i in $PROVIDE; do
1526 DEST=''
1527 echo $i | fgrep -q : && DEST="${i#*:}:"
1528 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1529 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1530 $PKGS/packages.equiv
1531 else
1532 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1533 fi
1534 done
1536 # files.list provides a list of all packages files.
1537 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1538 $PKGS/files.list
1540 # list of duplicates
1541 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1542 else
1543 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1544 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1545 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1546 fi
1547 fi
1548 done
1550 # Display list size.
1551 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1552 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1553 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1554 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1556 cd $PKGS
1559 # Check package duplicates
1560 if [ -s "$PKGS/packages.toremove" ]; then
1561 newline | dblog
1562 _ 'Removing duplicates:' | dblog
1563 while read pkgsum pkgfile; do
1564 echo " - $pkgfile" | dblog
1565 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1566 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1567 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1568 done < $PKGS/packages.toremove
1569 newline | dblog
1570 fi
1571 rm $PKGS/packages.toremove
1574 # files.list.lzma
1575 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1576 touch files.list
1577 # pkgs.slitaz.org strongly depends on list sorted by packages names
1578 lzma e files.list files.list.lzma
1579 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1581 # Pre-sorting filenames causes 10% smaller resulting lzma file
1582 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1583 cat files.list | sort -k2 -o files.list.sorted
1584 lzma e files.list.sorted files-list.lzma
1585 rm -f files.list files.list.sorted
1586 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1588 [ -e files.list.md5 ] && rm files.list.md5
1589 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1591 # packages.info.lzma
1592 PI=packages.info
1593 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1594 touch $PI
1595 lzma e $PI $PI.lzma
1596 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1598 # Make bundle to fast recharge
1599 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1600 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1601 # Make sure to get "mirrors" file
1602 until [ -e 'mirrors' ]; do
1603 wget -q http://mirror1.slitaz.org/mirrors
1604 echo -n '.' | dblog; sleep 5
1605 done
1606 # Make sure to get "extra.list" file
1607 until [ -e 'extra.list' ]; do
1608 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1609 echo -n '.' | dblog; sleep 5
1610 done
1611 busybox tar -chaf bundle.tar.lzma \
1612 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1613 packages.desc packages.md5 packages.txt packages.list packages.equiv
1614 rm ./mirrors
1615 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1617 # Display some info.
1618 separator | dblog
1619 nb=$(ls $PKGS/*.tazpkg | wc -l)
1620 time=$(($(date +%s) - $time))
1621 # L10n: 's' is for seconds (cooking time)
1622 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1625 # Create all flavors files at once. Do we really need code to monitor
1626 # flavors changes? Lets just build them with packages lists before
1627 # syncing the mirror.
1628 [ "$2" != '--flavors' ] && exit 1
1630 if [ ! -d "$flavors" ]; then
1631 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1632 exit 1
1633 fi
1635 [ ! -d "$live" ] && mkdir -p $live
1636 _ 'Creating flavors files in "%s"' "$live" | dblog
1637 _ 'Cook pkgdb: Creating all flavors' | log
1638 separator | dblog
1640 _ 'Recharging lists to use latest packages...' | dblog
1641 tazpkg recharge >/dev/null 2>/dev/null
1643 # We need a custom tazlito config to set working dir to /home/slitaz.
1644 if [ ! -f "$live/tazlito.conf" ]; then
1645 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1646 cp /etc/tazlito/tazlito.conf $live
1647 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1648 $live/tazlito.conf
1649 fi
1651 # Update Hg flavors repo and pack.
1652 if [ -d "$flavors/.hg" ]; then
1653 cd $flavors; hg pull -u
1654 fi
1656 cd $live
1657 _ 'Starting to generate flavors...' | dblog
1658 rm -f flavors.list *.flavor
1659 for i in $flavors/*; do
1660 fl=$(basename $i)
1661 _ 'Packing flavor "%s"' "$fl" | dblog
1662 tazlito pack-flavor $fl >/dev/null || exit 1
1663 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1664 done
1665 cp -f $live/*.flavor $live/flavors.list $PKGS
1666 separator | dblog
1667 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1668 rm -f $command
1669 separator | dblog
1670 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1671 ;;
1673 *)
1674 # Just cook and generate a package.
1675 check_root
1676 time=$(date +%s)
1677 pkg="$1"
1678 [ -z "$pkg" ] && usage
1679 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1680 $LOGS/$pkg.log 2> /dev/null)
1681 receipt="$WOK/$pkg/receipt"
1682 check_pkg_in_wok
1683 newline
1685 unset inst
1686 unset_receipt
1687 . $receipt
1689 # Handle cross compilation.
1690 case "$ARCH" in
1691 arm*)
1692 if [ -z "$HOST_ARCH" ]; then
1693 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1694 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1695 _ 'cook: %s' "$error"
1696 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1697 _ 'Cook skip: %s' "$error" | log
1698 newline
1699 exit 1
1700 fi ;;
1701 esac
1703 # Some packages are not included in some arch or fail to cross compile.
1704 : ${HOST_ARCH=i486}
1705 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1706 # Handle arm{v6hf,v7,..}
1707 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1708 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1709 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1710 _ 'cook: %s' "error"
1711 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1712 _ 'Cook skip: %s' "$error" | log
1713 sed -i /^${pkg}$/d $broken
1714 newline
1715 exit 0
1716 fi
1718 # Skip blocked, 3 lines also for the Cooker.
1719 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1720 _ 'Package "%s" is blocked' "$pkg"; newline
1721 exit 0
1722 fi
1724 try_aufs_chroot "$@"
1726 # Log and source receipt.
1727 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1728 echo "cook:$pkg" > $command
1729 [ "$lastcooktime" ] &&
1730 echo "cook:$pkg $lastcooktime $(date +%s)" > $cooktime
1732 # Display and log info if cook process stopped.
1733 # FIXME: gettext not working (in single quotes) here!
1734 trap '_ "\n\nCook stopped: control-C\n\n" | \
1735 tee -a $LOGS/$pkg.log' INT
1737 # Handle --options
1738 case "$2" in
1739 --clean|-c)
1740 _n 'Cleaning "%s"' "$pkg"
1741 cd $WOK/$pkg; rm -rf install taz source
1742 status; newline
1743 exit 0 ;;
1745 --install|-i)
1746 inst='yes' ;;
1748 --getsrc|-gs)
1749 _ 'Getting source for "%s"' "$pkg"; separator
1750 get_source
1751 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1752 exit 0 ;;
1754 --block|-b)
1755 _n 'Blocking package "%s"' "$pkg"
1756 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1757 status; newline
1758 exit 0 ;;
1760 --unblock|-ub)
1761 _n 'Unblocking package "%s"' "$pkg"
1762 sed -i "/^${pkg}$/"d $blocked
1763 status; newline
1764 exit 0 ;;
1766 --pack)
1767 if [ -d $WOK/$pkg/taz ]; then
1768 rm -rf $WOK/$pkg/taz
1769 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1770 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1771 clean_log
1772 else
1773 _ 'Need to build "%s"' "$pkg"
1774 exit 0
1775 fi
1776 exit 0 ;;
1778 --cdeps)
1779 if [ ! -d $WOK/$pkg/taz ]; then
1780 _ 'Need to build "%s"' "$pkg"
1781 exit 0
1782 fi
1784 _ 'Checking depends'; separator
1785 lddlist='/tmp/lddlist'; touch $lddlist
1786 missing='/var/cache/missing.file'
1788 # find all deps using ldd
1789 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1790 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1791 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1792 done #"
1794 # remove exe/so duplicates
1795 sort -u $lddlist > $lddlist.sorted
1797 # search packages
1798 for exefile in $(cat $lddlist.sorted); do
1799 search_file $exefile
1800 echo "$found" >> $lddlist.pkgs
1801 echo -n '.'
1802 done
1803 echo
1805 # remove packages duplicates
1806 sort -u $lddlist.pkgs > $lddlist.final
1807 sort -u $missing > $missing.final
1808 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1809 exit 0 ;;
1810 esac
1812 # Check if wanted is built now so we have separate log files.
1813 for wanted in $WANTED ; do
1814 if grep -q "^$wanted$" $blocked; then
1815 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1816 newline
1817 rm -f $command
1818 exit 1
1819 fi
1820 if grep -q "^$wanted$" $broken; then
1821 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1822 newline
1823 rm -f $command
1824 exit 1
1825 fi
1826 if [ ! -d "$WOK/$wanted/install" ]; then
1827 cook "$wanted" || exit 1
1828 fi
1829 done
1831 # Cook and pack or exit on error and log everything.
1832 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1833 remove_deps | tee -a $LOGS/$pkg.log
1834 cookit_quality
1835 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1836 clean_log
1838 # Exit if any error in packing.
1839 lerror=$(_n 'ERROR')
1840 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1841 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1842 debug_info | tee -a $LOGS/$pkg.log
1843 rm -f $command
1844 exit 1
1845 fi
1847 # Create an XML feed
1848 gen_rss
1850 # Time and summary
1851 time=$(($(date +%s) - $time))
1852 summary | tee -a $LOGS/$pkg.log
1853 newline
1855 # We may want to install/update (outside aufs jail !).
1856 [ -s /aufs-umount.sh ] ||
1857 install_package
1859 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1860 # You want automation: use the Cooker Build Bot.
1861 rm -f $command ;;
1862 esac
1864 exit 0