cookutils view cook @ rev 421

cook, cross, *.conf: improve cross compilation and small clean
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 19 04:47:53 2012 +0200 (2012-05-19)
parents 999aed12cf89
children 50cd87593dae
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifing any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /lib/libtaz.sh
11 [ -f "/etc/slitaz/cook.conf" ] && . /etc/slitaz/cook.conf
12 [ -f "cook.conf" ] && . ./cook.conf
14 # Share DB and status with the Cooker.
15 activity="$CACHE/activity"
16 command="$CACHE/command"
17 broken="$CACHE/broken"
18 blocked="$CACHE/blocked"
20 #
21 # Functions
22 #
24 usage() {
25 cat << EOT
27 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
29 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
30 usage|help $(gettext "Display this short usage.")
31 setup $(gettext "Setup your build environment.")
32 arm-setup $(gettext "Create packages DB lists and flavors.")
33 test $(gettext "Test environment and cook a package.")
34 list-wok $(gettext "List packages in the wok.")
35 search $(gettext "Simple packages search function.")
36 new $(gettext "Create a new package with a receipt".)
37 list $(gettext "Cook a list of packages.")
38 clean-wok $(gettext "Clean-up all packages files.")
39 clean-src $(gettext "Clean-up all packages sources.")
40 pkgdb $(gettext "Create packages DB lists and flavors.")
42 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
43 --clean|-c Cook : $(gettext "clean the package in the wok.")
44 --install|-i Cook : $(gettext "cook and install the package.")
45 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
46 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
47 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
48 --interactive|-x New : $(gettext "create a receipt interactively.")
49 --wok Setup: $(gettext "clone the cooking wok from Hg repo.")
50 --stable Setup: $(gettext "clone the stable wok from Hg repo.")
51 --undigest Setup: $(gettext "clone the undigest wok from Hg repo.")
52 --tiny Setup: $(gettext "clone the tiny SliTaz wok from Hg repo.")
53 --forced Setup: $(gettext "force reinstall of chroot packages.")
54 --flavors Pkgdb: $(gettext "create up-to-date flavors files.")
56 EOT
57 exit 0
58 }
60 # Log activities, we want first letter capitalized.
61 log() {
62 grep ^[A-Z] | \
63 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
64 }
66 # We don't want these escapes in web interface.
67 clean_log() {
68 sed -i -e s'|\[70G\[ \[1;32m| |' \
69 -e s'|\[0;39m \]||' $LOGS/$pkg.log
70 }
72 # Log broken packages.
73 broken() {
74 if ! grep -q "^$pkg$" $broken; then
75 echo "$pkg" >> $broken
76 fi
77 }
79 # Be sure package exists in wok.
80 check_pkg_in_wok() {
81 if [ ! -d "$WOK/$pkg" ]; then
82 gettext -e "\nUnable to find package in the wok:"
83 echo -e " $pkg\n" && exit 1
84 fi
85 }
87 if_empty_value() {
88 if [ -z "$value" ]; then
89 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
90 exit 1
91 fi
92 }
94 # Initialize files used in $CACHE
95 init_db_files() {
96 gettext "Creating directories structure in:"; echo " $SLITAZ"
97 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS
98 gettext "Creating DB files in:"; echo " $CACHE"
99 for f in $activity $command $broken $blocked
100 do
101 touch $f
102 done
103 }
105 # QA: check a receipt consistency before building.
106 receipt_quality() {
107 gettext -e "QA: checking package receipt...\n"
108 unset online
109 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
110 online="online"
111 fi
112 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
113 do
114 unset value
115 value="$(. $receipt ; eval echo \$$var)"
116 case "$var" in
117 PACKAGE|VERSION|SHORT_DESC)
118 if_empty_value ;;
119 CATEGORY)
120 [ -z "$value" ] && value="empty"
121 valid="base-system x-window utilities network graphics \
122 multimedia office development system-tools security games \
123 misc meta non-free"
124 if ! echo "$valid" | grep -q -w "$value"; then
125 gettext "QA: unknown category:"; echo -e " $value\n"
126 exit 1
127 fi ;;
128 WEB_SITE)
129 # We don't check WGET_URL since if dl is needed it will fail.
130 # Break also if we're not online. Here error is not fatal.
131 if_empty_value
132 [ -z "$online" ] || break
133 if ! busybox wget -T 12 -s $value 2>/dev/null; then
134 gettext "QA: Unable to reach:"; echo -e " $value"
135 fi ;;
136 esac
137 done
138 }
140 # Executed before sourcing a receipt.
141 unset_receipt() {
142 unset DEPENDS BUILD_DEPENDS WANTED EXTRAVERSION WGET_URL PROVIDE TARBALL
143 unset HOST_ARCH CROSS_BUGS
144 }
146 # Paths used in receipt and by cook itself.
147 set_paths() {
148 pkgdir=$WOK/$PACKAGE
149 src=$pkgdir/source/$PACKAGE-$VERSION
150 taz=$pkgdir/taz
151 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
152 fs=$pack/fs
153 stuff=$pkgdir/stuff
154 install=$pkgdir/install
155 if [ "$WANTED" ]; then
156 wanted=${WANTED%% *}
157 src=$WOK/$wanted/source/$wanted-$VERSION
158 install=$WOK/$wanted/install
159 wanted_stuff=$WOK/$wanted/stuff
160 fi
161 # Kernel version is set from linux-api-headers since it is part of toolchain.
162 if [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
163 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
164 fi
165 # Old way compatibility.
166 _pkg=$install
167 }
169 # Create source tarball when URL is a SCM.
170 create_tarball() {
171 gettext "Creating tarball: "; echo "$tarball"
172 if [ "$LZMA_SRC" ]; then
173 tar -c $pkgsrc | lzma e $SRC/$tarball -si || exit 1
174 else
175 tar cjf $tarball $pkgsrc || exit 1
176 mv $tarball $SRC && rm -rf $pkgsrc
177 fi
178 }
180 # Get package source. For SCM we are in cache so clone here and create a
181 # tarball here.
182 get_source() {
183 pwd=$(pwd)
184 pkgsrc=${SOURCE:-$PACKAGE}-$VERSION
185 tarball=$pkgsrc.tar.bz2
186 [ "$LZMA_SRC" ] && tarball=$pkgsrc.tar.lzma
187 case "$WGET_URL" in
188 http://*|ftp://*)
189 # Busybox Wget is better!
190 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
191 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
192 https://*)
193 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
194 (echo -e "ERROR: wget $WGET_URL" && exit 1) ;;
195 hg*|mercurial*)
196 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
197 url=${WGET_URL#hg|}
198 else
199 url=${WGET_URL#mercurial|}
200 fi
201 gettext -e "Getting source from Hg...\n"
202 echo "URL: $url"
203 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
204 if [ "$BRANCH" ]; then
205 echo "Hg branch: $BRANCH"
206 hg clone $url --rev $BRANCH $pkgsrc || \
207 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
208 else
209 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
210 fi
211 rm -rf $pkgsrc/.hg
212 create_tarball ;;
213 git*)
214 url=${WGET_URL#git|}
215 gettext -e "Getting source from Git...\n"
216 echo "URL: $url"
217 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
218 if [ "$BRANCH" ]; then
219 echo "Git branch: $BRANCH"
220 cd $pkgsrc && git checkout $BRANCH && cd ..
221 fi
222 create_tarball ;;
223 cvs*)
224 url=${WGET_URL#cvs|}
225 mod=$PACKAGE
226 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
227 gettext -e "Getting source from CVS...\n"
228 echo "URL: $url"
229 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
230 gettext "Cloning to: "; echo "$pwd/$mod"
231 cvs -d:$url co $mod && mv $mod $pkgsrc
232 create_tarball ;;
233 svn*|subversion*)
234 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
235 url=${WGET_URL#svn|}
236 else
237 url=${WGET_URL#subversion|}
238 fi
239 gettext -e "Getting source from SVN...\n"
240 echo "URL: $url"
241 if [ "$BRANCH" ]; then
242 echo t | svn co $url -r $BRANCH $pkgsrc
243 else
244 echo t | svn co $url $pkgsrc
245 fi
246 create_tarball ;;
247 *)
248 gettext -e "\nERROR: Unable to handle:"; echo -e " $WGET_URL \n" | \
249 tee -a $LOGS/$PACKAGE.log
250 exit 1 ;;
251 esac
252 }
254 # Extract source package.
255 extract_source() {
256 if [ ! -s "$SRC/$TARBALL" ]; then
257 local url
258 url="http://mirror.slitaz.org/sources/packages"
259 url=$url/${TARBALL:0:1}/$TARBALL
260 gettext "Getting source from mirror:"; echo " $url"
261 busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
262 fi
263 gettext "Extracting:"; echo " $TARBALL"
264 case "$TARBALL" in
265 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
266 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
267 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
268 *.tar) tar xf $SRC/$TARBALL ;;
269 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
270 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
271 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
272 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
273 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
274 *) cp $SRC/$TARBALL $(pwd) ;;
275 esac
276 }
278 # Display cooked package summary.
279 summary() {
280 cd $WOK/$pkg
281 [ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
282 fs=$(du -sh taz/* | awk '{print $1}')
283 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
284 files=$(cat taz/$pkg-*/files.list | wc -l)
285 cookdate=$(date "+%Y-%m-%d %H:%M")
286 sec=$time
287 div=$(( ($time + 30) / 60))
288 [ "$div" != 0 ] && min="~ ${div}m"
289 gettext "Summary for:"; echo " $PACKAGE $VERSION"
290 separator
291 [ "$prod" ] && echo "Produced : $prod"
292 cat << EOT
293 Packed : $fs
294 Compressed : $size
295 Files : $files
296 Cook time : ${sec}s $min
297 Cook date : $cookdate
298 Host arch : $ARCH
299 $(separator)
300 EOT
301 }
303 # Display debugging error info.
304 debug_info() {
305 echo -e "\nDebug information"
306 separator
307 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
308 for error in \
309 ERROR "No package" "cp: can't" "can't open" "can't cd" \
310 "error:" "fatal error:"
311 do
312 fgrep "$error" $LOGS/$pkg.log
313 done
314 separator && echo ""
315 }
317 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
318 # so some packages need to copy these files with the receipt and genpkg_rules.
319 copy_generic_files() {
320 # $LOCALE is set in cook.conf
321 if [ "$LOCALE" ]; then
322 if [ -d "$install/usr/share/locale" ]; then
323 mkdir -p $fs/usr/share/locale
324 for i in $LOCALE
325 do
326 if [ -d "$install/usr/share/locale/$i" ]; then
327 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
328 fi
329 done
330 fi
331 fi
333 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
334 if [ "$GENERIC_PIXMAPS" != "no" ]; then
335 if [ -d "$install/usr/share/pixmaps" ]; then
336 mkdir -p $fs/usr/share/pixmaps
337 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
338 $fs/usr/share/pixmaps 2>/dev/null || continue
339 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
340 $fs/usr/share/pixmaps 2>/dev/null || continue
341 fi
343 # Custom or homemade PNG pixmap can be in stuff.
344 if [ -f "$stuff/$PACKAGE.png" ]; then
345 mkdir -p $fs/usr/share/pixmaps
346 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
347 fi
348 fi
350 # Desktop entry (.desktop).
351 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
352 if [ "$GENERIC_MENUS" != "no" ]; then
353 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
354 cp -a $install/usr/share/applications $fs/usr/share
355 fi
356 fi
358 # Homemade desktop file(s) can be in stuff.
359 if [ -d "$stuff/applications" ]; then
360 mkdir -p $fs/usr/share
361 cp -a $stuff/applications $fs/usr/share
362 fi
363 if [ -f "$stuff/$PACKAGE.desktop" ]; then
364 mkdir -p $fs/usr/share/applications
365 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
366 fi
367 }
369 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
370 # as removing uneeded files like in Python packages. Cross compiled binaries
371 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
372 strip_package() {
373 case "$ARCH" in
374 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
375 *) export STRIP=strip ;;
376 esac
377 gettext "Executing strip on all files..."
378 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
379 do
380 if [ -d "$dir" ]; then
381 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
382 fi
383 done
384 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
385 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
386 status
388 # Remove Python .pyc and .pyo from packages.
389 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
390 gettext "Removing Python compiled files..."
391 find $fs -type f -name "*.pyc" -delete 2>/dev/null
392 find $fs -type f -name "*.pyo" -delete 2>/dev/null
393 status
394 fi
396 # Remove Perl perllocal.pod and .packlist from packages.
397 if echo "$DEPENDS" | fgrep -q "perl"; then
398 gettext "Removing Perl compiled files..."
399 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
400 find $fs -type f -name ".packlist" -delete 2>/dev/null
401 status
402 fi
403 }
405 # Remove installed deps.
406 remove_deps() {
407 # Now remove installed build deps.
408 diff="$CACHE/installed.cook.diff"
409 if [ -s "$CACHE/installed.cook.diff" ]; then
410 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
411 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
412 gettext "Build dependencies to remove:"; echo " $nb"
413 gettext "Removing:"
414 for dep in $deps
415 do
416 echo -n " $dep"
417 echo 'y' | tazpkg remove $dep >/dev/null
418 done
419 echo -e "\n"
420 # Keep the last diff for debug and info.
421 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
422 fi
423 }
425 # The main cook function.
426 cookit() {
427 echo "Cook: $PACKAGE $VERSION"
428 separator
429 set_paths
431 # Handle cross-tools.
432 case "$ARCH" in
433 arm|x86_64)
434 # CROSS_COMPILE is used by at least Busybox and the kernel to set
435 # the cross-tools prefix but first check if sysroot is used.
436 if [ "$SYSROOT" ]; then
437 echo "cook: $ARCH sysroot: $SYSROOT"
438 else
439 echo "cook: adding /usr/cross/$ARCH/bin to PATH"
440 export PATH=$PATH:$CROSS_PREFIX/bin
441 fi
442 export CROSS_COMPILE=${HOST_SYSTEM}-
443 echo "cook: using cross-tools: $CROSS_COMPILE"
444 export CC=${HOST_SYSTEM}-gcc
445 export CXX=${HOST_SYSTEM}-g++
446 export AR=${HOST_SYSTEM}-ar
447 export AS=${HOST_SYSTEM}-as
448 export RANLIB=${HOST_SYSTEM}-ranlib
449 export LD=${HOST_SYSTEM}-ld
450 export STRIP=${HOST_SYSTEM}-strip ;;
451 esac
453 [ "$QA" ] && receipt_quality
454 cd $pkgdir
455 rm -rf install taz source
457 # Disable -pipe if less than 512Mb free RAM.
458 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
459 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
460 gettext -e "Disabling -pipe compile flag: $free RAM\n"
461 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
462 CXXFLAGS="${CXXFLAGS/-pipe}" && \
463 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
464 fi
465 unset free
467 # Export flags and path to be used by make and receipt.
468 DESTDIR=$pkgdir/install
469 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
470 #LDFLAGS
472 # Check for build deps and handle implicit depends of *-dev packages
473 # (ex: libusb-dev :: libusb).
474 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
475 touch $CACHE/installed.local $CACHE/installed.web
476 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
477 for dep in $BUILD_DEPENDS
478 do
479 implicit=${dep%-dev}
480 for i in $dep $implicit
481 do
482 if [ ! -f "$INSTALLED/$i/receipt" ]; then
483 # Try local package first. In some cases implicit doesn't exist, ex:
484 # libboost-dev exists but not libboost, so check if we got vers.
485 unset vers
486 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
487 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
488 echo $i-$vers.tazpkg >> $CACHE/installed.local
489 else
490 # Priority to package version in wok (maybe more up-to-date)
491 # than the mirrored one.
492 if [ "$vers" ]; then
493 if fgrep -q $i-$vers $DB/packages.list; then
494 echo $i >> $CACHE/installed.web
495 else
496 # So package exists in wok but not available.
497 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
498 echo $i >> $CACHE/missing.dep
499 fi
500 else
501 # Package is not in wok but may be in repo.
502 if fgrep -q $i-$vers $DB/packages.list; then
503 echo $i >> $CACHE/installed.web
504 else
505 echo "ERROR: unknown dep $i" && exit 1
506 fi
507 fi
508 fi
509 fi
510 done
511 done
513 # Get the list of installed packages
514 cd $INSTALLED && ls -1 > $CACHE/installed.list
516 # Have we a missing build dep to cook ?
517 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
518 gettext -e "Auto cook config is set : AUTO_COOK\n"
519 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
520 for i in $(uniq $CACHE/missing.dep)
521 do
522 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
523 tee -a $LOGS/$PACKAGE.log.$$
524 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
525 fgrep "remove: " $LOGS/$i.log && \
526 fgrep "Removing: " $LOGS/$i.log && echo "") | \
527 tee -a $LOGS/$PACKAGE.log.$$ && break
528 done
529 rm -f $CACHE/missing.dep
530 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
531 fi
533 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
534 # is enabled and cook fails we have ERROR in log, if no auto cook we have
535 # missing dep in cached file.
536 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
537 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
538 echo "ERROR: missing dep $nb" && exit 1
539 fi
541 # Install local packages.
542 cd $PKGS
543 for i in $(uniq $CACHE/installed.local)
544 do
545 gettext "Installing dep (pkg/local):"; echo " $i"
546 tazpkg install $i >/dev/null
547 done
549 # Install web or cached packages (if mirror is set to $PKGS we only
550 # use local packages).
551 for i in $(uniq $CACHE/installed.web)
552 do
553 gettext "Installing dep (web/cache):"; echo " $i"
554 tazpkg get-install $i >/dev/null
555 done
557 # If a cook failed deps are removed.
558 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
559 [ ! -s "installed.cook.diff" ] && \
560 busybox diff installed.list installed.cook > installed.cook.diff
561 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
563 # Get source tarball and make sure we have source dir named:
564 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
565 # tarball if it exists.
566 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
567 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
568 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
569 LZMA_SRC=""
570 else
571 get_source || exit 1
572 fi
573 fi
574 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
575 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
576 if ! extract_source ; then
577 get_source
578 extract_source || exit 1
579 fi
580 if [ "$LZMA_SRC" ]; then
581 cd $pkgdir/source
582 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
583 mv tmp tmp-1 && mkdir tmp
584 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
585 fi
586 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
587 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
588 fi
589 fi
590 cd $pkgdir/source/tmp
591 # Some archives are not well done and don't extract to one dir (ex lzma).
592 files=$(ls | wc -l)
593 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
594 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
595 mv * ../$PACKAGE-$VERSION/$TARBALL
596 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
597 mv * ../$PACKAGE-$VERSION
598 cd .. && rm -rf tmp
599 fi
601 # Execute receipt rules.
602 if grep -q ^compile_rules $receipt; then
603 echo "Executing: compile_rules"
604 echo "CFLAGS : $CFLAGS"
605 #echo "LDFLAGS : $LDFLAGS"
606 [ -d "$src" ] && cd $src
607 compile_rules $@ || exit 1
608 # Stay compatible with _pkg
609 [ -d "$src/_pkg" ] && mv $src/_pkg $install
610 # QA: compile_rules success so valid.
611 mkdir -p $install
612 else
613 # QA: No compile_rules so no error, valid.
614 mkdir -p $install
615 fi
616 separator && echo ""
618 # Execute testsuite.
619 if grep -q ^testsuite $receipt; then
620 echo "Running testsuite"
621 separator
622 testsuite $@ || exit 1
623 separator && echo ""
624 fi
625 }
627 # Cook quality assurance.
628 cookit_quality() {
629 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
630 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
631 fi
632 # ERROR can be echoed any time in cookit()
633 if fgrep -q ERROR: $LOGS/$pkg.log; then
634 debug_info | tee -a $LOGS/$pkg.log
635 rm -f $command && exit 1
636 fi
637 }
639 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
640 # but it doesn't handle EXTRAVERSION.
641 packit() {
642 set_paths
644 # Handle cross compilation
645 case "$ARCH" in
646 arm|x86_64) VERSION="$VERSION-$ARCH" ;;
647 esac
649 echo "Pack: $PACKAGE $VERSION"
650 separator
652 if grep -q ^genpkg_rules $receipt; then
653 gettext -e "Executing: genpkg_rules\n"
654 set -e && cd $pkgdir && mkdir -p $fs
655 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
656 $LOGS/$pkg.log
657 else
658 gettext "No packages rules: meta package"; echo
659 mkdir -p $fs
660 fi
662 # First QA check to stop now if genpkg_rules failed.
663 if fgrep -q ERROR: $LOGS/$pkg.log; then
664 exit 1
665 fi
667 cd $taz
668 for file in receipt description.txt
669 do
670 [ ! -f "../$file" ] && continue
671 gettext "Copying"; echo -n " $file..."
672 cp -f ../$file $pack && chown 0.0 $pack/$file && status
673 done
674 copy_generic_files
676 # Create files.list with redirecting find output.
677 gettext "Creating the list of files..." && cd $fs
678 find . -type f -print > ../files.list
679 find . -type l -print >> ../files.list
680 cd .. && sed -i s/'^.'/''/ files.list
681 status
683 # Strip and stuff files.
684 strip_package
686 # Md5sum of files.
687 gettext "Creating md5sum of files..."
688 while read file; do
689 [ -L "fs$file" ] && continue
690 [ -f "fs$file" ] || continue
691 case "$file" in
692 /lib/modules/*/modules.*|*.pyc) continue ;;
693 esac
694 md5sum "fs$file" | sed 's/ fs/ /'
695 done < files.list > md5sum
696 status
697 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
698 description.txt 2> /dev/null | awk \
699 '{ sz=$1 } END { print sz }')
701 # Build cpio archives.
702 gettext "Compressing the fs... "
703 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
704 rm -rf fs
705 status
706 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
707 md5sum description.txt 2> /dev/null | awk \
708 '{ sz=$1 } END { print sz }')
709 gettext "Updating receipt sizes..."
710 sed -i s/^PACKED_SIZE.*$// receipt
711 sed -i s/^UNPACKED_SIZE.*$// receipt
712 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
713 status
715 # Set extra version.
716 if [ "$EXTRAVERSION" ]; then
717 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
718 sed -i s/^EXTRAVERSION.*$// receipt
719 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
720 status
721 fi
723 # Compress.
724 gettext "Creating full cpio archive... "
725 find . -print | cpio -o -H newc --quiet > \
726 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
727 status
728 gettext "Restoring original package tree... "
729 unlzma -c fs.cpio.lzma | cpio -idm --quiet
730 status
731 rm fs.cpio.lzma && cd ..
733 # QA and give info.
734 tazpkg=$(ls *.tazpkg)
735 packit_quality
736 separator && gettext "Package:"; echo -e " $tazpkg\n"
737 }
739 # Verify package quality and consistency.
740 packit_quality() {
741 #gettext "QA: Checking for broken link..."
742 #link=$(find $fs/usr -type l -follow)
743 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
744 #status
746 # Exit if any error found in log file.
747 if fgrep -q ERROR: $LOGS/$pkg.log; then
748 rm -f $command && exit 1
749 fi
751 gettext "QA: Checking for empty package..."
752 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
753 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
754 echo -e "\nERROR: empty package"
755 rm -f $command && exit 1
756 else
757 # Ls sort by name so the first file is the one we want.
758 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
759 status
760 if [ -f "$old" ]; then
761 gettext "Removing old: $(basename $old)"
762 rm -f $old && status
763 fi
764 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
765 sed -i /^${pkg}$/d $broken
766 #gettext "Removing source tree..."
767 #rm -f $WOK/$pkg/source && status
768 fi
769 }
771 tac() {
772 sed '1!G;h;$!d' $1
773 }
775 # Launch the cook command into a chroot jail protected by aufs.
776 # The current filesystems are used read-only and updates are
777 # stored in a separate branch.
778 try_aufs_chroot() {
780 base=/dev/shm/aufsmnt$$
782 # Can we setup the chroot ? Is it already done ?
783 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
784 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
785 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
786 mkdir ${base}root ${base}rw || return
788 echo "Setup aufs chroot..."
790 # Sanity check
791 for i in / /proc /sys /dev/shm /home ; do
792 case " $AUFS_MOUNTS " in
793 *\ $i\ *) ;;
794 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
795 esac
796 done
797 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
798 mount --bind $mnt ${base}root$mnt
799 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
800 echo "Aufs mountage failure"
801 umount ${base}root
802 rmdir ${base}*
803 return
804 fi
805 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
806 done
808 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
809 status=$?
811 echo "Leaving aufs chroot..."
812 tac ${base}rw/aufs-umount.sh | sh
813 rm -rf ${base}rw
814 umount ${base}root
815 rmdir $base*
817 # Install package if requested
818 if [ "$inst" ]; then
819 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
820 cd $PKGS && tazpkg install \
821 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
822 else
823 gettext -e "Unable to install package, build has failed.\n\n"
824 exit 1
825 fi
826 fi
828 # Skip install if target host doesn't match build system.
829 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
830 # Install package if part of the chroot to keep env up-to-date.
831 if [ -d "$INSTALLED/$pkg" ] && [ "$build" == "$ARCH" ]; then
832 . /etc/slitaz/cook.conf
833 . $WOK/$pkg/taz/$pkg-*/receipt
834 echo "Updating $ARCH chroot environment..."
835 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION})" | log
836 cd $PKGS && tazpkg install \
837 $pkg-${VERSION}${EXTRAVERSION}.tazpkg --forced
838 fi
839 exit $status
840 }
842 # Create a XML feed for freshly built packages.
843 gen_rss() {
844 pubdate=$(date "+%a, %d %b %Y %X")
845 cat > $FEEDS/$pkg.xml << EOT
846 <item>
847 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
848 <link>${COOKER_URL}?pkg=$PACKAGE</link>
849 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
850 <pubDate>$pubdate</pubDate>
851 <description>$SHORT_DESC</description>
852 </item>
853 EOT
854 }
856 #
857 # Commands
858 #
860 case "$1" in
861 usage|help|-u|-h)
862 usage ;;
863 list-wok)
864 gettext -e "\nList of packages in:"; echo " $WOK"
865 separator
866 cd $WOK && ls -1
867 separator
868 echo -n "Packages: " && ls | wc -l
869 echo "" ;;
870 activity)
871 cat $activity ;;
872 search)
873 # Just a simple search function, we dont need more actually.
874 query="$2"
875 gettext -e "\nSearch results for:"; echo " $query"
876 separator
877 cd $WOK && ls -1 | grep "$query"
878 separator && echo "" ;;
879 setup)
880 # Setup a build environment
881 check_root
882 echo "Cook: setting up the environment" | log
883 gettext -e "\nSetting up your environment\n"
884 separator && cd $SLITAZ
885 init_db_files
886 gettext "Checking for packages to install..."; echo
887 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
888 # ARCH-setup or 'cross check-env' should be used before: cook setup
889 case "$ARCH" in
890 arm|x86_64)
891 if [ ! -x "/usr/bin/cross" ]; then
892 gettext "ERROR: cross is not installed"; echo
893 exit 1
894 fi
895 gettext "Using config file: /etc/slitaz/cross.conf"; echo
896 . /etc/slitaz/cross.conf ;;
897 esac
898 for pkg in $SETUP_PKGS; do
899 if [ "$forced" ]; then
900 tazpkg -gi $pkg --forced
901 else
902 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
903 fi
904 done
906 # Handle --options
907 case "$2" in
908 --wok)
909 hg clone $WOK_URL wok || exit 1 ;;
910 --stable)
911 hg clone $WOK_URL-stable wok || exit 1 ;;
912 --undigest)
913 hg clone $WOK_URL-undigest wok || exit 1 ;;
914 --tiny)
915 hg clone $WOK_URL-tiny wok || exit 1 ;;
916 esac
918 # SliTaz group and permissions
919 if ! grep -q ^slitaz /etc/group; then
920 gettext -e "Adding group: slitaz\n"
921 addgroup slitaz
922 fi
923 gettext -e "Setting permissions for slitaz group...\n"
924 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
925 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
926 separator
927 gettext -e "All done, ready to cook packages :-)\n\n" ;;
928 *-setup)
929 # Setup for cross compiling.
930 arch=${1%-setup}
931 check_root
932 echo ""
933 boldify $(gettext "Setting up your cross environment")
934 separator
935 init_db_files
936 sed -i \
937 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
938 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
939 /etc/slitaz/cook.conf
940 case "$arch" in
941 arm)
942 sed -i \
943 -e s'/CFLAGS=.*/CFLAGS="-march=armv6"/' \
944 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
945 -e s'/xorg-dev/""/' \
946 /etc/slitaz/cook.conf ;;
947 x86_64)
948 sed -i \
949 -e s'/CFLAGS=.*/CFLAGS=""/' \
950 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
951 /etc/slitaz/cook.conf ;;
952 esac
953 . /etc/slitaz/cook.conf
954 echo "Target arch : $ARCH"
955 echo "Configure args : $CONFIGURE_ARGS"
956 if [ "$SYSROOT" ]; then
957 echo "Arch sysroot : $SYSROOT"
958 CC=/usr/bin/${HOST_SYSTEM}-gcc
959 else
960 echo "Additional path : /usr/cross/$ARCH/bin"
961 CC=/usr/cross/$ARCH/bin/${HOST_SYSTEM}-gcc
962 fi
963 if [ -x $CC ]; then
964 echo "Cross compiler : ${HOST_SYSTEM}-gcc"
965 else
966 colorize "C compiler is missing: ${HOST_SYSTEM}-gcc" 36
967 echo "Run 'cross compile' to cook a toolchain"
968 fi
969 separator && echo "" ;;
970 test)
971 # Test a cook environment.
972 echo "Cook test: testing the cook environment" | log
973 [ ! -d "$WOK" ] && exit 1
974 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
975 cook cooktest ;;
976 new)
977 # Create the package folder and an empty receipt.
978 pkg="$2"
979 [ "$pkg" ] || usage
980 echo ""
981 if [ -d "$WOK/$pkg" ]; then
982 echo -n "$pkg " && gettext "package already exists."
983 echo -e "\n" && exit 1
984 fi
985 gettext "Creating"; echo -n " $WOK/$pkg"
986 mkdir $WOK/$pkg && cd $WOK/$pkg && status
987 gettext "Preparing the package receipt..."
988 cp $DATA/receipt .
989 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
990 status && echo ""
992 # Interactive mode, asking and seding.
993 case "$3" in
994 --interactive|-x)
995 gettext -e "Entering interactive mode...\n"
996 separator
997 echo "Package : $pkg"
998 # Version.
999 echo -n "Version : " ; read anser
1000 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1001 # Category.
1002 echo -n "Category : " ; read anser
1003 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1004 # Short description.
1005 echo -n "Short desc : " ; read anser
1006 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1007 # Maintainer.
1008 echo -n "Maintainer : " ; read anser
1009 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1010 # Web site.
1011 echo -n "Web site : " ; read anser
1012 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1013 echo ""
1014 # Wget URL.
1015 echo "Wget URL to download source tarball."
1016 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1017 echo -n "Wget url : " ; read anser
1018 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1019 # Ask for a stuff dir.
1020 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1021 if [ "$anser" = "y" ]; then
1022 echo -n "Creating the stuff directory..."
1023 mkdir $WOK/$pkg/stuff && status
1024 fi
1025 # Ask for a description file.
1026 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1027 if [ "$anser" = "y" ]; then
1028 echo -n "Creating the description.txt file..."
1029 echo "" > $WOK/$pkg/description.txt && status
1030 fi
1031 separator
1032 gettext -e "Receipt is ready to use.\n"
1033 echo "" ;;
1034 esac ;;
1035 list)
1036 # Cook a list of packages (better use the Cooker since it will order
1037 # packages before executing cook).
1038 check_root
1039 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1040 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1041 echo -e " $2\n" && exit 1
1042 echo "Cook list starting: $2" | log
1043 for pkg in $(cat $2)
1044 do
1045 cook $pkg || broken
1046 done ;;
1047 clean-wok)
1048 check_root
1049 gettext -e "\nCleaning all packages files..."
1050 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1051 status && echo "" ;;
1052 clean-src)
1053 check_root
1054 gettext -e "\nCleaning all packages sources..."
1055 rm -rf $WOK/*/source
1056 status && echo "" ;;
1057 pkgdb)
1058 # Create suitable packages list for TazPKG and only for built packages
1059 # as well as flavors files for TazLiTo. We dont need logs since we do it
1060 # manually to ensure everything is fine before syncing the mirror.
1061 case "$2" in
1062 --flavors)
1063 continue ;;
1064 *)
1065 [ "$2" ] && PKGS="$2"
1066 [ ! -d "$PKGS" ] && \
1067 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1068 esac
1069 time=$(date +%s)
1070 flavors=$SLITAZ/flavors
1071 live=$SLITAZ/live
1072 echo "cook:pkgdb" > $command
1073 echo "Cook pkgdb: Creating all packages lists" | log
1074 echo ""
1075 gettext "Creating lists for: "; echo "$PKGS"
1076 separator
1077 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1078 cd $PKGS
1079 rm -f packages.*
1080 gettext -e "Creating: packages.list\n"
1081 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1082 gettext -e "Creating: packages.md5\n"
1083 md5sum *.tazpkg > $PKGS/packages.md5
1084 md5sum packages.md5 | cut -f1 -d' ' > ID
1085 gettext -e "Creating lists from: "; echo "$WOK"
1086 cd $WOK
1087 for pkg in *
1088 do
1089 unset_receipt
1090 . $pkg/receipt
1091 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1092 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1093 if [ -s $pkg/taz/*/receipt ]; then
1094 . $pkg/taz/*/receipt
1095 fi
1096 # packages.desc lets us search easily in DB
1097 cat >> $PKGS/packages.desc << EOT
1098 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1099 EOT
1100 # packages.txt used by tazpkg and tazpkg-web also to provide
1101 # a human readable package list with version and description.
1102 cat >> $PKGS/packages.txt << EOT
1103 $PACKAGE
1104 ${VERSION}$EXTRAVERSION
1105 $SHORT_DESC
1106 $PACKED_SIZE ($UNPACKED_SIZE installed)
1108 EOT
1109 # packages.equiv is used by tazpkg install to check depends.
1110 for i in $PROVIDE; do
1111 DEST=""
1112 echo $i | fgrep -q : && DEST="${i#*:}:"
1113 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1114 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1115 $PKGS/packages.equiv
1116 else
1117 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1118 fi
1119 done
1120 # files.list provides a list of all packages files.
1121 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1122 $PKGS/files.list
1123 fi
1124 done
1126 # Display list size.
1127 gettext -e "Done: packages.desc\n"
1128 gettext -e "Done: packages.txt\n"
1129 gettext -e "Done: packages.equiv\n"
1131 # files.list.lzma
1132 gettext -e "Creating: files.list.lzma\n"
1133 cd $PKGS && lzma e files.list files.list.lzma
1134 rm -f files.list
1136 # Display some info.
1137 separator
1138 nb=$(ls $PKGS/*.tazpkg | wc -l)
1139 time=$(($(date +%s) - $time))
1140 echo -e "Packages: $nb - Time: ${time}s\n"
1142 # Create all flavors files at once. Do we really need code to monitor
1143 # flavors changes ? Lets just build them with packages lists before
1144 # syncing the mirror.
1145 [ "$2" == "--flavors" ] || exit 1
1146 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1147 [ -d "$live" ] || mkdir -p $live
1148 gettext "Creating flavors files in:"; echo " $live"
1149 echo "Cook pkgdb: Creating all flavors" | log
1150 separator
1151 gettext -e "Recharging lists to use latest packages...\n"
1152 tazpkg recharge >/dev/null 2>/dev/null
1154 # We need a custom tazlito config to set working dir to /home/slitaz.
1155 if [ ! -f "$live/tazlito.conf" ]; then
1156 echo "Creating configuration file: tazlito.conf"
1157 cp /etc/tazlito/tazlito.conf $live
1158 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1159 $live/tazlito.conf
1160 fi
1162 # Update Hg flavors repo and pack.
1163 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1165 cd $live
1166 echo "Starting to generate flavors..."
1167 rm -f flavors.list *.flavor
1168 for i in $flavors/*
1169 do
1170 fl=$(basename $i)
1171 echo "Packing flavor: $(basename $i)"
1172 tazlito pack-flavor $fl >/dev/null || exit 1
1173 tazlito show-flavor $fl --brief --noheader 2> \
1174 /dev/null >> flavors.list
1175 done
1176 cp -f $live/*.flavor $live/flavors.list $PKGS
1177 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1178 echo "" && rm -f $command ;;
1179 *)
1180 # Just cook and generate a package.
1181 check_root
1182 time=$(date +%s)
1183 pkg="$1"
1184 [ -z "$pkg" ] && usage
1185 receipt="$WOK/$pkg/receipt"
1186 check_pkg_in_wok && echo ""
1188 unset inst
1189 unset_receipt
1190 . $receipt
1192 # Handle cross compilation.
1194 # CROSS_NOTE: Actually we are running an ARM cooker but running
1195 # the cooker and build each commit in wok is not possible since
1196 # we dont cook the full wok for this arch. For ARM we need a set
1197 # of packages to handle a touch screen desktop, servers but not
1198 # erland.
1200 # The temporary solution is to build only reviewed and tested
1201 # packages with HOST_ARCH set in receipt.
1202 case "$ARCH" in
1203 arm)
1204 if [ ! "$HOST_ARCH" ]; then
1205 echo "cook: HOST_ARCH is not set in $pkg receipt"
1206 echo "cook: This package is not included in: $ARCH"
1207 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1208 echo "Cook skip: $pkg is not included in: $ARCH" | log
1209 echo "" && exit 1
1210 fi ;;
1211 esac
1213 # Some packages are not included in some arch or fail to cross compile.
1214 : ${HOST_ARCH=i486}
1215 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1216 echo "cook: HOST_ARCH=$HOST_ARCH"
1217 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1218 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1219 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1220 echo "" && exit 1
1221 fi
1223 # Skip blocked, 3 lines also for the Cooker.
1224 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1225 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1226 fi
1228 try_aufs_chroot "$@"
1230 # Log and source receipt.
1231 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1232 echo "cook:$pkg" > $command
1234 # Display and log info if cook process stopped.
1235 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1236 tee -a $LOGS/$pkg.log' INT
1238 # Handle --options
1239 case "$2" in
1240 --clean|-c)
1241 gettext -e "Cleaning:"; echo -n " $pkg"
1242 cd $WOK/$pkg && rm -rf install taz source
1243 status && echo "" && exit 0 ;;
1244 --install|-i)
1245 inst='yes' ;;
1246 --getsrc|-gs)
1247 gettext "Getting source for:"; echo " $pkg"
1248 separator && get_source
1249 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1250 --block|-b)
1251 gettext "Blocking:"; echo -n " $pkg"
1252 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1253 status && echo "" && exit 0 ;;
1254 --unblock|-ub)
1255 gettext "Unblocking:"; echo -n " $pkg"
1256 sed -i "/^${pkg}$/"d $blocked
1257 status && echo "" && exit 0 ;;
1259 esac
1261 # Check if wanted is built now so we have separate log files.
1262 for wanted in $WANTED ; do
1263 if grep -q "^$wanted$" $blocked; then
1264 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
1265 echo "" && rm -f $command && exit 1
1266 fi
1267 if grep -q "^$wanted$" $broken; then
1268 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
1269 echo "" && rm -f $command && exit 1
1270 fi
1271 if [ ! -d "$WOK/$wanted/install" ]; then
1272 cook "$wanted" || exit 1
1273 fi
1274 done
1276 # Cook and pack or exit on error and log everything.
1277 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1278 remove_deps | tee -a $LOGS/$pkg.log
1279 cookit_quality
1280 packit 2>&1 | tee -a $LOGS/$pkg.log
1281 clean_log
1283 # Exit if any error in packing.
1284 if grep -q ^ERROR $LOGS/$pkg.log; then
1285 debug_info | tee -a $LOGS/$pkg.log
1286 rm -f $command && exit 1
1287 fi
1289 # Create an XML feed
1290 gen_rss
1292 # Time and summary
1293 time=$(($(date +%s) - $time))
1294 summary | tee -a $LOGS/$pkg.log
1295 echo ""
1297 # Install package if requested
1298 if [ "$inst" ]; then
1299 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1300 cd $PKGS && tazpkg install \
1301 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1302 else
1303 gettext -e "Unable to install package, build has failed.\n\n"
1304 exit 1
1305 fi
1306 fi
1308 # Skip install if target host dont match build system.
1309 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
1310 # Install package if part of the chroot to keep env up-to-date.
1311 if [ -d "$INSTALLED/$PACKAGE" ] && [ -z "$AUFS_MOUNTS" ] && \
1312 [ "$build" == "$ARCH" ]; then
1313 echo "Updating chroot environment..."
1314 echo "Updating chroot: $PACKAGE (${VERSION}${EXTRAVERSION})" | log
1315 cd $PKGS && tazpkg install \
1316 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1317 fi
1319 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1320 # You want automation: use the Cooker Build Bot.
1321 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1322 rm -f $command ;;
1323 esac
1325 exit 0