cookutils view cook @ rev 666

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