cookutils view cook @ rev 707

cookall.sh: skip broken packages
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Mar 04 10:58:57 2015 +0100 (2015-03-04)
parents d81d9cd03f7b
children 4aeb98e0ff3c
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.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar xf - 2>/dev/null ;;
309 *.tar) tar xf $SRC/$TARBALL ;;
310 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
311 *.xz) unxz -c $SRC/$TARBALL | tar xf - || tar xf $SRC/$TARBALL 2>/dev/null;;
312 *.7z) 7zr x $SRC/$TARBALL ;;
313 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar xf - ;;
314 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
315 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
316 *) cp $SRC/$TARBALL $(pwd) ;;
317 esac
318 }
320 # Display cooked package summary.
321 summary() {
322 cd $WOK/$pkg
323 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
324 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
325 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
326 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
327 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
328 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
329 cookdate=$(date "$(_ '+%Y-%m-%d %H:%M')")
330 sec=$time
331 div=$(( ($time + 30) / 60))
332 # L10n: 'm' is for minutes (approximate cooking time)
333 min=$(_n "~ \${div}m"); [ "$div" = 0 ] && min=""
334 _ "Summary for: \$PACKAGE \$VERSION"
335 separator
336 # L10n: keep the same width of translations to get a consistent view
337 [ "$srcdir" ] && _ "Source dir : \$srcdir"
338 [ "$TARBALL" ] && _ "Src file : \$TARBALL"
339 [ "$srcsize" ] && _ "Src size : \$srcsize"
340 [ "$prod" ] && _ "Produced : \$prod"
341 _ "Packed : \$fs"
342 _ "Compressed : \$size"
343 _ "Files : \$files"
344 # L10n: 's' is for seconds (cooking time)
345 _ "Cook time : \${sec}s \$min"
346 _ "Cook date : \$cookdate"
347 _ "Host arch : \$ARCH"
348 separator
349 }
351 # Display debugging error info.
352 debug_info() {
353 newline; _ "Debug information"; separator
354 # L10n: specify your format of date and time (to help: man date)
355 # L10n: not bad one is '+%x %R'
356 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
357 _ "Cook date: \$datenow"
358 # L10n: Please, translate all messages beginning with ERROR in a same way
359 lerror=$(_n "ERROR")
360 for error in \
361 ERROR $lerror "No package" "cp: can't" "can't open" "can't cd" \
362 "error:" "fatal error:" "undefined reference to" \
363 "Unable to connect to" "link: cannot find the library" \
364 "CMake Error" ": No such file or directory"
365 do
366 fgrep "$error" $LOGS/$pkg.log
367 done > $LOGS/$pkg.log.debug_info 2>&1
368 cat $LOGS/$pkg.log.debug_info
369 rm -f $LOGS/$pkg.log.debug_info
370 separator; newline
371 }
373 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
374 # so some packages need to copy these files with the receipt and genpkg_rules.
375 copy_generic_files()
376 {
377 # $LOCALE is set in cook.conf
378 if [ "$LOCALE" -a "$WANTED" = "" ]; then
379 if [ -d "$install/usr/share/locale" ]; then
380 mkdir -p $fs/usr/share/locale
381 for i in $LOCALE
382 do
383 if [ -d "$install/usr/share/locale/$i" ]; then
384 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
385 fi
386 done
387 fi
388 fi
390 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
391 if [ "$GENERIC_PIXMAPS" != "no" ]; then
392 if [ -d "$install/usr/share/pixmaps" ]; then
393 mkdir -p $fs/usr/share/pixmaps
394 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
395 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
396 $fs/usr/share/pixmaps
397 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
398 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
399 $fs/usr/share/pixmaps
400 fi
401 fi
403 # Custom or homemade PNG pixmap can be in stuff.
404 if [ -f "$stuff/$PACKAGE.png" ]; then
405 mkdir -p $fs/usr/share/pixmaps
406 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
407 fi
408 fi
410 # Desktop entry (.desktop).
411 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
412 if [ "$GENERIC_MENUS" != "no" ]; then
413 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
414 mkdir -p $fs/usr/share
415 cp -a $install/usr/share/applications $fs/usr/share
416 fi
417 fi
419 # Homemade desktop file(s) can be in stuff.
420 if [ -d "$stuff/applications" ]; then
421 mkdir -p $fs/usr/share
422 cp -a $stuff/applications $fs/usr/share
423 fi
424 if [ -f "$stuff/$PACKAGE.desktop" ]; then
425 mkdir -p $fs/usr/share/applications
426 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
427 fi
429 # Add custom licenses
430 if [ -d "$stuff/licenses" ]; then
431 mkdir -p $fs/usr/share/licenses
432 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
433 fi
434 }
436 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
437 # as removing unneeded files like in Python packages. Cross compiled binaries
438 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
439 strip_package() {
440 case "$ARCH" in
441 arm*|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
442 *) export STRIP=strip ;;
443 esac
444 _n "Executing strip on all files..."
445 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
446 do
447 if [ -d "$dir" ]; then
448 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
449 fi
450 done
451 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
452 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
453 status
455 # Remove Python .pyc and .pyo from packages.
456 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
457 _n "Removing Python compiled files..."
458 find $fs -type f -name "*.pyc" -delete 2>/dev/null
459 find $fs -type f -name "*.pyo" -delete 2>/dev/null
460 status
461 fi
463 # Remove Perl perllocal.pod and .packlist from packages.
464 if echo "$DEPENDS" | fgrep -q "perl"; then
465 _n "Removing Perl compiled files..."
466 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
467 find $fs -type f -name ".packlist" -delete 2>/dev/null
468 status
469 fi
470 }
472 # Remove installed deps.
473 remove_deps() {
474 # Now remove installed build deps.
475 diff="/tmp/installed.cook.diff"
476 if [ -s $diff ]; then
477 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
478 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
479 _n "Build dependencies to remove: "; echo $nb $root
480 _n "Removing:"
481 for dep in $deps
482 do
483 echo -n " $dep"
484 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
485 done
486 newline; newline
487 # Keep the last diff for debug and info.
488 mv -f $diff $CACHE/installed.diff
489 fi
490 }
492 # The main cook function.
493 cookit() {
494 _ "Cook: \$PACKAGE \$VERSION"; separator
495 set_paths
497 # Handle cross-tools.
498 case "$ARCH" in
499 arm*|x86_64)
500 # CROSS_COMPILE is used by at least Busybox and the kernel to set
501 # the cross-tools prefix. Sysroot is the root of our target arch
502 sysroot=$CROSS_TREE/sysroot
503 tools=$CROSS_TREE/tools
504 # Set root path when cross compiling. ARM tested but not x86_64
505 # When cross compiling we must install build deps in $sysroot.
506 arch="-${ARCH}"
507 root=$sysroot
508 _ "\$ARCH sysroot: \$sysroot"
509 _ "Adding \$tools/bin to PATH"
510 export PATH=$PATH:$tools/bin
511 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
512 export CROSS_COMPILE=${HOST_SYSTEM}-
513 _ "Using cross-tools: \$CROSS_COMPILE"
514 if [ "$ARCH" == "x86_64" ]; then
515 export CC="${HOST_SYSTEM}-gcc -m64"
516 export CXX="${HOST_SYSTEM}-g++ -m64"
517 else
518 export CC=${HOST_SYSTEM}-gcc
519 export CXX=${HOST_SYSTEM}-g++
520 fi
521 export AR=${HOST_SYSTEM}-ar
522 export AS=${HOST_SYSTEM}-as
523 export RANLIB=${HOST_SYSTEM}-ranlib
524 export LD=${HOST_SYSTEM}-ld
525 export STRIP=${HOST_SYSTEM}-strip
526 export LIBTOOL=${HOST_SYSTEM}-libtool ;;
527 esac
529 [ "$QA" ] && receipt_quality
530 cd $pkgdir
531 [ "$continue" ] || rm -rf source 2> /dev/null
532 rm -rf install taz 2> /dev/null
534 # Disable -pipe if less than 512Mb free RAM.
535 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
536 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
537 _ "Disabling -pipe compile flag: \$free RAM"
538 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
539 CXXFLAGS="${CXXFLAGS/-pipe}" && CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
540 fi
541 unset free
543 # Export flags and path to be used by make and receipt.
544 DESTDIR=$pkgdir/install
545 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
546 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
547 #LDFLAGS
549 # Check for build deps and handle implicit depends of *-dev packages
550 # (ex: libusb-dev :: libusb).
551 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
552 touch $CACHE/installed.local $CACHE/installed.web
553 [ "$BUILD_DEPENDS" ] && _ "Checking build dependencies..."
554 [ "$root" ] && _ "Using packages DB: \${root}\$DB"
555 for dep in $BUILD_DEPENDS
556 do
557 implicit=${dep%-dev}
558 for i in $dep $implicit
559 do
560 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
561 # Try local package first. In some cases implicit doesn't exist, ex:
562 # libboost-dev exists but not libboost, so check if we got vers.
563 unset vers
564 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
565 # We may have a local package.
566 if [ ! "$vers" ]; then
567 vers=$(grep "^$i |" $PKGS/packages.desc | awk '{print $3}')
568 fi
569 debug "bdep: $i version: $vers"
570 if [ -f "$PKGS/$i-${vers}${arch}.tazpkg" ]; then
571 echo $i-${vers}${arch}.tazpkg >> $CACHE/installed.local
572 else
573 # Priority to package version in wok (maybe more up-to-date)
574 # than the mirrored one.
575 if [ "$vers" ]; then
576 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
577 echo $i >> $CACHE/installed.web
578 else
579 # So package exists in wok but not available.
580 _ "Missing dep (wok/pkg): \$i \$vers"
581 echo $i >> $CACHE/missing.dep
582 fi
583 else
584 # Package is not in wok but may be in online repo.
585 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
586 echo $i >> $CACHE/installed.web
587 else
588 _ "ERROR: unknown dep \$i"; exit 1
589 fi
590 fi
591 fi
592 fi
593 done
594 done
596 # Get the list of installed packages
597 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.list
599 # Have we a missing build dep to cook?
600 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
601 _ "Auto cook config is set: AUTO_COOK"
602 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
603 for i in $(uniq $CACHE/missing.dep)
604 do
605 (_ "Building dep (wok/pkg) : \$i \$vers") | \
606 tee -a $LOGS/$PACKAGE.log.$$
607 # programmers: next two messages are exact copy from remove_deps()
608 togrep1=$(_n "Build dependencies to remove: ")
609 togrep2=$(_n "Removing:")
610 cook $i || (_ "ERROR: can't cook dep '\$i'" && newline && \
611 fgrep $togrep1 $LOGS/$i.log && \
612 fgrep $togrep2 $LOGS/$i.log && newline) | \
613 tee -a $LOGS/$PACKAGE.log.$$ && break
614 done
615 rm -f $CACHE/missing.dep
616 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
617 fi
619 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
620 # is enabled and cook fails we have ERROR in log, if no auto cook we have
621 # missing dep in cached file.
622 lerror=$(_n "ERROR")
623 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
624 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
625 _ "ERROR: missing dep \$nb" && exit 1
626 fi
628 # Install local packages: package-version${arch}
629 cd $PKGS
630 for i in $(uniq $CACHE/installed.local)
631 do
632 _ "Installing dep (pkg/local): \$i"
633 tazpkg install $i --root=$root >/dev/null
634 done
636 # Install web or cached packages (if mirror is set to $PKGS we only
637 # use local packages).
638 for i in $(uniq $CACHE/installed.web)
639 do
640 _ "Installing dep (web/cache): \$i"
641 tazpkg get-install $i --root=$root >/dev/null
642 done
644 # If a cook failed deps are removed.
645 cd ${root}$INSTALLED && ls -1 > $CACHE/installed.cook && cd $CACHE
646 [ ! -s "/tmp/installed.cook.diff" ] && \
647 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
648 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
650 # Get source tarball and make sure we have source dir named:
651 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
652 # tarball if it exists.
653 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
654 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
655 TARBALL=${SOURCE:-$PACKAGE}-$VERSION.tar.lzma
656 LZMA_SRC=""
657 else
658 get_source || exit 1
659 fi
660 fi
661 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! -d "$src" ]; then
662 mkdir -p $pkgdir/source/tmp && cd $pkgdir/source/tmp
663 if ! extract_source ; then
664 get_source
665 extract_source || exit 1
666 fi
667 if [ "$LZMA_SRC" ]; then
668 cd $pkgdir/source
669 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
670 mv tmp tmp-1 && mkdir tmp
671 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
672 fi
673 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
674 cd tmp && tar -c * | lzma e $SRC/$TARBALL -si
675 fi
676 fi
677 cd $pkgdir/source/tmp
678 # Some archives are not well done and don't extract to one dir (ex lzma).
679 files=$(ls | wc -l)
680 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
681 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
682 mv * ../$PACKAGE-$VERSION/$TARBALL
683 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
684 mv * ../$PACKAGE-$VERSION
685 cd .. && rm -rf tmp
686 fi
688 # Libtool shared libs path hack.
689 case "$ARCH" in
690 arm*) cross libhack ;;
691 esac
693 # Execute receipt rules.
694 if grep -q ^compile_rules $receipt; then
695 _ "Executing: compile_rules"
696 echo "CFLAGS : $CFLAGS"
697 #echo "LDFLAGS : $LDFLAGS"
698 [ -d "$src" ] && cd $src
699 compile_rules $@ || exit 1
700 # Stay compatible with _pkg
701 [ -d "$src/_pkg" ] && mv $src/_pkg $install
702 # QA: compile_rules success so valid.
703 mkdir -p $install
704 else
705 # QA: no compile_rules so no error, valid.
706 mkdir -p $install
707 fi
708 separator; newline
710 # Execute testsuite.
711 if grep -q ^testsuite $receipt; then
712 _ "Running testsuite"; separator
713 testsuite $@ || exit 1
714 separator; newline
715 fi
716 }
718 # Cook quality assurance.
719 cookit_quality() {
720 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
721 _ "ERROR: cook failed" | tee -a $LOGS/$pkg.log
722 fi
723 # ERROR can be echoed any time in cookit()
724 lerror=$(_n "ERROR")
725 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
726 grep -Eq "(^$lerror|undefined reference to)" ; then
727 debug_info | tee -a $LOGS/$pkg.log
728 rm -f $command && exit 1
729 fi
730 }
732 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
733 # but it doesn't handle EXTRAVERSION.
734 packit() {
735 set_paths
737 # Handle cross compilation
738 case "$ARCH" in
739 arm*|x86_64) arch="-$ARCH" ;;
740 esac
742 _ "Pack: \$PACKAGE \${VERSION}\${arch}"; separator
744 if grep -q ^genpkg_rules $receipt; then
745 _ "Executing: genpkg_rules"
746 set -e && cd $pkgdir && mkdir -p $fs
747 genpkg_rules || (newline; _ "ERROR: genpkg_rules failed"; newline) >> \
748 $LOGS/$pkg.log
749 else
750 _ "No packages rules: meta package"
751 mkdir -p $fs
752 fi
754 # First QA check to stop now if genpkg_rules failed.
755 lerror=$(_n "ERROR")
756 if fgrep -q ^$lerror $LOGS/$pkg.log; then
757 exit 1
758 fi
760 cd $taz
761 for file in receipt description.txt
762 do
763 [ ! -f "../$file" ] && continue
764 _n "Copying \$file..."
765 cp -f ../$file $pack && chown 0.0 $pack/$file && status
766 done
767 copy_generic_files
769 # Create files.list with redirecting find output.
770 _n "Creating the list of files..."
771 cd $fs
772 find . -type f -print > ../files.list
773 find . -type l -print >> ../files.list
774 cd .. && sed -i s/'^.'/''/ files.list
775 status
777 # Strip and stuff files.
778 strip_package
780 # Md5sum of files.
781 _n "Creating md5sum of files..."
782 while read file; do
783 [ -L "fs$file" ] && continue
784 [ -f "fs$file" ] || continue
785 case "$file" in
786 /lib/modules/*/modules.*|*.pyc) continue ;;
787 esac
788 md5sum "fs$file" | sed 's/ fs/ /'
789 done < files.list > md5sum
790 status
791 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum \
792 description.txt 2> /dev/null | awk \
793 '{ sz=$1 } END { print sz }')
795 # Build cpio archives.
796 _n "Compressing the fs..."
797 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
798 rm -rf fs
799 status
800 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
801 md5sum description.txt 2> /dev/null | awk \
802 '{ sz=$1 } END { print sz }')
803 _n "Updating receipt sizes..."
804 sed -i s/^PACKED_SIZE.*$// receipt
805 sed -i s/^UNPACKED_SIZE.*$// receipt
806 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
807 status
809 # Set extra version.
810 if [ "$EXTRAVERSION" ]; then
811 _n "Updating receipt EXTRAVERSION: \$EXTRAVERSION"
812 sed -i s/^EXTRAVERSION.*$// receipt
813 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
814 status
815 fi
817 # Compress.
818 _n "Creating full cpio archive..."
819 find . -print | cpio -o -H newc --quiet > \
820 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
821 status
822 _n "Restoring original package tree..."
823 unlzma -c fs.cpio.lzma | cpio -idm --quiet
824 status
825 rm fs.cpio.lzma && cd ..
827 # QA and give info.
828 tazpkg=$(ls *.tazpkg)
829 packit_quality
830 separator; _ "Package: \$tazpkg"; newline
831 }
833 # Verify package quality and consistency.
834 packit_quality() {
835 #gettext "QA: checking for broken link..."
836 #link=$(find $fs/usr -type l -follow)
837 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
838 #status
840 # Exit if any error found in log file.
841 lerror=$(_n "ERROR")
842 if fgrep -q ^$lerror $LOGS/$pkg.log; then
843 rm -f $command && exit 1
844 fi
846 _n "QA: checking for empty package..."
847 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
848 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
849 newline; _ "ERROR: empty package"
850 rm -f $command && exit 1
851 else
852 # Ls sort by name so the first file is the one we want.
853 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n 1)
854 status
855 if [ -f "$old" ]; then
856 old_pkg=$(basename $old)
857 _n "Removing old: \$old_pkg"
858 rm -f $old && status
859 fi
860 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
861 sed -i /^${pkg}$/d $broken
862 #gettext "Removing source tree..."
863 #rm -f $WOK/$pkg/source && status
864 fi
865 }
867 # Tic tac, tic tac...
868 tac() {
869 sed '1!G;h;$!d' $1
870 }
872 # Install package on --install or update the chroot.
873 install_package() {
874 case "$ARCH" in
875 arm*|x86_64)
876 arch="-${ARCH}"
877 root=$CROSS_TREE/sysroot ;;
878 esac
879 # Install package if requested but skip install if target host doesn't
880 # match build system or it will break the build chroot.
881 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
882 if [ "$inst" ] && [ "$build" == "$ARCH" ]; then
883 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
884 cd $PKGS && tazpkg install \
885 $PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg --forced
886 else
887 _ "Unable to install package, build has failed."; newline
888 exit 1
889 fi
890 fi
892 # Install package if part of the chroot to keep env up-to-date.
893 if [ -d "${root}$INSTALLED/$pkg" ]; then
894 . /etc/slitaz/cook.conf
895 . $WOK/$pkg/taz/$pkg-*/receipt
896 _ "Updating \$ARCH chroot environment..."
897 _ "Updating chroot: \$pkg (\${VERSION}\${EXTRAVERSION}\${arch})" | log
898 cd $PKGS && tazpkg install \
899 $pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
900 --forced --root=$root
901 fi
902 }
904 # remove chroot jail
905 umount_aufs() {
906 tac ${1}rw/aufs-umount.sh | sh
907 rm -rf ${1}rw
908 umount ${1}root
909 rmdir ${1}r*
910 }
912 # Launch the cook command into a chroot jail protected by aufs.
913 # The current filesystems are used read-only and updates are
914 # stored in a separate branch.
915 try_aufs_chroot() {
917 base=/dev/shm/aufsmnt$$
919 # Can we setup the chroot? Is it already done?
920 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
921 grep -q ^AUFS_NOT_RAMFS $receipt && base=/mnt/aufsmnt$$
922 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
923 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
924 mkdir ${base}root ${base}rw || return
926 _ "Setup aufs chroot..."
928 # Sanity check
929 for i in / /proc /sys /dev/shm /home ; do
930 case " $AUFS_MOUNTS " in
931 *\ $i\ *) ;;
932 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
933 esac
934 done
935 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
936 mount --bind $mnt ${base}root$mnt
937 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
938 _ "Aufs mountage failure"
939 umount ${base}root
940 rm -rf ${base}r*
941 return
942 fi
943 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
944 done
945 trap "umount_aufs ${base}" INT
947 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
948 status=$?
950 _ "Leaving aufs chroot..."
951 umount_aufs ${base}
952 # Install package outside the aufs jail
953 install_package
954 exit $status
955 }
957 # Encode predefined XML entities
958 xml_ent() {
959 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
960 }
962 # Create a XML feed for freshly built packages.
963 gen_rss() {
964 pubdate=$(date "+%a, %d %b %Y %X")
965 cat > $FEEDS/$pkg.xml << EOT
966 <item>
967 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
968 <link>${COOKER_URL}?pkg=$PACKAGE</link>
969 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
970 <pubDate>$pubdate</pubDate>
971 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
972 </item>
973 EOT
974 }
976 # Truncate stdout log file to $1 Mb.
977 loglimit()
978 {
979 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
980 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
981 else
982 tee /dev/stderr
983 fi
984 }
986 # Search file in mirrored packages
987 search_file_mirror()
988 {
989 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
990 }
992 # Search file in local wok packages
993 search_file_local()
994 {
995 # existing packages have precedence over the package/taz folder
996 srch=$1
997 { for package in $(find $PKGS -name '*.tazpkg'); do
998 if [ ! "x$(busybox cpio --to-stdout --quiet -i files.list < $package | grep /$srch\$)" == "x" ]; then
999 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1000 fi
1001 done } | sort -u
1004 # Ask in multiple choice
1005 ask_multiple()
1007 local multiples first my_choice
1008 multiples="$1"
1009 first=$(echo "$multiples" | head -n1)
1010 newline; _ "Multiple choice:\n$multiples\n"
1011 _ "Select one [$first]: "; read my_choice
1012 [ "x$my_choice" == "x" ] && my_choice="$first"
1013 found=$my_choice
1016 # Search file in local cache (fast), local wok packages, mirrored packages
1017 search_file()
1019 local srch cache missing
1020 srch=$1
1021 cache=/var/cache/ldsearch.cache
1022 missing=/var/cache/missing.file
1023 touch $cache $missing
1024 found=$(grep $srch $cache | cut -d' ' -f2)
1025 if [ "x$found" == "x" ]; then
1026 found=$(search_file_local $srch)
1027 if [ "x$found" != "x" ]; then
1028 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1029 ask_multiple "$found"
1030 fi
1031 echo "$srch $found" >> $cache
1032 else
1033 found=$(search_file_mirror $srch)
1034 if [ "x$found" != "x" ]; then
1035 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1036 ask_multiple "$found"
1037 fi
1038 echo "$srch $found" >> $cache
1039 else
1040 echo "$srch" >> $missing
1041 fi
1042 fi
1043 fi
1047 # Receipt functions to ease packaging
1050 get_dev_files() {
1051 _n "Getting standard devel files..."
1052 mkdir -p $fs/usr/lib
1053 cp -a $install/usr/lib/*.so* $fs/usr/lib
1054 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1055 cp -a $install/usr/include $fs/usr
1056 status
1060 # Commands
1063 case "$1" in
1064 usage|help|-u|-h)
1065 usage ;;
1066 list-wok)
1067 newline; _ "List of \$ARCH packages in: \$WOK"; separator
1068 cd $WOK
1069 if [ "$ARCH" != "i486" ]; then
1070 count=0
1071 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d : -f 1)
1072 do
1073 unset HOST_ARCH
1074 . $pkg
1075 count=$(($count + 1))
1076 colorize 34 "$PACKAGE"
1077 done
1078 else
1079 count=$(ls | wc -l)
1080 ls -1
1081 fi
1082 separator
1083 _n "Packages:"; colorize 32 " $count"
1084 newline ;;
1085 activity)
1086 cat $activity ;;
1087 search)
1088 # Just a simple search function, we dont need more actually.
1089 query="$2"
1090 newline; _ "Search results for: \$query"; separator
1091 cd $WOK && ls -1 | grep "$query"
1092 separator; newline ;;
1093 setup)
1094 # Setup a build environment
1095 check_root
1096 _ "Cook: setup environment" | log
1097 newline; _ "Setting up your environment"; separator
1098 cd $SLITAZ
1099 init_db_files
1100 _ "Checking for packages to install..."
1101 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1102 # ARCH-setup or 'cross check' should be used before: cook setup
1103 case "$ARCH" in
1104 arm*|x86_64)
1105 if [ ! -x "/usr/bin/cross" ]; then
1106 _ "ERROR: cross is not installed"
1107 exit 1
1108 fi
1109 _ "Using config file: /etc/slitaz/cross.conf"
1110 . /etc/slitaz/cross.conf ;;
1111 esac
1112 for pkg in $SETUP_PKGS; do
1113 if [ "$forced" ]; then
1114 tazpkg -gi $pkg --forced
1115 else
1116 [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg
1117 fi
1118 done
1120 # Handle --options
1121 case "$2" in
1122 --wok)
1123 hg clone $WOK_URL wok || exit 1 ;;
1124 --stable)
1125 hg clone $WOK_URL-stable wok || exit 1 ;;
1126 --undigest)
1127 hg clone $WOK_URL-undigest wok || exit 1 ;;
1128 --tiny)
1129 hg clone $WOK_URL-tiny wok || exit 1 ;;
1130 esac
1132 # SliTaz group and permissions
1133 if ! grep -q ^slitaz /etc/group; then
1134 _ "Adding group: slitaz"
1135 addgroup slitaz
1136 fi
1137 _ "Setting permissions for slitaz group..."
1138 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1139 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1140 separator; _ "All done, ready to cook packages :-)"; newline ;;
1141 *-setup)
1142 # Setup for cross compiling.
1143 arch=${1%-setup}
1144 check_root
1145 . /etc/slitaz/cook.conf
1146 for pkg in $CROSS_SETUP; do
1147 if [ "$forced" ]; then
1148 tazpkg -gi $pkg --forced
1149 else
1150 [ -d "$INSTALLED/$pkg" ] || tazpkg -gi $pkg
1151 fi
1152 done
1153 _ "Cook: setup \$arch cross environment" | log
1154 newline; boldify $(_n "Setting up your \$arch cross environment"); separator
1155 init_db_files
1156 sed -i \
1157 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1158 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1159 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1160 /etc/slitaz/cook.conf
1161 case "$arch" in
1162 arm)
1163 flags="-O2 -march=armv6"
1164 host="$ARCH-slitaz-linux-gnueabi" ;;
1165 armv6hf)
1166 flags="-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard"
1167 host="$ARCH-slitaz-linux-gnueabi" ;;
1168 armv7)
1169 flags="-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe"
1170 host="$ARCH-slitaz-linux-gnueabi" ;;
1171 x86_64)
1172 flags="-O2 -mtune=generic -pipe"
1173 host="$ARCH-slitaz-linux" ;;
1174 esac
1175 sed -i \
1176 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1177 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1178 . /etc/slitaz/cook.conf
1179 sysroot=$CROSS_TREE/sysroot
1180 tools=/cross/$arch/tools
1181 root=$sysroot
1182 # L10n: keep the same width of translations to get a consistent view
1183 _ "Target arch : \$ARCH"
1184 _ "Configure args : \$CONFIGURE_ARGS"
1185 _ "Build flags : \$flags"
1186 _ "Arch sysroot : \$sysroot"
1187 _ "Tools prefix : \$tools/bin"
1188 # Tell the packages manager where to find packages.
1189 _ "Packages DB : \${root}\$DB"
1190 mkdir -p ${root}$INSTALLED
1191 cd ${root}$DB && rm -f *.bak
1192 for list in packages.list packages.desc packages.equiv packages.md5
1193 do
1194 rm -f $list && ln -s $SLITAZ/packages/$list $list
1195 done
1196 # We must have the cross compiled glibc-base installed or default
1197 # i486 package will be used as dep by tazpkg and then break the
1198 # cross environment
1199 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1200 colorize 36 $(_ "WARNING: (e)glibc-base is not installed in sysroot")
1201 fi
1202 # Show GCC version or warn if not yet compiled.
1203 if [ -x "$tools/bin/${HOST_SYSTEM}-gcc" ]; then
1204 _ "Cross compiler : \${HOST_SYSTEM}-gcc"
1205 else
1206 colorize 36 $(_ "C compiler is missing: \${HOST_SYSTEM}-gcc")
1207 _ "Run 'cross compile' to cook a toolchain"
1208 fi
1209 separator; newline ;;
1210 test)
1211 # Test a cook environment.
1212 _ "Cook test: testing the cook environment" | log
1213 [ ! -d "$WOK" ] && exit 1
1214 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1215 cook cooktest ;;
1216 new)
1217 # Create the package folder and an empty receipt.
1218 pkg="$2"
1219 [ "$pkg" ] || usage
1220 newline
1221 if [ -d "$WOK/$pkg" ]; then
1222 _ "\$pkg package already exists."
1223 exit 1
1224 fi
1225 _n "Creating \$WOK/\$pkg"
1226 mkdir $WOK/$pkg && cd $WOK/$pkg && status
1227 _n "Preparing the package receipt..."
1228 cp $DATA/receipt .
1229 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1230 status && newline
1232 # Interactive mode, asking and seding.
1233 case "$3" in
1234 --interactive|-x)
1235 _ "Entering interactive mode..."
1236 separator
1237 _ "Package : \$pkg"
1238 _n "Version : " ; read answer
1239 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1240 _n "Category : " ; read answer
1241 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1242 # L10n: Short description
1243 _n "Short desc : " ; read answer
1244 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1245 _n "Maintainer : " ; read answer
1246 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1247 _n "License : " ; read answer
1248 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1249 _n "Web site : " ; read answer
1250 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1251 newline
1252 # Wget URL.
1253 _ "Wget URL to download source tarball."
1254 _n "Example : " ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1255 _n "Wget url : " ; read answer
1256 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$answer\""# receipt
1257 # Ask for a stuff dir.
1258 _n "Do you need a stuff directory? (y/N) : " ; read answer
1259 if [ "$answer" = "y" ]; then
1260 _n "Creating the stuff directory..."
1261 mkdir $WOK/$pkg/stuff && status
1262 fi
1263 # Ask for a description file.
1264 _n "Are you going to write a description? (y/N) : " ; read answer
1265 if [ "$answer" = "y" ]; then
1266 _n "Creating the description.txt file..."
1267 newline > $WOK/$pkg/description.txt && status
1268 fi
1269 separator; _ "Receipt is ready to use."; newline ;;
1270 esac ;;
1271 list)
1272 # Cook a list of packages (better use the Cooker since it will order
1273 # packages before executing cook).
1274 check_root
1275 [ -z "$2" ] && (newline; _ "No list in argument."; newline) && exit 1
1276 list2=$2
1277 [ ! -f "$2" ] && (newline; _ "No list found: \$list2"; newline) && exit 1
1278 _ "Cook list starting: \$list2" | log
1279 for pkg in $(cat $2)
1280 do
1281 cook $pkg || broken
1282 done ;;
1283 clean-wok)
1284 check_root
1285 newline; _n "Cleaning all packages files..."
1286 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1287 status; newline ;;
1288 clean-src)
1289 check_root
1290 newline; _n "Cleaning all packages sources..."
1291 rm -rf $WOK/*/source
1292 status; newline ;;
1293 uncook)
1294 cd $WOK
1295 count=0
1296 newline
1297 _ "Checking for uncooked packages"
1298 separator
1299 for pkg in *
1300 do
1301 unset HOST_ARCH EXTRAVERSION
1302 . $pkg/receipt
1303 # Source cooked pkg receipt to get EXTRAVERSION
1304 if [ -d "$WOK/$pkg/taz" ]; then
1305 cd $WOK/$pkg/taz/$pkg-*
1306 . receipt && cd $WOK
1307 fi
1308 case "$ARCH" in
1309 i486)
1310 debug "Package: $PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}.tazpkg"
1311 if [ ! -f "$PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}.tazpkg" ]; then
1312 count=$(($count + 1))
1313 colorize 34 "$pkg"
1314 fi ;;
1315 arm*)
1316 # Check only packages included in arch
1317 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1318 # *.tazpkg
1319 if [ ! -f "$PKGS/${PACKAGE}-${VERSION}${EXTRAVERSION}-${ARCH}.tazpkg" ]; then
1320 count=$(($count + 1))
1321 colorize 34 "$pkg"
1322 fi
1323 fi ;;
1324 esac
1325 done
1326 if [ "$count" -gt "0" ]; then
1327 separator
1328 _n "Uncooked packages: "; colorize 31 "$count"
1329 else
1330 _ "All packages are cooked :-)"
1331 fi
1332 newline ;;
1333 pkgdb)
1334 # Create suitable packages list for TazPKG and only for built packages
1335 # as well as flavors files for TazLiTo. We dont need logs since we do it
1336 # manually to ensure everything is fine before syncing the mirror.
1337 case "$2" in
1338 --flavors)
1339 continue ;;
1340 *)
1341 [ "$2" ] && PKGS="$2"
1342 [ ! -d "$PKGS" ] && \
1343 newline && _ "Packages directory doesn't exist" && \
1344 newline && exit 1 ;;
1345 esac
1346 time=$(date +%s)
1347 flavors=$SLITAZ/flavors
1348 live=$SLITAZ/live
1349 echo "cook:pkgdb" > $command
1350 _ "Cook pkgdb: Creating all packages lists" | log
1351 newline; _ "Creating lists for: \$PKGS"; separator
1352 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1353 _ "Cook pkgdb started: \$datenow"
1354 cd $PKGS
1355 rm -f packages.* extra.list
1356 ln -s ../get.list extra.list
1357 _ "Creating: packages.list"
1358 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1359 _ "Creating: packages.md5"
1360 md5sum *.tazpkg > $PKGS/packages.md5
1361 md5sum packages.md5 | cut -f1 -d' ' > ID
1362 _ "Creating lists from: \$WOK"
1363 cd $WOK
1364 for pkg in *
1365 do
1366 unset_receipt
1367 . $pkg/receipt
1368 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1369 if [ -s $pkg/taz/*/receipt ]; then
1370 . $pkg/taz/*/receipt
1371 fi
1372 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}.tazpkg" ] || \
1373 [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}-${ARCH}.tazpkg" ]; then
1375 # packages.desc lets us search easily in DB
1376 cat >> $PKGS/packages.desc << EOT
1377 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1378 EOT
1380 # packages.txt used by tazpkg and tazpkg-web also to provide
1381 # a human readable package list with version and description.
1382 cat >> $PKGS/packages.txt << EOT
1383 $PACKAGE
1384 ${VERSION}$EXTRAVERSION
1385 $SHORT_DESC
1386 $PACKED_SIZE ($UNPACKED_SIZE installed)
1388 EOT
1390 # packages.info combines two previous files
1391 # and will substitute them both
1392 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1393 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1394 cat >> $PKGS/packages.info << EOT
1395 $PACKAGE ${VERSION}$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS
1396 EOT
1398 # packages.equiv is used by tazpkg install to check depends.
1399 for i in $PROVIDE; do
1400 DEST=""
1401 echo $i | fgrep -q : && DEST="${i#*:}:"
1402 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1403 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1404 $PKGS/packages.equiv
1405 else
1406 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1407 fi
1408 done
1410 # files.list provides a list of all packages files.
1411 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1412 $PKGS/files.list
1413 fi
1414 done
1416 # Display list size.
1417 _ "Done: packages.desc"
1418 _ "Done: packages.txt"
1419 _ "Done: packages.equiv"
1421 # files.list.lzma
1422 _ "Creating: files.list.lzma"
1423 touch $PKGS/files.list
1424 cd $PKGS; lzma e files.list files.list.lzma
1425 rm -f files.list
1427 # packages.info.lzma
1428 PI=packages.info
1429 _ 'Creating: packages.info.lzma'
1430 touch $PKGS/$PI
1431 cd $PKGS; lzma e $PI $PI.lzma
1432 rm -f $PI
1434 # Display some info.
1435 separator
1436 nb=$(ls $PKGS/*.tazpkg | wc -l)
1437 time=$(($(date +%s) - $time))
1438 # L10n: 's' is for seconds (cooking time)
1439 _ "Packages: \$nb - Time: \${time}s"; newline
1441 # Create all flavors files at once. Do we really need code to monitor
1442 # flavors changes? Lets just build them with packages lists before
1443 # syncing the mirror.
1444 [ "$2" == "--flavors" ] || exit 1
1445 [ ! -d "$flavors" ] && (_ "Missing flavors: \$flavors"; newline) && exit 1
1446 [ -d "$live" ] || mkdir -p $live
1447 _ "Creating flavors files in: \$live"
1448 _ "Cook pkgdb: Creating all flavors" | log
1449 separator
1450 _ "Recharging lists to use latest packages..."
1451 tazpkg recharge >/dev/null 2>/dev/null
1453 # We need a custom tazlito config to set working dir to /home/slitaz.
1454 if [ ! -f "$live/tazlito.conf" ]; then
1455 _ "Creating configuration file: tazlito.conf"
1456 cp /etc/tazlito/tazlito.conf $live
1457 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1458 $live/tazlito.conf
1459 fi
1461 # Update Hg flavors repo and pack.
1462 [ -d "$flavors/.hg" ] && cd $flavors && hg pull -u
1464 cd $live
1465 _ "Starting to generate flavors..."
1466 rm -f flavors.list *.flavor
1467 for i in $flavors/*
1468 do
1469 fl=$(basename $i)
1470 _ "Packing flavor: \$fl"
1471 tazlito pack-flavor $fl >/dev/null || exit 1
1472 tazlito show-flavor $fl --brief --noheader 2> \
1473 /dev/null >> flavors.list
1474 done
1475 cp -f $live/*.flavor $live/flavors.list $PKGS
1476 separator
1477 fl_size=$(du -sh $live | awk '{print $1}')
1478 _ "Flavors size: \$fl_size"; newline
1479 rm -f $command
1480 separator
1481 datenow=$(date "$(_ '+%Y-%m-%d %H:%M')")
1482 _ "Cook pkgdb end: \$datenow" ;;
1483 *)
1484 # Just cook and generate a package.
1485 check_root
1486 time=$(date +%s)
1487 pkg="$1"
1488 [ -z "$pkg" ] && usage
1489 receipt="$WOK/$pkg/receipt"
1490 check_pkg_in_wok && newline
1492 unset inst
1493 unset_receipt
1494 . $receipt
1496 # Handle cross compilation.
1497 case "$ARCH" in
1498 arm*)
1499 if [ ! "$HOST_ARCH" ]; then
1500 _ "cook: HOST_ARCH is not set in \$pkg receipt"
1501 _ "cook: This package is not included in: \$ARCH"
1502 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1503 _ "Cook skip: \$pkg is not included in: \$ARCH" | log
1504 newline && exit 1
1505 fi ;;
1506 esac
1508 # Some packages are not included in some arch or fail to cross compile.
1509 : ${HOST_ARCH=i486}
1510 debug "Host arch $HOST_ARCH"
1511 # Handle arm{v6hf,v7,..}
1512 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1513 _ "cook: HOST_ARCH=\$HOST_ARCH"
1514 _ "cook: \$pkg doesn't cook or is not included in: \$ARCH"
1515 [ "$CROSS_BUGS" ] && _ "bugs: \$CROSS_BUGS"
1516 _ "Cook skip: \$pkg doesn't cook or is not included in: \$ARCH" | log
1517 sed -i /^${pkg}$/d $broken
1518 newline && exit 0
1519 fi
1521 # Skip blocked, 3 lines also for the Cooker.
1522 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1523 _ "Blocked package: \$pkg"; newline
1524 exit 0
1525 fi
1527 try_aufs_chroot "$@"
1529 # Log and source receipt.
1530 _ "Cook started for: <a href='cooker.cgi?pkg=\$pkg'>\$pkg</a>" | log
1531 echo "cook:$pkg" > $command
1533 # Display and log info if cook process stopped.
1534 # FIXME: gettext not working (in single quotes) here!
1535 trap '_ "\n\nCook stopped: control-C\n\n" | \
1536 tee -a $LOGS/$pkg.log' INT
1538 # Handle --options
1539 case "$2" in
1540 --clean|-c)
1541 _n "Cleaning: \$pkg"
1542 cd $WOK/$pkg && rm -rf install taz source
1543 status && newline && exit 0 ;;
1544 --install|-i)
1545 inst='yes' ;;
1546 --getsrc|-gs)
1547 _ "Getting source for: \$pkg"; separator
1548 get_source
1549 _ "Tarball: \$SRC/\$TARBALL"; newline
1550 exit 0 ;;
1551 --block|-b)
1552 _n "Blocking: \$pkg"
1553 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1554 status && newline && exit 0 ;;
1555 --unblock|-ub)
1556 _n "Unblocking: \$pkg"
1557 sed -i "/^${pkg}$/"d $blocked
1558 status && newline && exit 0 ;;
1559 --pack)
1560 if [ -d $WOK/$pkg/taz ]; then
1561 rm -rf $WOK/$pkg/taz
1562 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1563 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1564 clean_log
1565 else
1566 _ "Need to build \$pkg." && exit 0
1567 fi
1568 exit 0 ;;
1569 --cdeps)
1570 [ ! -d $WOK/$pkg/taz ] && _ "Need to build \$pkg." && exit 0
1571 _ "Checking depends"; separator
1572 lddlist=/tmp/lddlist; touch $lddlist
1573 missing=/var/cache/missing.file
1574 # find all deps using ldd
1575 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1576 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1577 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1578 done
1579 # remove exe/so duplicates
1580 sort -u $lddlist > $lddlist.sorted
1581 # search packages
1582 for exefile in $(cat $lddlist.sorted); do
1583 search_file $exefile
1584 echo $found >> $lddlist.pkgs
1585 echo -n "."
1586 done
1587 echo
1588 # remove packages duplicates
1589 sort -u $lddlist.pkgs > $lddlist.final
1590 sort -u $missing > $missing.final
1591 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1592 exit 0 ;;
1593 esac
1595 # Check if wanted is built now so we have separate log files.
1596 for wanted in $WANTED ; do
1597 if grep -q "^$wanted$" $blocked; then
1598 _ "WANTED package is blocked: \$wanted" | tee $LOGS/$pkg.log
1599 newline && rm -f $command && exit 1
1600 fi
1601 if grep -q "^$wanted$" $broken; then
1602 _ "WANTED package is broken: \$wanted" | tee $LOGS/$pkg.log
1603 newline && rm -f $command && exit 1
1604 fi
1605 if [ ! -d "$WOK/$wanted/install" ]; then
1606 cook "$wanted" || exit 1
1607 fi
1608 done
1610 # Cook and pack or exit on error and log everything.
1611 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1612 remove_deps | tee -a $LOGS/$pkg.log
1613 cookit_quality
1614 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1615 clean_log
1617 # Exit if any error in packing.
1618 lerror=$(_n "ERROR")
1619 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1620 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors)"; then
1621 debug_info | tee -a $LOGS/$pkg.log
1622 rm -f $command && exit 1
1623 fi
1625 # Create an XML feed
1626 gen_rss
1628 # Time and summary
1629 time=$(($(date +%s) - $time))
1630 summary | tee -a $LOGS/$pkg.log
1631 newline
1633 # We may want to install/update (outside aufs jail !).
1634 [ -s /aufs-umount.sh ] ||
1635 install_package
1637 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1638 # You want automation: use the Cooker Build Bot.
1639 rm -f $command ;;
1640 esac
1642 exit 0