cookutils view cook @ rev 880

cook: cook_copy_folders() and cook_copy_files(): allow spaces in the path, preserve existing hardlinks
Package mesa-dri-ati-12.0.6: before 10.0MB, after 4.3MB (3 hardlinked files + other 2 hardlinked files)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Feb 18 15:02:59 2017 +0200 (2017-02-18)
parents 230109645bba
children ab9148a85031
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"
13 export output=raw
16 # Internationalization.
18 export TEXTDOMAIN='cook'
21 #
22 # Functions
23 #
25 usage() {
26 cat <<EOT
28 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
30 $(boldify "$(_ 'Commands:')")
31 usage|help $(_ 'Display this short usage.')
32 setup $(_ 'Setup your build environment.')
33 *-setup $(_ 'Setup a cross environment.')
34 * = {arm|armv6hf|armv7|x86_64}
35 test $(_ 'Test environment and cook a package.')
36 list-wok $(_ 'List packages in the wok.')
37 search $(_ 'Simple packages search function.')
38 new $(_ 'Create a new package with a receipt.')
39 list $(_ 'Cook a list of packages.')
40 clean-wok $(_ 'Clean-up all packages files.')
41 clean-src $(_ 'Clean-up all packages sources.')
42 uncook $(_ 'Check for uncooked packages')
43 pkgdb $(_ 'Create packages DB lists and flavors.')
45 $(boldify "$(_ 'Options:')")
46 cook <pkg>
47 --clean -c $(_ 'clean the package in the wok.')
48 --install -i $(_ 'cook and install the package.')
49 --getsrc -gs $(_ 'get the package source tarball.')
50 --block -b $(_ 'block a package so cook will skip it.')
51 --unblock -ub $(_ 'unblock a blocked package.')
52 --cdeps $(_ 'check dependencies of cooked package.')
53 --pack $(_ 'repack an already built package.')
54 --debug $(_ 'display debugging messages.')
55 --continue $(_ 'continue running compile_rules.')
56 cook new <pkg>
57 --interactive -x $(_ 'create a receipt interactively.')
58 cook setup
59 --wok $(_ 'clone the cooking wok from Hg repo.')
60 --stable $(_ 'clone the stable wok from Hg repo.')
61 --undigest $(_ 'clone the undigest wok from Hg repo.')
62 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
63 --forced $(_ 'force reinstall of chroot packages.')
64 cook pkgdb
65 --flavors $(_ 'create up-to-date flavors files.')
67 EOT
68 exit 0
69 }
72 # We don't want these escapes in web interface.
74 clean_log() {
75 sed -i -e s'|\[70G\[ \[1;32m| |' \
76 -e s'|\[0;39m \]||' $LOGS/$pkg.log
77 }
80 # Be sure package exists in wok.
82 check_pkg_in_wok() {
83 if [ ! -d "$WOK/$pkg" ]; then
84 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
85 exit 1
86 fi
87 }
90 if_empty_value() {
91 if [ -z "$value" ]; then
92 # L10n: QA is quality assurance
93 _ 'QA: empty variable: %s' "$var=\"\""; newline
94 exit 1
95 fi
96 }
99 # Initialize files used in $CACHE
101 init_db_files() {
102 _ 'Creating directories structure in "%s"' "$SLITAZ"
103 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
104 _ 'Creating DB files in "%s"' "$CACHE"
105 for f in $activity $command $broken $blocked; do
106 touch $f
107 done
108 }
111 # QA: check a receipt consistency before building.
113 receipt_quality() {
114 _ 'QA: checking package receipt...'
115 unset online
116 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
117 online='online'
118 fi
119 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
120 unset value
121 value="$(. $receipt; eval echo \$$var)"
122 case "$var" in
123 PACKAGE|VERSION|SHORT_DESC)
124 if_empty_value ;;
125 CATEGORY)
126 value="${value:-empty}"
127 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
128 if ! echo " $valid " | grep -q " $value "; then
129 _ 'QA: unknown category "%s"' "$value"
130 longline "$(_ 'Please, use one of: %s' "$valid")"
131 newline
132 exit 1
133 fi ;;
134 WEB_SITE)
135 # We don't check WGET_URL since if dl is needed it will fail.
136 # Break also if we're not online. Here error is not fatal.
137 if_empty_value
138 [ -z "$online" ] && break
139 if ! busybox wget -T 12 -s $value 2>/dev/null; then
140 _ 'QA: unable to reach "%s"' "$value"
141 fi ;;
142 esac
143 done
144 }
147 # Paths used in receipt and by cook itself.
149 set_paths() {
150 pkgdir="$WOK/$PACKAGE"
151 . "$pkgdir/receipt"
152 basesrc="$pkgdir/source"
153 tmpsrc="$basesrc/tmp"
154 src="$basesrc/$PACKAGE-$VERSION"
155 taz="$pkgdir/taz"
156 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
157 fs="$pack/fs"
158 stuff="$pkgdir/stuff"
159 install="$pkgdir/install"
160 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
161 lzma_tarball="$pkgsrc.tar.lzma"
162 if [ -n "$PATCH" ]; then
163 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
164 fi
165 if [ -n "$WANTED" ]; then
166 basesrc="$WOK/$WANTED/source"
167 src="$basesrc/$WANTED-$VERSION"
168 install="$WOK/$WANTED/install"
169 wanted_stuff="$WOK/$WANTED/stuff"
170 fi
171 if [ -n "$SOURCE" ]; then
172 source_stuff="$WOK/$SOURCE/stuff"
173 fi
174 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
175 if [ -f "$WOK/linux/receipt" ]; then
176 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
177 kbasevers=${kvers:0:3}
178 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
179 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
180 kbasevers=${kvers:0:3}
181 fi
182 # Python version
183 if [ -f "$WOK/python/receipt" ]; then
184 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
185 fi
186 # Perl version for some packages needed it
187 if [ -f "$WOK/perl/receipt" ]; then
188 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
189 fi
190 # Old way compatibility.
191 _pkg="$install"
192 }
195 # Create source tarball when URL is a SCM.
197 create_tarball() {
198 local tarball
199 tarball="$pkgsrc.tar.bz2"
200 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
201 _ 'Creating tarball "%s"' "$tarball"
202 if [ -n "$LZMA_SRC" ]; then
203 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
204 LZMA_SRC=''
205 else
206 tar -cjf $tarball $pkgsrc || exit 1
207 mv $tarball $SRC; rm -rf $pkgsrc
208 fi
209 TARBALL="$tarball"
210 }
213 # Get package source. For SCM we are in cache so clone here and create a
214 # tarball here.
216 get_source() {
217 local url
218 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
219 set_paths
220 pwd=$(pwd)
221 case "$WGET_URL" in
222 http://*|ftp://*)
223 # Busybox Wget is better!
224 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
225 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
226 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
228 https://*)
229 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
230 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
231 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
233 hg*|mercurial*)
234 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
235 url=${WGET_URL#hg|}
236 else
237 url=${WGET_URL#mercurial|}
238 fi
239 _ 'Getting source from %s...' 'Hg'
240 _ 'URL: %s' "$url"
241 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
242 if [ -n "$BRANCH" ]; then
243 _ 'Hg branch: %s' "$BRANCH"
244 hg clone $url --rev $BRANCH $pkgsrc || \
245 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
246 else
247 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
248 fi
249 rm -rf $pkgsrc/.hg
250 create_tarball ;;
252 git*)
253 url=${WGET_URL#git|}
254 _ 'Getting source from %s...' 'Git'
255 _ 'URL: %s' "$url"
256 cd $SRC
257 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
258 if [ -n "$BRANCH" ]; then
259 _ 'Git branch: %s' "$BRANCH"
260 cd $pkgsrc; git checkout $BRANCH; cd ..
261 fi
262 cd $SRC
263 create_tarball ;;
265 cvs*)
266 url=${WGET_URL#cvs|}
267 mod=$PACKAGE
268 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
269 _ 'Getting source from %s...' 'CVS'
270 _ 'URL: %s' "$url"
271 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
272 _ 'Cloning to "%s"' "$pwd/$mod"
273 cvs -d:$url co $mod && mv $mod $pkgsrc
274 create_tarball ;;
276 svn*|subversion*)
277 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
278 url=${WGET_URL#svn|}
279 else
280 url=${WGET_URL#subversion|}
281 fi
282 _ 'Getting source from %s...' 'SVN'
283 _ 'URL: %s' "$url"
284 if [ -n "$BRANCH" ]; then
285 echo t | svn co $url -r $BRANCH $pkgsrc
286 else
287 echo t | svn co $url $pkgsrc
288 fi
289 create_tarball ;;
291 bzr*)
292 url=${WGET_URL#bzr|}
293 _ 'Getting source from %s...' 'bazaar'
294 cd $SRC
295 pkgsrc=${url#*:}
296 if [ -n "$BRANCH" ]; then
297 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
298 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
299 else
300 echo "bzr -Ossl.cert_reqs=none branch $url"
301 bzr -Ossl.cert_reqs=none branch $url
302 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
303 _ "Don't forget to add to receipt:"
304 echo -e "BRANCH=\"$BRANCH\"\n"
305 fi
306 mv $pkgsrc $pkgsrc-$BRANCH
307 pkgsrc="$pkgsrc-$BRANCH"
308 create_tarball ;;
310 *)
311 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
312 tee -a $LOGS/$PACKAGE.log
313 exit 1 ;;
314 esac
315 }
318 # Extract source package.
320 extract_source() {
321 if [ ! -s "$SRC/$TARBALL" ]; then
322 local url
323 url="$MIRROR_URL/sources/packages"
324 url="$url/${TARBALL:0:1}/$TARBALL"
325 _ 'Getting source from %s...' 'mirror'
326 _ 'URL: %s' "$url"
327 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
328 fi
329 _ 'Extracting source archive "%s"' "$TARBALL"
330 case "$TARBALL" in
331 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
332 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
333 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
334 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
335 *.tar) tar -xf $SRC/$TARBALL ;;
336 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
337 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
338 tar -xf $SRC/$TARBALL 2>/dev/null;;
339 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
340 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
341 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
342 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
343 *) cp $SRC/$TARBALL $(pwd) ;;
344 esac
345 }
348 # Display time.
350 disp_time() {
351 local sec div min
352 sec="$1"
353 div=$(( ($1 + 30) / 60))
354 case $div in
355 0) min='';;
356 # L10n: 'm' is for minutes (approximate cooking time)
357 *) min=$(_n ' ~ %dm' "$div");;
358 esac
360 # L10n: 's' is for seconds (cooking time)
361 _ '%ds%s' "$sec" "$min"
362 }
365 # Display cooked package summary.
367 summary() {
368 set_paths
369 cd $WOK/$pkg
370 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
371 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
372 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
373 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
374 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
375 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
377 _ 'Summary for: %s' "$PACKAGE $VERSION"
378 separator
380 # L10n: keep the same width of translations to get a consistent view
381 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
382 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
383 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
384 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
385 _ 'Packed : %s' "$fs"
386 _ 'Compressed : %s' "$size"
387 _ 'Files : %s' "$files"
388 _ 'Cook time : %s' "$(disp_time "$time")"
389 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
390 _ 'Host arch : %s' "$ARCH"
391 separator
392 }
395 # Display debugging error info.
397 debug_info() {
398 title 'Debug information'
399 # L10n: specify your format of date and time (to help: man date)
400 # L10n: not bad one is '+%x %R'
401 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
402 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
403 # L10n: Please, translate all messages beginning with ERROR in a same way
404 lerror=$(_n 'ERROR')
405 for error in \
406 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
407 'error:' 'fatal error:' 'undefined reference to' \
408 'Unable to connect to' 'link: cannot find the library' \
409 'CMake Error' ': No such file or directory' \
410 'Could not read symbols: File in wrong format'
411 do
412 fgrep "$error" $LOGS/$pkg.log
413 done > $LOGS/$pkg.log.debug_info 2>&1
414 cat $LOGS/$pkg.log.debug_info
415 rm -f $LOGS/$pkg.log.debug_info
416 footer
417 }
420 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
421 # so some packages need to copy these files with the receipt and genpkg_rules.
423 copy_generic_files() {
424 # $LOCALE is set in cook.conf
425 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
426 if [ -d "$install/usr/share/locale" ]; then
427 mkdir -p $fs/usr/share/locale
428 for i in $LOCALE; do
429 if [ -d "$install/usr/share/locale/$i" ]; then
430 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
431 fi
432 done
433 fi
434 fi
436 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
437 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
438 if [ -d "$install/usr/share/pixmaps" ]; then
439 mkdir -p $fs/usr/share/pixmaps
440 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
441 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
442 $fs/usr/share/pixmaps
443 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
444 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
445 $fs/usr/share/pixmaps
446 fi
447 fi
449 # Custom or homemade PNG pixmap can be in stuff.
450 if [ -f "$stuff/$PACKAGE.png" ]; then
451 mkdir -p $fs/usr/share/pixmaps
452 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
453 fi
454 fi
456 # Desktop entry (.desktop).
457 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
458 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
459 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
460 mkdir -p $fs/usr/share
461 cp -a $install/usr/share/applications $fs/usr/share
462 fi
463 fi
465 # Homemade desktop file(s) can be in stuff.
466 if [ -d "$stuff/applications" ]; then
467 mkdir -p $fs/usr/share
468 cp -a $stuff/applications $fs/usr/share
469 fi
470 if [ -f "$stuff/$PACKAGE.desktop" ]; then
471 mkdir -p $fs/usr/share/applications
472 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
473 fi
475 # Add custom licenses
476 if [ -d "$stuff/licenses" ]; then
477 mkdir -p $fs/usr/share/licenses
478 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
479 fi
480 }
483 # Remove files provided by split packages
484 # For example:
485 # 1. Package "pkg-main":
486 # SPLIT="pkg-1 pkg-2 pkg-extra"
487 # 2. Package="pkg-extra":
488 # WANTED="pkg-main"
489 # BUILD_DEPENDS="pkg-1 pkg-2"
490 # cook_copy_folders usr
491 # cook_split_rm $BUILD_DEPENDS
493 cook_split_rm() {
494 for i in $@; do
495 action 'Remove files provided by split package %s...' "$i"
496 while read j; do
497 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
498 rmdir "$(dirname "$fs$j")" 2>/dev/null
499 done < $WOK/$i/taz/$i-$VERSION/files.list
500 :; status
501 done
502 }
505 # Update installed.cook.diff
507 update_installed_cook_diff() {
508 # If a cook failed deps are removed.
509 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
510 cd $CACHE
511 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
512 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
513 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
514 }
517 # Remove installed deps.
519 remove_deps() {
520 # Now remove installed build deps.
521 diff='/tmp/installed.cook.diff'
522 if [ -s $diff ]; then
523 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
524 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
525 _n 'Build dependencies to remove:'; echo " $nb"
526 [ -n "$root" ] && echo "root=\"$root\""
527 _n 'Removing:'
528 for dep in $deps; do
529 echo -n " $dep"
530 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
531 done
532 newline; newline
533 # Keep the last diff for debug and info.
534 mv -f $diff $CACHE/installed.diff
535 fi
536 }
539 # The main cook function.
541 cookit() {
542 title 'Cook: %s' "$PACKAGE $VERSION"
543 set_paths
545 # Handle cross-tools.
546 case "$ARCH" in
547 arm*|x86_64)
548 # CROSS_COMPILE is used by at least Busybox and the kernel to set
549 # the cross-tools prefix. Sysroot is the root of our target arch
550 sysroot="$CROSS_TREE/sysroot"
551 tools="$CROSS_TREE/tools"
552 # Set root path when cross compiling. ARM tested but not x86_64
553 # When cross compiling we must install build deps in $sysroot.
554 arch="-$ARCH"
555 root="$sysroot"
556 _ '%s sysroot: %s' "$ARCH" "$sysroot"
557 _ 'Adding "%s" to PATH' "$tools/bin"
558 export PATH="$PATH:$tools/bin"
559 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
560 export CROSS_COMPILE="$HOST_SYSTEM-"
561 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
562 if [ "$ARCH" == 'x86_64' ]; then
563 export CC="$HOST_SYSTEM-gcc -m64"
564 export CXX="$HOST_SYSTEM-g++ -m64"
565 else
566 export CC="$HOST_SYSTEM-gcc"
567 export CXX="$HOST_SYSTEM-g++"
568 fi
569 export AR="$HOST_SYSTEM-ar"
570 export AS="$HOST_SYSTEM-as"
571 export RANLIB="$HOST_SYSTEM-ranlib"
572 export LD="$HOST_SYSTEM-ld"
573 export STRIP="$HOST_SYSTEM-strip"
574 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
575 esac
577 [ -n "$QA" ] && receipt_quality
578 cd $pkgdir
579 [ -z "$continue" ] && rm -rf source 2>/dev/null
580 rm -rf install taz 2>/dev/null
582 # Disable -pipe if less than 512 MB free RAM.
583 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
584 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
585 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
586 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
587 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
588 fi
589 unset free
591 # Export flags and path to be used by make and receipt.
592 DESTDIR="$pkgdir/install"
593 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
594 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
595 #LDFLAGS
597 # Check for build deps and handle implicit depends of *-dev packages
598 # (ex: libusb-dev :: libusb).
599 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
600 touch $CACHE/installed.local $CACHE/installed.web
601 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
602 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
603 for dep in $BUILD_DEPENDS; do
604 implicit="${dep%-dev}"
605 # Don't add implicit dependency if it defined in DEPENDS
606 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
607 for i in $dep $implicit; do
608 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
609 # Try local package first. In some cases implicit doesn't exist, ex:
610 # libboost-dev exists but not libboost, so check if we got vers.
611 unset vers
612 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
613 # We may have a local package.
614 if [ -z "$vers" ]; then
615 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
616 fi
617 debug "bdep: $i version: $vers"
618 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
619 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
620 else
621 # Priority to package version in wok (maybe more up-to-date)
622 # than the mirrored one.
623 if [ -n "$vers" ]; then
624 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
625 echo $i >> $CACHE/installed.web
626 else
627 # So package exists in wok but not available.
628 _ 'Missing dep (wok/pkg): %s' "$i $vers"
629 echo $i >> $CACHE/missing.dep
630 fi
631 else
632 # Package is not in wok but may be in online repo.
633 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
634 echo $i >> $CACHE/installed.web
635 else
636 _ 'ERROR: unknown dep "%s"' "$i"
637 exit 1
638 fi
639 fi
640 fi
641 fi
642 done
643 done
645 # Get the list of installed packages
646 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
648 # Have we a missing build dep to cook?
649 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
650 _ 'Auto cook config is set: %s' "$AUTO_COOK"
651 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
652 for i in $(uniq $CACHE/missing.dep); do
653 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
654 tee -a $LOGS/$PACKAGE.log.$$
655 # programmers: next two messages are exact copy from remove_deps()
656 togrep1=$(_n 'Build dependencies to remove:')
657 togrep2=$(_n 'Removing:')
658 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
659 fgrep $togrep1 $LOGS/$i.log && \
660 fgrep $togrep2 $LOGS/$i.log && newline) | \
661 tee -a $LOGS/$PACKAGE.log.$$ && break
662 done
663 rm -f $CACHE/missing.dep
664 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
665 fi
667 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
668 # is enabled and cook fails we have ERROR in log, if no auto cook we have
669 # missing dep in cached file.
670 lerror=$(_n 'ERROR')
671 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
672 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
673 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
674 exit 1
675 fi
677 # Install local packages: package-version$arch
678 cd $PKGS
679 for i in $(uniq $CACHE/installed.local); do
680 # _ 'Installing dep (pkg/local): %s' "$i"
681 tazpkg install $i --root=$root --local --quiet --cookmode
682 done
684 # Install web or cached packages (if mirror is set to $PKGS we only
685 # use local packages).
686 for i in $(uniq $CACHE/installed.web); do
687 # _ 'Installing dep (web/cache): %s' "$i"
688 tazpkg get-install $i --root=$root --quiet --cookmode
689 done
691 update_installed_cook_diff
693 # Get source tarball and make sure we have source dir named:
694 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
695 # tarball if it exists.
696 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
697 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
698 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
699 LZMA_SRC=''
700 else
701 get_source || exit 1
702 fi
703 fi
704 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
705 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
706 if ! extract_source ; then
707 get_source
708 extract_source || exit 1
709 fi
710 if [ -n "$LZMA_SRC" ]; then
711 cd $pkgdir/source
712 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
713 mv tmp tmp-1; mkdir tmp
714 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
715 fi
716 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
717 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
718 fi
719 fi
720 cd $pkgdir/source/tmp
721 # Some archives are not well done and don't extract to one dir (ex lzma).
722 files=$(ls | wc -l)
723 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
724 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
725 mv * ../$PACKAGE-$VERSION/$TARBALL
726 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
727 mv * ../$PACKAGE-$VERSION
728 cd ..; rm -rf tmp
729 fi
731 # Libtool shared libs path hack.
732 case "$ARCH" in
733 arm*) cross libhack ;;
734 esac
736 # Execute receipt rules.
737 if grep -q ^compile_rules $receipt; then
738 _ 'Executing: %s' 'compile_rules'
739 echo "CFLAGS : $CFLAGS"
740 #echo "LDFLAGS : $LDFLAGS"
741 [ -d "$src" ] && cd $src
742 compile_rules $@ || exit 1
743 # Stay compatible with _pkg
744 [ -d "$src/_pkg" ] && mv $src/_pkg $install
745 # QA: compile_rules success so valid.
746 mkdir -p $install
747 else
748 # QA: no compile_rules so no error, valid.
749 mkdir -p $install
750 fi
752 # Actions to do after compiling the package
753 # Skip all for split packages (already done in main package)
754 if [ -z "$WANTED" ]; then
755 footer
756 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
757 fi
758 footer
760 # Execute testsuite.
761 if grep -q ^testsuite $receipt; then
762 title 'Running testsuite'
763 testsuite $@ || exit 1
764 footer
765 fi
767 update_installed_cook_diff force
768 }
771 # Cook quality assurance.
773 cookit_quality() {
774 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
775 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
776 fi
777 # ERROR can be echoed any time in cookit()
778 lerror=$(_n 'ERROR')
779 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
780 grep -Eq "(^$lerror|undefined reference to)" ; then
781 debug_info | tee -a $LOGS/$pkg.log
782 rm -f $command
783 exit 1
784 fi
785 }
788 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
789 # but it doesn't handle EXTRAVERSION.
791 packit() {
792 set_paths
794 # Handle cross compilation
795 case "$ARCH" in
796 arm*|x86_64) arch="-$ARCH" ;;
797 esac
799 title 'Pack: %s' "$PACKAGE $VERSION$arch"
801 if grep -q ^genpkg_rules $receipt; then
802 _ 'Executing: %s' 'genpkg_rules'
803 set -e; cd $pkgdir; mkdir -p $fs
804 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
805 $LOGS/$pkg.log
806 else
807 _ 'No packages rules: meta package'
808 mkdir -p $fs
809 fi
811 # Check CONFIG_FILES
812 if [ -n "$CONFIG_FILES" ]; then
813 for i in $CONFIG_FILES; do
814 if [ ! -e $fs$i ]; then
815 case $i in
816 */) mkdir -p $fs$i ;;
817 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
818 esac
819 fi
820 done
821 fi
823 # First QA check to stop now if genpkg_rules failed.
824 lerror=$(_n 'ERROR')
825 if fgrep -q ^$lerror $LOGS/$pkg.log; then
826 exit 1
827 fi
829 cd $taz
830 for file in receipt description.txt; do
831 [ ! -f "../$file" ] && continue
832 action 'Copying "%s"...' "$file"
833 cp -f ../$file $pack; chown 0.0 $pack/$file; status
834 done
835 copy_generic_files
837 # Strip and stuff files.
838 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
840 # Create files.list with redirecting find output.
841 action 'Creating the list of files...'
842 cd $fs
843 find . -type f -print > ../files.list
844 find . -type l -print >> ../files.list
845 cd ..; sed -i s/'^.'/''/ files.list
846 status
848 # Md5sum of files.
849 action 'Creating md5sum of files...'
850 while read file; do
851 [ -L "fs$file" ] && continue
852 [ -f "fs$file" ] || continue
853 case "$file" in
854 /lib/modules/*/modules.*|*.pyc) continue ;;
855 esac
856 md5sum "fs$file" | sed 's/ fs/ /'
857 done < files.list > md5sum
858 status
860 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
861 2>/dev/null | awk 'END{ print $1 }')
863 # Build cpio archives.
864 action 'Compressing the FS...'
865 find fs -newer $receipt -exec touch -hr $receipt {} \;
866 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
867 rm -rf fs
868 status
870 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
871 2>/dev/null | awk 'END{ print $1 }')
873 action 'Updating receipt sizes...'
874 sed -i s/^PACKED_SIZE.*$// receipt
875 sed -i s/^UNPACKED_SIZE.*$// receipt
876 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
877 status
879 # Set extra version.
880 if [ -n "$EXTRAVERSION" ]; then
881 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
882 sed -i s/^EXTRAVERSION.*$// receipt
883 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
884 status
885 fi
887 # Compress.
888 action 'Creating full cpio archive...'
889 find . -print | cpio -o -H newc --quiet > \
890 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
891 status
893 action 'Restoring original package tree...'
894 unlzma -c fs.cpio.lzma | cpio -idm --quiet
895 status
897 rm fs.cpio.lzma; cd ..
899 # QA and give info.
900 tazpkg=$(ls *.tazpkg)
901 packit_quality
902 footer "$(_ 'Package "%s" created' "$tazpkg")"
903 }
906 # Verify package quality and consistency.
908 packit_quality() {
909 #action 'QA: checking for broken link...'
910 #link=$(find $fs/usr -type l -follow)
911 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
912 #status
914 # Exit if any error found in log file.
915 lerror=$(_n 'ERROR')
916 if fgrep -q ^$lerror $LOGS/$pkg.log; then
917 rm -f $command
918 exit 1
919 fi
921 action 'QA: checking for empty package...'
922 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
923 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
924 newline; _ 'ERROR: empty package'
925 rm -f $command
926 exit 1
927 else
928 :; status
929 # Find and remove old package(s)
930 tempd="$(mktemp -d)"; cd "$tempd"
931 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
932 # Extract receipt from each matched package
933 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
934 name=$(. receipt; echo $PACKAGE)
935 rm receipt
936 if [ "$name" == "$pkg" ]; then
937 action 'Removing old package "%s"' "$(basename "$testpkg")"
938 rm -f "$testpkg"
939 status
940 fi
941 done
942 rm -r "$tempd"
943 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
944 sed -i /^${pkg}$/d $broken
945 #action 'Removing source tree...'
946 #rm -f $WOK/$pkg/source; status
947 fi
948 }
951 # Reverse "cat" command: prints input lines in the reverse order
953 tac() {
954 sed '1!G;h;$!d' $1
955 }
958 # Install package on --install or update the chroot.
960 install_package() {
961 case "$ARCH" in
962 arm*|x86_64)
963 arch="-$ARCH"
964 root="$CROSS_TREE/sysroot" ;;
965 esac
966 # Install package if requested but skip install if target host doesn't
967 # match build system or it will break the build chroot.
968 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
969 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
970 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
971 cd $PKGS
972 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
973 else
974 _ 'Unable to install package, build has failed.'; newline
975 exit 1
976 fi
977 fi
979 # Install package if part of the chroot to keep env up-to-date.
980 if [ -d "$root$INSTALLED/$pkg" ]; then
981 . /etc/slitaz/cook.conf
982 . $WOK/$pkg/taz/$pkg-*/receipt
983 _ 'Updating %s chroot environment...' "$ARCH"
984 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
985 cd $PKGS
986 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
987 fi
988 }
991 # remove chroot jail
993 umount_aufs() {
994 tac ${1}rw/aufs-umount.sh | sh
995 rm -rf ${1}rw
996 umount ${1}root
997 rmdir ${1}r*
998 }
1001 # Launch the cook command into a chroot jail protected by aufs.
1002 # The current filesystems are used read-only and updates are
1003 # stored in a separate branch.
1005 try_aufs_chroot() {
1007 base="/dev/shm/aufsmnt$$"
1009 # Can we setup the chroot? Is it already done?
1010 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1011 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1012 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1013 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1014 mkdir ${base}root ${base}rw || return
1016 _ 'Setup aufs chroot...'
1018 # Sanity check
1019 for i in / /proc /sys /dev/shm /home ; do
1020 case " $AUFS_MOUNTS " in
1021 *\ $i\ *) ;;
1022 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1023 esac
1024 done
1025 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1026 mount --bind $mnt ${base}root$mnt
1027 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1028 _ 'Aufs mount failure'
1029 umount ${base}root
1030 rm -rf ${base}r*
1031 return
1032 fi
1033 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1034 done
1035 trap "umount_aufs ${base}" INT
1037 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1038 status=$?
1040 _ 'Leaving aufs chroot...'
1041 umount_aufs $base
1042 # Install package outside the aufs jail
1043 install_package
1044 exit $status
1048 # Encode predefined XML entities
1050 xml_ent() {
1051 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1055 # Create a XML feed for freshly built packages.
1057 gen_rss() {
1058 pubdate=$(date '+%a, %d %b %Y %X')
1059 cat > $FEEDS/$pkg.xml <<EOT
1060 <item>
1061 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1062 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1063 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1064 <pubDate>$pubdate</pubDate>
1065 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1066 </item>
1067 EOT
1071 # Truncate stdout log file to $1 Mb.
1073 loglimit() {
1074 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1075 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1076 else
1077 tee /dev/stderr
1078 fi
1082 # Search file in mirrored packages
1084 search_file_mirror() {
1085 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1089 # Search file in local wok packages
1091 search_file_local() {
1092 # existing packages have precedence over the package/taz folder
1093 srch=$1
1094 { for package in $(find $PKGS -name '*.tazpkg'); do
1095 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1096 grep /$srch\$)" ]; then
1097 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1098 fi
1099 done } | sort -u
1103 # Ask in multiple choice
1105 ask_multiple() {
1106 local multiples first my_choice
1107 multiples="$1"
1108 first=$(echo "$multiples" | head -n1)
1109 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1110 _ 'Select one [%s]: ' "$first"; read my_choice
1111 found="${my_choice:-$first}"
1115 # Search file in local cache (fast), local wok packages, mirrored packages
1117 search_file() {
1118 local srch cache missing
1119 srch="$1"
1120 cache='/var/cache/ldsearch.cache'
1121 missing='/var/cache/missing.file'
1122 touch $cache $missing
1123 found=$(grep $srch $cache | cut -d$'\t' -f2)
1124 if [ -z "$found" ]; then
1125 found=$(search_file_local $srch)
1126 if [ -n "$found" ]; then
1127 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1128 ask_multiple "$found"
1129 fi
1130 echo -e "$srch\t$found" >> $cache
1131 else
1132 found=$(search_file_mirror $srch)
1133 if [ -n "$found" ]; then
1134 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1135 ask_multiple "$found"
1136 fi
1137 echo -e "$srch\t$found" >> $cache
1138 else
1139 echo "$srch" >> $missing
1140 fi
1141 fi
1142 fi
1147 # Receipt functions to ease packaging
1150 get_dev_files() {
1151 action 'Getting standard devel files...'
1152 mkdir -p $fs/usr/lib
1153 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1154 cp -a $install/usr/lib/*a $fs/usr/lib
1155 cp -a $install/usr/include $fs/usr
1156 status
1160 # Function to use in compile_rules() to copy man page from $src to $install
1162 cook_pick_manpages() {
1163 local name section
1164 action 'Copying man pages...'
1166 for i in $@; do
1167 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1168 section=${name##*/}; section=${section##*.}
1169 mkdir -p $install/usr/share/man/man$section
1170 cp -a $i $install/usr/share/man/man$section
1171 done
1172 status
1176 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1178 cook_copy_files() {
1179 action 'Copying files...'
1180 cd $install
1181 local i j
1182 IFS=$'\n'
1183 for i in $@; do
1184 for j in $(find . -name $i ! -type d); do
1185 mkdir -p $fs$(dirname ${j#.})
1186 cp -al $j $fs$(dirname ${j#.})
1187 done
1188 done
1189 cd - >/dev/null
1190 status
1194 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1196 cook_copy_folders() {
1197 action 'Copying folders...'
1198 cd $install
1199 local i j
1200 IFS=$'\n'
1201 for i in $@; do
1202 for j in $(find . -name $i -type d); do
1203 mkdir -p $fs$(dirname ${j#.})
1204 cp -al $j $fs$(dirname ${j#.})
1205 done
1206 done
1207 cd - >/dev/null
1208 status
1212 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1213 # (default: 16 and 48) from $install to $fs
1215 cook_copy_icons() {
1216 local sizes=$@
1217 action 'Copying hicolor icons...'
1218 mkdir -p $fs/usr/share/icons/hicolor
1219 for i in ${sizes:-16 48}; do
1220 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1221 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1222 $fs/usr/share/icons/hicolor
1223 done
1224 status
1231 # Commands
1234 case "$1" in
1235 usage|help|-u|-h)
1236 usage ;;
1238 list-wok)
1239 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1240 cd $WOK
1241 if [ "$ARCH" != 'i486' ]; then
1242 count=0
1243 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1244 do
1245 unset HOST_ARCH
1246 . $pkg
1247 count=$(($count + 1))
1248 colorize 34 "$PACKAGE"
1249 done
1250 else
1251 count=$(ls | wc -l)
1252 ls -1
1253 fi
1254 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1255 ;;
1257 activity)
1258 cat $activity ;;
1260 search)
1261 # Just a simple search function, we dont need more actually.
1262 query="$2"
1263 title 'Search results for "%s"' "$query"
1264 cd $WOK; ls -1 | grep "$query"
1265 footer ;;
1267 setup)
1268 # Setup a build environment
1269 check_root
1270 _ 'Cook: setup environment' | log
1271 title 'Setting up your environment'
1272 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1273 cd $SLITAZ
1274 init_db_files
1275 _ 'Checking for packages to install...'
1276 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1277 # ARCH-setup or 'cross check' should be used before: cook setup
1278 case "$ARCH" in
1279 arm*|x86_64)
1280 if [ ! -x '/usr/bin/cross' ]; then
1281 _ 'ERROR: %s is not installed' 'cross'
1282 exit 1
1283 fi
1284 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1285 . /etc/slitaz/cross.conf ;;
1286 esac
1287 for pkg in $SETUP_PKGS; do
1288 if [ -n "$forced" ]; then
1289 tazpkg -gi $pkg --forced
1290 else
1291 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1292 fi
1293 done
1295 # Handle --options
1296 case "$2" in
1297 --wok) hg clone $WOK_URL wok || exit 1 ;;
1298 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1299 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1300 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1301 esac
1303 # SliTaz group and permissions
1304 if ! grep -q ^slitaz /etc/group; then
1305 _ 'Adding group "%s"' 'slitaz'
1306 addgroup slitaz
1307 fi
1308 _ 'Setting permissions for group "%s"...' 'slitaz'
1309 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1310 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1311 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1313 *-setup)
1314 # Setup for cross compiling.
1315 arch="${1%-setup}"
1316 check_root
1317 . /etc/slitaz/cook.conf
1318 for pkg in $CROSS_SETUP; do
1319 if [ -n "$forced" ]; then
1320 tazpkg -gi $pkg --forced
1321 else
1322 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1323 fi
1324 done
1326 _ 'Cook: setup %s cross environment' "$arch" | log
1327 title 'Setting up your %s cross environment' "$arch"
1328 init_db_files
1329 sed -i \
1330 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1331 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1332 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1333 /etc/slitaz/cook.conf
1334 case "$arch" in
1335 arm)
1336 flags='-O2 -march=armv6'
1337 host="$ARCH-slitaz-linux-gnueabi" ;;
1338 armv6hf)
1339 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1340 host="$ARCH-slitaz-linux-gnueabi" ;;
1341 armv7)
1342 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1343 host="$ARCH-slitaz-linux-gnueabi" ;;
1344 x86_64)
1345 flags='-O2 -mtune=generic -pipe'
1346 host="$ARCH-slitaz-linux" ;;
1347 esac
1348 sed -i \
1349 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1350 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1351 . /etc/slitaz/cook.conf
1352 sysroot="$CROSS_TREE/sysroot"
1353 tools="/cross/$arch/tools"
1354 root="$sysroot"
1355 # L10n: keep the same width of translations to get a consistent view
1356 _ 'Target arch : %s' "$ARCH"
1357 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1358 _ 'Build flags : %s' "$flags"
1359 _ 'Arch sysroot : %s' "$sysroot"
1360 _ 'Tools prefix : %s' "$tools/bin"
1361 # Tell the packages manager where to find packages.
1362 _ 'Packages DB : %s' "$root$DB"
1363 mkdir -p $root$INSTALLED
1364 cd $root$DB; rm -f *.bak
1365 for list in packages.list packages.desc packages.equiv packages.md5; do
1366 rm -f $list
1367 ln -s $SLITAZ/packages/$list $list
1368 done
1369 # We must have the cross compiled glibc-base installed or default
1370 # i486 package will be used as dep by tazpkg and then break the
1371 # cross environment
1372 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1373 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1374 fi
1375 # Show GCC version or warn if not yet compiled.
1376 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1377 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1378 else
1379 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1380 _ 'Run "%s" to cook a toolchain' 'cross compile'
1381 fi
1382 footer ;;
1384 test)
1385 # Test a cook environment.
1386 _ 'Cook test: testing the cook environment' | log
1387 [ ! -d "$WOK" ] && exit 1
1388 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1389 cook cooktest ;;
1391 new)
1392 # Create the package folder and an empty receipt.
1393 pkg="$2"
1394 [ -z "$pkg" ] && usage
1395 newline
1396 if [ -d "$WOK/$pkg" ]; then
1397 _ 'Package "%s" already exists.' "$pkg"
1398 exit 1
1399 fi
1401 action 'Creating folder "%s"' "$WOK/$pkg"
1402 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1404 action 'Preparing the package receipt...'
1405 cp $DATA/receipt .
1406 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1407 status; newline
1409 # Interactive mode, asking and seding.
1410 case "$3" in
1411 --interactive|-x)
1412 _ 'Entering interactive mode...'
1413 separator
1414 _ 'Package : %s' "$pkg"
1416 _n 'Version : ' ; read answer
1417 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1419 _n 'Category : ' ; read answer
1420 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1422 # L10n: Short description
1423 _n 'Short desc : ' ; read answer
1424 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1426 _n 'Maintainer : ' ; read answer
1427 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1429 _n 'License : ' ; read answer
1430 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1432 _n 'Web site : ' ; read answer
1433 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1434 newline
1436 # Wget URL.
1437 _ 'Wget URL to download source tarball.'
1438 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1439 _n 'Wget url : ' ; read answer
1440 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1442 # Ask for a stuff dir.
1443 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1444 if [ "$?" -eq 0 ]; then
1445 action 'Creating the stuff directory...'
1446 mkdir $WOK/$pkg/stuff; status
1447 fi
1449 # Ask for a description file.
1450 confirm "$(_n 'Are you going to write a description? (y/N)')"
1451 if [ "$?" -eq 0 ]; then
1452 action 'Creating the "%s" file...' 'description.txt'
1453 touch $WOK/$pkg/description.txt; status
1454 fi
1456 footer "$(_ 'Receipt is ready to use.')" ;;
1457 esac ;;
1459 list)
1460 # Cook a list of packages (better use the Cooker since it will order
1461 # packages before executing cook).
1462 check_root
1463 if [ -z "$2" ]; then
1464 newline; _ 'No list in argument.'; newline
1465 exit 1
1466 fi
1467 if [ ! -f "$2" ]; then
1468 newline; _ 'List "%s" not found.' "$2"; newline
1469 exit 1
1470 fi
1472 _ 'Starting cooking the list "%s"' "$2" | log
1474 for pkg in $(cat $2); do
1475 cook $pkg || broken
1476 done ;;
1478 clean-wok)
1479 check_root
1480 newline; action 'Cleaning all packages files...'
1481 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1482 status; newline ;;
1484 clean-src)
1485 check_root
1486 newline; action 'Cleaning all packages sources...'
1487 rm -rf $WOK/*/source
1488 status; newline ;;
1490 uncook)
1491 cd $WOK
1492 count=0
1493 title 'Checking for uncooked packages'
1495 for pkg in *; do
1496 unset HOST_ARCH EXTRAVERSION
1497 [ ! -e $pkg/receipt ] && continue
1498 . $pkg/receipt
1499 # Source cooked pkg receipt to get EXTRAVERSION
1500 if [ -d "$WOK/$pkg/taz" ]; then
1501 cd $WOK/$pkg/taz/$pkg-*
1502 . receipt; cd $WOK
1503 fi
1504 case "$ARCH" in
1505 i486)
1506 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1507 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1508 count=$(($count + 1))
1509 colorize 34 "$pkg"
1510 fi ;;
1511 arm*)
1512 # Check only packages included in arch
1513 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1514 # *.tazpkg
1515 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1516 count=$(($count + 1))
1517 colorize 34 "$pkg"
1518 fi
1519 fi ;;
1520 esac
1521 done
1523 if [ "$count" -gt "0" ]; then
1524 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1525 else
1526 _ 'All packages are cooked :-)'
1527 newline
1528 fi
1529 ;;
1531 pkgdb)
1532 # Create suitable packages list for TazPkg and only for built packages
1533 # as well as flavors files for TazLiTo. We don't need logs since we do it
1534 # manually to ensure everything is fine before syncing the mirror.
1535 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1536 ;;
1538 *)
1539 # Just cook and generate a package.
1540 check_root
1541 time=$(date +%s)
1542 pkg="$1"
1543 [ -z "$pkg" ] && usage
1544 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1545 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1546 receipt="$WOK/$pkg/receipt"
1547 check_pkg_in_wok
1548 newline
1550 unset inst
1551 unset_receipt
1552 . $receipt
1554 # Handle cross compilation.
1555 case "$ARCH" in
1556 arm*)
1557 if [ -z "$HOST_ARCH" ]; then
1558 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1559 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1560 _ 'cook: %s' "$error"
1561 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1562 _ 'Cook skip: %s' "$error" | log
1563 newline
1564 exit 1
1565 fi ;;
1566 esac
1568 # Some packages are not included in some arch or fail to cross compile.
1569 : ${HOST_ARCH=i486}
1570 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1571 # Handle arm{v6hf,v7,..}
1572 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1573 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1574 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1575 _ 'cook: %s' "error"
1576 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1577 _ 'Cook skip: %s' "$error" | log
1578 sed -i /^${pkg}$/d $broken
1579 newline
1580 exit 0
1581 fi
1583 # Skip blocked, 3 lines also for the Cooker.
1584 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1585 _ 'Package "%s" is blocked' "$pkg"; newline
1586 exit 0
1587 fi
1589 try_aufs_chroot "$@"
1591 # Log and source receipt.
1592 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1593 echo "cook:$pkg" > $command
1594 [ "$lastcooktime" ] &&
1595 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1596 while read cmd duration start; do
1597 [ $(($start + $duration)) -lt $(date +%s) ] &&
1598 echo "sed -i '/^$cmd $duration/d' $cooktime"
1599 done < $cooktime | sh
1601 # Display and log info if cook process stopped.
1602 # FIXME: gettext not working (in single quotes) here!
1603 trap '_ "\n\nCook stopped: control-C\n\n" | \
1604 tee -a $LOGS/$pkg.log' INT
1606 # Handle --options
1607 case "$2" in
1608 --clean|-c)
1609 action 'Cleaning "%s"' "$pkg"
1610 cd $WOK/$pkg; rm -rf install taz source
1611 status; newline
1612 exit 0 ;;
1614 --install|-i)
1615 inst='yes' ;;
1617 --getsrc|-gs)
1618 title 'Getting source for "%s"' "$pkg"
1619 get_source
1620 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1621 exit 0 ;;
1623 --block|-b)
1624 action 'Blocking package "%s"' "$pkg"
1625 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1626 status; newline
1627 exit 0 ;;
1629 --unblock|-ub)
1630 action 'Unblocking package "%s"' "$pkg"
1631 sed -i "/^${pkg}$/"d $blocked
1632 status; newline
1633 exit 0 ;;
1635 --pack)
1636 if [ -d $WOK/$pkg/taz ]; then
1637 rm -rf $WOK/$pkg/taz
1638 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1639 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1640 clean_log
1641 else
1642 _ 'Need to build "%s"' "$pkg"
1643 exit 0
1644 fi
1645 exit 0 ;;
1647 --cdeps)
1648 if [ ! -d $WOK/$pkg/taz ]; then
1649 _ 'Need to build "%s"' "$pkg"
1650 exit 0
1651 fi
1653 title 'Checking depends'
1654 lddlist='/tmp/lddlist'; touch $lddlist
1655 missing='/var/cache/missing.file'
1657 # find all deps using ldd
1658 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1659 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1660 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1661 done #"
1663 # remove exe/so duplicates
1664 sort -u $lddlist > $lddlist.sorted
1666 # search packages
1667 for exefile in $(cat $lddlist.sorted); do
1668 search_file $exefile
1669 echo "$found" >> $lddlist.pkgs
1670 echo -n '.'
1671 done
1672 echo
1674 # remove packages duplicates
1675 sort -u $lddlist.pkgs > $lddlist.final
1676 sort -u $missing > $missing.final
1677 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1678 exit 0 ;;
1679 esac
1681 # Rotate log
1682 for i in $(seq 9 -1 1); do
1683 j=$(($i - 1))
1684 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1685 done
1686 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1688 # Check if wanted is built now so we have separate log files.
1689 for wanted in $WANTED ; do
1690 if grep -q "^$wanted$" $blocked; then
1691 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1692 newline
1693 rm -f $command
1694 exit 1
1695 fi
1696 if grep -q "^$wanted$" $broken; then
1697 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1698 newline
1699 rm -f $command
1700 exit 1
1701 fi
1702 if [ ! -d "$WOK/$wanted/install" ]; then
1703 cook "$wanted" || exit 1
1704 fi
1705 done
1707 # Cook and pack or exit on error and log everything.
1708 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1709 remove_deps | tee -a $LOGS/$pkg.log
1710 cookit_quality
1711 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1712 clean_log
1714 # Exit if any error in packing.
1715 lerror=$(_n 'ERROR')
1716 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1717 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1718 debug_info | tee -a $LOGS/$pkg.log
1719 rm -f $command
1720 exit 1
1721 fi
1723 # Create an XML feed
1724 gen_rss
1726 # Time and summary
1727 time=$(($(date +%s) - $time))
1728 summary | tee -a $LOGS/$pkg.log
1729 newline
1731 # We may want to install/update (outside aufs jail !).
1732 [ -s /aufs-umount.sh ] ||
1733 install_package
1735 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1736 # You want automation: use the Cooker Build Bot.
1737 rm -f $command ;;
1738 esac
1740 exit 0