cookutils view cook @ rev 658

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