cookutils view cook @ rev 673

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