cookutils view cook @ rev 697

cookutils: catch control-c in aufs jail (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 25 11:27:23 2014 +0200 (2014-10-25)
parents 6988444ceee1
children 365737d21d92
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifying 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 VERSION="3.2"
13 # Internationalization.
14 . /usr/bin/gettext.sh
15 TEXTDOMAIN='cook'
16 export TEXTDOMAIN
18 _() echo -e "$(eval_gettext "$1")"
19 _n() echo -en "$(eval_gettext "$1")"
20 # to disable i18n:
21 # _() echo -e "$1"
22 # _n() echo -en "$1"
25 #
26 # Functions
27 #
29 usage() {
30 cat << EOT
32 $(_ "\033[1mUsage:\033[0m cook [package|command] [list|--option]")
34 $(_ "\033[1mCommands:\033[0m")
35 usage|help $(_ "Display this short usage.")
36 setup $(_ "Setup your build environment.")
37 *-setup $(_ "Setup a cross environment.")
38 test $(_ "Test environment and cook a package.")
39 list-wok $(_ "List packages in the wok.")
40 search $(_ "Simple packages search function.")
41 new $(_ "Create a new package with a receipt.")
42 list $(_ "Cook a list of packages.")
43 clean-wok $(_ "Clean-up all packages files.")
44 clean-src $(_ "Clean-up all packages sources.")
45 uncook $(_ "Check for uncooked packages")
46 pkgdb $(_ "Create packages DB lists and flavors.")
48 $(_ "\033[1mOptions:\033[0m")
49 --clean|-c Cook : $(_ "clean the package in the wok.")
50 --install|-i Cook : $(_ "cook and install the package.")
51 --getsrc|-gs Cook : $(_ "get the package source tarball.")
52 --block|-b Cook : $(_ "block a package so cook will skip it.")
53 --unblock|-ub Cook : $(_ "unblock a blocked package.")
54 --cdeps Cook : $(_ "check dependencies of cooked package.")
55 --pack Cook : $(_ "repack an already built package.")
56 --debug Cook : $(_ "display debugging messages.")
57 --continue Cook : $(_ "continue running compile_rules.")
58 --interactive|-x New : $(_ "create a receipt interactively.")
59 --wok Setup: $(_ "clone the cooking wok from Hg repo.")
60 --stable Setup: $(_ "clone the stable wok from Hg repo.")
61 --undigest Setup: $(_ "clone the undigest wok from Hg repo.")
62 --tiny Setup: $(_ "clone the tiny SliTaz wok from Hg repo.")
63 --forced Setup: $(_ "force reinstall of chroot packages.")
64 --flavors Pkgdb: $(_ "create up-to-date flavors files.")
66 EOT
67 exit 0
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 # Be sure package exists in wok.
77 check_pkg_in_wok() {
78 if [ ! -d "$WOK/$pkg" ]; then
79 newline; _ "Unable to find package in the wok: \$pkg"; newline
80 exit 1
81 fi
82 }
84 if_empty_value() {
85 if [ -z "$value" ]; then
86 # L10n: QA is quality assurance
87 _ "QA: empty variable: \${var}=\"\""; newline
88 exit 1
89 fi
90 }
92 # Initialize files used in $CACHE
93 init_db_files() {
94 _ "Creating directories structure in: \$SLITAZ"
95 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
96 _ "Creating DB files in: \$CACHE"
97 for f in $activity $command $broken $blocked
98 do
99 touch $f
100 done
101 }
103 # QA: check a receipt consistency before building.
104 receipt_quality() {
105 _ "QA: checking package receipt..."
106 unset online
107 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
108 online="online"
109 fi
110 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
111 do
112 unset value
113 value="$(. $receipt ; eval echo \$$var)"
114 case "$var" in
115 PACKAGE|VERSION|SHORT_DESC)
116 if_empty_value ;;
117 CATEGORY)
118 [ -z "$value" ] && value="empty"
119 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
120 if ! echo "$valid" | grep -q -w "$value"; then
121 _ "QA: unknown category: \$value"
122 _ "Please, use one of: \$valid" | busybox fold -s
123 newline; exit 1
124 fi ;;
125 WEB_SITE)
126 # We don't check WGET_URL since if dl is needed it will fail.
127 # Break also if we're not online. Here error is not fatal.
128 if_empty_value
129 [ -z "$online" ] || break
130 if ! busybox wget -T 12 -s $value 2>/dev/null; then
131 _ "QA: unable to reach: \$value"
132 fi ;;
133 esac
134 done
135 }
137 # Paths used in receipt and by cook itself.
138 set_paths() {
139 pkgdir=$WOK/$PACKAGE
140 basesrc=$pkgdir/source
141 tmpsrc=$basesrc/tmp
142 src=$basesrc/$PACKAGE-$VERSION
143 taz=$pkgdir/taz
144 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
145 fs=$pack/fs
146 stuff=$pkgdir/stuff
147 install=$pkgdir/install
148 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
149 lzma_tarball="$pkgsrc.tar.lzma"
150 if [ "$PATCH" ]; then
151 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
152 fi
153 if [ "$WANTED" ]; then
154 basesrc=$WOK/$WANTED/source
155 src=$basesrc/$WANTED-$VERSION
156 install=$WOK/$WANTED/install
157 wanted_stuff=$WOK/$WANTED/stuff
158 fi
159 if [ "$SOURCE" ]; then
160 source_stuff=$WOK/$SOURCE/stuff
161 fi
162 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
163 if [ -f "$WOK/linux/receipt" ]; then
164 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
165 kbasevers=${kvers:0:3}
166 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
167 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d '"' -f 2)
168 kbasevers=${kvers:0:3}
169 fi
170 # Python version
171 if [ -f "$WOK/python/receipt" ]; then
172 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
173 fi
174 # perl version for some packages needed it
175 if [ -f "$WOK/perl/receipt" ]; then
176 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
177 fi
178 # Old way compatibility.
179 _pkg=$install
180 }
182 # Create source tarball when URL is a SCM.
183 create_tarball() {
184 local tarball
185 tarball=$pkgsrc.tar.bz2
186 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
187 _ "Creating tarball: \$tarball"
188 if [ "$LZMA_SRC" ]; then
189 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
190 LZMA_SRC=""
191 else
192 tar cjf $tarball $pkgsrc || exit 1
193 mv $tarball $SRC && rm -rf $pkgsrc
194 fi
195 TARBALL=$tarball
196 }
198 # Get package source. For SCM we are in cache so clone here and create a
199 # tarball here.
200 get_source() {
201 local url
202 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
203 set_paths
204 pwd=$(pwd)
205 case "$WGET_URL" in
206 http://*|ftp://*)
207 # Busybox Wget is better!
208 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
209 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
210 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
211 https://*)
212 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
213 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
214 (_ "ERROR: wget \$WGET_URL" && exit 1) ;;
215 hg*|mercurial*)
216 if $(echo "$WGET_URL" | fgrep -q "hg|"); then
217 url=${WGET_URL#hg|}
218 else
219 url=${WGET_URL#mercurial|}
220 fi
221 _ "Getting source from Hg..."
222 _ "URL: \$url"
223 _ "Cloning to: \$pwd/\$pkgsrc"
224 if [ "$BRANCH" ]; then
225 _ "Hg branch: \$BRANCH"
226 hg clone $url --rev $BRANCH $pkgsrc || \
227 (_ "ERROR: hg clone \$url --rev \$BRANCH" && exit 1)
228 else
229 hg clone $url $pkgsrc || (_ "ERROR: hg clone \$url" && exit 1)
230 fi
231 rm -rf $pkgsrc/.hg
232 create_tarball ;;
233 git*)
234 url=${WGET_URL#git|}
235 _ "Getting source from Git..."
236 _ "URL: \$url"
237 cd $SRC
238 git clone $url $pkgsrc || (_ "ERROR: git clone \$url" && exit 1)
239 if [ "$BRANCH" ]; then
240 _ "Git branch: \$BRANCH"
241 cd $pkgsrc && git checkout $BRANCH && cd ..
242 fi
243 cd $SRC
244 create_tarball ;;
245 cvs*)
246 url=${WGET_URL#cvs|}
247 mod=$PACKAGE
248 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
249 _ "Getting source from CVS..."
250 _ "URL: \$url"
251 [ "$CVS_MODULE" ] && _ "CVS module: \$mod"
252 _ "Cloning to: \$pwd/\$mod"
253 cvs -d:$url co $mod && mv $mod $pkgsrc
254 create_tarball ;;
255 svn*|subversion*)
256 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
257 url=${WGET_URL#svn|}
258 else
259 url=${WGET_URL#subversion|}
260 fi
261 _ "Getting source from SVN..."
262 _ "URL: \$url"
263 if [ "$BRANCH" ]; then
264 echo t | svn co $url -r $BRANCH $pkgsrc
265 else
266 echo t | svn co $url $pkgsrc
267 fi
268 create_tarball ;;
269 bzr*)
270 url=${WGET_URL#bzr|}
271 _ "Getting source from bazaar..."
272 cd $SRC
273 pkgsrc=${url#*:}
274 if [ "$BRANCH" ]; then
275 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
276 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
277 else
278 echo "bzr -Ossl.cert_reqs=none branch $url"
279 bzr -Ossl.cert_reqs=none branch $url
280 cd $pkgsrc && BRANCH=$(bzr revno) && cd ..
281 _ "Don't forget to add to receipt:"
282 echo 'BRANCH="'$BRANCH'"'; newline
283 fi
284 mv $pkgsrc $pkgsrc-$BRANCH
285 pkgsrc=$pkgsrc-$BRANCH
286 create_tarball ;;
287 *)
288 (newline; _ "ERROR: Unable to handle: \$WGET_URL"; newline) | \
289 tee -a $LOGS/$PACKAGE.log
290 exit 1 ;;
291 esac
292 }
294 # Extract source package.
295 extract_source() {
296 if [ ! -s "$SRC/$TARBALL" ]; then
297 local url
298 url="$MIRROR_URL/sources/packages"
299 url=$url/${TARBALL:0:1}/$TARBALL
300 _ "Getting source from mirror: \$url"
301 busybox wget -c -P $SRC $url || _ "ERROR: wget \$url"
302 fi
303 _ "Extracting: \$TARBALL"
304 case "$TARBALL" in
305 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
306 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
307 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
308 *.tar) tar xf $SRC/$TARBALL ;;
309 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
310 *.xz) unxz -c $SRC/$TARBALL | tar xf - || tar xf $SRC/$TARBALL 2>/dev/null;;
311 *.7z) 7zr x $SRC/$TARBALL ;;
312 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
313 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
314 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
315 *) cp $SRC/$TARBALL $(pwd) ;;
316 esac
317 }
319 # Display cooked package summary.
320 summary() {
321 cd $WOK/$pkg
322 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
323 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
324 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
325 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
326 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
327 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
328 cookdate=$(date "$(_ '+%Y-%m-%d %H:%M')")
329 sec=$time
330 div=$(( ($time + 30) / 60))
331 # L10n: 'm' is for minutes (approximate cooking time)
332 min=$(_n "~ \${div}m"); [ "$div" = 0 ] && min=""
333 _ "Summary for: \$PACKAGE \$VERSION"
334 separator
335 # L10n: keep the same width of translations to get a consistent view
336 [ "$srcdir" ] && _ "Source dir : \$srcdir"
337 [ "$TARBALL" ] && _ "Src file : \$TARBALL"
338 [ "$srcsize" ] && _ "Src size : \$srcsize"
339 [ "$prod" ] && _ "Produced : \$prod"
340 _ "Packed : \$fs"
341 _ "Compressed : \$size"
342 _ "Files : \$files"
343 # L10n: 's' is for seconds (cooking time)
344 _ "Cook time : \${sec}s \$min"
345 _ "Cook date : \$cookdate"
346 _ "Host arch : \$ARCH"
347 separator
348 }
350 # Display debugging error info.
351 debug_info() {
352 newline; _ "Debug information"; separator
353 # L10n: specify your format of date and time (to help: man date)
354 # L10n: not bad one is '+%x %R'
355 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
356 _ "Cook date: \$datenow"
357 # L10n: Please, translate all messages beginning with ERROR in a same way
358 lerror=$(_n "ERROR")
359 for error in \
360 ERROR $lerror "No package" "cp: can't" "can't open" "can't cd" \
361 "error:" "fatal error:" "undefined reference to" \
362 "Unable to connect to" "link: cannot find the library" \
363 "CMake Error" ": No such file or directory"
364 do
365 fgrep "$error" $LOGS/$pkg.log
366 done > $LOGS/$pkg.log.debug_info 2>&1
367 cat $LOGS/$pkg.log.debug_info
368 rm -f $LOGS/$pkg.log.debug_info
369 separator; newline
370 }
372 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
373 # so some packages need to copy these files with the receipt and genpkg_rules.
374 copy_generic_files()
375 {
376 # $LOCALE is set in cook.conf
377 if [ "$LOCALE" -a "$WANTED" = "" ]; then
378 if [ -d "$install/usr/share/locale" ]; then
379 mkdir -p $fs/usr/share/locale
380 for i in $LOCALE
381 do
382 if [ -d "$install/usr/share/locale/$i" ]; then
383 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
384 fi
385 done
386 fi
387 fi
389 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
390 if [ "$GENERIC_PIXMAPS" != "no" ]; then
391 if [ -d "$install/usr/share/pixmaps" ]; then
392 mkdir -p $fs/usr/share/pixmaps
393 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
394 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
395 $fs/usr/share/pixmaps
396 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
397 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
398 $fs/usr/share/pixmaps
399 fi
400 fi
402 # Custom or homemade PNG pixmap can be in stuff.
403 if [ -f "$stuff/$PACKAGE.png" ]; then
404 mkdir -p $fs/usr/share/pixmaps
405 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
406 fi
407 fi
409 # Desktop entry (.desktop).
410 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
411 if [ "$GENERIC_MENUS" != "no" ]; then
412 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
413 mkdir -p $fs/usr/share
414 cp -a $install/usr/share/applications $fs/usr/share
415 fi
416 fi
418 # Homemade desktop file(s) can be in stuff.
419 if [ -d "$stuff/applications" ]; then
420 mkdir -p $fs/usr/share
421 cp -a $stuff/applications $fs/usr/share
422 fi
423 if [ -f "$stuff/$PACKAGE.desktop" ]; then
424 mkdir -p $fs/usr/share/applications
425 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
426 fi
428 # Add custom licenses
429 if [ -d "$stuff/licenses" ]; then
430 mkdir -p $fs/usr/share/licenses
431 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
432 fi
433 }
435 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
436 # as removing unneeded files like in Python packages. Cross compiled binaries
437 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
438 strip_package() {
439 case "$ARCH" in
440 arm*|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
441 *) export STRIP=strip ;;
442 esac
443 _n "Executing strip on all files..."
444 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
445 do
446 if [ -d "$dir" ]; then
447 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
448 fi
449 done
450 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
451 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
452 status
454 # Remove Python .pyc and .pyo from packages.
455 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
456 _n "Removing Python compiled files..."
457 find $fs -type f -name "*.pyc" -delete 2>/dev/null
458 find $fs -type f -name "*.pyo" -delete 2>/dev/null
459 status
460 fi
462 # Remove Perl perllocal.pod and .packlist from packages.
463 if echo "$DEPENDS" | fgrep -q "perl"; then
464 _n "Removing Perl compiled files..."
465 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
466 find $fs -type f -name ".packlist" -delete 2>/dev/null
467 status
468 fi
469 }
471 # Remove installed deps.
472 remove_deps() {
473 # Now remove installed build deps.
474 diff="/tmp/installed.cook.diff"
475 if [ -s $diff ]; then
476 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
477 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
478 _n "Build dependencies to remove: "; echo $nb $root
479 _n "Removing:"
480 for dep in $deps
481 do
482 echo -n " $dep"
483 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
484 done
485 newline; newline
486 # Keep the last diff for debug and info.
487 mv -f $diff $CACHE/installed.diff
488 fi
489 }
491 # The main cook function.
492 cookit() {
493 _ "Cook: \$PACKAGE \$VERSION"; separator
494 set_paths
496 # Handle cross-tools.
497 case "$ARCH" in
498 arm*|x86_64)
499 # CROSS_COMPILE is used by at least Busybox and the kernel to set
500 # the cross-tools prefix. Sysroot is the root of our target arch
501 sysroot=$CROSS_TREE/sysroot
502 tools=$CROSS_TREE/tools
503 # Set root path when cross compiling. ARM tested but not x86_64
504 # When cross compiling we must install build deps in $sysroot.
505 arch="-${ARCH}"
506 root=$sysroot
507 _ "\$ARCH sysroot: \$sysroot"
508 _ "Adding \$tools/bin to PATH"
509 export PATH=$PATH:$tools/bin
510 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
511 export CROSS_COMPILE=${HOST_SYSTEM}-
512 _ "Using cross-tools: \$CROSS_COMPILE"
513 if [ "$ARCH" == "x86_64" ]; then
514 export CC="${HOST_SYSTEM}-gcc -m64"
515 export CXX="${HOST_SYSTEM}-g++ -m64"
516 else
517 export CC=${HOST_SYSTEM}-gcc
518 export CXX=${HOST_SYSTEM}-g++
519 fi
520 export AR=${HOST_SYSTEM}-ar
521 export AS=${HOST_SYSTEM}-as
522 export RANLIB=${HOST_SYSTEM}-ranlib
523 export LD=${HOST_SYSTEM}-ld
524 export STRIP=${HOST_SYSTEM}-strip
525 export LIBTOOL=${HOST_SYSTEM}-libtool ;;
526 esac
528 [ "$QA" ] && receipt_quality
529 cd $pkgdir
530 [ "$continue" ] || rm -rf source 2> /dev/null
531 rm -rf install taz 2> /dev/null
533 # Disable -pipe if less than 512Mb free RAM.
534 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
535 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
536 _ "Disabling -pipe compile flag: \$free RAM"
537 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
538 CXXFLAGS="${CXXFLAGS/-pipe}" && CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
539 fi
540 unset free
542 # Export flags and path to be used by make and receipt.
543 DESTDIR=$pkgdir/install
544 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
545 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
546 #LDFLAGS
548 # Check for build deps and handle implicit depends of *-dev packages
549 # (ex: libusb-dev :: libusb).
550 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
551 touch $CACHE/installed.local $CACHE/installed.web
552 [ "$BUILD_DEPENDS" ] && _ "Checking build dependencies..."
553 [ "$root" ] && _ "Using packages DB: \${root}\$DB"
554 for dep in $BUILD_DEPENDS
555 do
556 implicit=${dep%-dev}
557 for i in $dep $implicit
558 do
559 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
560 # Try local package first. In some cases implicit doesn't exist, ex:
561 # libboost-dev exists but not libboost, so check if we got vers.
562 unset vers
563 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
564 # We may have a local package.
565 if [ ! "$vers" ]; then
566 vers=$(grep "^$i |" $PKGS/packages.desc | awk '{print $3}')
567 fi
568 debug "bdep: $i version: $vers"
569 if [ -f "$PKGS/$i-${vers}${arch}.tazpkg" ]; then
570 echo $i-${vers}${arch}.tazpkg >> $CACHE/installed.local
571 else
572 # Priority to package version in wok (maybe more up-to-date)
573 # than the mirrored one.
574 if [ "$vers" ]; then
575 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
576 echo $i >> $CACHE/installed.web
577 else
578 # So package exists in wok but not available.
579 _ "Missing dep (wok/pkg): \$i \$vers"
580 echo $i >> $CACHE/missing.dep
581 fi
582 else
583 # Package is not in wok but may be in online repo.
584 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
585 echo $i >> $CACHE/installed.web
586 else
587 _ "ERROR: unknown dep \$i"; exit 1
588 fi
589 fi
590 fi
591 fi
592 done
593 done
595 # Get the list of installed packages
596 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.list
598 # Have we a missing build dep to cook?
599 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
600 _ "Auto cook config is set: AUTO_COOK"
601 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
602 for i in $(uniq $CACHE/missing.dep)
603 do
604 (_ "Building dep (wok/pkg) : \$i \$vers") | \
605 tee -a $LOGS/$PACKAGE.log.$$
606 # programmers: next two messages are exact copy from remove_deps()
607 togrep1=$(_n "Build dependencies to remove: ")
608 togrep2=$(_n "Removing:")
609 cook $i || (_ "ERROR: can't cook dep '\$i'" && newline && \
610 fgrep $togrep1 $LOGS/$i.log && \
611 fgrep $togrep2 $LOGS/$i.log && newline) | \
612 tee -a $LOGS/$PACKAGE.log.$$ && break
613 done
614 rm -f $CACHE/missing.dep
615 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
616 fi
618 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
619 # is enabled and cook fails we have ERROR in log, if no auto cook we have
620 # missing dep in cached file.
621 lerror=$(_n "ERROR")
622 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
623 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
624 _ "ERROR: missing dep \$nb" && exit 1
625 fi
627 # Install local packages: package-version${arch}
628 cd $PKGS
629 for i in $(uniq $CACHE/installed.local)
630 do
631 _ "Installing dep (pkg/local): \$i"
632 tazpkg install $i --root=$root >/dev/null
633 done
635 # Install web or cached packages (if mirror is set to $PKGS we only
636 # use local packages).
637 for i in $(uniq $CACHE/installed.web)
638 do
639 _ "Installing dep (web/cache): \$i"
640 tazpkg get-install $i --root=$root >/dev/null
641 done
643 # If a cook failed deps are removed.
644 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
645 [ ! -s "/tmp/installed.cook.diff" ] && \
646 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
647 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
649 # Get source tarball and make sure we have source dir named:
650 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
651 # tarball if it exists.
652 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
653 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
654 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
655 LZMA_SRC=""
656 else
657 get_source || exit 1
658 fi
659 fi
660 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
661 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
662 if ! extract_source ; then
663 get_source
664 extract_source || exit 1
665 fi
666 if [ "$LZMA_SRC" ]; then
667 cd $pkgdir/source
668 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
669 mv tmp tmp-1 && mkdir tmp
670 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
671 fi
672 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
673 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
674 fi
675 fi
676 cd $pkgdir/source/tmp
677 # Some archives are not well done and don't extract to one dir (ex lzma).
678 files=$(ls | wc -l)
679 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
680 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
681 mv * ../$PACKAGE-$VERSION/$TARBALL
682 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
683 mv * ../$PACKAGE-$VERSION
684 cd .. && rm -rf tmp
685 fi
687 # Libtool shared libs path hack.
688 case "$ARCH" in
689 arm*) cross libhack ;;
690 esac
692 # Execute receipt rules.
693 if grep -q ^compile_rules $receipt; then
694 _ "Executing: compile_rules"
695 echo "CFLAGS : $CFLAGS"
696 #echo "LDFLAGS : $LDFLAGS"
697 [ -d "$src" ] && cd $src
698 compile_rules $@ || exit 1
699 # Stay compatible with _pkg
700 [ -d "$src/_pkg" ] && mv $src/_pkg $install
701 # QA: compile_rules success so valid.
702 mkdir -p $install
703 else
704 # QA: no compile_rules so no error, valid.
705 mkdir -p $install
706 fi
707 separator; newline
709 # Execute testsuite.
710 if grep -q ^testsuite $receipt; then
711 _ "Running testsuite"; separator
712 testsuite $@ || exit 1
713 separator; newline
714 fi
715 }
717 # Cook quality assurance.
718 cookit_quality() {
719 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
720 _ "ERROR: cook failed" | tee -a $LOGS/$pkg.log
721 fi
722 # ERROR can be echoed any time in cookit()
723 lerror=$(_n "ERROR")
724 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
725 grep -Eq "(^$lerror|undefined reference to)" ; then
726 debug_info | tee -a $LOGS/$pkg.log
727 rm -f $command && exit 1
728 fi
729 }
731 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
732 # but it doesn't handle EXTRAVERSION.
733 packit() {
734 set_paths
736 # Handle cross compilation
737 case "$ARCH" in
738 arm*|x86_64) arch="-$ARCH" ;;
739 esac
741 _ "Pack: \$PACKAGE \${VERSION}\${arch}"; separator
743 if grep -q ^genpkg_rules $receipt; then
744 _ "Executing: genpkg_rules"
745 set -e && cd $pkgdir && mkdir -p $fs
746 genpkg_rules || (newline; _ "ERROR: genpkg_rules failed"; newline) >> \
747 $LOGS/$pkg.log
748 else
749 _ "No packages rules: meta package"
750 mkdir -p $fs
751 fi
753 # First QA check to stop now if genpkg_rules failed.
754 lerror=$(_n "ERROR")
755 if fgrep -q ^$lerror $LOGS/$pkg.log; then
756 exit 1
757 fi
759 cd $taz
760 for file in receipt description.txt
761 do
762 [ ! -f "../$file" ] && continue
763 _n "Copying \$file..."
764 cp -f ../$file $pack && chown 0.0 $pack/$file && status
765 done
766 copy_generic_files
768 # Create files.list with redirecting find output.
769 _n "Creating the list of files..."
770 cd $fs
771 find . -type f -print > ../files.list
772 find . -type l -print >> ../files.list
773 cd .. && sed -i s/'^.'/''/ files.list
774 status
776 # Strip and stuff files.
777 strip_package
779 # Md5sum of files.
780 _n "Creating md5sum of files..."
781 while read file; do
782 [ -L "fs$file" ] && continue
783 [ -f "fs$file" ] || continue
784 case "$file" in
785 /lib/modules/*/modules.*|*.pyc) continue ;;
786 esac
787 md5sum "fs$file" | sed 's/ fs/ /'
788 done < files.list > md5sum
789 status
790 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
791 description.txt 2> /dev/null | awk \
792 '{ sz=$1 } END { print sz }')
794 # Build cpio archives.
795 _n "Compressing the fs..."
796 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
797 rm -rf fs
798 status
799 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
800 md5sum description.txt 2> /dev/null | awk \
801 '{ sz=$1 } END { print sz }')
802 _n "Updating receipt sizes..."
803 sed -i s/^PACKED_SIZE.*$// receipt
804 sed -i s/^UNPACKED_SIZE.*$// receipt
805 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
806 status
808 # Set extra version.
809 if [ "$EXTRAVERSION" ]; then
810 _n "Updating receipt EXTRAVERSION: \$EXTRAVERSION"
811 sed -i s/^EXTRAVERSION.*$// receipt
812 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
813 status
814 fi
816 # Compress.
817 _n "Creating full cpio archive..."
818 find . -print | cpio -o -H newc --quiet > \
819 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
820 status
821 _n "Restoring original package tree..."
822 unlzma -c fs.cpio.lzma | cpio -idm --quiet
823 status
824 rm fs.cpio.lzma && cd ..
826 # QA and give info.
827 tazpkg=$(ls *.tazpkg)
828 packit_quality
829 separator; _ "Package: \$tazpkg"; newline
830 }
832 # Verify package quality and consistency.
833 packit_quality() {
834 #gettext "QA: checking for broken link..."
835 #link=$(find $fs/usr -type l -follow)
836 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
837 #status
839 # Exit if any error found in log file.
840 lerror=$(_n "ERROR")
841 if fgrep -q ^$lerror $LOGS/$pkg.log; then
842 rm -f $command && exit 1
843 fi
845 _n "QA: checking for empty package..."
846 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
847 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
848 newline; _ "ERROR: empty package"
849 rm -f $command && exit 1
850 else
851 # Ls sort by name so the first file is the one we want.
852 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
853 status
854 if [ -f "$old" ]; then
855 old_pkg=$(basename $old)
856 _n "Removing old: \$old_pkg"
857 rm -f $old && status
858 fi
859 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
860 sed -i /^${pkg}$/d $broken
861 #gettext "Removing source tree..."
862 #rm -f $WOK/$pkg/source && status
863 fi
864 }
866 # Tic tac, tic tac...
867 tac() {
868 sed '1!G;h;$!d' $1
869 }
871 # Install package on --install or update the chroot.
872 install_package() {
873 case "$ARCH" in
874 arm*|x86_64)
875 arch="-${ARCH}"
876 root=$CROSS_TREE/sysroot ;;
877 esac
878 # Install package if requested but skip install if target host doesn't
879 # match build system or it will break the build chroot.
880 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
881 if [ "$inst" ] && [ "$build" == "$ARCH" ]; then
882 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
883 cd $PKGS && tazpkg install \
884 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
885 else
886 _ "Unable to install package, build has failed."; newline
887 exit 1
888 fi
889 fi
891 # Install package if part of the chroot to keep env up-to-date.
892 if [ -d "${root}$INSTALLED/$pkg" ]; then
893 . /etc/slitaz/cook.conf
894 . $WOK/$pkg/taz/$pkg-*/receipt
895 _ "Updating \$ARCH chroot environment..."
896 _ "Updating chroot: \$pkg (\${VERSION}\${EXTRAVERSION}\${arch})" | log
897 cd $PKGS && tazpkg install \
898 $pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
899 --forced --root=$root
900 fi
901 }
903 # remove chroot jail
904 umount_aufs() {
905 tac ${1}rw/aufs-umount.sh | sh
906 rm -rf ${1}rw
907 umount ${1}root
908 rmdir ${1}r*
909 }
911 # Launch the cook command into a chroot jail protected by aufs.
912 # The current filesystems are used read-only and updates are
913 # stored in a separate branch.
914 try_aufs_chroot() {
916 base=/dev/shm/aufsmnt$$
918 # Can we setup the chroot? Is it already done?
919 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
920 grep -q ^AUFS_NOT_RAMFS $receipt && base=/mnt/aufsmnt$$
921 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
922 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
923 mkdir ${base}root ${base}rw || return
925 _ "Setup aufs chroot..."
927 # Sanity check
928 for i in / /proc /sys /dev/shm /home ; do
929 case " $AUFS_MOUNTS " in
930 *\ $i\ *) ;;
931 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
932 esac
933 done
934 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
935 mount --bind $mnt ${base}root$mnt
936 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
937 _ "Aufs mountage failure"
938 umount ${base}root
939 rm -rf ${base}r*
940 return
941 fi
942 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
943 done
944 trap "umount_aufs ${base}" INT
946 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
947 status=$?
949 _ "Leaving aufs chroot..."
950 umount_aufs ${base}
951 # Install package outside the aufs jail
952 install_package
953 exit $status
954 }
956 # Create a XML feed for freshly built packages.
957 gen_rss() {
958 pubdate=$(date "+%a, %d %b %Y %X")
959 cat > $FEEDS/$pkg.xml << EOT
960 <item>
961 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
962 <link>${COOKER_URL}?pkg=$PACKAGE</link>
963 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
964 <pubDate>$pubdate</pubDate>
965 <description>$SHORT_DESC</description>
966 </item>
967 EOT
968 }
970 # Truncate stdout log file to $1 Mb.
971 loglimit()
972 {
973 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
974 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
975 else
976 tee /dev/stderr
977 fi
978 }
980 # Search file in mirrored packages
981 search_file_mirror()
982 {
983 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
984 }
986 # Search file in local wok packages
987 search_file_local()
988 {
989 # existing packages have precedence over the package/taz folder
990 srch=$1
991 { for package in $(find $PKGS -name '*.tazpkg'); do
992 if [ ! "x$(busybox cpio --to-stdout --quiet -i files.list < $package | grep /$srch\$)" == "x" ]; then
993 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
994 fi
995 done } | sort -u
996 }
998 # Ask in multiple choice
999 ask_multiple()
1001 local multiples first my_choice
1002 multiples="$1"
1003 first=$(echo "$multiples" | head -n1)
1004 newline; _ "Multiple choice:\n$multiples\n"
1005 _ "Select one [$first]: "; read my_choice
1006 [ "x$my_choice" == "x" ] && my_choice="$first"
1007 found=$my_choice
1010 # Search file in local cache (fast), local wok packages, mirrored packages
1011 search_file()
1013 local srch cache missing
1014 srch=$1
1015 cache=/var/cache/ldsearch.cache
1016 missing=/var/cache/missing.file
1017 touch $cache $missing
1018 found=$(grep $srch $cache | cut -d' ' -f2)
1019 if [ "x$found" == "x" ]; then
1020 found=$(search_file_local $srch)
1021 if [ "x$found" != "x" ]; then
1022 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1023 ask_multiple "$found"
1024 fi
1025 echo "$srch $found" >> $cache
1026 else
1027 found=$(search_file_mirror $srch)
1028 if [ "x$found" != "x" ]; then
1029 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1030 ask_multiple "$found"
1031 fi
1032 echo "$srch $found" >> $cache
1033 else
1034 echo "$srch" >> $missing
1035 fi
1036 fi
1037 fi
1041 # Receipt functions to ease packaging
1044 get_dev_files() {
1045 _n "Getting standard devel files..."
1046 mkdir -p $fs/usr/lib
1047 cp -a $install/usr/lib/*.so* $fs/usr/lib
1048 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1049 cp -a $install/usr/include $fs/usr
1050 status
1054 # Commands
1057 case "$1" in
1058 usage|help|-u|-h)
1059 usage ;;
1060 list-wok)
1061 newline; _ "List of \$ARCH packages in: \$WOK"; separator
1062 cd $WOK
1063 if [ "$ARCH" != "i486" ]; then
1064 count=0
1065 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d : -f 1)
1066 do
1067 unset HOST_ARCH
1068 . $pkg
1069 count=$(($count + 1))
1070 colorize 34 "$PACKAGE"
1071 done
1072 else
1073 count=$(ls | wc -l)
1074 ls -1
1075 fi
1076 separator
1077 _n "Packages:"; colorize 32 " $count"
1078 newline ;;
1079 activity)
1080 cat $activity ;;
1081 search)
1082 # Just a simple search function, we dont need more actually.
1083 query="$2"
1084 newline; _ "Search results for: \$query"; separator
1085 cd $WOK && ls -1 | grep "$query"
1086 separator; newline ;;
1087 setup)
1088 # Setup a build environment
1089 check_root
1090 _ "Cook: setup environment" | log
1091 newline; _ "Setting up your environment"; separator
1092 cd $SLITAZ
1093 init_db_files
1094 _ "Checking for packages to install..."
1095 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1096 # ARCH-setup or 'cross check' should be used before: cook setup
1097 case "$ARCH" in
1098 arm*|x86_64)
1099 if [ ! -x "/usr/bin/cross" ]; then
1100 _ "ERROR: cross is not installed"
1101 exit 1
1102 fi
1103 _ "Using config file: /etc/slitaz/cross.conf"
1104 . /etc/slitaz/cross.conf ;;
1105 esac
1106 for pkg in $SETUP_PKGS; do
1107 if [ "$forced" ]; then
1108 tazpkg -gi $pkg --forced
1109 else
1110 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
1111 fi
1112 done
1114 # Handle --options
1115 case "$2" in
1116 --wok)
1117 hg clone $WOK_URL wok || exit 1 ;;
1118 --stable)
1119 hg clone $WOK_URL-stable wok || exit 1 ;;
1120 --undigest)
1121 hg clone $WOK_URL-undigest wok || exit 1 ;;
1122 --tiny)
1123 hg clone $WOK_URL-tiny wok || exit 1 ;;
1124 esac
1126 # SliTaz group and permissions
1127 if ! grep -q ^slitaz /etc/group; then
1128 _ "Adding group: slitaz"
1129 addgroup slitaz
1130 fi
1131 _ "Setting permissions for slitaz group..."
1132 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1133 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1134 separator; _ "All done, ready to cook packages :-)"; newline ;;
1135 *-setup)
1136 # Setup for cross compiling.
1137 arch=${1%-setup}
1138 check_root
1139 . /etc/slitaz/cook.conf
1140 for pkg in $CROSS_SETUP; do
1141 if [ "$forced" ]; then
1142 tazpkg -gi $pkg --forced
1143 else
1144 [ -d "$INSTALLED/$pkg" ] || tazpkg -gi $pkg
1145 fi
1146 done
1147 _ "Cook: setup \$arch cross environment" | log
1148 newline; boldify $(_n "Setting up your \$arch cross environment"); separator
1149 init_db_files
1150 sed -i \
1151 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1152 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1153 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1154 /etc/slitaz/cook.conf
1155 case "$arch" in
1156 arm)
1157 flags="-O2 -march=armv6"
1158 host="$ARCH-slitaz-linux-gnueabi" ;;
1159 armv6hf)
1160 flags="-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard"
1161 host="$ARCH-slitaz-linux-gnueabi" ;;
1162 armv7)
1163 flags="-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe"
1164 host="$ARCH-slitaz-linux-gnueabi" ;;
1165 x86_64)
1166 flags="-O2 -mtune=generic -pipe"
1167 host="$ARCH-slitaz-linux" ;;
1168 esac
1169 sed -i \
1170 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1171 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1172 . /etc/slitaz/cook.conf
1173 sysroot=$CROSS_TREE/sysroot
1174 tools=/cross/$arch/tools
1175 root=$sysroot
1176 # L10n: keep the same width of translations to get a consistent view
1177 _ "Target arch : \$ARCH"
1178 _ "Configure args : \$CONFIGURE_ARGS"
1179 _ "Build flags : \$flags"
1180 _ "Arch sysroot : \$sysroot"
1181 _ "Tools prefix : \$tools/bin"
1182 # Tell the packages manager where to find packages.
1183 _ "Packages DB : \${root}\$DB"
1184 mkdir -p ${root}$INSTALLED
1185 cd ${root}$DB && rm -f *.bak
1186 for list in packages.list packages.desc packages.equiv packages.md5
1187 do
1188 rm -f $list && ln -s $SLITAZ/packages/$list $list
1189 done
1190 # We must have the cross compiled glibc-base installed or default
1191 # i486 package will be used as dep by tazpkg and then break the
1192 # cross environment
1193 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1194 colorize 36 $(_ "WARNING: (e)glibc-base is not installed in sysroot")
1195 fi
1196 # Show GCC version or warn if not yet compiled.
1197 if [ -x "$tools/bin/${HOST_SYSTEM}-gcc" ]; then
1198 _ "Cross compiler : \${HOST_SYSTEM}-gcc"
1199 else
1200 colorize 36 $(_ "C compiler is missing: \${HOST_SYSTEM}-gcc")
1201 _ "Run 'cross compile' to cook a toolchain"
1202 fi
1203 separator; newline ;;
1204 test)
1205 # Test a cook environment.
1206 _ "Cook test: testing the cook environment" | log
1207 [ ! -d "$WOK" ] && exit 1
1208 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1209 cook cooktest ;;
1210 new)
1211 # Create the package folder and an empty receipt.
1212 pkg="$2"
1213 [ "$pkg" ] || usage
1214 newline
1215 if [ -d "$WOK/$pkg" ]; then
1216 _ "\$pkg package already exists."
1217 exit 1
1218 fi
1219 _n "Creating \$WOK/\$pkg"
1220 mkdir $WOK/$pkg && cd $WOK/$pkg && status
1221 _n "Preparing the package receipt..."
1222 cp $DATA/receipt .
1223 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1224 status && newline
1226 # Interactive mode, asking and seding.
1227 case "$3" in
1228 --interactive|-x)
1229 _ "Entering interactive mode..."
1230 separator
1231 _ "Package : \$pkg"
1232 _n "Version : " ; read answer
1233 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1234 _n "Category : " ; read answer
1235 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1236 # L10n: Short description
1237 _n "Short desc : " ; read answer
1238 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1239 _n "Maintainer : " ; read answer
1240 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1241 _n "License : " ; read answer
1242 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1243 _n "Web site : " ; read answer
1244 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1245 newline
1246 # Wget URL.
1247 _ "Wget URL to download source tarball."
1248 _n "Example : " ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1249 _n "Wget url : " ; read answer
1250 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$answer\""# receipt
1251 # Ask for a stuff dir.
1252 _n "Do you need a stuff directory? (y/N) : " ; read answer
1253 if [ "$answer" = "y" ]; then
1254 _n "Creating the stuff directory..."
1255 mkdir $WOK/$pkg/stuff && status
1256 fi
1257 # Ask for a description file.
1258 _n "Are you going to write a description? (y/N) : " ; read answer
1259 if [ "$answer" = "y" ]; then
1260 _n "Creating the description.txt file..."
1261 newline > $WOK/$pkg/description.txt && status
1262 fi
1263 separator; _ "Receipt is ready to use."; newline ;;
1264 esac ;;
1265 list)
1266 # Cook a list of packages (better use the Cooker since it will order
1267 # packages before executing cook).
1268 check_root
1269 [ -z "$2" ] && (newline; _ "No list in argument."; newline) && exit 1
1270 list2=$2
1271 [ ! -f "$2" ] && (newline; _ "No list found: \$list2"; newline) && exit 1
1272 _ "Cook list starting: \$list2" | log
1273 for pkg in $(cat $2)
1274 do
1275 cook $pkg || broken
1276 done ;;
1277 clean-wok)
1278 check_root
1279 newline; _n "Cleaning all packages files..."
1280 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1281 status; newline ;;
1282 clean-src)
1283 check_root
1284 newline; _n "Cleaning all packages sources..."
1285 rm -rf $WOK/*/source
1286 status; newline ;;
1287 uncook)
1288 cd $WOK
1289 count=0
1290 newline
1291 _ "Checking for uncooked packages"
1292 separator
1293 for pkg in *
1294 do
1295 unset HOST_ARCH EXTRAVERSION
1296 . $pkg/receipt
1297 # Source cooked pkg receipt to get EXTRAVERSION
1298 if [ -d "$WOK/$pkg/taz" ]; then
1299 cd $WOK/$pkg/taz/$pkg-*
1300 . receipt && cd $WOK
1301 fi
1302 case "$ARCH" in
1303 i486)
1304 debug "Package: $PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}.tazpkg"
1305 if [ ! -f "$PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1306 count=$(($count + 1))
1307 colorize 34 "$pkg"
1308 fi ;;
1309 arm*)
1310 # Check only packages included in arch
1311 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1312 # *.tazpkg
1313 if [ ! -f "$PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}-${ARCH}.tazpkg" ]; then
1314 count=$(($count + 1))
1315 colorize 34 "$pkg"
1316 fi
1317 fi ;;
1318 esac
1319 done
1320 if [ "$count" -gt "0" ]; then
1321 separator
1322 _n "Uncooked packages: "; colorize 31 "$count"
1323 else
1324 _ "All packages are cooked :-)"
1325 fi
1326 newline ;;
1327 pkgdb)
1328 # Create suitable packages list for TazPKG and only for built packages
1329 # as well as flavors files for TazLiTo. We dont need logs since we do it
1330 # manually to ensure everything is fine before syncing the mirror.
1331 case "$2" in
1332 --flavors)
1333 continue ;;
1334 *)
1335 [ "$2" ] && PKGS="$2"
1336 [ ! -d "$PKGS" ] && \
1337 newline && _ "Packages directory doesn't exist" && \
1338 newline && exit 1 ;;
1339 esac
1340 time=$(date +%s)
1341 flavors=$SLITAZ/flavors
1342 live=$SLITAZ/live
1343 echo "cook:pkgdb" > $command
1344 _ "Cook pkgdb: Creating all packages lists" | log
1345 newline; _ "Creating lists for: \$PKGS"; separator
1346 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1347 _ "Cook pkgdb started: \$datenow"
1348 cd $PKGS
1349 rm -f packages.*
1350 _ "Creating: packages.list"
1351 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1352 _ "Creating: packages.md5"
1353 md5sum *.tazpkg > $PKGS/packages.md5
1354 md5sum packages.md5 | cut -f1 -d' ' > ID
1355 _ "Creating lists from: \$WOK"
1356 cd $WOK
1357 for pkg in *
1358 do
1359 unset_receipt
1360 . $pkg/receipt
1361 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1362 if [ -s $pkg/taz/*/receipt ]; then
1363 . $pkg/taz/*/receipt
1364 fi
1365 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1366 # packages.desc lets us search easily in DB
1367 cat >> $PKGS/packages.desc << EOT
1368 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1369 EOT
1370 # packages.txt used by tazpkg and tazpkg-web also to provide
1371 # a human readable package list with version and description.
1372 cat >> $PKGS/packages.txt << EOT
1373 $PACKAGE
1374 ${VERSION}$EXTRAVERSION
1375 $SHORT_DESC
1376 $PACKED_SIZE ($UNPACKED_SIZE installed)
1378 EOT
1379 # packages.equiv is used by tazpkg install to check depends.
1380 for i in $PROVIDE; do
1381 DEST=""
1382 echo $i | fgrep -q : && DEST="${i#*:}:"
1383 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1384 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1385 $PKGS/packages.equiv
1386 else
1387 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1388 fi
1389 done
1390 # files.list provides a list of all packages files.
1391 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1392 $PKGS/files.list
1393 fi
1394 done
1396 # Display list size.
1397 _ "Done: packages.desc"
1398 _ "Done: packages.txt"
1399 _ "Done: packages.equiv"
1401 # files.list.lzma
1402 _ "Creating: files.list.lzma"
1403 cd $PKGS && lzma e files.list files.list.lzma
1404 rm -f files.list
1406 # Display some info.
1407 separator
1408 nb=$(ls $PKGS/*.tazpkg | wc -l)
1409 time=$(($(date +%s) - $time))
1410 # L10n: 's' is for seconds (cooking time)
1411 _ "Packages: \$nb - Time: \${time}s"; newline
1413 # Create all flavors files at once. Do we really need code to monitor
1414 # flavors changes? Lets just build them with packages lists before
1415 # syncing the mirror.
1416 [ "$2" == "--flavors" ] || exit 1
1417 [ ! -d "$flavors" ] && (_ "Missing flavors: \$flavors"; newline) && exit 1
1418 [ -d "$live" ] || mkdir -p $live
1419 _ "Creating flavors files in: \$live"
1420 _ "Cook pkgdb: Creating all flavors" | log
1421 separator
1422 _ "Recharging lists to use latest packages..."
1423 tazpkg recharge >/dev/null 2>/dev/null
1425 # We need a custom tazlito config to set working dir to /home/slitaz.
1426 if [ ! -f "$live/tazlito.conf" ]; then
1427 _ "Creating configuration file: tazlito.conf"
1428 cp /etc/tazlito/tazlito.conf $live
1429 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1430 $live/tazlito.conf
1431 fi
1433 # Update Hg flavors repo and pack.
1434 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1436 cd $live
1437 _ "Starting to generate flavors..."
1438 rm -f flavors.list *.flavor
1439 for i in $flavors/*
1440 do
1441 fl=$(basename $i)
1442 _ "Packing flavor: \$fl"
1443 tazlito pack-flavor $fl >/dev/null || exit 1
1444 tazlito show-flavor $fl --brief --noheader 2> \
1445 /dev/null >> flavors.list
1446 done
1447 cp -f $live/*.flavor $live/flavors.list $PKGS
1448 separator
1449 fl_size=$(du -sh $live | awk '{print $1}')
1450 _ "Flavors size: \$fl_size"; newline
1451 rm -f $command
1452 separator
1453 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1454 _ "Cook pkgdb end: \$datenow" ;;
1455 *)
1456 # Just cook and generate a package.
1457 check_root
1458 time=$(date +%s)
1459 pkg="$1"
1460 [ -z "$pkg" ] && usage
1461 receipt="$WOK/$pkg/receipt"
1462 check_pkg_in_wok && newline
1464 unset inst
1465 unset_receipt
1466 . $receipt
1468 # Handle cross compilation.
1469 case "$ARCH" in
1470 arm*)
1471 if [ ! "$HOST_ARCH" ]; then
1472 _ "cook: HOST_ARCH is not set in \$pkg receipt"
1473 _ "cook: This package is not included in: \$ARCH"
1474 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1475 _ "Cook skip: \$pkg is not included in: \$ARCH" | log
1476 newline && exit 1
1477 fi ;;
1478 esac
1480 # Some packages are not included in some arch or fail to cross compile.
1481 : ${HOST_ARCH=i486}
1482 debug "Host arch $HOST_ARCH"
1483 # Handle arm{v6hf,v7,..}
1484 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1485 _ "cook: HOST_ARCH=\$HOST_ARCH"
1486 _ "cook: \$pkg doesn't cook or is not included in: \$ARCH"
1487 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1488 _ "Cook skip: \$pkg doesn't cook or is not included in: \$ARCH" | log
1489 sed -i /^${pkg}$/d $broken
1490 newline && exit 0
1491 fi
1493 # Skip blocked, 3 lines also for the Cooker.
1494 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1495 _ "Blocked package: \$pkg"; newline
1496 exit 0
1497 fi
1499 try_aufs_chroot "$@"
1501 # Log and source receipt.
1502 _ "Cook started for: <a href='cooker.cgi?pkg=\$pkg'>\$pkg</a>" | log
1503 echo "cook:$pkg" > $command
1505 # Display and log info if cook process stopped.
1506 # FIXME: gettext not working (in single quotes) here!
1507 trap '_ "\n\nCook stopped: control-C\n\n" | \
1508 tee -a $LOGS/$pkg.log' INT
1510 # Handle --options
1511 case "$2" in
1512 --clean|-c)
1513 _n "Cleaning: \$pkg"
1514 cd $WOK/$pkg && rm -rf install taz source
1515 status && newline && exit 0 ;;
1516 --install|-i)
1517 inst='yes' ;;
1518 --getsrc|-gs)
1519 _ "Getting source for: \$pkg"; separator
1520 get_source
1521 _ "Tarball: \$SRC/\$TARBALL"; newline
1522 exit 0 ;;
1523 --block|-b)
1524 _n "Blocking: \$pkg"
1525 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1526 status && newline && exit 0 ;;
1527 --unblock|-ub)
1528 _n "Unblocking: \$pkg"
1529 sed -i "/^${pkg}$/"d $blocked
1530 status && newline && exit 0 ;;
1531 --pack)
1532 if [ -d $WOK/$pkg/taz ]; then
1533 rm -rf $WOK/$pkg/taz
1534 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1535 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1536 clean_log
1537 else
1538 _ "Need to build \$pkg." && exit 0
1539 fi
1540 exit 0 ;;
1541 --cdeps)
1542 [ ! -d $WOK/$pkg/taz ] && _ "Need to build \$pkg." && exit 0
1543 _ "Checking depends"; separator
1544 lddlist=/tmp/lddlist; touch $lddlist
1545 missing=/var/cache/missing.file
1546 # find all deps using ldd
1547 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1548 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1549 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1550 done
1551 # remove exe/so duplicates
1552 sort -u $lddlist > $lddlist.sorted
1553 # search packages
1554 for exefile in $(cat $lddlist.sorted); do
1555 search_file $exefile
1556 echo $found >> $lddlist.pkgs
1557 echo -n "."
1558 done
1559 echo
1560 # remove packages duplicates
1561 sort -u $lddlist.pkgs > $lddlist.final
1562 sort -u $missing > $missing.final
1563 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1564 exit 0 ;;
1565 esac
1567 # Check if wanted is built now so we have separate log files.
1568 for wanted in $WANTED ; do
1569 if grep -q "^$wanted$" $blocked; then
1570 _ "WANTED package is blocked: \$wanted" | tee $LOGS/$pkg.log
1571 newline && rm -f $command && exit 1
1572 fi
1573 if grep -q "^$wanted$" $broken; then
1574 _ "WANTED package is broken: \$wanted" | tee $LOGS/$pkg.log
1575 newline && rm -f $command && exit 1
1576 fi
1577 if [ ! -d "$WOK/$wanted/install" ]; then
1578 cook "$wanted" || exit 1
1579 fi
1580 done
1582 # Cook and pack or exit on error and log everything.
1583 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1584 remove_deps | tee -a $LOGS/$pkg.log
1585 cookit_quality
1586 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1587 clean_log
1589 # Exit if any error in packing.
1590 lerror=$(_n "ERROR")
1591 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1592 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors)"; then
1593 debug_info | tee -a $LOGS/$pkg.log
1594 rm -f $command && exit 1
1595 fi
1597 # Create an XML feed
1598 gen_rss
1600 # Time and summary
1601 time=$(($(date +%s) - $time))
1602 summary | tee -a $LOGS/$pkg.log
1603 newline
1605 # We may want to install/update (outside aufs jail !).
1606 [ -s /aufs-umount.sh ] ||
1607 install_package
1609 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1610 # You want automation: use the Cooker Build Bot.
1611 rm -f $command ;;
1612 esac
1614 exit 0