cookutils view cook @ rev 625

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