cookutils view cook @ rev 415

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