cookutils view cook @ rev 414

cook: use the cross compiled strip if cross compiling
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 14 13:38:16 2012 +0200 (2012-05-14)
parents 2e5c6cfad4ed
children 999aed12cf89
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.
375 strip_package()
376 {
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:/usr/cross/$ARCH/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 #export PKGCONFIG=${HOST_SYSTEM}-pkg-config
452 ;;
453 *)
454 export STRIP=strip
455 esac
457 [ "$QA" ] && receipt_quality
458 cd $pkgdir
459 rm -rf install taz source
461 # Disable -pipe if less than 512Mb free RAM.
462 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
463 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
464 gettext -e "Disabling -pipe compile flag: $free RAM\n"
465 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
466 CXXFLAGS="${CXXFLAGS/-pipe}" && \
467 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
468 fi
469 unset free
471 # Export flags and path to be used by make and receipt.
472 DESTDIR=$pkgdir/install
473 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
474 #LDFLAGS
476 # Check for build deps and handle implicit depends of *-dev packages
477 # (ex: libusb-dev :: libusb).
478 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
479 touch $CACHE/installed.local $CACHE/installed.web
480 [ "$BUILD_DEPENDS" ] && gettext -e "Checking build dependencies...\n"
481 for dep in $BUILD_DEPENDS
482 do
483 implicit=${dep%-dev}
484 for i in $dep $implicit
485 do
486 if [ ! -f "$INSTALLED/$i/receipt" ]; then
487 # Try local package first. In some cases implicit doesn't exist, ex:
488 # libboost-dev exists but not libboost, so check if we got vers.
489 unset vers
490 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
491 if [ -f "$PKGS/$i-$vers.tazpkg" ]; then
492 echo $i-$vers.tazpkg >> $CACHE/installed.local
493 else
494 # Priority to package version in wok (maybe more up-to-date)
495 # than the mirrored one.
496 if [ "$vers" ]; then
497 if fgrep -q $i-$vers $DB/packages.list; then
498 echo $i >> $CACHE/installed.web
499 else
500 # So package exists in wok but not available.
501 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
502 echo $i >> $CACHE/missing.dep
503 fi
504 else
505 # Package is not in wok but may be in repo.
506 if fgrep -q $i-$vers $DB/packages.list; then
507 echo $i >> $CACHE/installed.web
508 else
509 echo "ERROR: unknown dep $i" && exit 1
510 fi
511 fi
512 fi
513 fi
514 done
515 done
517 # Get the list of installed packages
518 cd $INSTALLED && ls -1 > $CACHE/installed.list
520 # Have we a missing build dep to cook ?
521 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
522 gettext -e "Auto cook config is set : AUTO_COOK\n"
523 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
524 for i in $(uniq $CACHE/missing.dep)
525 do
526 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
527 tee -a $LOGS/$PACKAGE.log.$$
528 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
529 fgrep "remove: " $LOGS/$i.log && \
530 fgrep "Removing: " $LOGS/$i.log && echo "") | \
531 tee -a $LOGS/$PACKAGE.log.$$ && break
532 done
533 rm -f $CACHE/missing.dep
534 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
535 fi
537 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
538 # is enabled and cook fails we have ERROR in log, if no auto cook we have
539 # missing dep in cached file.
540 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
541 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
542 echo "ERROR: missing dep $nb" && exit 1
543 fi
545 # Install local packages.
546 cd $PKGS
547 for i in $(uniq $CACHE/installed.local)
548 do
549 gettext "Installing dep (pkg/local):"; echo " $i"
550 tazpkg install $i >/dev/null
551 done
553 # Install web or cached packages (if mirror is set to $PKGS we only
554 # use local packages).
555 for i in $(uniq $CACHE/installed.web)
556 do
557 gettext "Installing dep (web/cache):"; echo " $i"
558 tazpkg get-install $i >/dev/null
559 done
561 # If a cook failed deps are removed.
562 cd $INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
563 [ ! -s "installed.cook.diff" ] && \
564 busybox diff installed.list installed.cook > installed.cook.diff
565 deps=$(cat installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
567 # Get source tarball and make sure we have source dir named:
568 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
569 # tarball if it exists.
570 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
571 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
572 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
573 LZMA_SRC=""
574 else
575 get_source || exit 1
576 fi
577 fi
578 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
579 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
580 if ! extract_source ; then
581 get_source
582 extract_source || exit 1
583 fi
584 if [ "$LZMA_SRC" ]; then
585 cd $pkgdir/source
586 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
587 mv tmp tmp-1 && mkdir tmp
588 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
589 fi
590 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
591 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
592 fi
593 fi
594 cd $pkgdir/source/tmp
595 # Some archives are not well done and don't extract to one dir (ex lzma).
596 files=$(ls | wc -l)
597 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
598 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
599 mv * ../$PACKAGE-$VERSION/$TARBALL
600 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
601 mv * ../$PACKAGE-$VERSION
602 cd .. && rm -rf tmp
603 fi
605 # Execute receipt rules.
606 if grep -q ^compile_rules $receipt; then
607 echo "Executing: compile_rules"
608 echo "CFLAGS : $CFLAGS"
609 #echo "LDFLAGS : $LDFLAGS"
610 [ -d "$src" ] && cd $src
611 compile_rules $@ || exit 1
612 # Stay compatible with _pkg
613 [ -d "$src/_pkg" ] && mv $src/_pkg $install
614 # QA: compile_rules success so valid.
615 mkdir -p $install
616 else
617 # QA: No compile_rules so no error, valid.
618 mkdir -p $install
619 fi
620 separator && echo ""
622 # Execute testsuite.
623 if grep -q ^testsuite $receipt; then
624 echo "Running testsuite"
625 separator
626 testsuite $@ || exit 1
627 separator && echo ""
628 fi
629 }
631 # Cook quality assurance.
632 cookit_quality() {
633 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
634 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
635 fi
636 # ERROR can be echoed any time in cookit()
637 if fgrep -q ERROR: $LOGS/$pkg.log; then
638 debug_info | tee -a $LOGS/$pkg.log
639 rm -f $command && exit 1
640 fi
641 }
643 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
644 # but it doesn't handle EXTRAVERSION.
645 packit() {
646 set_paths
648 # Handle cross compilation
649 case "$ARCH" in
650 arm|x86_64) VERSION="$VERSION-$ARCH" ;;
651 esac
653 echo "Pack: $PACKAGE $VERSION"
654 separator
656 if grep -q ^genpkg_rules $receipt; then
657 gettext -e "Executing: genpkg_rules\n"
658 set -e && cd $pkgdir && mkdir -p $fs
659 genpkg_rules || echo -e "\nERROR: genpkg_rules failed\n" >> \
660 $LOGS/$pkg.log
661 else
662 gettext "No packages rules: meta package"; echo
663 mkdir -p $fs
664 fi
666 # First QA check to stop now if genpkg_rules failed.
667 if fgrep -q ERROR: $LOGS/$pkg.log; then
668 exit 1
669 fi
671 cd $taz
672 for file in receipt description.txt
673 do
674 [ ! -f "../$file" ] && continue
675 gettext "Copying"; echo -n " $file..."
676 cp -f ../$file $pack && chown 0.0 $pack/$file && status
677 done
678 copy_generic_files
680 # Create files.list with redirecting find output.
681 gettext "Creating the list of files..." && cd $fs
682 find . -type f -print > ../files.list
683 find . -type l -print >> ../files.list
684 cd .. && sed -i s/'^.'/''/ files.list
685 status
687 # Strip and stuff files.
688 strip_package
690 # Md5sum of files.
691 gettext "Creating md5sum of files..."
692 while read file; do
693 [ -L "fs$file" ] && continue
694 [ -f "fs$file" ] || continue
695 case "$file" in
696 /lib/modules/*/modules.*|*.pyc) continue ;;
697 esac
698 md5sum "fs$file" | sed 's/ fs/ /'
699 done < files.list > md5sum
700 status
701 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
702 description.txt 2> /dev/null | awk \
703 '{ sz=$1 } END { print sz }')
705 # Build cpio archives.
706 gettext "Compressing the fs... "
707 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
708 rm -rf fs
709 status
710 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
711 md5sum description.txt 2> /dev/null | awk \
712 '{ sz=$1 } END { print sz }')
713 gettext "Updating receipt sizes..."
714 sed -i s/^PACKED_SIZE.*$// receipt
715 sed -i s/^UNPACKED_SIZE.*$// receipt
716 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
717 status
719 # Set extra version.
720 if [ "$EXTRAVERSION" ]; then
721 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
722 sed -i s/^EXTRAVERSION.*$// receipt
723 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
724 status
725 fi
727 # Compress.
728 gettext "Creating full cpio archive... "
729 find . -print | cpio -o -H newc --quiet > \
730 ../$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg
731 status
732 gettext "Restoring original package tree... "
733 unlzma -c fs.cpio.lzma | cpio -idm --quiet
734 status
735 rm fs.cpio.lzma && cd ..
737 # QA and give info.
738 tazpkg=$(ls *.tazpkg)
739 packit_quality
740 separator && gettext "Package:"; echo -e " $tazpkg\n"
741 }
743 # Verify package quality and consistency.
744 packit_quality() {
745 #gettext "QA: Checking for broken link..."
746 #link=$(find $fs/usr -type l -follow)
747 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
748 #status
750 # Exit if any error found in log file.
751 if fgrep -q ERROR: $LOGS/$pkg.log; then
752 rm -f $command && exit 1
753 fi
755 gettext "QA: Checking for empty package..."
756 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
757 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
758 echo -e "\nERROR: empty package"
759 rm -f $command && exit 1
760 else
761 # Ls sort by name so the first file is the one we want.
762 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
763 status
764 if [ -f "$old" ]; then
765 gettext "Removing old: $(basename $old)"
766 rm -f $old && status
767 fi
768 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
769 sed -i /^${pkg}$/d $broken
770 #gettext "Removing source tree..."
771 #rm -f $WOK/$pkg/source && status
772 fi
773 }
775 tac()
776 {
777 sed '1!G;h;$!d' $1
778 }
780 # Launch the cook command into a chroot jail protected by aufs.
781 # The current filesystems are used read-only and updates are
782 # stored in a separate branch.
783 try_aufs_chroot() {
785 base=/dev/shm/aufsmnt$$
787 # Can we setup the chroot ? Is it already done ?
788 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
789 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
790 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
791 mkdir ${base}root ${base}rw || return
793 echo "Setup aufs chroot..."
795 # Sanity check
796 for i in / /proc /sys /dev/shm /home ; do
797 case " $AUFS_MOUNTS " in
798 *\ $i\ *) ;;
799 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
800 esac
801 done
802 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
803 mount --bind $mnt ${base}root$mnt
804 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
805 echo "Aufs mountage failure"
806 umount ${base}root
807 rmdir ${base}*
808 return
809 fi
810 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
811 done
813 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
814 status=$?
816 echo "Leaving aufs chroot..."
817 tac ${base}rw/aufs-umount.sh | sh
818 rm -rf ${base}rw
819 umount ${base}root
820 rmdir $base*
822 # Install package if requested
823 if [ "$inst" ]; then
824 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
825 cd $PKGS && tazpkg install \
826 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
827 else
828 gettext -e "Unable to install package, build has failed.\n\n"
829 exit 1
830 fi
831 fi
833 # Skip install if target host doesn't match build system.
834 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
835 # Install package if part of the chroot to keep env up-to-date.
836 if [ -d "$INSTALLED/$pkg" ] && [ "$build" == "$ARCH" ]; then
837 . /etc/slitaz/cook.conf
838 . $WOK/$pkg/taz/$pkg-*/receipt
839 echo "Updating $ARCH chroot environment..."
840 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION})" | log
841 cd $PKGS && tazpkg install \
842 $pkg-${VERSION}${EXTRAVERSION}.tazpkg --forced
843 fi
844 exit $status
845 }
847 # Create a XML feed for freshly built packages.
848 gen_rss() {
849 pubdate=$(date "+%a, %d %b %Y %X")
850 cat > $FEEDS/$pkg.xml << EOT
851 <item>
852 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
853 <link>${COOKER_URL}?pkg=$PACKAGE</link>
854 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
855 <pubDate>$pubdate</pubDate>
856 <description>$SHORT_DESC</description>
857 </item>
858 EOT
859 }
861 #
862 # Commands
863 #
865 case "$1" in
866 usage|help|-u|-h)
867 usage ;;
868 list-wok)
869 gettext -e "\nList of packages in:"; echo " $WOK"
870 separator
871 cd $WOK && ls -1
872 separator
873 echo -n "Packages: " && ls | wc -l
874 echo "" ;;
875 activity)
876 cat $activity ;;
877 search)
878 # Just a simple search function, we dont need more actually.
879 query="$2"
880 gettext -e "\nSearch results for:"; echo " $query"
881 separator
882 cd $WOK && ls -1 | grep "$query"
883 separator && echo "" ;;
884 setup)
885 # Setup a build environment
886 check_root
887 echo "Cook: setting up the environment" | log
888 gettext -e "\nSetting up your environment\n"
889 separator && cd $SLITAZ
890 init_db_files
891 gettext "Checking for packages to install..."; echo
892 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
893 # ARCH-setup or 'cross check-env' should be used before: cook setup
894 case "$ARCH" in
895 arm)
896 if [ ! -x "/usr/bin/cross" ]; then
897 gettext "ERROR: cross is not installed"; echo
898 exit 1
899 fi
900 gettext "Using config file: /etc/slitaz/cross.conf"; echo
901 . /etc/slitaz/cross.conf ;;
902 esac
903 for pkg in $SETUP_PKGS; do
904 if [ "$forced" ]; then
905 tazpkg get-install $pkg --forced
906 else
907 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
908 fi
909 done
911 # Handle --options
912 case "$2" in
913 --wok)
914 hg clone $WOK_URL wok || exit 1 ;;
915 --stable)
916 hg clone $WOK_URL-stable wok || exit 1 ;;
917 --undigest)
918 hg clone $WOK_URL-undigest wok || exit 1 ;;
919 --tiny)
920 hg clone $WOK_URL-tiny wok || exit 1 ;;
921 esac
923 # SliTaz group and permissions
924 if ! grep -q ^slitaz /etc/group; then
925 gettext -e "Adding group: slitaz\n"
926 addgroup slitaz
927 fi
928 gettext -e "Setting permissions for slitaz group...\n"
929 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
930 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
931 separator
932 gettext -e "All done, ready to cook packages :-)\n\n" ;;
933 *-setup)
934 # Setup for cross compiling.
935 arch=${1%-setup}
936 check_root
937 echo ""
938 gettext "Setting up your cross environment"; echo
939 separator
940 init_db_files
941 sed -i \
942 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
943 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
944 /etc/slitaz/cook.conf
945 case "$arch" in
946 arm)
947 sed -i \
948 -e s'/CFLAGS=.*/CFLAGS="-march=armv6"/' \
949 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
950 -e s'/xorg-dev/""/' \
951 /etc/slitaz/cook.conf ;;
952 x86_64)
953 sed -i \
954 -e s'/CFLAGS=.*/CFLAGS=""/' \
955 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
956 /etc/slitaz/cook.conf ;;
957 esac
958 . /etc/slitaz/cook.conf
959 echo "Target arch : $ARCH"
960 echo "Configure args: $CONFIGURE_ARGS"
961 if [ "$SYSROOT" ]; then
962 echo "Arch sysroot: $SYSROOT"
963 CC=/usr/bin/${HOST_SYSTEM}-gcc
964 else
965 echo "Path: /usr/cross/$ARCH/bin"
966 CC=/usr/cross/$ARCH/bin/${HOST_SYSTEM}-gcc
967 fi
968 if [ -x $CC ]; then
969 echo "Cross compiler: ${HOST_SYSTEM}-gcc"
970 else
971 echo "WARNING: C compiler is missing: ${HOST_SYSTEM}-gcc"
972 echo "Run 'cross compile' to cook a toolchain"
973 fi
974 echo "" ;;
975 test)
976 # Test a cook environment.
977 echo "Cook test: testing the cook environment" | log
978 [ ! -d "$WOK" ] && exit 1
979 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
980 cook cooktest ;;
981 new)
982 # Create the package folder and an empty receipt.
983 pkg="$2"
984 [ "$pkg" ] || usage
985 echo ""
986 if [ -d "$WOK/$pkg" ]; then
987 echo -n "$pkg " && gettext "package already exists."
988 echo -e "\n" && exit 1
989 fi
990 gettext "Creating"; echo -n " $WOK/$pkg"
991 mkdir $WOK/$pkg && cd $WOK/$pkg && status
992 gettext "Preparing the package receipt..."
993 cp $DATA/receipt .
994 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
995 status && echo ""
997 # Interactive mode, asking and seding.
998 case "$3" in
999 --interactive|-x)
1000 gettext -e "Entering interactive mode...\n"
1001 separator
1002 echo "Package : $pkg"
1003 # Version.
1004 echo -n "Version : " ; read anser
1005 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1006 # Category.
1007 echo -n "Category : " ; read anser
1008 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1009 # Short description.
1010 echo -n "Short desc : " ; read anser
1011 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1012 # Maintainer.
1013 echo -n "Maintainer : " ; read anser
1014 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1015 # Web site.
1016 echo -n "Web site : " ; read anser
1017 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1018 echo ""
1019 # Wget URL.
1020 echo "Wget URL to download source tarball."
1021 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1022 echo -n "Wget url : " ; read anser
1023 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1024 # Ask for a stuff dir.
1025 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1026 if [ "$anser" = "y" ]; then
1027 echo -n "Creating the stuff directory..."
1028 mkdir $WOK/$pkg/stuff && status
1029 fi
1030 # Ask for a description file.
1031 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1032 if [ "$anser" = "y" ]; then
1033 echo -n "Creating the description.txt file..."
1034 echo "" > $WOK/$pkg/description.txt && status
1035 fi
1036 separator
1037 gettext -e "Receipt is ready to use.\n"
1038 echo "" ;;
1039 esac ;;
1040 list)
1041 # Cook a list of packages (better use the Cooker since it will order
1042 # packages before executing cook).
1043 check_root
1044 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1045 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1046 echo -e " $2\n" && exit 1
1047 echo "Cook list starting: $2" | log
1048 for pkg in $(cat $2)
1049 do
1050 cook $pkg || broken
1051 done ;;
1052 clean-wok)
1053 check_root
1054 gettext -e "\nCleaning all packages files..."
1055 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1056 status && echo "" ;;
1057 clean-src)
1058 check_root
1059 gettext -e "\nCleaning all packages sources..."
1060 rm -rf $WOK/*/source
1061 status && echo "" ;;
1062 pkgdb)
1063 # Create suitable packages list for TazPKG and only for built packages
1064 # as well as flavors files for TazLiTo. We dont need logs since we do it
1065 # manually to ensure everything is fine before syncing the mirror.
1066 case "$2" in
1067 --flavors)
1068 continue ;;
1069 *)
1070 [ "$2" ] && PKGS="$2"
1071 [ ! -d "$PKGS" ] && \
1072 gettext -e "\nPackages directory doesn't exist\n\n" && exit 1 ;;
1073 esac
1074 time=$(date +%s)
1075 flavors=$SLITAZ/flavors
1076 live=$SLITAZ/live
1077 echo "cook:pkgdb" > $command
1078 echo "Cook pkgdb: Creating all packages lists" | log
1079 echo ""
1080 gettext "Creating lists for: "; echo "$PKGS"
1081 separator
1082 gettext "Cook pkgdb started: "; date "+%Y-%m-%d %H:%M"
1083 cd $PKGS
1084 rm -f packages.*
1085 gettext -e "Creating: packages.list\n"
1086 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1087 gettext -e "Creating: packages.md5\n"
1088 md5sum *.tazpkg > $PKGS/packages.md5
1089 md5sum packages.md5 | cut -f1 -d' ' > ID
1090 gettext -e "Creating lists from: "; echo "$WOK"
1091 cd $WOK
1092 for pkg in *
1093 do
1094 unset_receipt
1095 . $pkg/receipt
1096 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1097 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1098 if [ -s $pkg/taz/*/receipt ]; then
1099 . $pkg/taz/*/receipt
1100 fi
1101 # packages.desc lets us search easily in DB
1102 cat >> $PKGS/packages.desc << EOT
1103 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1104 EOT
1105 # packages.txt used by tazpkg and tazpkg-web also to provide
1106 # a human readable package list with version and description.
1107 cat >> $PKGS/packages.txt << EOT
1108 $PACKAGE
1109 ${VERSION}$EXTRAVERSION
1110 $SHORT_DESC
1111 $PACKED_SIZE ($UNPACKED_SIZE installed)
1113 EOT
1114 # packages.equiv is used by tazpkg install to check depends.
1115 for i in $PROVIDE; do
1116 DEST=""
1117 echo $i | fgrep -q : && DEST="${i#*:}:"
1118 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1119 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1120 $PKGS/packages.equiv
1121 else
1122 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1123 fi
1124 done
1125 # files.list provides a list of all packages files.
1126 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1127 $PKGS/files.list
1128 fi
1129 done
1131 # Display list size.
1132 gettext -e "Done: packages.desc\n"
1133 gettext -e "Done: packages.txt\n"
1134 gettext -e "Done: packages.equiv\n"
1136 # files.list.lzma
1137 gettext -e "Creating: files.list.lzma\n"
1138 cd $PKGS && lzma e files.list files.list.lzma
1139 rm -f files.list
1141 # Display some info.
1142 separator
1143 nb=$(ls $PKGS/*.tazpkg | wc -l)
1144 time=$(($(date +%s) - $time))
1145 echo -e "Packages: $nb - Time: ${time}s\n"
1147 # Create all flavors files at once. Do we really need code to monitor
1148 # flavors changes ? Lets just build them with packages lists before
1149 # syncing the mirror.
1150 [ "$2" == "--flavors" ] || exit 1
1151 [ ! -d "$flavors" ] && echo -e "Missing flavors: $flavors\n" && exit 1
1152 [ -d "$live" ] || mkdir -p $live
1153 gettext "Creating flavors files in:"; echo " $live"
1154 echo "Cook pkgdb: Creating all flavors" | log
1155 separator
1156 gettext -e "Recharging lists to use latest packages...\n"
1157 tazpkg recharge >/dev/null 2>/dev/null
1159 # We need a custom tazlito config to set working dir to /home/slitaz.
1160 if [ ! -f "$live/tazlito.conf" ]; then
1161 echo "Creating configuration file: tazlito.conf"
1162 cp /etc/tazlito/tazlito.conf $live
1163 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1164 $live/tazlito.conf
1165 fi
1167 # Update Hg flavors repo and pack.
1168 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1170 cd $live
1171 echo "Starting to generate flavors..."
1172 rm -f flavors.list *.flavor
1173 for i in $flavors/*
1174 do
1175 fl=$(basename $i)
1176 echo "Packing flavor: $(basename $i)"
1177 tazlito pack-flavor $fl >/dev/null || exit 1
1178 tazlito show-flavor $fl --brief --noheader 2> \
1179 /dev/null >> flavors.list
1180 done
1181 cp -f $live/*.flavor $live/flavors.list $PKGS
1182 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1183 echo "" && rm -f $command ;;
1184 *)
1185 # Just cook and generate a package.
1186 check_root
1187 time=$(date +%s)
1188 pkg="$1"
1189 [ -z "$pkg" ] && usage
1190 receipt="$WOK/$pkg/receipt"
1191 check_pkg_in_wok && echo ""
1193 unset inst
1194 unset_receipt
1195 . $receipt
1197 # Handle cross compilation.
1199 # CROSS_NOTE: Actually we are running an ARM cooker but running
1200 # the cooker and build each commit in wok is not possible since
1201 # we dont cook the full wok for this arch. For ARM we need a set
1202 # of packages to handle a touch screen desktop, servers but not
1203 # erland.
1205 # The temporary solution is to build only reviewed and tested
1206 # packages with HOST_ARCH set in receipt.
1207 case "$ARCH" in
1208 arm)
1209 if [ ! "$HOST_ARCH" ]; then
1210 echo "cook: HOST_ARCH is not set in $pkg receipt"
1211 echo "cook: This package is not included in: $ARCH"
1212 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1213 echo "Cook skip: $pkg is not included in: $ARCH" | log
1214 echo "" && exit 1
1215 fi ;;
1216 esac
1218 # Some packages are not included in some arch or fail to cross compile.
1219 : ${HOST_ARCH=i486}
1220 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1221 echo "cook: HOST_ARCH=$HOST_ARCH"
1222 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1223 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1224 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1225 echo "" && exit 1
1226 fi
1228 # Skip blocked, 3 lines also for the Cooker.
1229 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1230 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1231 fi
1233 try_aufs_chroot "$@"
1235 # Log and source receipt.
1236 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1237 echo "cook:$pkg" > $command
1239 # Display and log info if cook process stopped.
1240 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1241 tee -a $LOGS/$pkg.log' INT
1243 # Handle --options
1244 case "$2" in
1245 --clean|-c)
1246 gettext -e "Cleaning:"; echo -n " $pkg"
1247 cd $WOK/$pkg && rm -rf install taz source
1248 status && echo "" && exit 0 ;;
1249 --install|-i)
1250 inst='yes' ;;
1251 --getsrc|-gs)
1252 gettext "Getting source for:"; echo " $pkg"
1253 separator && get_source
1254 echo -e "Tarball: $SRC/$TARBALL\n" && exit 0 ;;
1255 --block|-b)
1256 gettext "Blocking:"; echo -n " $pkg"
1257 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1258 status && echo "" && exit 0 ;;
1259 --unblock|-ub)
1260 gettext "Unblocking:"; echo -n " $pkg"
1261 sed -i "/^${pkg}$/"d $blocked
1262 status && echo "" && exit 0 ;;
1264 esac
1266 # Check if wanted is built now so we have separate log files.
1267 for wanted in $WANTED ; do
1268 if grep -q "^$wanted$" $blocked; then
1269 echo "WANTED package is blocked: $wanted" | tee $LOGS/$pkg.log
1270 echo "" && rm -f $command && exit 1
1271 fi
1272 if grep -q "^$wanted$" $broken; then
1273 echo "WANTED package is broken: $wanted" | tee $LOGS/$pkg.log
1274 echo "" && rm -f $command && exit 1
1275 fi
1276 if [ ! -d "$WOK/$wanted/install" ]; then
1277 cook "$wanted" || exit 1
1278 fi
1279 done
1281 # Cook and pack or exit on error and log everything.
1282 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1283 remove_deps | tee -a $LOGS/$pkg.log
1284 cookit_quality
1285 packit 2>&1 | tee -a $LOGS/$pkg.log
1286 clean_log
1288 # Exit if any error in packing.
1289 if grep -q ^ERROR $LOGS/$pkg.log; then
1290 debug_info | tee -a $LOGS/$pkg.log
1291 rm -f $command && exit 1
1292 fi
1294 # Create an XML feed
1295 gen_rss
1297 # Time and summary
1298 time=$(($(date +%s) - $time))
1299 summary | tee -a $LOGS/$pkg.log
1300 echo ""
1302 # Install package if requested
1303 if [ "$inst" ]; then
1304 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1305 cd $PKGS && tazpkg install \
1306 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1307 else
1308 gettext -e "Unable to install package, build has failed.\n\n"
1309 exit 1
1310 fi
1311 fi
1313 # Skip install if target host dont match build system.
1314 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
1315 # Install package if part of the chroot to keep env up-to-date.
1316 if [ -d "$INSTALLED/$PACKAGE" ] && [ -z "$AUFS_MOUNTS" ] && \
1317 [ "$build" == "$ARCH" ]; then
1318 echo "Updating chroot environment..."
1319 echo "Updating chroot: $PACKAGE (${VERSION}${EXTRAVERSION})" | log
1320 cd $PKGS && tazpkg install \
1321 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
1322 fi
1324 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1325 # You want automation: use the Cooker Build Bot.
1326 #[ -d "$WOK/$pkg-dev" ] && cook $pkg-dev
1327 rm -f $command ;;
1328 esac
1330 exit 0