cookutils view cook @ rev 405

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