cookutils view cook @ rev 737

cook: tiny edits.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri May 15 16:50:15 2015 +0300 (2015-05-15)
parents b0c983a10873
children 46ba9289aa46
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 #
10 . /usr/lib/slitaz/libcook.sh
12 VERSION="3.2"
15 # Internationalization.
17 export TEXTDOMAIN='cook'
18 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
19 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
20 _p() {
21 local S="$1" P="$2" N="$3"; shift; shift; shift;
22 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
25 #
26 # Functions
27 #
29 usage() {
30 cat <<EOT
32 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
34 $(boldify "$(_ 'Commands:')")
35 usage|help $(_ 'Display this short usage.')
36 setup $(_ 'Setup your build environment.')
37 *-setup $(_ 'Setup a cross environment.')
38 * = {arm|armv6hf|armv7|x86_64}
39 test $(_ 'Test environment and cook a package.')
40 list-wok $(_ 'List packages in the wok.')
41 search $(_ 'Simple packages search function.')
42 new $(_ 'Create a new package with a receipt.')
43 list $(_ 'Cook a list of packages.')
44 clean-wok $(_ 'Clean-up all packages files.')
45 clean-src $(_ 'Clean-up all packages sources.')
46 uncook $(_ 'Check for uncooked packages')
47 pkgdb $(_ 'Create packages DB lists and flavors.')
49 $(boldify "$(_ 'Options:')")
50 cook <pkg>
51 --clean -c $(_ 'clean the package in the wok.')
52 --install -i $(_ 'cook and install the package.')
53 --getsrc -gs $(_ 'get the package source tarball.')
54 --block -b $(_ 'block a package so cook will skip it.')
55 --unblock -ub $(_ 'unblock a blocked package.')
56 --cdeps $(_ 'check dependencies of cooked package.')
57 --pack $(_ 'repack an already built package.')
58 --debug $(_ 'display debugging messages.')
59 --continue $(_ 'continue running compile_rules.')
60 cook new <pkg>
61 --interactive -x $(_ 'create a receipt interactively.')
62 cook setup
63 --wok $(_ 'clone the cooking wok from Hg repo.')
64 --stable $(_ 'clone the stable wok from Hg repo.')
65 --undigest $(_ 'clone the undigest wok from Hg repo.')
66 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
67 --forced $(_ 'force reinstall of chroot packages.')
68 cook pkgdb
69 --flavors $(_ 'create up-to-date flavors files.')
71 EOT
72 exit 0
73 }
76 # We don't want these escapes in web interface.
78 clean_log() {
79 sed -i -e s'|\[70G\[ \[1;32m| |' \
80 -e s'|\[0;39m \]||' $LOGS/$pkg.log
81 }
84 # Be sure package exists in wok.
86 check_pkg_in_wok() {
87 if [ ! -d "$WOK/$pkg" ]; then
88 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
89 exit 1
90 fi
91 }
94 if_empty_value() {
95 if [ -z "$value" ]; then
96 # L10n: QA is quality assurance
97 _ 'QA: empty variable: %s' "$var=\"\""; newline
98 exit 1
99 fi
100 }
103 # Initialize files used in $CACHE
105 init_db_files() {
106 _ 'Creating directories structure in "%s"' "$SLITAZ"
107 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
108 _ 'Creating DB files in "%s"' "$CACHE"
109 for f in $activity $command $broken $blocked; do
110 touch $f
111 done
112 }
115 # QA: check a receipt consistency before building.
117 receipt_quality() {
118 _ 'QA: checking package receipt...'
119 unset online
120 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
121 online='online'
122 fi
123 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
124 unset value
125 value="$(. $receipt; eval echo \$$var)"
126 case "$var" in
127 PACKAGE|VERSION|SHORT_DESC)
128 if_empty_value ;;
129 CATEGORY)
130 value="${value:-empty}"
131 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
132 if ! echo " $valid " | grep -q " $value "; then
133 _ 'QA: unknown category "%s"' "$value"
134 longline "$(_ 'Please, use one of: %s' "$valid")"
135 newline
136 exit 1
137 fi ;;
138 WEB_SITE)
139 # We don't check WGET_URL since if dl is needed it will fail.
140 # Break also if we're not online. Here error is not fatal.
141 if_empty_value
142 [ -z "$online" ] && break
143 if ! busybox wget -T 12 -s $value 2>/dev/null; then
144 _ 'QA: unable to reach "%s"' "$value"
145 fi ;;
146 esac
147 done
148 }
151 # Paths used in receipt and by cook itself.
153 set_paths() {
154 pkgdir="$WOK/$PACKAGE"
155 basesrc="$pkgdir/source"
156 tmpsrc="$basesrc/tmp"
157 src="$basesrc/$PACKAGE-$VERSION"
158 taz="$pkgdir/taz"
159 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
160 fs="$pack/fs"
161 stuff="$pkgdir/stuff"
162 install="$pkgdir/install"
163 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
164 lzma_tarball="$pkgsrc.tar.lzma"
165 if [ -n "$PATCH" ]; then
166 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
167 fi
168 if [ -n "$WANTED" ]; then
169 basesrc="$WOK/$WANTED/source"
170 src="$basesrc/$WANTED-$VERSION"
171 install="$WOK/$WANTED/install"
172 wanted_stuff="$WOK/$WANTED/stuff"
173 fi
174 if [ -n "$SOURCE" ]; then
175 source_stuff="$WOK/$SOURCE/stuff"
176 fi
177 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
178 if [ -f "$WOK/linux/receipt" ]; then
179 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
180 kbasevers=${kvers:0:3}
181 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
182 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
183 kbasevers=${kvers:0:3}
184 fi
185 # Python version
186 if [ -f "$WOK/python/receipt" ]; then
187 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
188 fi
189 # Perl version for some packages needed it
190 if [ -f "$WOK/perl/receipt" ]; then
191 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
192 fi
193 # Old way compatibility.
194 _pkg="$install"
195 }
198 # Create source tarball when URL is a SCM.
200 create_tarball() {
201 local tarball
202 tarball="$pkgsrc.tar.bz2"
203 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
204 _ 'Creating tarball "%s"' "$tarball"
205 if [ -n "$LZMA_SRC" ]; then
206 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
207 LZMA_SRC=''
208 else
209 tar -cjf $tarball $pkgsrc || exit 1
210 mv $tarball $SRC; rm -rf $pkgsrc
211 fi
212 TARBALL="$tarball"
213 }
216 # Get package source. For SCM we are in cache so clone here and create a
217 # tarball here.
219 get_source() {
220 local url
221 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
222 set_paths
223 pwd=$(pwd)
224 case "$WGET_URL" in
225 http://*|ftp://*)
226 # Busybox Wget is better!
227 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
228 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
229 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
231 https://*)
232 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
233 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
234 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
236 hg*|mercurial*)
237 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
238 url=${WGET_URL#hg|}
239 else
240 url=${WGET_URL#mercurial|}
241 fi
242 _ 'Getting source from %s...' 'Hg'
243 _ 'URL: %s' "$url"
244 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
245 if [ -n "$BRANCH" ]; then
246 _ 'Hg branch: %s' "$BRANCH"
247 hg clone $url --rev $BRANCH $pkgsrc || \
248 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
249 else
250 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
251 fi
252 rm -rf $pkgsrc/.hg
253 create_tarball ;;
255 git*)
256 url=${WGET_URL#git|}
257 _ 'Getting source from %s...' 'Git'
258 _ 'URL: %s' "$url"
259 cd $SRC
260 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
261 if [ -n "$BRANCH" ]; then
262 _ 'Git branch: %s' "$BRANCH"
263 cd $pkgsrc; git checkout $BRANCH; cd ..
264 fi
265 cd $SRC
266 create_tarball ;;
268 cvs*)
269 url=${WGET_URL#cvs|}
270 mod=$PACKAGE
271 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
272 _ 'Getting source from %s...' 'CVS'
273 _ 'URL: %s' "$url"
274 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
275 _ 'Cloning to "%s"' "$pwd/$mod"
276 cvs -d:$url co $mod && mv $mod $pkgsrc
277 create_tarball ;;
279 svn*|subversion*)
280 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
281 url=${WGET_URL#svn|}
282 else
283 url=${WGET_URL#subversion|}
284 fi
285 _ 'Getting source from %s...' 'SVN'
286 _ 'URL: %s' "$url"
287 if [ -n "$BRANCH" ]; then
288 echo t | svn co $url -r $BRANCH $pkgsrc
289 else
290 echo t | svn co $url $pkgsrc
291 fi
292 create_tarball ;;
294 bzr*)
295 url=${WGET_URL#bzr|}
296 _ 'Getting source from %s...' 'bazaar'
297 cd $SRC
298 pkgsrc=${url#*:}
299 if [ -n "$BRANCH" ]; then
300 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
301 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
302 else
303 echo "bzr -Ossl.cert_reqs=none branch $url"
304 bzr -Ossl.cert_reqs=none branch $url
305 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
306 _ "Don't forget to add to receipt:"
307 echo -e "BRANCH=\"$BRANCH\"\n"
308 fi
309 mv $pkgsrc $pkgsrc-$BRANCH
310 pkgsrc="$pkgsrc-$BRANCH"
311 create_tarball ;;
313 *)
314 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
315 tee -a $LOGS/$PACKAGE.log
316 exit 1 ;;
317 esac
318 }
321 # Extract source package.
323 extract_source() {
324 if [ ! -s "$SRC/$TARBALL" ]; then
325 local url
326 url="$MIRROR_URL/sources/packages"
327 url="$url/${TARBALL:0:1}/$TARBALL"
328 _ 'Getting source from %s...' 'mirror'
329 _ 'URL: %s' "$url"
330 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
331 fi
332 _ 'Extracting source archive "%s"' "$TARBALL"
333 case "$TARBALL" in
334 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
335 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
336 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
337 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
338 *.tar) tar -xf $SRC/$TARBALL ;;
339 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
340 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
341 tar -xf $SRC/$TARBALL 2>/dev/null;;
342 *.7z) 7zr x $SRC/$TARBALL ;;
343 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
344 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
345 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
346 *) cp $SRC/$TARBALL $(pwd) ;;
347 esac
348 }
351 # Display cooked package summary.
353 summary() {
354 cd $WOK/$pkg
355 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
356 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
357 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
358 size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
359 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
360 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
362 sec="$time"
363 div=$(( ($time + 30) / 60))
364 case $div in
365 0) min='';;
366 # L10n: 'm' is for minutes (approximate cooking time)
367 *) min=$(_n '~ %dm' "$div");;
368 esac
370 _ 'Summary for: %s' "$PACKAGE $VERSION"
371 separator
373 # L10n: keep the same width of translations to get a consistent view
374 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
375 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
376 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
377 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
378 _ 'Packed : %s' "$fs"
379 _ 'Compressed : %s' "$size"
380 _ 'Files : %s' "$files"
381 # L10n: 's' is for seconds (cooking time)
382 _ 'Cook time : %ds %s' "$sec" "$min"
383 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
384 _ 'Host arch : %s' "$ARCH"
385 separator
386 }
389 # Display debugging error info.
391 debug_info() {
392 newline; _ 'Debug information'; separator
393 # L10n: specify your format of date and time (to help: man date)
394 # L10n: not bad one is '+%x %R'
395 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
396 # L10n: Please, translate all messages beginning with ERROR in a same way
397 lerror=$(_n 'ERROR')
398 for error in \
399 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
400 'error:' 'fatal error:' 'undefined reference to' \
401 'Unable to connect to' 'link: cannot find the library' \
402 'CMake Error' ': No such file or directory'
403 do
404 fgrep "$error" $LOGS/$pkg.log
405 done > $LOGS/$pkg.log.debug_info 2>&1
406 cat $LOGS/$pkg.log.debug_info
407 rm -f $LOGS/$pkg.log.debug_info
408 separator; newline
409 }
412 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
413 # so some packages need to copy these files with the receipt and genpkg_rules.
415 copy_generic_files() {
416 # $LOCALE is set in cook.conf
417 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
418 if [ -d "$install/usr/share/locale" ]; then
419 mkdir -p $fs/usr/share/locale
420 for i in $LOCALE; do
421 if [ -d "$install/usr/share/locale/$i" ]; then
422 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
423 fi
424 done
425 fi
426 fi
428 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
429 if [ "$GENERIC_PIXMAPS" != 'no' ]; then
430 if [ -d "$install/usr/share/pixmaps" ]; then
431 mkdir -p $fs/usr/share/pixmaps
432 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
433 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
434 $fs/usr/share/pixmaps
435 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
436 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
437 $fs/usr/share/pixmaps
438 fi
439 fi
441 # Custom or homemade PNG pixmap can be in stuff.
442 if [ -f "$stuff/$PACKAGE.png" ]; then
443 mkdir -p $fs/usr/share/pixmaps
444 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
445 fi
446 fi
448 # Desktop entry (.desktop).
449 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
450 if [ "$GENERIC_MENUS" != 'no' ]; then
451 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
452 mkdir -p $fs/usr/share
453 cp -a $install/usr/share/applications $fs/usr/share
454 fi
455 fi
457 # Homemade desktop file(s) can be in stuff.
458 if [ -d "$stuff/applications" ]; then
459 mkdir -p $fs/usr/share
460 cp -a $stuff/applications $fs/usr/share
461 fi
462 if [ -f "$stuff/$PACKAGE.desktop" ]; then
463 mkdir -p $fs/usr/share/applications
464 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
465 fi
467 # Add custom licenses
468 if [ -d "$stuff/licenses" ]; then
469 mkdir -p $fs/usr/share/licenses
470 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
471 fi
472 }
475 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
476 # as removing unneeded files like in Python packages. Cross compiled binaries
477 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
479 strip_package() {
480 case "$ARCH" in
481 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
482 *) export STRIP='strip' ;;
483 esac
484 _n 'Executing strip on all files...'
485 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
486 if [ -d "$dir" ]; then
487 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
488 fi
489 done
490 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
491 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
492 status
494 # Remove Python .pyc and .pyo from packages.
495 if echo "$PACKAGE $DEPENDS" | fgrep -q 'python'; then
496 _n 'Removing Python compiled files...'
497 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
498 status
499 fi
501 # Remove Perl perllocal.pod and .packlist from packages.
502 if echo "$DEPENDS" | fgrep -q 'perl'; then
503 _n 'Removing Perl compiled files...'
504 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
505 status
506 fi
507 }
510 # Remove installed deps.
512 remove_deps() {
513 # Now remove installed build deps.
514 diff='/tmp/installed.cook.diff'
515 if [ -s $diff ]; then
516 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
517 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
518 _n 'Build dependencies to remove:'; echo " $nb"
519 [ -n "$root" ] && echo "root=\"$root\""
520 _n 'Removing:'
521 for dep in $deps; do
522 echo -n " $dep"
523 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
524 done
525 newline; newline
526 # Keep the last diff for debug and info.
527 mv -f $diff $CACHE/installed.diff
528 fi
529 }
532 # The main cook function.
534 cookit() {
535 _ 'Cook: %s' "$PACKAGE $VERSION"; separator
536 set_paths
538 # Handle cross-tools.
539 case "$ARCH" in
540 arm*|x86_64)
541 # CROSS_COMPILE is used by at least Busybox and the kernel to set
542 # the cross-tools prefix. Sysroot is the root of our target arch
543 sysroot="$CROSS_TREE/sysroot"
544 tools="$CROSS_TREE/tools"
545 # Set root path when cross compiling. ARM tested but not x86_64
546 # When cross compiling we must install build deps in $sysroot.
547 arch="-$ARCH"
548 root="$sysroot"
549 _ '%s sysroot: %s' "$ARCH" "$sysroot"
550 _ 'Adding "%s" to PATH' "$tools/bin"
551 export PATH="$PATH:$tools/bin"
552 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
553 export CROSS_COMPILE="$HOST_SYSTEM-"
554 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
555 if [ "$ARCH" == 'x86_64' ]; then
556 export CC="$HOST_SYSTEM-gcc -m64"
557 export CXX="$HOST_SYSTEM-g++ -m64"
558 else
559 export CC="$HOST_SYSTEM-gcc"
560 export CXX="$HOST_SYSTEM-g++"
561 fi
562 export AR="$HOST_SYSTEM-ar"
563 export AS="$HOST_SYSTEM-as"
564 export RANLIB="$HOST_SYSTEM-ranlib"
565 export LD="$HOST_SYSTEM-ld"
566 export STRIP="$HOST_SYSTEM-strip"
567 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
568 esac
570 [ -n "$QA" ] && receipt_quality
571 cd $pkgdir
572 [ -z "$continue" ] && rm -rf source 2>/dev/null
573 rm -rf install taz 2>/dev/null
575 # Disable -pipe if less than 512Mb free RAM.
576 free=$(free | awk '/buffers:/{print $4}')
577 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
578 _ 'Disabling -pipe compile flag: %d RAM free' "$free"
579 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
580 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
581 fi
582 unset free
584 # Export flags and path to be used by make and receipt.
585 DESTDIR="$pkgdir/install"
586 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
587 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
588 #LDFLAGS
590 # Check for build deps and handle implicit depends of *-dev packages
591 # (ex: libusb-dev :: libusb).
592 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
593 touch $CACHE/installed.local $CACHE/installed.web
594 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
595 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
596 for dep in $BUILD_DEPENDS; do
597 implicit="${dep%-dev}"
598 for i in $dep $implicit; do
599 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
600 # Try local package first. In some cases implicit doesn't exist, ex:
601 # libboost-dev exists but not libboost, so check if we got vers.
602 unset vers
603 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
604 # We may have a local package.
605 if [ -z "$vers" ]; then
606 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info)
607 fi
608 debug "bdep: $i version: $vers"
609 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
610 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
611 else
612 # Priority to package version in wok (maybe more up-to-date)
613 # than the mirrored one.
614 if [ -n "$vers" ]; then
615 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
616 echo $i >> $CACHE/installed.web
617 else
618 # So package exists in wok but not available.
619 _ 'Missing dep (wok/pkg): %s' "$i $vers"
620 echo $i >> $CACHE/missing.dep
621 fi
622 else
623 # Package is not in wok but may be in online repo.
624 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
625 echo $i >> $CACHE/installed.web
626 else
627 _ 'ERROR: unknown dep "%s"' "$i"
628 exit 1
629 fi
630 fi
631 fi
632 fi
633 done
634 done
636 # Get the list of installed packages
637 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
639 # Have we a missing build dep to cook?
640 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
641 _ 'Auto cook config is set: %s' "$AUTO_COOK"
642 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
643 for i in $(uniq $CACHE/missing.dep); do
644 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
645 tee -a $LOGS/$PACKAGE.log.$$
646 # programmers: next two messages are exact copy from remove_deps()
647 togrep1=$(_n 'Build dependencies to remove:')
648 togrep2=$(_n 'Removing:')
649 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
650 fgrep $togrep1 $LOGS/$i.log && \
651 fgrep $togrep2 $LOGS/$i.log && newline) | \
652 tee -a $LOGS/$PACKAGE.log.$$ && break
653 done
654 rm -f $CACHE/missing.dep
655 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
656 fi
658 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
659 # is enabled and cook fails we have ERROR in log, if no auto cook we have
660 # missing dep in cached file.
661 lerror=$(_n 'ERROR')
662 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
663 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
664 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
665 exit 1
666 fi
668 # Install local packages: package-version$arch
669 cd $PKGS
670 for i in $(uniq $CACHE/installed.local); do
671 _ 'Installing dep (pkg/local): %s' "$i"
672 tazpkg install $i --root=$root >/dev/null
673 done
675 # Install web or cached packages (if mirror is set to $PKGS we only
676 # use local packages).
677 for i in $(uniq $CACHE/installed.web); do
678 _ 'Installing dep (web/cache): %s' "$i"
679 tazpkg get-install $i --root=$root >/dev/null
680 done
682 # If a cook failed deps are removed.
683 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
684 cd $CACHE
685 [ ! -s '/tmp/installed.cook.diff' ] && \
686 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
687 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
689 # Get source tarball and make sure we have source dir named:
690 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
691 # tarball if it exists.
692 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
693 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
694 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
695 LZMA_SRC=''
696 else
697 get_source || exit 1
698 fi
699 fi
700 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
701 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
702 if ! extract_source ; then
703 get_source
704 extract_source || exit 1
705 fi
706 if [ -n "$LZMA_SRC" ]; then
707 cd $pkgdir/source
708 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
709 mv tmp tmp-1; mkdir tmp
710 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
711 fi
712 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
713 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
714 fi
715 fi
716 cd $pkgdir/source/tmp
717 # Some archives are not well done and don't extract to one dir (ex lzma).
718 files=$(ls | wc -l)
719 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
720 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
721 mv * ../$PACKAGE-$VERSION/$TARBALL
722 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
723 mv * ../$PACKAGE-$VERSION
724 cd ..; rm -rf tmp
725 fi
727 # Libtool shared libs path hack.
728 case "$ARCH" in
729 arm*) cross libhack ;;
730 esac
732 # Execute receipt rules.
733 if grep -q ^compile_rules $receipt; then
734 _ 'Executing: %s' 'compile_rules'
735 echo "CFLAGS : $CFLAGS"
736 #echo "LDFLAGS : $LDFLAGS"
737 [ -d "$src" ] && cd $src
738 compile_rules $@ || exit 1
739 # Stay compatible with _pkg
740 [ -d "$src/_pkg" ] && mv $src/_pkg $install
741 # QA: compile_rules success so valid.
742 mkdir -p $install
743 else
744 # QA: no compile_rules so no error, valid.
745 mkdir -p $install
746 fi
747 separator; newline
749 # Execute testsuite.
750 if grep -q ^testsuite $receipt; then
751 _ 'Running testsuite'; separator
752 testsuite $@ || exit 1
753 separator; newline
754 fi
755 }
758 # Cook quality assurance.
760 cookit_quality() {
761 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
762 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
763 fi
764 # ERROR can be echoed any time in cookit()
765 lerror=$(_n 'ERROR')
766 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
767 grep -Eq "(^$lerror|undefined reference to)" ; then
768 debug_info | tee -a $LOGS/$pkg.log
769 rm -f $command
770 exit 1
771 fi
772 }
775 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
776 # but it doesn't handle EXTRAVERSION.
778 packit() {
779 set_paths
781 # Handle cross compilation
782 case "$ARCH" in
783 arm*|x86_64) arch="-$ARCH" ;;
784 esac
786 _ 'Pack: %s' "$PACKAGE $VERSION$arch"; separator
788 if grep -q ^genpkg_rules $receipt; then
789 _ 'Executing: %s' 'genpkg_rules'
790 set -e; cd $pkgdir; mkdir -p $fs
791 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
792 $LOGS/$pkg.log
793 else
794 _ 'No packages rules: meta package'
795 mkdir -p $fs
796 fi
798 # First QA check to stop now if genpkg_rules failed.
799 lerror=$(_n 'ERROR')
800 if fgrep -q ^$lerror $LOGS/$pkg.log; then
801 exit 1
802 fi
804 cd $taz
805 for file in receipt description.txt; do
806 [ ! -f "../$file" ] && continue
807 _n 'Copying "%s"...' "$file"
808 cp -f ../$file $pack; chown 0.0 $pack/$file; status
809 done
810 copy_generic_files
812 # Strip and stuff files.
813 strip_package
815 # Create files.list with redirecting find output.
816 _n 'Creating the list of files...'
817 cd $fs
818 find . -type f -print > ../files.list
819 find . -type l -print >> ../files.list
820 cd ..; sed -i s/'^.'/''/ files.list
821 status
823 # Md5sum of files.
824 _n 'Creating md5sum of files...'
825 while read file; do
826 [ -L "fs$file" ] && continue
827 [ -f "fs$file" ] || continue
828 case "$file" in
829 /lib/modules/*/modules.*|*.pyc) continue ;;
830 esac
831 md5sum "fs$file" | sed 's/ fs/ /'
832 done < files.list > md5sum
833 status
835 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
836 2>/dev/null | awk 'END{ print $1 }')
838 # Build cpio archives.
839 _n 'Compressing the FS...'
840 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
841 rm -rf fs
842 status
844 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
845 2>/dev/null | awk 'END{ print $1 }')
847 _n 'Updating receipt sizes...'
848 sed -i s/^PACKED_SIZE.*$// receipt
849 sed -i s/^UNPACKED_SIZE.*$// receipt
850 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
851 status
853 # Set extra version.
854 if [ -n "$EXTRAVERSION" ]; then
855 _n 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
856 sed -i s/^EXTRAVERSION.*$// receipt
857 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
858 status
859 fi
861 # Compress.
862 _n 'Creating full cpio archive...'
863 find . -print | cpio -o -H newc --quiet > \
864 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
865 status
867 _n 'Restoring original package tree...'
868 unlzma -c fs.cpio.lzma | cpio -idm --quiet
869 status
871 rm fs.cpio.lzma; cd ..
873 # QA and give info.
874 tazpkg=$(ls *.tazpkg)
875 packit_quality
876 separator; _ 'Package "%s" created' "$tazpkg"; newline
877 }
880 # Verify package quality and consistency.
882 packit_quality() {
883 #gettext "QA: checking for broken link..."
884 #link=$(find $fs/usr -type l -follow)
885 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
886 #status
888 # Exit if any error found in log file.
889 lerror=$(_n 'ERROR')
890 if fgrep -q ^$lerror $LOGS/$pkg.log; then
891 rm -f $command
892 exit 1
893 fi
895 _n 'QA: checking for empty package...'
896 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
897 if [ "$files" == 0 ] && [ "$CATEGORY" != 'meta' ]; then
898 newline; _ 'ERROR: empty package'
899 rm -f $command
900 exit 1
901 else
902 # Ls sort by name so the first file is the one we want.
903 old=$(ls $PKGS/$pkg-*.tazpkg 2>/dev/null | head -n1)
904 status
905 if [ -f "$old" ]; then
906 _n 'Removing old package "%s"' "$(basename $old)"
907 rm -f $old; status
908 fi
909 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
910 sed -i /^${pkg}$/d $broken
911 #gettext "Removing source tree..."
912 #rm -f $WOK/$pkg/source && status
913 fi
914 }
917 # Reverse "cat" command: prints input lines in the reverse order
919 tac() {
920 sed '1!G;h;$!d' $1
921 }
924 # Install package on --install or update the chroot.
926 install_package() {
927 case "$ARCH" in
928 arm*|x86_64)
929 arch="-$ARCH"
930 root="$CROSS_TREE/sysroot" ;;
931 esac
932 # Install package if requested but skip install if target host doesn't
933 # match build system or it will break the build chroot.
934 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
935 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
936 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
937 cd $PKGS
938 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
939 else
940 _ 'Unable to install package, build has failed.'; newline
941 exit 1
942 fi
943 fi
945 # Install package if part of the chroot to keep env up-to-date.
946 if [ -d "$root$INSTALLED/$pkg" ]; then
947 . /etc/slitaz/cook.conf
948 . $WOK/$pkg/taz/$pkg-*/receipt
949 _ 'Updating %s chroot environment...' "$ARCH"
950 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
951 cd $PKGS
952 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
953 fi
954 }
957 # remove chroot jail
959 umount_aufs() {
960 tac ${1}rw/aufs-umount.sh | sh
961 rm -rf ${1}rw
962 umount ${1}root
963 rmdir ${1}r*
964 }
967 # Launch the cook command into a chroot jail protected by aufs.
968 # The current filesystems are used read-only and updates are
969 # stored in a separate branch.
971 try_aufs_chroot() {
973 base="/dev/shm/aufsmnt$$"
975 # Can we setup the chroot? Is it already done?
976 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
977 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
978 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
979 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
980 mkdir ${base}root ${base}rw || return
982 _ 'Setup aufs chroot...'
984 # Sanity check
985 for i in / /proc /sys /dev/shm /home ; do
986 case " $AUFS_MOUNTS " in
987 *\ $i\ *) ;;
988 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
989 esac
990 done
991 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
992 mount --bind $mnt ${base}root$mnt
993 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
994 _ 'Aufs mount failure'
995 umount ${base}root
996 rm -rf ${base}r*
997 return
998 fi
999 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1000 done
1001 trap "umount_aufs ${base}" INT
1003 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1004 status=$?
1006 _ 'Leaving aufs chroot...'
1007 umount_aufs $base
1008 # Install package outside the aufs jail
1009 install_package
1010 exit $status
1014 # Encode predefined XML entities
1016 xml_ent() {
1017 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1021 # Create a XML feed for freshly built packages.
1023 gen_rss() {
1024 pubdate=$(date '+%a, %d %b %Y %X')
1025 cat > $FEEDS/$pkg.xml <<EOT
1026 <item>
1027 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1028 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1029 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1030 <pubDate>$pubdate</pubDate>
1031 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1032 </item>
1033 EOT
1037 # Truncate stdout log file to $1 Mb.
1039 loglimit() {
1040 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1041 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1042 else
1043 tee /dev/stderr
1044 fi
1048 # Search file in mirrored packages
1050 search_file_mirror() {
1051 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1055 # Search file in local wok packages
1057 search_file_local() {
1058 # existing packages have precedence over the package/taz folder
1059 srch=$1
1060 { for package in $(find $PKGS -name '*.tazpkg'); do
1061 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1062 grep /$srch\$)" ]; then
1063 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1064 fi
1065 done } | sort -u
1069 # Ask in multiple choice
1071 ask_multiple() {
1072 local multiples first my_choice
1073 multiples="$1"
1074 first=$(echo "$multiples" | head -n1)
1075 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1076 _ 'Select one [%s]: ' "$first"; read my_choice
1077 found="${my_choice:-$first}"
1081 # Search file in local cache (fast), local wok packages, mirrored packages
1083 search_file() {
1084 local srch cache missing
1085 srch="$1"
1086 cache='/var/cache/ldsearch.cache'
1087 missing='/var/cache/missing.file'
1088 touch $cache $missing
1089 found=$(grep $srch $cache | cut -d$'\t' -f2)
1090 if [ -z "$found" ]; then
1091 found=$(search_file_local $srch)
1092 if [ -n "$found" ]; then
1093 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1094 ask_multiple "$found"
1095 fi
1096 echo -e "$srch\t$found" >> $cache
1097 else
1098 found=$(search_file_mirror $srch)
1099 if [ -n "$found" ]; then
1100 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1101 ask_multiple "$found"
1102 fi
1103 echo -e "$srch\t$found" >> $cache
1104 else
1105 echo "$srch" >> $missing
1106 fi
1107 fi
1108 fi
1112 # Return size of file in human readible format
1113 # Note, "du" in opposite returns size occupied by file on disk (4KB multiple in most cases)
1114 filesize() {
1115 busybox ls -lh "$1" | awk '{print $5 "B"}'
1120 # Receipt functions to ease packaging
1123 get_dev_files() {
1124 _n 'Getting standard devel files...'
1125 mkdir -p $fs/usr/lib
1126 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1127 cp -a $install/usr/include $fs/usr
1128 status
1133 # Commands
1136 case "$1" in
1137 usage|help|-u|-h)
1138 usage ;;
1140 list-wok)
1141 newline; _ 'List of %s packages in "%s"' "$ARCH" "$WOK"; separator
1142 cd $WOK
1143 if [ "$ARCH" != 'i486' ]; then
1144 count=0
1145 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1146 do
1147 unset HOST_ARCH
1148 . $pkg
1149 count=$(($count + 1))
1150 colorize 34 "$PACKAGE"
1151 done
1152 else
1153 count=$(ls | wc -l)
1154 ls -1
1155 fi
1156 separator
1157 _p '%s package' '%s packages' "$count" "$(colorize 32 "$count")"
1158 newline ;;
1160 activity)
1161 cat $activity ;;
1163 search)
1164 # Just a simple search function, we dont need more actually.
1165 query="$2"
1166 newline; _ 'Search results for "%s"' "$query"; separator
1167 cd $WOK; ls -1 | grep "$query"
1168 separator; newline ;;
1170 setup)
1171 # Setup a build environment
1172 check_root
1173 _ 'Cook: setup environment' | log
1174 newline; _ 'Setting up your environment'; separator
1175 cd $SLITAZ
1176 init_db_files
1177 _ 'Checking for packages to install...'
1178 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1179 # ARCH-setup or 'cross check' should be used before: cook setup
1180 case "$ARCH" in
1181 arm*|x86_64)
1182 if [ ! -x '/usr/bin/cross' ]; then
1183 _ 'ERROR: %s is not installed' 'cross'
1184 exit 1
1185 fi
1186 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1187 . /etc/slitaz/cross.conf ;;
1188 esac
1189 for pkg in $SETUP_PKGS; do
1190 if [ -n "$forced" ]; then
1191 tazpkg -gi $pkg --forced
1192 else
1193 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1194 fi
1195 done
1197 # Handle --options
1198 case "$2" in
1199 --wok) hg clone $WOK_URL wok || exit 1 ;;
1200 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1201 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1202 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1203 esac
1205 # SliTaz group and permissions
1206 if ! grep -q ^slitaz /etc/group; then
1207 _ 'Adding group "%s"' 'slitaz'
1208 addgroup slitaz
1209 fi
1210 _ 'Setting permissions for group "%s"...' 'slitaz'
1211 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1212 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1213 separator; _ 'All done, ready to cook packages :-)'; newline ;;
1215 *-setup)
1216 # Setup for cross compiling.
1217 arch="${1%-setup}"
1218 check_root
1219 . /etc/slitaz/cook.conf
1220 for pkg in $CROSS_SETUP; do
1221 if [ -n "$forced" ]; then
1222 tazpkg -gi $pkg --forced
1223 else
1224 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1225 fi
1226 done
1228 _ 'Cook: setup %s cross environment' "$arch" | log
1229 newline; boldify $(_n 'Setting up your %s cross environment' "$arch"); separator
1230 init_db_files
1231 sed -i \
1232 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1233 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1234 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1235 /etc/slitaz/cook.conf
1236 case "$arch" in
1237 arm)
1238 flags='-O2 -march=armv6'
1239 host="$ARCH-slitaz-linux-gnueabi" ;;
1240 armv6hf)
1241 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1242 host="$ARCH-slitaz-linux-gnueabi" ;;
1243 armv7)
1244 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1245 host="$ARCH-slitaz-linux-gnueabi" ;;
1246 x86_64)
1247 flags='-O2 -mtune=generic -pipe'
1248 host="$ARCH-slitaz-linux" ;;
1249 esac
1250 sed -i \
1251 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1252 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1253 . /etc/slitaz/cook.conf
1254 sysroot="$CROSS_TREE/sysroot"
1255 tools="/cross/$arch/tools"
1256 root="$sysroot"
1257 # L10n: keep the same width of translations to get a consistent view
1258 _ 'Target arch : %s' "$ARCH"
1259 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1260 _ 'Build flags : %s' "$flags"
1261 _ 'Arch sysroot : %s' "$sysroot"
1262 _ 'Tools prefix : %s' "$tools/bin"
1263 # Tell the packages manager where to find packages.
1264 _ 'Packages DB : %s' "$root$DB"
1265 mkdir -p $root$INSTALLED
1266 cd $root$DB; rm -f *.bak
1267 for list in packages.list packages.desc packages.equiv packages.md5; do
1268 rm -f $list
1269 ln -s $SLITAZ/packages/$list $list
1270 done
1271 # We must have the cross compiled glibc-base installed or default
1272 # i486 package will be used as dep by tazpkg and then break the
1273 # cross environment
1274 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1275 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1276 fi
1277 # Show GCC version or warn if not yet compiled.
1278 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1279 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1280 else
1281 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1282 _ 'Run "%s" to cook a toolchain' 'cross compile'
1283 fi
1284 separator; newline ;;
1286 test)
1287 # Test a cook environment.
1288 _ 'Cook test: testing the cook environment' | log
1289 [ ! -d "$WOK" ] && exit 1
1290 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1291 cook cooktest ;;
1293 new)
1294 # Create the package folder and an empty receipt.
1295 pkg="$2"
1296 [ -z "$pkg" ] && usage
1297 newline
1298 if [ -d "$WOK/$pkg" ]; then
1299 _ 'Package "%s" already exists.' "$pkg"
1300 exit 1
1301 fi
1303 _n 'Creating folder "%s"' "$WOK/$pkg"
1304 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1306 _n 'Preparing the package receipt...'
1307 cp $DATA/receipt .
1308 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1309 status; newline
1311 # Interactive mode, asking and seding.
1312 case "$3" in
1313 --interactive|-x)
1314 _ 'Entering interactive mode...'
1315 separator
1316 _ 'Package : %s' "$pkg"
1318 _n 'Version : ' ; read answer
1319 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1321 _n 'Category : ' ; read answer
1322 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1324 # L10n: Short description
1325 _n 'Short desc : ' ; read answer
1326 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1328 _n 'Maintainer : ' ; read answer
1329 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1331 _n 'License : ' ; read answer
1332 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1334 _n 'Web site : ' ; read answer
1335 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1336 newline
1338 # Wget URL.
1339 _ 'Wget URL to download source tarball.'
1340 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1341 _n 'Wget url : ' ; read answer
1342 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1344 # Ask for a stuff dir.
1345 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1346 if [ "$?" == 0 ]; then
1347 _n 'Creating the stuff directory...'
1348 mkdir $WOK/$pkg/stuff; status
1349 fi
1351 # Ask for a description file.
1352 confirm "$(_n 'Are you going to write a description? (y/N)')"
1353 if [ "$?" == 0 ]; then
1354 _n 'Creating the "%s" file...' 'description.txt'
1355 touch $WOK/$pkg/description.txt; status
1356 fi
1358 separator; _ 'Receipt is ready to use.'; newline ;;
1359 esac ;;
1361 list)
1362 # Cook a list of packages (better use the Cooker since it will order
1363 # packages before executing cook).
1364 check_root
1365 if [ -z "$2" ]; then
1366 newline; _ 'No list in argument.'; newline
1367 exit 1
1368 fi
1369 if [ ! -f "$2" ]; then
1370 newline; _ 'List "%s" not found.' "$2"; newline
1371 exit 1
1372 fi
1374 _ 'Starting cooking the list "%s"' "$2" | log
1376 for pkg in $(cat $2); do
1377 cook $pkg || broken
1378 done ;;
1380 clean-wok)
1381 check_root
1382 newline; _n 'Cleaning all packages files...'
1383 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1384 status; newline ;;
1386 clean-src)
1387 check_root
1388 newline; _n 'Cleaning all packages sources...'
1389 rm -rf $WOK/*/source
1390 status; newline ;;
1392 uncook)
1393 cd $WOK
1394 count=0
1395 newline; _ 'Checking for uncooked packages'; separator
1397 for pkg in *; do
1398 unset HOST_ARCH EXTRAVERSION
1399 [ ! -e $pkg/receipt ] && continue
1400 . $pkg/receipt
1401 # Source cooked pkg receipt to get EXTRAVERSION
1402 if [ -d "$WOK/$pkg/taz" ]; then
1403 cd $WOK/$pkg/taz/$pkg-*
1404 . receipt; cd $WOK
1405 fi
1406 case "$ARCH" in
1407 i486)
1408 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1409 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1410 count=$(($count + 1))
1411 colorize 34 "$pkg"
1412 fi ;;
1413 arm*)
1414 # Check only packages included in arch
1415 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1416 # *.tazpkg
1417 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1418 count=$(($count + 1))
1419 colorize 34 "$pkg"
1420 fi
1421 fi ;;
1422 esac
1423 done
1425 if [ "$count" -gt "0" ]; then
1426 separator
1427 _p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")"
1428 else
1429 _ 'All packages are cooked :-)'
1430 fi
1431 newline ;;
1433 pkgdb)
1434 # Create suitable packages list for TazPKG and only for built packages
1435 # as well as flavors files for TazLiTo. We dont need logs since we do it
1436 # manually to ensure everything is fine before syncing the mirror.
1437 case "$2" in
1438 --flavors) ;;
1439 *)
1440 [ -n "$2" ] && PKGS="$2"
1441 if [ ! -d "$PKGS" ]; then
1442 newline; _ "Packages directory \"%s\" doesn't exist" "$PKGS"; newline
1443 exit 1
1444 fi ;;
1445 esac
1447 time=$(date +%s)
1448 flavors="$SLITAZ/flavors"
1449 live="$SLITAZ/live"
1451 echo 'cook:pkgdb' > $command
1452 _ 'Cook pkgdb: Creating all packages lists' | log
1453 newline; _ 'Creating lists for "%s"' "$PKGS"; separator
1455 _ 'Cook pkgdb started: %s' "$(date "$(_ '+%%F %%R')")"
1457 cd $PKGS
1458 rm -f packages.* extra.list
1459 touch packages.equiv
1461 _n 'Creating file "%s"' 'packages.list'
1462 ls -1 *.tazpkg | sed s'/.tazpkg//' > $PKGS/packages.list
1463 echo " ($(filesize $PKGS/packages.list))"
1465 _n 'Creating file "%s"' 'packages.md5'
1466 md5sum *.tazpkg > $PKGS/packages.md5
1467 echo " ($(filesize $PKGS/packages.md5))"
1469 md5sum packages.md5 | cut -d' ' -f1 > ID
1470 ( cat ./ID | tr $'\n' ' '; date -ur ./ID +%s ) > IDs # md5 and timestamp
1472 _ 'Creating lists from "%s"' "$WOK"
1473 cd $WOK
1474 for pkg in *; do
1475 unset_receipt
1476 . $pkg/receipt
1477 # PACKED_SIZE and UNPACKED_SIZE are only in built receipt
1478 [ -s $pkg/taz/*/receipt ] && . $pkg/taz/*/receipt
1480 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ] || \
1481 [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1483 # packages.desc lets us search easily in DB
1484 cat >> $PKGS/packages.desc <<EOT
1485 $PACKAGE | $VERSION$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
1486 EOT
1488 # packages.txt used by tazpkg and tazpkg-web also to provide
1489 # a human readable package list with version and description.
1490 cat >> $PKGS/packages.txt <<EOT
1491 $PACKAGE
1492 $VERSION$EXTRAVERSION
1493 $SHORT_DESC
1494 $PACKED_SIZE ($UNPACKED_SIZE installed)
1496 EOT
1498 # packages.info combines TazPkg separate files
1499 # and will substitute them all
1500 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1501 DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
1502 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
1503 cat >> $PKGS/packages.info <<EOT
1504 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5
1505 EOT
1507 # packages.equiv is used by tazpkg install to check depends.
1508 for i in $PROVIDE; do
1509 DEST=''
1510 echo $i | fgrep -q : && DEST="${i#*:}:"
1511 if grep -qs ^${i%:*}= $PKGS/packages.equiv; then
1512 sed -i "s/^${i%:*}=/${i%:*}=$DEST$PACKAGE /" \
1513 $PKGS/packages.equiv
1514 else
1515 echo "${i%:*}=$DEST$PACKAGE" >> $PKGS/packages.equiv
1516 fi
1517 done
1519 # files.list provides a list of all packages files.
1520 cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
1521 $PKGS/files.list
1522 fi
1523 done
1525 # Display list size.
1526 _ 'Done: %s (%s)' 'packages.desc' "$(filesize $PKGS/packages.desc)"
1527 _ 'Done: %s (%s)' 'packages.txt' "$(filesize $PKGS/packages.txt)"
1528 _ 'Done: %s (%s)' 'packages.info' "$(filesize $PKGS/packages.info)"
1529 _ 'Done: %s (%s)' 'packages.equiv' "$(filesize $PKGS/packages.equiv)"
1531 cd $PKGS
1533 # files.list.lzma
1534 _n 'Creating file "%s"' 'files.list.lzma'
1535 touch files.list
1536 # pkgs.slitaz.org strongly depends on list sorted by packages names
1537 lzma e files.list files.list.lzma
1538 echo " ($(filesize $PKGS/files.list.lzma))"
1540 # Pre-sorting filenames causes 10% smaller resulting lzma file
1541 _n 'Creating file "%s"' 'files-list.lzma'
1542 cat files.list | sort -k2 -o files.list.sorted
1543 lzma e files.list.sorted files-list.lzma
1544 rm -f files.list files.list.sorted
1545 echo " ($(filesize $PKGS/files-list.lzma))"
1547 [ -e files.list.md5 ] && rm files.list.md5
1548 md5sum files-list.lzma | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
1550 # packages.info.lzma
1551 PI=packages.info
1552 _n 'Creating file "%s"' 'packages.info.lzma'
1553 touch $PI
1554 lzma e $PI $PI.lzma
1555 echo " ($(filesize $PKGS/packages.info.lzma))"
1557 # Make bundle to fast recharge
1558 _n 'Creating file "%s"' 'bundle.tar.lzma'
1559 [ -f bundle.tar.lzma ] && rm bundle.tar.lzma
1560 wget -q http://mirror1.slitaz.org/mirrors
1561 wget -q -O extra.list http://mirror1.slitaz.org/packages/get.list
1562 busybox tar -chaf bundle.tar.lzma \
1563 mirrors extra.list files-list.md5 packages.info \
1564 packages.desc packages.md5 packages.txt packages.list packages.equiv
1565 rm ./mirrors
1566 echo " ($(filesize $PKGS/bundle.tar.lzma))"
1568 # Display some info.
1569 separator
1570 nb=$(ls $PKGS/*.tazpkg | wc -l)
1571 time=$(($(date +%s) - $time))
1572 # L10n: 's' is for seconds (cooking time)
1573 _ 'Packages: %s - Time: %ss' "$nb" "$time"; newline
1576 # Create all flavors files at once. Do we really need code to monitor
1577 # flavors changes? Lets just build them with packages lists before
1578 # syncing the mirror.
1579 [ "$2" != '--flavors' ] && exit 1
1581 if [ ! -d "$flavors" ]; then
1582 _ 'Missing flavors folder "%s"' "$flavors"; newline
1583 exit 1
1584 fi
1586 [ ! -d "$live" ] && mkdir -p $live
1587 _ 'Creating flavors files in "%s"' "$live"
1588 _ 'Cook pkgdb: Creating all flavors' | log
1589 separator
1591 _ 'Recharging lists to use latest packages...'
1592 tazpkg recharge >/dev/null 2>/dev/null
1594 # We need a custom tazlito config to set working dir to /home/slitaz.
1595 if [ ! -f "$live/tazlito.conf" ]; then
1596 _ 'Creating configuration file "%s"' 'tazlito.conf'
1597 cp /etc/tazlito/tazlito.conf $live
1598 sed -i s@WORK_DIR=.*@WORK_DIR=\"/home/slitaz\"@ \
1599 $live/tazlito.conf
1600 fi
1602 # Update Hg flavors repo and pack.
1603 if [ -d "$flavors/.hg" ]; then
1604 cd $flavors; hg pull -u
1605 fi
1607 cd $live
1608 _ 'Starting to generate flavors...'
1609 rm -f flavors.list *.flavor
1610 for i in $flavors/*; do
1611 fl=$(basename $i)
1612 _ 'Packing flavor "%s"' "$fl"
1613 tazlito pack-flavor $fl >/dev/null || exit 1
1614 tazlito show-flavor $fl --brief --noheader 2>/dev/null >> flavors.list
1615 done
1616 cp -f $live/*.flavor $live/flavors.list $PKGS
1617 separator
1618 _ 'Total flavors size: %s' "$(du -sh $live | awk '{print $1}')"; newline
1619 rm -f $command
1620 separator
1621 _ 'Cook pkgdb end: %s' "$(date "$(_ '+%%F %%R')")" ;;
1623 *)
1624 # Just cook and generate a package.
1625 check_root
1626 time=$(date +%s)
1627 pkg="$1"
1628 [ -z "$pkg" ] && usage
1629 receipt="$WOK/$pkg/receipt"
1630 check_pkg_in_wok
1631 newline
1633 unset inst
1634 unset_receipt
1635 . $receipt
1637 # Handle cross compilation.
1638 case "$ARCH" in
1639 arm*)
1640 if [ -z "$HOST_ARCH" ]; then
1641 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1642 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1643 _ 'cook: %s' "$error"
1644 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1645 _ 'Cook skip: %s' "$error" | log
1646 newline
1647 exit 1
1648 fi ;;
1649 esac
1651 # Some packages are not included in some arch or fail to cross compile.
1652 : ${HOST_ARCH=i486}
1653 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1654 # Handle arm{v6hf,v7,..}
1655 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1656 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1657 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1658 _ 'cook: %s' "error"
1659 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1660 _ 'Cook skip: %s' "$error" | log
1661 sed -i /^${pkg}$/d $broken
1662 newline
1663 exit 0
1664 fi
1666 # Skip blocked, 3 lines also for the Cooker.
1667 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1668 _ 'Package "%s" is blocked' "$pkg"; newline
1669 exit 0
1670 fi
1672 try_aufs_chroot "$@"
1674 # Log and source receipt.
1675 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1676 echo "cook:$pkg" > $command
1678 # Display and log info if cook process stopped.
1679 # FIXME: gettext not working (in single quotes) here!
1680 trap '_ "\n\nCook stopped: control-C\n\n" | \
1681 tee -a $LOGS/$pkg.log' INT
1683 # Handle --options
1684 case "$2" in
1685 --clean|-c)
1686 _n 'Cleaning "%s"' "$pkg"
1687 cd $WOK/$pkg; rm -rf install taz source
1688 status; newline
1689 exit 0 ;;
1691 --install|-i)
1692 inst='yes' ;;
1694 --getsrc|-gs)
1695 _ 'Getting source for "%s"' "$pkg"; separator
1696 get_source
1697 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1698 exit 0 ;;
1700 --block|-b)
1701 _n 'Blocking package "%s"' "$pkg"
1702 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1703 status; newline
1704 exit 0 ;;
1706 --unblock|-ub)
1707 _n 'Unblocking package "%s"' "$pkg"
1708 sed -i "/^${pkg}$/"d $blocked
1709 status; newline
1710 exit 0 ;;
1712 --pack)
1713 if [ -d $WOK/$pkg/taz ]; then
1714 rm -rf $WOK/$pkg/taz
1715 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1716 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1717 clean_log
1718 else
1719 _ 'Need to build "%s"' "$pkg"
1720 exit 0
1721 fi
1722 exit 0 ;;
1724 --cdeps)
1725 if [ ! -d $WOK/$pkg/taz ]; then
1726 _ 'Need to build "%s"' "$pkg"
1727 exit 0
1728 fi
1730 _ 'Checking depends'; separator
1731 lddlist='/tmp/lddlist'; touch $lddlist
1732 missing='/var/cache/missing.file'
1734 # find all deps using ldd
1735 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1736 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1737 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1738 done #"
1740 # remove exe/so duplicates
1741 sort -u $lddlist > $lddlist.sorted
1743 # search packages
1744 for exefile in $(cat $lddlist.sorted); do
1745 search_file $exefile
1746 echo "$found" >> $lddlist.pkgs
1747 echo -n '.'
1748 done
1749 echo
1751 # remove packages duplicates
1752 sort -u $lddlist.pkgs > $lddlist.final
1753 sort -u $missing > $missing.final
1754 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1755 exit 0 ;;
1756 esac
1758 # Check if wanted is built now so we have separate log files.
1759 for wanted in $WANTED ; do
1760 if grep -q "^$wanted$" $blocked; then
1761 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1762 newline
1763 rm -f $command
1764 exit 1
1765 fi
1766 if grep -q "^$wanted$" $broken; then
1767 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1768 newline
1769 rm -f $command
1770 exit 1
1771 fi
1772 if [ ! -d "$WOK/$wanted/install" ]; then
1773 cook "$wanted" || exit 1
1774 fi
1775 done
1777 # Cook and pack or exit on error and log everything.
1778 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1779 remove_deps | tee -a $LOGS/$pkg.log
1780 cookit_quality
1781 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1782 clean_log
1784 # Exit if any error in packing.
1785 lerror=$(_n 'ERROR')
1786 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1787 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors)"; then
1788 debug_info | tee -a $LOGS/$pkg.log
1789 rm -f $command
1790 exit 1
1791 fi
1793 # Create an XML feed
1794 gen_rss
1796 # Time and summary
1797 time=$(($(date +%s) - $time))
1798 summary | tee -a $LOGS/$pkg.log
1799 newline
1801 # We may want to install/update (outside aufs jail !).
1802 [ -s /aufs-umount.sh ] ||
1803 install_package
1805 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1806 # You want automation: use the Cooker Build Bot.
1807 rm -f $command ;;
1808 esac
1810 exit 0