cookutils view cook @ rev 669

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