cookutils view cook @ rev 701

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