cookutils view cook @ rev 755
cook: add cook time in debug_info
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Wed Sep 23 10:21:48 2015 +0200 (2015-09-23) |
parents | ebd654564cf3 |
children | 050f39040fe4 |
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 time=$(($(date +%s) - $time))
393 newline; _ 'Debug information'; separator
394 # L10n: specify your format of date and time (to help: man date)
395 # L10n: not bad one is '+%x %R'
396 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
397 # L10n: Please, translate all messages beginning with ERROR in a same way
398 lerror=$(_n 'ERROR')
399 for error in \
400 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
401 'error:' 'fatal error:' 'undefined reference to' \
402 'Unable to connect to' 'link: cannot find the library' \
403 'CMake Error' ': No such file or directory'
404 do
405 fgrep "$error" $LOGS/$pkg.log
406 done > $LOGS/$pkg.log.debug_info 2>&1
407 cat $LOGS/$pkg.log.debug_info
408 _ 'Cook time : %ds' "$time"
409 rm -f $LOGS/$pkg.log.debug_info
410 separator; newline
411 }
414 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
415 # so some packages need to copy these files with the receipt and genpkg_rules.
417 copy_generic_files() {
418 # $LOCALE is set in cook.conf
419 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
420 if [ -d "$install/usr/share/locale" ]; then
421 mkdir -p $fs/usr/share/locale
422 for i in $LOCALE; do
423 if [ -d "$install/usr/share/locale/$i" ]; then
424 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
425 fi
426 done
427 fi
428 fi
430 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
431 if [ "$GENERIC_PIXMAPS" != 'no' ]; then
432 if [ -d "$install/usr/share/pixmaps" ]; then
433 mkdir -p $fs/usr/share/pixmaps
434 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
435 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
436 $fs/usr/share/pixmaps
437 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
438 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
439 $fs/usr/share/pixmaps
440 fi
441 fi
443 # Custom or homemade PNG pixmap can be in stuff.
444 if [ -f "$stuff/$PACKAGE.png" ]; then
445 mkdir -p $fs/usr/share/pixmaps
446 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
447 fi
448 fi
450 # Desktop entry (.desktop).
451 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
452 if [ "$GENERIC_MENUS" != 'no' ]; then
453 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
454 mkdir -p $fs/usr/share
455 cp -a $install/usr/share/applications $fs/usr/share
456 fi
457 fi
459 # Homemade desktop file(s) can be in stuff.
460 if [ -d "$stuff/applications" ]; then
461 mkdir -p $fs/usr/share
462 cp -a $stuff/applications $fs/usr/share
463 fi
464 if [ -f "$stuff/$PACKAGE.desktop" ]; then
465 mkdir -p $fs/usr/share/applications
466 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
467 fi
469 # Add custom licenses
470 if [ -d "$stuff/licenses" ]; then
471 mkdir -p $fs/usr/share/licenses
472 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
473 fi
474 }
477 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
478 # as removing unneeded files like in Python packages. Cross compiled binaries
479 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
481 strip_package() {
482 case "$ARCH" in
483 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
484 *) export STRIP='strip' ;;
485 esac
486 _n 'Executing strip on all files...'
487 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
488 if [ -d "$dir" ]; then
489 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
490 fi
491 done
492 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
493 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
494 status
496 # Remove Python .pyc and .pyo from packages.
497 #_n 'Removing Python compiled files...'
498 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
499 #status
501 # Remove Perl perllocal.pod and .packlist from packages.
502 #_n 'Removing Perl compiled files...'
503 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
504 #status
505 }
508 # Remove installed deps.
510 remove_deps() {
511 # Now remove installed build deps.
512 diff='/tmp/installed.cook.diff'
513 if [ -s $diff ]; then
514 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
515 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
516 _n 'Build dependencies to remove:'; echo " $nb"
517 [ -n "$root" ] && echo "root=\"$root\""
518 _n 'Removing:'
519 for dep in $deps; do
520 echo -n " $dep"
521 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
522 done
523 newline; newline
524 # Keep the last diff for debug and info.
525 mv -f $diff $CACHE/installed.diff
526 fi
527 }
530 # The main cook function.
532 cookit() {
533 _ 'Cook: %s' "$PACKAGE $VERSION"; separator
534 set_paths
536 # Handle cross-tools.
537 case "$ARCH" in
538 arm*|x86_64)
539 # CROSS_COMPILE is used by at least Busybox and the kernel to set
540 # the cross-tools prefix. Sysroot is the root of our target arch
541 sysroot="$CROSS_TREE/sysroot"
542 tools="$CROSS_TREE/tools"
543 # Set root path when cross compiling. ARM tested but not x86_64
544 # When cross compiling we must install build deps in $sysroot.
545 arch="-$ARCH"
546 root="$sysroot"
547 _ '%s sysroot: %s' "$ARCH" "$sysroot"
548 _ 'Adding "%s" to PATH' "$tools/bin"
549 export PATH="$PATH:$tools/bin"
550 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
551 export CROSS_COMPILE="$HOST_SYSTEM-"
552 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
553 if [ "$ARCH" == 'x86_64' ]; then
554 export CC="$HOST_SYSTEM-gcc -m64"
555 export CXX="$HOST_SYSTEM-g++ -m64"
556 else
557 export CC="$HOST_SYSTEM-gcc"
558 export CXX="$HOST_SYSTEM-g++"
559 fi
560 export AR="$HOST_SYSTEM-ar"
561 export AS="$HOST_SYSTEM-as"
562 export RANLIB="$HOST_SYSTEM-ranlib"
563 export LD="$HOST_SYSTEM-ld"
564 export STRIP="$HOST_SYSTEM-strip"
565 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
566 esac
568 [ -n "$QA" ] && receipt_quality
569 cd $pkgdir
570 [ -z "$continue" ] && rm -rf source 2>/dev/null
571 rm -rf install taz 2>/dev/null
573 # Disable -pipe if less than 512Mb free RAM.
574 free=$(free | awk '/buffers:/{print $4}')
575 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
576 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
577 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
578 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
579 fi
580 unset free
582 # Export flags and path to be used by make and receipt.
583 DESTDIR="$pkgdir/install"
584 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
585 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
586 #LDFLAGS
588 # Check for build deps and handle implicit depends of *-dev packages
589 # (ex: libusb-dev :: libusb).
590 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
591 touch $CACHE/installed.local $CACHE/installed.web
592 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
593 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
594 for dep in $BUILD_DEPENDS; do
595 implicit="${dep%-dev}"
596 for i in $dep $implicit; do
597 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
598 # Try local package first. In some cases implicit doesn't exist, ex:
599 # libboost-dev exists but not libboost, so check if we got vers.
600 unset vers
601 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
602 # We may have a local package.
603 if [ -z "$vers" ]; then
604 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info)
605 fi
606 debug "bdep: $i version: $vers"
607 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
608 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
609 else
610 # Priority to package version in wok (maybe more up-to-date)
611 # than the mirrored one.
612 if [ -n "$vers" ]; then
613 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
614 echo $i >> $CACHE/installed.web
615 else
616 # So package exists in wok but not available.
617 _ 'Missing dep (wok/pkg): %s' "$i $vers"
618 echo $i >> $CACHE/missing.dep
619 fi
620 else
621 # Package is not in wok but may be in online repo.
622 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
623 echo $i >> $CACHE/installed.web
624 else
625 _ 'ERROR: unknown dep "%s"' "$i"
626 exit 1
627 fi
628 fi
629 fi
630 fi
631 done
632 done
634 # Get the list of installed packages
635 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
637 # Have we a missing build dep to cook?
638 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
639 _ 'Auto cook config is set: %s' "$AUTO_COOK"
640 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
641 for i in $(uniq $CACHE/missing.dep); do
642 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
643 tee -a $LOGS/$PACKAGE.log.$$
644 # programmers: next two messages are exact copy from remove_deps()
645 togrep1=$(_n 'Build dependencies to remove:')
646 togrep2=$(_n 'Removing:')
647 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
648 fgrep $togrep1 $LOGS/$i.log && \
649 fgrep $togrep2 $LOGS/$i.log && newline) | \
650 tee -a $LOGS/$PACKAGE.log.$$ && break
651 done
652 rm -f $CACHE/missing.dep
653 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
654 fi
656 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
657 # is enabled and cook fails we have ERROR in log, if no auto cook we have
658 # missing dep in cached file.
659 lerror=$(_n 'ERROR')
660 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
661 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
662 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
663 exit 1
664 fi
666 # Install local packages: package-version$arch
667 cd $PKGS
668 for i in $(uniq $CACHE/installed.local); do
669 _ 'Installing dep (pkg/local): %s' "$i"
670 tazpkg install $i --root=$root >/dev/null
671 done
673 # Install web or cached packages (if mirror is set to $PKGS we only
674 # use local packages).
675 for i in $(uniq $CACHE/installed.web); do
676 _ 'Installing dep (web/cache): %s' "$i"
677 tazpkg get-install $i --root=$root >/dev/null
678 done
680 # If a cook failed deps are removed.
681 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
682 cd $CACHE
683 [ ! -s '/tmp/installed.cook.diff' ] && \
684 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
685 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
687 # Get source tarball and make sure we have source dir named:
688 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
689 # tarball if it exists.
690 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
691 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
692 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
693 LZMA_SRC=''
694 else
695 get_source || exit 1
696 fi
697 fi
698 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
699 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
700 if ! extract_source ; then
701 get_source
702 extract_source || exit 1
703 fi
704 if [ -n "$LZMA_SRC" ]; then
705 cd $pkgdir/source
706 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
707 mv tmp tmp-1; mkdir tmp
708 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
709 fi
710 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
711 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
712 fi
713 fi
714 cd $pkgdir/source/tmp
715 # Some archives are not well done and don't extract to one dir (ex lzma).
716 files=$(ls | wc -l)
717 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
718 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
719 mv * ../$PACKAGE-$VERSION/$TARBALL
720 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
721 mv * ../$PACKAGE-$VERSION
722 cd ..; rm -rf tmp
723 fi
725 # Libtool shared libs path hack.
726 case "$ARCH" in
727 arm*) cross libhack ;;
728 esac
730 # Execute receipt rules.
731 if grep -q ^compile_rules $receipt; then
732 _ 'Executing: %s' 'compile_rules'
733 echo "CFLAGS : $CFLAGS"
734 #echo "LDFLAGS : $LDFLAGS"
735 [ -d "$src" ] && cd $src
736 compile_rules $@ || exit 1
737 # Stay compatible with _pkg
738 [ -d "$src/_pkg" ] && mv $src/_pkg $install
739 # QA: compile_rules success so valid.
740 mkdir -p $install
741 else
742 # QA: no compile_rules so no error, valid.
743 mkdir -p $install
744 fi
745 separator; newline
747 # Execute testsuite.
748 if grep -q ^testsuite $receipt; then
749 _ 'Running testsuite'; separator
750 testsuite $@ || exit 1
751 separator; newline
752 fi
753 }
756 # Cook quality assurance.
758 cookit_quality() {
759 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
760 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
761 fi
762 # ERROR can be echoed any time in cookit()
763 lerror=$(_n 'ERROR')
764 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
765 grep -Eq "(^$lerror|undefined reference to)" ; then
766 debug_info | tee -a $LOGS/$pkg.log
767 rm -f $command
768 exit 1
769 fi
770 }
773 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
774 # but it doesn't handle EXTRAVERSION.
776 packit() {
777 set_paths
779 # Handle cross compilation
780 case "$ARCH" in
781 arm*|x86_64) arch="-$ARCH" ;;
782 esac
784 _ 'Pack: %s' "$PACKAGE $VERSION$arch"; separator
786 if grep -q ^genpkg_rules $receipt; then
787 _ 'Executing: %s' 'genpkg_rules'
788 set -e; cd $pkgdir; mkdir -p $fs
789 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
790 $LOGS/$pkg.log
791 else
792 _ 'No packages rules: meta package'
793 mkdir -p $fs
794 fi
796 # First QA check to stop now if genpkg_rules failed.
797 lerror=$(_n 'ERROR')
798 if fgrep -q ^$lerror $LOGS/$pkg.log; then
799 exit 1
800 fi
802 cd $taz
803 for file in receipt description.txt; do
804 [ ! -f "../$file" ] && continue
805 _n 'Copying "%s"...' "$file"
806 cp -f ../$file $pack; chown 0.0 $pack/$file; status
807 done
808 copy_generic_files
810 # Strip and stuff files.
811 strip_package
813 # Create files.list with redirecting find output.
814 _n 'Creating the list of files...'
815 cd $fs
816 find . -type f -print > ../files.list
817 find . -type l -print >> ../files.list
818 cd ..; sed -i s/'^.'/''/ files.list
819 status
821 # Md5sum of files.
822 _n 'Creating md5sum of files...'
823 while read file; do
824 [ -L "fs$file" ] && continue
825 [ -f "fs$file" ] || continue
826 case "$file" in
827 /lib/modules/*/modules.*|*.pyc) continue ;;
828 esac
829 md5sum "fs$file" | sed 's/ fs/ /'
830 done < files.list > md5sum
831 status
833 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
834 2>/dev/null | awk 'END{ print $1 }')
836 # Build cpio archives.
837 _n 'Compressing the FS...'
838 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
839 rm -rf fs
840 status
842 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
843 2>/dev/null | awk 'END{ print $1 }')
845 _n 'Updating receipt sizes...'
846 sed -i s/^PACKED_SIZE.*$// receipt
847 sed -i s/^UNPACKED_SIZE.*$// receipt
848 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
849 status
851 # Set extra version.
852 if [ -n "$EXTRAVERSION" ]; then
853 _n 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
854 sed -i s/^EXTRAVERSION.*$// receipt
855 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
856 status
857 fi
859 # Compress.
860 _n 'Creating full cpio archive...'
861 find . -print | cpio -o -H newc --quiet > \
862 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
863 status
865 _n 'Restoring original package tree...'
866 unlzma -c fs.cpio.lzma | cpio -idm --quiet
867 status
869 rm fs.cpio.lzma; cd ..
871 # QA and give info.
872 tazpkg=$(ls *.tazpkg)
873 packit_quality
874 separator; _ 'Package "%s" created' "$tazpkg"; newline
875 }
878 # Verify package quality and consistency.
880 packit_quality() {
881 #gettext "QA: checking for broken link..."
882 #link=$(find $fs/usr -type l -follow)
883 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
884 #status
886 # Exit if any error found in log file.
887 lerror=$(_n 'ERROR')
888 if fgrep -q ^$lerror $LOGS/$pkg.log; then
889 rm -f $command
890 exit 1
891 fi
893 _n 'QA: checking for empty package...'
894 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
895 if [ "$files" == 0 ] && [ "$CATEGORY" != 'meta' ]; then
896 newline; _ 'ERROR: empty package'
897 rm -f $command
898 exit 1
899 else
900 # Ls sort by name so the first file is the one we want.
901 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n1)
902 status
903 if [ -f "$old" ]; then
904 _n 'Removing old package "%s"' "$(basename $old)"
905 rm -f $old; status
906 fi
907 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
908 sed -i /^${pkg}$/d $broken
909 #gettext "Removing source tree..."
910 #rm -f $WOK/$pkg/source && status
911 fi
912 }
915 # Reverse "cat" command: prints input lines in the reverse order
917 tac() {
918 sed '1!G;h;$!d' $1
919 }
922 # Install package on --install or update the chroot.
924 install_package() {
925 case "$ARCH" in
926 arm*|x86_64)
927 arch="-$ARCH"
928 root="$CROSS_TREE/sysroot" ;;
929 esac
930 # Install package if requested but skip install if target host doesn't
931 # match build system or it will break the build chroot.
932 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
933 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
934 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
935 cd $PKGS
936 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
937 else
938 _ 'Unable to install package, build has failed.'; newline
939 exit 1
940 fi
941 fi
943 # Install package if part of the chroot to keep env up-to-date.
944 if [ -d "$root$INSTALLED/$pkg" ]; then
945 . /etc/slitaz/cook.conf
946 . $WOK/$pkg/taz/$pkg-*/receipt
947 _ 'Updating %s chroot environment...' "$ARCH"
948 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
949 cd $PKGS
950 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
951 fi
952 }
955 # remove chroot jail
957 umount_aufs() {
958 tac ${1}rw/aufs-umount.sh | sh
959 rm -rf ${1}rw
960 umount ${1}root
961 rmdir ${1}r*
962 }
965 # Launch the cook command into a chroot jail protected by aufs.
966 # The current filesystems are used read-only and updates are
967 # stored in a separate branch.
969 try_aufs_chroot() {
971 base="/dev/shm/aufsmnt$$"
973 # Can we setup the chroot? Is it already done?
974 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
975 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
976 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
977 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
978 mkdir ${base}root ${base}rw || return
980 _ 'Setup aufs chroot...'
982 # Sanity check
983 for i in / /proc /sys /dev/shm /home ; do
984 case " $AUFS_MOUNTS " in
985 *\ $i\ *) ;;
986 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
987 esac
988 done
989 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
990 mount --bind $mnt ${base}root$mnt
991 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
992 _ 'Aufs mount failure'
993 umount ${base}root
994 rm -rf ${base}r*
995 return
996 fi
997 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
998 done
999 trap "umount_aufs ${base}" INT
1001 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1002 status=$?
1004 _ 'Leaving aufs chroot...'
1005 umount_aufs $base
1006 # Install package outside the aufs jail
1007 install_package
1008 exit $status
1009 }
1012 # Encode predefined XML entities
1014 xml_ent() {
1015 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1016 }
1019 # Create a XML feed for freshly built packages.
1021 gen_rss() {
1022 pubdate=$(date '+%a, %d %b %Y %X')
1023 cat > $FEEDS/$pkg.xml <<EOT
1024 <item>
1025 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1026 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1027 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1028 <pubDate>$pubdate</pubDate>
1029 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1030 </item>
1031 EOT
1032 }
1035 # Truncate stdout log file to $1 Mb.
1037 loglimit() {
1038 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1039 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1040 else
1041 tee /dev/stderr
1042 fi
1043 }
1046 # Search file in mirrored packages
1048 search_file_mirror() {
1049 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1050 }
1053 # Search file in local wok packages
1055 search_file_local() {
1056 # existing packages have precedence over the package/taz folder
1057 srch=$1
1058 { for package in $(find $PKGS -name '*.tazpkg'); do
1059 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1060 grep /$srch\$)" ]; then
1061 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1062 fi
1063 done } | sort -u
1064 }
1067 # Ask in multiple choice
1069 ask_multiple() {
1070 local multiples first my_choice
1071 multiples="$1"
1072 first=$(echo "$multiples" | head -n1)
1073 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1074 _ 'Select one [%s]: ' "$first"; read my_choice
1075 found="${my_choice:-$first}"
1076 }
1079 # Search file in local cache (fast), local wok packages, mirrored packages
1081 search_file() {
1082 local srch cache missing
1083 srch="$1"
1084 cache='/var/cache/ldsearch.cache'
1085 missing='/var/cache/missing.file'
1086 touch $cache $missing
1087 found=$(grep $srch $cache | cut -d$'\t' -f2)
1088 if [ -z "$found" ]; then
1089 found=$(search_file_local $srch)
1090 if [ -n "$found" ]; then
1091 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1092 ask_multiple "$found"
1093 fi
1094 echo -e "$srch\t$found" >> $cache
1095 else
1096 found=$(search_file_mirror $srch)
1097 if [ -n "$found" ]; then
1098 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1099 ask_multiple "$found"
1100 fi
1101 echo -e "$srch\t$found" >> $cache
1102 else
1103 echo "$srch" >> $missing
1104 fi
1105 fi
1106 fi
1107 }
1110 # Return size of file in human readible format
1111 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1112 filesize() {
1113 busybox ls -lh "$1" | awk '{print $5 "B"}'
1114 }
1117 #
1118 # Receipt functions to ease packaging
1119 #
1121 get_dev_files() {
1122 _n 'Getting standard devel files...'
1123 mkdir -p $fs/usr/lib
1124 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1125 cp -a $install/usr/lib/*a $fs/usr/lib
1126 cp -a $install/usr/include $fs/usr
1127 status
1128 }
1130 dblog() { tee -a $LOGS/pkgdb.log; }
1135 #
1136 # Commands
1137 #
1139 case "$1" in
1140 usage|help|-u|-h)
1141 usage ;;
1143 list-wok)
1144 newline; _ 'List of %s packages in "%s"' "$ARCH" "$WOK"; separator
1145 cd $WOK
1146 if [ "$ARCH" != 'i486' ]; then
1147 count=0
1148 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1149 do
1150 unset HOST_ARCH
1151 . $pkg
1152 count=$(($count + 1))
1153 colorize 34 "$PACKAGE"
1154 done
1155 else
1156 count=$(ls | wc -l)
1157 ls -1
1158 fi
1159 separator
1160 _p '%s package' '%s packages' "$count" "$(colorize 32 "$count")"
1161 newline ;;
1163 activity)
1164 cat $activity ;;
1166 search)
1167 # Just a simple search function, we dont need more actually.
1168 query="$2"
1169 newline; _ 'Search results for "%s"' "$query"; separator
1170 cd $WOK; ls -1 | grep "$query"
1171 separator; newline ;;
1173 setup)
1174 # Setup a build environment
1175 check_root
1176 _ 'Cook: setup environment' | log
1177 newline; _ 'Setting up your environment'; separator
1178 cd $SLITAZ
1179 init_db_files
1180 _ 'Checking for packages to install...'
1181 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1182 # ARCH-setup or 'cross check' should be used before: cook setup
1183 case "$ARCH" in
1184 arm*|x86_64)
1185 if [ ! -x '/usr/bin/cross' ]; then
1186 _ 'ERROR: %s is not installed' 'cross'
1187 exit 1
1188 fi
1189 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1190 . /etc/slitaz/cross.conf ;;
1191 esac
1192 for pkg in $SETUP_PKGS; do
1193 if [ -n "$forced" ]; then
1194 tazpkg -gi $pkg --forced
1195 else
1196 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1197 fi
1198 done
1200 # Handle --options
1201 case "$2" in
1202 --wok) hg clone $WOK_URL wok || exit 1 ;;
1203 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1204 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1205 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1206 esac
1208 # SliTaz group and permissions
1209 if ! grep -q ^slitaz /etc/group; then
1210 _ 'Adding group "%s"' 'slitaz'
1211 addgroup slitaz
1212 fi
1213 _ 'Setting permissions for group "%s"...' 'slitaz'
1214 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1215 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1216 separator; _ 'All done, ready to cook packages :-)'; newline ;;
1218 *-setup)
1219 # Setup for cross compiling.
1220 arch="${1%-setup}"
1221 check_root
1222 . /etc/slitaz/cook.conf
1223 for pkg in $CROSS_SETUP; do
1224 if [ -n "$forced" ]; then
1225 tazpkg -gi $pkg --forced
1226 else
1227 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1228 fi
1229 done
1231 _ 'Cook: setup %s cross environment' "$arch" | log
1232 newline; boldify $(_n 'Setting up your %s cross environment' "$arch"); separator
1233 init_db_files
1234 sed -i \
1235 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1236 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1237 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1238 /etc/slitaz/cook.conf
1239 case "$arch" in
1240 arm)
1241 flags='-O2 -march=armv6'
1242 host="$ARCH-slitaz-linux-gnueabi" ;;
1243 armv6hf)
1244 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1245 host="$ARCH-slitaz-linux-gnueabi" ;;
1246 armv7)
1247 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1248 host="$ARCH-slitaz-linux-gnueabi" ;;
1249 x86_64)
1250 flags='-O2 -mtune=generic -pipe'
1251 host="$ARCH-slitaz-linux" ;;
1252 esac
1253 sed -i \
1254 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1255 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1256 . /etc/slitaz/cook.conf
1257 sysroot="$CROSS_TREE/sysroot"
1258 tools="/cross/$arch/tools"
1259 root="$sysroot"
1260 # L10n: keep the same width of translations to get a consistent view
1261 _ 'Target arch : %s' "$ARCH"
1262 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1263 _ 'Build flags : %s' "$flags"
1264 _ 'Arch sysroot : %s' "$sysroot"
1265 _ 'Tools prefix : %s' "$tools/bin"
1266 # Tell the packages manager where to find packages.
1267 _ 'Packages DB : %s' "$root$DB"
1268 mkdir -p $root$INSTALLED
1269 cd $root$DB; rm -f *.bak
1270 for list in packages.list packages.desc packages.equiv packages.md5; do
1271 rm -f $list
1272 ln -s $SLITAZ/packages/$list $list
1273 done
1274 # We must have the cross compiled glibc-base installed or default
1275 # i486 package will be used as dep by tazpkg and then break the
1276 # cross environment
1277 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1278 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1279 fi
1280 # Show GCC version or warn if not yet compiled.
1281 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1282 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1283 else
1284 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1285 _ 'Run "%s" to cook a toolchain' 'cross compile'
1286 fi
1287 separator; newline ;;
1289 test)
1290 # Test a cook environment.
1291 _ 'Cook test: testing the cook environment' | log
1292 [ ! -d "$WOK" ] && exit 1
1293 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1294 cook cooktest ;;
1296 new)
1297 # Create the package folder and an empty receipt.
1298 pkg="$2"
1299 [ -z "$pkg" ] && usage
1300 newline
1301 if [ -d "$WOK/$pkg" ]; then
1302 _ 'Package "%s" already exists.' "$pkg"
1303 exit 1
1304 fi
1306 _n 'Creating folder "%s"' "$WOK/$pkg"
1307 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1309 _n 'Preparing the package receipt...'
1310 cp $DATA/receipt .
1311 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1312 status; newline
1314 # Interactive mode, asking and seding.
1315 case "$3" in
1316 --interactive|-x)
1317 _ 'Entering interactive mode...'
1318 separator
1319 _ 'Package : %s' "$pkg"
1321 _n 'Version : ' ; read answer
1322 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1324 _n 'Category : ' ; read answer
1325 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1327 # L10n: Short description
1328 _n 'Short desc : ' ; read answer
1329 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1331 _n 'Maintainer : ' ; read answer
1332 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1334 _n 'License : ' ; read answer
1335 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1337 _n 'Web site : ' ; read answer
1338 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1339 newline
1341 # Wget URL.
1342 _ 'Wget URL to download source tarball.'
1343 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1344 _n 'Wget url : ' ; read answer
1345 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1347 # Ask for a stuff dir.
1348 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1349 if [ "$?" == 0 ]; then
1350 _n 'Creating the stuff directory...'
1351 mkdir $WOK/$pkg/stuff; status
1352 fi
1354 # Ask for a description file.
1355 confirm "$(_n 'Are you going to write a description? (y/N)')"
1356 if [ "$?" == 0 ]; then
1357 _n 'Creating the "%s" file...' 'description.txt'
1358 touch $WOK/$pkg/description.txt; status
1359 fi
1361 separator; _ 'Receipt is ready to use.'; newline ;;
1362 esac ;;
1364 list)
1365 # Cook a list of packages (better use the Cooker since it will order
1366 # packages before executing cook).
1367 check_root
1368 if [ -z "$2" ]; then
1369 newline; _ 'No list in argument.'; newline
1370 exit 1
1371 fi
1372 if [ ! -f "$2" ]; then
1373 newline; _ 'List "%s" not found.' "$2"; newline
1374 exit 1
1375 fi
1377 _ 'Starting cooking the list "%s"' "$2" | log
1379 for pkg in $(cat $2); do
1380 cook $pkg || broken
1381 done ;;
1383 clean-wok)
1384 check_root
1385 newline; _n 'Cleaning all packages files...'
1386 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1387 status; newline ;;
1389 clean-src)
1390 check_root
1391 newline; _n 'Cleaning all packages sources...'
1392 rm -rf $WOK/*/source
1393 status; newline ;;
1395 uncook)
1396 cd $WOK
1397 count=0
1398 newline; _ 'Checking for uncooked packages'; separator
1400 for pkg in *; do
1401 unset HOST_ARCH EXTRAVERSION
1402 [ ! -e $pkg/receipt ] && continue
1403 . $pkg/receipt
1404 # Source cooked pkg receipt to get EXTRAVERSION
1405 if [ -d "$WOK/$pkg/taz" ]; then
1406 cd $WOK/$pkg/taz/$pkg-*
1407 . receipt; cd $WOK
1408 fi
1409 case "$ARCH" in
1410 i486)
1411 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1412 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1413 count=$(($count + 1))
1414 colorize 34 "$pkg"
1415 fi ;;
1416 arm*)
1417 # Check only packages included in arch
1418 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1419 # *.tazpkg
1420 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1421 count=$(($count + 1))
1422 colorize 34 "$pkg"
1423 fi
1424 fi ;;
1425 esac
1426 done
1428 if [ "$count" -gt "0" ]; then
1429 separator
1430 _p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")"
1431 else
1432 _ 'All packages are cooked :-)'
1433 fi
1434 newline ;;
1436 pkgdb)
1437 # Create suitable packages list for TazPKG and only for built packages
1438 # as well as flavors files for TazLiTo. We dont need logs since we do it
1439 # manually to ensure everything is fine before syncing the mirror.
1441 rm $LOGS/pkgdb.log 2>/dev/null
1443 case "$2" in
1444 --flavors|--rmpkg) ;;
1445 *)
1446 [ -n "$2" ] && PKGS="$2"
1447 if [ ! -d "$PKGS" ]; then
1448 { newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline; } | dblog
1449 exit 1
1450 fi ;;
1451 esac
1453 time=$(date +%s)
1454 flavors="$SLITAZ/flavors"
1455 live="$SLITAZ/live"
1457 echo 'cook:pkgdb' > $command
1458 _ 'Cook pkgdb: Creating all packages lists' | log
1459 newline; { _ 'Creating lists for "%s"' "$PKGS"; separator; } | dblog
1461 { _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"; newline; } | dblog
1463 cd $PKGS
1464 rm -f packages.* extra.list
1465 touch packages.equiv
1467 _n 'Creating file "%s"' 'packages.list' | dblog
1468 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1469 echo " ($(filesize $PKGS/packages.list))" | dblog
1471 _n 'Creating file "%s"' 'packages.md5' | dblog
1472 md5sum *.tazpkg > $PKGS/packages.md5
1473 echo " ($(filesize $PKGS/packages.md5))" | dblog
1474 cp $PKGS/packages.md5 $PKGS/packages.toremove # list of duplicates
1476 md5sum packages.md5 | cut -d' ' -f1 > ID
1477 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1479 _n 'Creating file "%s"' 'descriptions.txt' | dblog
1480 rm $PKGS/descriptions.txt 2>/dev/null
1481 for i in $(ls $WOK | sort); do
1482 if [ -e "$WOK/$i/description.txt" ]; then
1483 echo "$i" >> descriptions.txt
1484 cat "$WOK/$i/description.txt" | sed 's|^$| |' >> descriptions.txt
1485 echo >> descriptions.txt
1486 fi
1487 done
1488 echo " ($(filesize $PKGS/descriptions.txt))" | dblog
1491 _ 'Creating lists from "%s"' "$WOK" | dblog
1492 cd $WOK
1493 for pkg in *; do
1494 unset_receipt
1495 . $pkg/receipt
1496 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1497 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1499 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1500 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1502 # packages.desc lets us search easily in DB
1503 cat >> $PKGS/packages.desc <<EOT
1504 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1505 EOT
1507 # packages.txt used by tazpkg and tazpkg-web also to provide
1508 # a human readable package list with version and description.
1509 cat >> $PKGS/packages.txt <<EOT
1510 $PACKAGE
1511 $VERSION$EXTRAVERSION
1512 $SHORT_DESC
1513 $PACKED_SIZE ($UNPACKED_SIZE installed)
1515 EOT
1517 # packages.info combines TazPkg separate files
1518 # and will substitute them all
1519 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1520 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1521 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1522 cat >> $PKGS/packages.info <<EOT
1523 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1524 EOT
1526 # packages.equiv is used by tazpkg install to check depends.
1527 for i in $PROVIDE; do
1528 DEST=''
1529 echo $i | fgrep -q : && DEST="${i#*:}:"
1530 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1531 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1532 $PKGS/packages.equiv
1533 else
1534 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1535 fi
1536 done
1538 # files.list provides a list of all packages files.
1539 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1540 $PKGS/files.list
1542 # list of duplicates
1543 sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
1544 else
1545 # if receipt variable HOST_ARCH absent/empty or contains ARCH
1546 if [ -z "$HOST_ARCH" -o "${HOST_ARCH/$ARCH/}" != "$HOST_ARCH" ]; then
1547 _ ' - absent: %s (%s)' "$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$ARCH" | dblog
1548 fi
1549 fi
1550 done
1552 # Display list size.
1553 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)" | dblog
1554 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)" | dblog
1555 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)" | dblog
1556 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)" | dblog
1558 cd $PKGS
1561 # Check package duplicates
1562 if [ -s "$PKGS/packages.toremove" ]; then
1563 newline | dblog
1564 _ 'Removing duplicates:' | dblog
1565 while read pkgsum pkgfile; do
1566 echo " - $pkgfile" | dblog
1567 sed -i "/${pkgfile%.tazpkg}/d" $PKGS/packages.list
1568 sed -i "/ $pkgfile/d" $PKGS/packages.md5
1569 [ -n "$rmpkg" ] && rm $PKGS/$pkgfile # remove packages only with --rmpkg
1570 done < $PKGS/packages.toremove
1571 newline | dblog
1572 fi
1573 rm $PKGS/packages.toremove
1576 # files.list.lzma
1577 _n 'Creating file "%s"' 'files.list.lzma' | dblog
1578 touch files.list
1579 # pkgs.slitaz.org strongly depends on list sorted by packages names
1580 lzma e files.list files.list.lzma
1581 echo " ($(filesize $PKGS/files.list.lzma))" | dblog
1583 # Pre-sorting filenames causes 10% smaller resulting lzma file
1584 _n 'Creating file "%s"' 'files-list.lzma' | dblog
1585 cat files.list | sort -k2 -o files.list.sorted
1586 lzma e files.list.sorted files-list.lzma
1587 rm -f files.list files.list.sorted
1588 echo " ($(filesize $PKGS/files-list.lzma))" | dblog
1590 [ -e files.list.md5 ] && rm files.list.md5
1591 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1593 # packages.info.lzma
1594 PI=packages.info
1595 _n 'Creating file "%s"' 'packages.info.lzma' | dblog
1596 touch $PI
1597 lzma e $PI $PI.lzma
1598 echo " ($(filesize $PKGS/packages.info.lzma))" | dblog
1600 # Make bundle to fast recharge
1601 _n 'Creating file "%s"' 'bundle.tar.lzma' | dblog
1602 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1603 # Make sure to get "mirrors" file
1604 until [ -e 'mirrors' ]; do
1605 wget -q http://mirror1.slitaz.org/mirrors
1606 echo -n '.' | dblog; sleep 5
1607 done
1608 # Make sure to get "extra.list" file
1609 until [ -e 'extra.list' ]; do
1610 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1611 echo -n '.' | dblog; sleep 5
1612 done
1613 busybox tar -chaf bundle.tar.lzma \
1614 mirrors extra.list files-list.md5 packages.info descriptions.txt \
1615 packages.desc packages.md5 packages.txt packages.list packages.equiv
1616 rm ./mirrors
1617 echo " ($(filesize $PKGS/bundle.tar.lzma))" | dblog
1619 # Display some info.
1620 separator | dblog
1621 nb=$(ls $PKGS/*.tazpkg | wc -l)
1622 time=$(($(date +%s) - $time))
1623 # L10n: 's' is for seconds (cooking time)
1624 { _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline; } | dblog
1627 # Create all flavors files at once. Do we really need code to monitor
1628 # flavors changes? Lets just build them with packages lists before
1629 # syncing the mirror.
1630 [ "$2" != '--flavors' ] && exit 1
1632 if [ ! -d "$flavors" ]; then
1633 { _ 'Missing flavors folder "%s"' "$flavors"; newline; } | dblog
1634 exit 1
1635 fi
1637 [ ! -d "$live" ] && mkdir -p $live
1638 _ 'Creating flavors files in "%s"' "$live" | dblog
1639 _ 'Cook pkgdb: Creating all flavors' | log
1640 separator | dblog
1642 _ 'Recharging lists to use latest packages...' | dblog
1643 tazpkg recharge >/dev/null 2>/dev/null
1645 # We need a custom tazlito config to set working dir to /home/slitaz.
1646 if [ ! -f "$live/tazlito.conf" ]; then
1647 _ 'Creating configuration file "%s"' 'tazlito.conf' | dblog
1648 cp /etc/tazlito/tazlito.conf $live
1649 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1650 $live/tazlito.conf
1651 fi
1653 # Update Hg flavors repo and pack.
1654 if [ -d "$flavors/.hg" ]; then
1655 cd $flavors; hg pull -u
1656 fi
1658 cd $live
1659 _ 'Starting to generate flavors...' | dblog
1660 rm -f flavors.list *.flavor
1661 for i in $flavors/*; do
1662 fl=$(basename $i)
1663 _ 'Packing flavor "%s"' "$fl" | dblog
1664 tazlito pack-flavor $fl >/dev/null || exit 1
1665 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1666 done
1667 cp -f $live/*.flavor $live/flavors.list $PKGS
1668 separator | dblog
1669 { _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline; } | dblog
1670 rm -f $command
1671 separator | dblog
1672 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" | dblog
1673 ;;
1675 *)
1676 # Just cook and generate a package.
1677 check_root
1678 time=$(date +%s)
1679 pkg="$1"
1680 [ -z "$pkg" ] && usage
1681 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1682 $LOGS/$pkg.log 2> /dev/null)
1683 receipt="$WOK/$pkg/receipt"
1684 check_pkg_in_wok
1685 newline
1687 unset inst
1688 unset_receipt
1689 . $receipt
1691 # Handle cross compilation.
1692 case "$ARCH" in
1693 arm*)
1694 if [ -z "$HOST_ARCH" ]; then
1695 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1696 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1697 _ 'cook: %s' "$error"
1698 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1699 _ 'Cook skip: %s' "$error" | log
1700 newline
1701 exit 1
1702 fi ;;
1703 esac
1705 # Some packages are not included in some arch or fail to cross compile.
1706 : ${HOST_ARCH=i486}
1707 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1708 # Handle arm{v6hf,v7,..}
1709 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1710 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1711 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1712 _ 'cook: %s' "error"
1713 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1714 _ 'Cook skip: %s' "$error" | log
1715 sed -i /^${pkg}$/d $broken
1716 newline
1717 exit 0
1718 fi
1720 # Skip blocked, 3 lines also for the Cooker.
1721 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1722 _ 'Package "%s" is blocked' "$pkg"; newline
1723 exit 0
1724 fi
1726 try_aufs_chroot "$@"
1728 # Log and source receipt.
1729 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1730 echo "cook:$pkg" > $command
1731 [ "$lastcooktime" ] &&
1732 echo "cook:$pkg $lastcooktime $(date +%s)" > $cooktime
1734 # Display and log info if cook process stopped.
1735 # FIXME: gettext not working (in single quotes) here!
1736 trap '_ "\n\nCook stopped: control-C\n\n" | \
1737 tee -a $LOGS/$pkg.log' INT
1739 # Handle --options
1740 case "$2" in
1741 --clean|-c)
1742 _n 'Cleaning "%s"' "$pkg"
1743 cd $WOK/$pkg; rm -rf install taz source
1744 status; newline
1745 exit 0 ;;
1747 --install|-i)
1748 inst='yes' ;;
1750 --getsrc|-gs)
1751 _ 'Getting source for "%s"' "$pkg"; separator
1752 get_source
1753 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1754 exit 0 ;;
1756 --block|-b)
1757 _n 'Blocking package "%s"' "$pkg"
1758 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1759 status; newline
1760 exit 0 ;;
1762 --unblock|-ub)
1763 _n 'Unblocking package "%s"' "$pkg"
1764 sed -i "/^${pkg}$/"d $blocked
1765 status; newline
1766 exit 0 ;;
1768 --pack)
1769 if [ -d $WOK/$pkg/taz ]; then
1770 rm -rf $WOK/$pkg/taz
1771 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1772 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1773 clean_log
1774 else
1775 _ 'Need to build "%s"' "$pkg"
1776 exit 0
1777 fi
1778 exit 0 ;;
1780 --cdeps)
1781 if [ ! -d $WOK/$pkg/taz ]; then
1782 _ 'Need to build "%s"' "$pkg"
1783 exit 0
1784 fi
1786 _ 'Checking depends'; separator
1787 lddlist='/tmp/lddlist'; touch $lddlist
1788 missing='/var/cache/missing.file'
1790 # find all deps using ldd
1791 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1792 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1793 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1794 done #"
1796 # remove exe/so duplicates
1797 sort -u $lddlist > $lddlist.sorted
1799 # search packages
1800 for exefile in $(cat $lddlist.sorted); do
1801 search_file $exefile
1802 echo "$found" >> $lddlist.pkgs
1803 echo -n '.'
1804 done
1805 echo
1807 # remove packages duplicates
1808 sort -u $lddlist.pkgs > $lddlist.final
1809 sort -u $missing > $missing.final
1810 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1811 exit 0 ;;
1812 esac
1814 # Check if wanted is built now so we have separate log files.
1815 for wanted in $WANTED ; do
1816 if grep -q "^$wanted$" $blocked; then
1817 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1818 newline
1819 rm -f $command
1820 exit 1
1821 fi
1822 if grep -q "^$wanted$" $broken; then
1823 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1824 newline
1825 rm -f $command
1826 exit 1
1827 fi
1828 if [ ! -d "$WOK/$wanted/install" ]; then
1829 cook "$wanted" || exit 1
1830 fi
1831 done
1833 # Cook and pack or exit on error and log everything.
1834 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1835 remove_deps | tee -a $LOGS/$pkg.log
1836 cookit_quality
1837 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1838 clean_log
1840 # Exit if any error in packing.
1841 lerror=$(_n 'ERROR')
1842 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1843 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1844 debug_info | tee -a $LOGS/$pkg.log
1845 rm -f $command
1846 exit 1
1847 fi
1849 # Create an XML feed
1850 gen_rss
1852 # Time and summary
1853 time=$(($(date +%s) - $time))
1854 summary | tee -a $LOGS/$pkg.log
1855 newline
1857 # We may want to install/update (outside aufs jail !).
1858 [ -s /aufs-umount.sh ] ||
1859 install_package
1861 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1862 # You want automation: use the Cooker Build Bot.
1863 rm -f $command ;;
1864 esac
1866 exit 0