cookutils view cook @ rev 508

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