cookutils view cook @ rev 667

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