cookutils view cook @ rev 861

cook: normalize file time
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Jan 08 14:29:40 2017 +0100 (2017-01-08)
parents 2fe198d0ed7b
children 1520231a65c2
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'
19 _() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; echo; }
20 _n() { local T="$1"; shift; printf "$(gettext "$T")" "$@"; }
21 _p() {
22 local S="$1" P="$2" N="$3"; shift; shift; shift;
23 printf "$(ngettext "$S" "$P" "$N")" "$@"; }
26 #
27 # Functions
28 #
30 usage() {
31 cat <<EOT
33 $(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
35 $(boldify "$(_ 'Commands:')")
36 usage|help $(_ 'Display this short usage.')
37 setup $(_ 'Setup your build environment.')
38 *-setup $(_ 'Setup a cross environment.')
39 * = {arm|armv6hf|armv7|x86_64}
40 test $(_ 'Test environment and cook a package.')
41 list-wok $(_ 'List packages in the wok.')
42 search $(_ 'Simple packages search function.')
43 new $(_ 'Create a new package with a receipt.')
44 list $(_ 'Cook a list of packages.')
45 clean-wok $(_ 'Clean-up all packages files.')
46 clean-src $(_ 'Clean-up all packages sources.')
47 uncook $(_ 'Check for uncooked packages')
48 pkgdb $(_ 'Create packages DB lists and flavors.')
50 $(boldify "$(_ 'Options:')")
51 cook <pkg>
52 --clean -c $(_ 'clean the package in the wok.')
53 --install -i $(_ 'cook and install the package.')
54 --getsrc -gs $(_ 'get the package source tarball.')
55 --block -b $(_ 'block a package so cook will skip it.')
56 --unblock -ub $(_ 'unblock a blocked package.')
57 --cdeps $(_ 'check dependencies of cooked package.')
58 --pack $(_ 'repack an already built package.')
59 --debug $(_ 'display debugging messages.')
60 --continue $(_ 'continue running compile_rules.')
61 cook new <pkg>
62 --interactive -x $(_ 'create a receipt interactively.')
63 cook setup
64 --wok $(_ 'clone the cooking wok from Hg repo.')
65 --stable $(_ 'clone the stable wok from Hg repo.')
66 --undigest $(_ 'clone the undigest wok from Hg repo.')
67 --tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
68 --forced $(_ 'force reinstall of chroot packages.')
69 cook pkgdb
70 --flavors $(_ 'create up-to-date flavors files.')
72 EOT
73 exit 0
74 }
77 # We don't want these escapes in web interface.
79 clean_log() {
80 sed -i -e s'|\[70G\[ \[1;32m| |' \
81 -e s'|\[0;39m \]||' $LOGS/$pkg.log
82 }
85 # Be sure package exists in wok.
87 check_pkg_in_wok() {
88 if [ ! -d "$WOK/$pkg" ]; then
89 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
90 exit 1
91 fi
92 }
95 if_empty_value() {
96 if [ -z "$value" ]; then
97 # L10n: QA is quality assurance
98 _ 'QA: empty variable: %s' "$var=\"\""; newline
99 exit 1
100 fi
101 }
104 # Initialize files used in $CACHE
106 init_db_files() {
107 _ 'Creating directories structure in "%s"' "$SLITAZ"
108 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
109 _ 'Creating DB files in "%s"' "$CACHE"
110 for f in $activity $command $broken $blocked; do
111 touch $f
112 done
113 }
116 # QA: check a receipt consistency before building.
118 receipt_quality() {
119 _ 'QA: checking package receipt...'
120 unset online
121 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
122 online='online'
123 fi
124 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
125 unset value
126 value="$(. $receipt; eval echo \$$var)"
127 case "$var" in
128 PACKAGE|VERSION|SHORT_DESC)
129 if_empty_value ;;
130 CATEGORY)
131 value="${value:-empty}"
132 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
133 if ! echo " $valid " | grep -q " $value "; then
134 _ 'QA: unknown category "%s"' "$value"
135 longline "$(_ 'Please, use one of: %s' "$valid")"
136 newline
137 exit 1
138 fi ;;
139 WEB_SITE)
140 # We don't check WGET_URL since if dl is needed it will fail.
141 # Break also if we're not online. Here error is not fatal.
142 if_empty_value
143 [ -z "$online" ] && break
144 if ! busybox wget -T 12 -s $value 2>/dev/null; then
145 _ 'QA: unable to reach "%s"' "$value"
146 fi ;;
147 esac
148 done
149 }
152 # Paths used in receipt and by cook itself.
154 set_paths() {
155 pkgdir="$WOK/$PACKAGE"
156 . "$pkgdir/receipt"
157 basesrc="$pkgdir/source"
158 tmpsrc="$basesrc/tmp"
159 src="$basesrc/$PACKAGE-$VERSION"
160 taz="$pkgdir/taz"
161 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
162 fs="$pack/fs"
163 stuff="$pkgdir/stuff"
164 install="$pkgdir/install"
165 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
166 lzma_tarball="$pkgsrc.tar.lzma"
167 if [ -n "$PATCH" ]; then
168 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
169 fi
170 if [ -n "$WANTED" ]; then
171 basesrc="$WOK/$WANTED/source"
172 src="$basesrc/$WANTED-$VERSION"
173 install="$WOK/$WANTED/install"
174 wanted_stuff="$WOK/$WANTED/stuff"
175 fi
176 if [ -n "$SOURCE" ]; then
177 source_stuff="$WOK/$SOURCE/stuff"
178 fi
179 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
180 if [ -f "$WOK/linux/receipt" ]; then
181 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
182 kbasevers=${kvers:0:3}
183 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
184 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
185 kbasevers=${kvers:0:3}
186 fi
187 # Python version
188 if [ -f "$WOK/python/receipt" ]; then
189 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
190 fi
191 # Perl version for some packages needed it
192 if [ -f "$WOK/perl/receipt" ]; then
193 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
194 fi
195 # Old way compatibility.
196 _pkg="$install"
197 }
200 # Create source tarball when URL is a SCM.
202 create_tarball() {
203 local tarball
204 tarball="$pkgsrc.tar.bz2"
205 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
206 _ 'Creating tarball "%s"' "$tarball"
207 if [ -n "$LZMA_SRC" ]; then
208 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
209 LZMA_SRC=''
210 else
211 tar -cjf $tarball $pkgsrc || exit 1
212 mv $tarball $SRC; rm -rf $pkgsrc
213 fi
214 TARBALL="$tarball"
215 }
218 # Get package source. For SCM we are in cache so clone here and create a
219 # tarball here.
221 get_source() {
222 local url
223 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
224 set_paths
225 pwd=$(pwd)
226 case "$WGET_URL" in
227 http://*|ftp://*)
228 # Busybox Wget is better!
229 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
230 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
231 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
233 https://*)
234 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
235 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
236 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
238 hg*|mercurial*)
239 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
240 url=${WGET_URL#hg|}
241 else
242 url=${WGET_URL#mercurial|}
243 fi
244 _ 'Getting source from %s...' 'Hg'
245 _ 'URL: %s' "$url"
246 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
247 if [ -n "$BRANCH" ]; then
248 _ 'Hg branch: %s' "$BRANCH"
249 hg clone $url --rev $BRANCH $pkgsrc || \
250 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
251 else
252 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
253 fi
254 rm -rf $pkgsrc/.hg
255 create_tarball ;;
257 git*)
258 url=${WGET_URL#git|}
259 _ 'Getting source from %s...' 'Git'
260 _ 'URL: %s' "$url"
261 cd $SRC
262 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
263 if [ -n "$BRANCH" ]; then
264 _ 'Git branch: %s' "$BRANCH"
265 cd $pkgsrc; git checkout $BRANCH; cd ..
266 fi
267 cd $SRC
268 create_tarball ;;
270 cvs*)
271 url=${WGET_URL#cvs|}
272 mod=$PACKAGE
273 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
274 _ 'Getting source from %s...' 'CVS'
275 _ 'URL: %s' "$url"
276 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
277 _ 'Cloning to "%s"' "$pwd/$mod"
278 cvs -d:$url co $mod && mv $mod $pkgsrc
279 create_tarball ;;
281 svn*|subversion*)
282 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
283 url=${WGET_URL#svn|}
284 else
285 url=${WGET_URL#subversion|}
286 fi
287 _ 'Getting source from %s...' 'SVN'
288 _ 'URL: %s' "$url"
289 if [ -n "$BRANCH" ]; then
290 echo t | svn co $url -r $BRANCH $pkgsrc
291 else
292 echo t | svn co $url $pkgsrc
293 fi
294 create_tarball ;;
296 bzr*)
297 url=${WGET_URL#bzr|}
298 _ 'Getting source from %s...' 'bazaar'
299 cd $SRC
300 pkgsrc=${url#*:}
301 if [ -n "$BRANCH" ]; then
302 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
303 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
304 else
305 echo "bzr -Ossl.cert_reqs=none branch $url"
306 bzr -Ossl.cert_reqs=none branch $url
307 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
308 _ "Don't forget to add to receipt:"
309 echo -e "BRANCH=\"$BRANCH\"\n"
310 fi
311 mv $pkgsrc $pkgsrc-$BRANCH
312 pkgsrc="$pkgsrc-$BRANCH"
313 create_tarball ;;
315 *)
316 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
317 tee -a $LOGS/$PACKAGE.log
318 exit 1 ;;
319 esac
320 }
323 # Extract source package.
325 extract_source() {
326 if [ ! -s "$SRC/$TARBALL" ]; then
327 local url
328 url="$MIRROR_URL/sources/packages"
329 url="$url/${TARBALL:0:1}/$TARBALL"
330 _ 'Getting source from %s...' 'mirror'
331 _ 'URL: %s' "$url"
332 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
333 fi
334 _ 'Extracting source archive "%s"' "$TARBALL"
335 case "$TARBALL" in
336 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
337 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
338 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
339 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
340 *.tar) tar -xf $SRC/$TARBALL ;;
341 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
342 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
343 tar -xf $SRC/$TARBALL 2>/dev/null;;
344 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
345 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
346 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
347 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
348 *) cp $SRC/$TARBALL $(pwd) ;;
349 esac
350 }
353 # Display time.
355 disp_time() {
356 local sec div min
357 sec="$1"
358 div=$(( ($1 + 30) / 60))
359 case $div in
360 0) min='';;
361 # L10n: 'm' is for minutes (approximate cooking time)
362 *) min=$(_n ' ~ %dm' "$div");;
363 esac
365 # L10n: 's' is for seconds (cooking time)
366 _ '%ds%s' "$sec" "$min"
367 }
370 # Display cooked package summary.
372 summary() {
373 set_paths
374 cd $WOK/$pkg
375 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
376 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
377 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
378 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
379 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
380 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
382 _ 'Summary for: %s' "$PACKAGE $VERSION"
383 separator
385 # L10n: keep the same width of translations to get a consistent view
386 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
387 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
388 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
389 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
390 _ 'Packed : %s' "$fs"
391 _ 'Compressed : %s' "$size"
392 _ 'Files : %s' "$files"
393 _ 'Cook time : %s' "$(disp_time "$time")"
394 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
395 _ 'Host arch : %s' "$ARCH"
396 separator
397 }
400 # Display debugging error info.
402 debug_info() {
403 title 'Debug information'
404 # L10n: specify your format of date and time (to help: man date)
405 # L10n: not bad one is '+%x %R'
406 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
407 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
408 # L10n: Please, translate all messages beginning with ERROR in a same way
409 lerror=$(_n 'ERROR')
410 for error in \
411 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
412 'error:' 'fatal error:' 'undefined reference to' \
413 'Unable to connect to' 'link: cannot find the library' \
414 'CMake Error' ': No such file or directory' \
415 'Could not read symbols: File in wrong format'
416 do
417 fgrep "$error" $LOGS/$pkg.log
418 done > $LOGS/$pkg.log.debug_info 2>&1
419 cat $LOGS/$pkg.log.debug_info
420 rm -f $LOGS/$pkg.log.debug_info
421 footer
422 }
425 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
426 # so some packages need to copy these files with the receipt and genpkg_rules.
428 copy_generic_files() {
429 # $LOCALE is set in cook.conf
430 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
431 if [ -d "$install/usr/share/locale" ]; then
432 mkdir -p $fs/usr/share/locale
433 for i in $LOCALE; do
434 if [ -d "$install/usr/share/locale/$i" ]; then
435 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
436 fi
437 done
438 fi
439 fi
441 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
442 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
443 if [ -d "$install/usr/share/pixmaps" ]; then
444 mkdir -p $fs/usr/share/pixmaps
445 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
446 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
447 $fs/usr/share/pixmaps
448 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
449 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
450 $fs/usr/share/pixmaps
451 fi
452 fi
454 # Custom or homemade PNG pixmap can be in stuff.
455 if [ -f "$stuff/$PACKAGE.png" ]; then
456 mkdir -p $fs/usr/share/pixmaps
457 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
458 fi
459 fi
461 # Desktop entry (.desktop).
462 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
463 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
464 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
465 mkdir -p $fs/usr/share
466 cp -a $install/usr/share/applications $fs/usr/share
467 fi
468 fi
470 # Homemade desktop file(s) can be in stuff.
471 if [ -d "$stuff/applications" ]; then
472 mkdir -p $fs/usr/share
473 cp -a $stuff/applications $fs/usr/share
474 fi
475 if [ -f "$stuff/$PACKAGE.desktop" ]; then
476 mkdir -p $fs/usr/share/applications
477 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
478 fi
480 # Add custom licenses
481 if [ -d "$stuff/licenses" ]; then
482 mkdir -p $fs/usr/share/licenses
483 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
484 fi
485 }
488 # Get list of supported locales...
490 get_supported_locales() {
491 local lpc='/slitaz-i18n/stuff/locale-pack.conf' LOCALE_PACK
492 if [ -e "$WOK$lpc" ]; then
493 # ... from package in the local wok
494 . "$WOK$lpc"
495 else
496 # ... from Hg
497 temp_conf=$(mktemp)
498 wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
499 if [ -s $temp_conf ]; then
500 . $temp_conf
501 else
502 # Give up and use hardcoded list
503 LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
504 pt_BR ro ru sl sv tr uk zh_CN zh_TW"
505 fi
506 rm $temp_conf
507 fi
508 echo $LOCALE_PACK
509 }
512 # Fix common errors and warnings in the .desktop files
513 # Fixing can be disabled with COOKOPTS="!fixdesktops"
515 fix_desktop_files() {
516 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
517 [ -z "$(find $install -type f -name '*.desktop')" ] && return
519 local size0=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
520 local time0=$(date +%s)
522 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
523 tazpkg -gi desktop-file-utils-extra --quiet
524 fi
526 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
527 # Default value is "" (empty). That means for us that we'll use the full
528 # list of supported locales here.
529 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
531 for desktop in $(find $install -type f -name '*.desktop'); do
532 cp "$desktop" "$desktop.orig"
534 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
535 sdft "$desktop" -i
537 # Fix common errors in .desktop file
538 fix-desktop-file "$desktop"
540 # Strip unsupported locales from .desktop file
541 [ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
542 sdft "$desktop" -i -k "$LOCALE"
544 # Extra-strip
545 [ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
546 sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
548 if [ -n "$QA" ]; then
549 # Check the rest of errors, warnings and tips
550 _ 'QA: Checking %s...' "$(basename $desktop)"
551 diff "$desktop.orig" "$desktop"
552 desktop-file-validate "$desktop" | busybox fold -s
553 echo
554 fi
556 rm "$desktop.orig"
557 done
559 local size1=$(find $install -type f -name '*.desktop' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
560 local time1=$(date +%s)
561 comp_summary "$time0" "$time1" "$size0" "$size1"
562 }
565 # Compressor mini summary
567 comp_summary() {
568 [ "$3" -eq 0 ] && return
569 local time=$(($2 - $1))
570 local saving=$(( ($3 - $4) / 1024 ))
571 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$3" "$4" "$saving"
572 }
575 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
576 # as removing unneeded files like in Python packages. Cross compiled binaries
577 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
578 # Stripping can be disabled with COOKOPTS="!strip"
580 strip_package() {
581 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
583 case "$ARCH" in
584 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
585 *) export STRIP='strip' ;;
586 esac
587 action 'Executing strip on all files...'
588 local size0=0 size1=0 oldsize newsize
589 local time0=$(date +%s)
591 # Strip executable files
592 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
593 if [ -d "$dir" ]; then
594 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
595 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
596 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
597 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
598 fi
599 done
601 # Strip shared and static libraries
602 # Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
603 oldsize=$(find $fs -type f \( \
604 -name '*.so*' -o -name '*.a' -o \
605 -name '*.pyc' -o -name '*.pyo' -o \
606 -name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
608 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
609 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
610 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
611 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
613 newsize=$(find $fs -type f \( \
614 -name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
616 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
618 local time1=$(date +%s)
619 status
620 comp_summary "$time0" "$time1" "$size0" "$size1"
621 }
624 # Strip unsupported locales (.mo files)
626 strip_mo_i18n() {
627 [ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
629 [ ! -d "$fs/usr/share/locale" ] && return
630 [ -z "$(find $fs/usr/share/locale -type f -name '*.mo')" ] && return
632 action 'Thin out translation files...'
633 local size0=$(find $fs/usr/share/locale -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
634 local time0=$(date +%s)
636 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
637 # Default value is "" (empty). That means for us that we'll use the full
638 # list of supported locales here.
639 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
641 # Existing locales
642 elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
644 # Thin out the list of existing locales. At the end there will be only locales that need
645 # deleting (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
646 for keep_locale in $LOCALE; do
647 elocales=${elocales//$keep_locale}
648 done
650 # Remove the unsupported locales
651 for rem_locale in $elocales; do
652 [ -d "$fs/usr/share/locale/$rem_locale" ] &&
653 rm -r "$fs/usr/share/locale/$rem_locale"
654 done
656 local size1=$(find $fs -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
657 local time1=$(date +%s)
658 status
659 comp_summary "$time0" "$time1" "$size0" "$size1"
660 }
663 # Normalize all *.mo files: unconditionally convert to UTF-8; remove strings that are not really added
664 # to the translation (msgid = msgstr)
665 # Normalization can be disabled with COOKOPTS="!monorm"
667 normalize_mo() {
668 [ "${COOKOPTS/!monorm/}" != "$COOKOPTS" ] && return
669 [ -z "$(find $install -type f -name '*.mo')" ] && return
671 action 'Normalizing mo files...'
672 local size0=$(find $install -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
673 local time0=$(date +%s)
675 # Gettext functions: msgunfmt, msguniq, msgconv, msgfmt
676 tazpkg -gi gettext --quiet
677 # Gconv modules (convert to UTF-8)
678 tazpkg -gi glibc-locale --quiet
680 # Process all existing *.mo files
681 for mo in $(find "$install" -type f -name '*.mo'); do
682 tmpfile="$(mktemp)"
684 msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'
685 # add newline
686 echo >> "$tmpfile"
688 # get Plural-Forms
689 awk '
690 BEGIN { skip = ""; }
691 {
692 if (! skip) {
693 s = $0;
694 gsub(/^[^\"]*\"/, "", s);
695 gsub(/\"$/, "", s);
696 printf("%s", s);
697 }
698 if (! $0) skip = "yes";
699 }
700 ' "$tmpfile" | sed 's|\\n|\n|g' | grep "^Plural-Forms:" > "$tmpfile.pf"
702 if ! grep -q 'msgid_plural' "$tmpfile"; then
703 echo > "$tmpfile.pf"
704 fi
706 # main
707 awk -v pf="$(cat "$tmpfile.pf")" '
708 function clean() {
709 mode = msgctxt = msgid = msgid_plural = msgstr = msgstr0 = msgstr1 = msgstr2 = msgstr3 = msgstr4 = msgstr5 = "";
710 }
712 function getstring() {
713 # Skip unquoted words at the beginning (msgid, msgstr...) and get string from inside quotes
714 s = $0;
715 gsub(/^[^\"]*\"/, "", s);
716 gsub(/\"$/, "", s);
717 return s;
718 }
720 BEGIN {
721 printf("msgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n");
722 if (pf)
723 printf("\"%s\\n\"\n", pf);
724 printf("\n");
725 skip = 1;
726 clean();
727 }
729 {
730 # Skip the entire header
731 if (!skip) {
732 if ($1 == "msgctxt" || $1 == "msgid" || $1 == "msgstr" || $1 == "msgid_plural")
733 mode = $1;
734 if ($1 == "msgstr[0]") mode = "msgstr0";
735 if ($1 == "msgstr[1]") mode = "msgstr1";
736 if ($1 == "msgstr[2]") mode = "msgstr2";
737 if ($1 == "msgstr[3]") mode = "msgstr3";
738 if ($1 == "msgstr[4]") mode = "msgstr4";
739 if ($1 == "msgstr[5]") mode = "msgstr5";
741 if (mode == "msgctxt") msgctxt = msgctxt getstring();
742 if (mode == "msgid") msgid = msgid getstring();
743 if (mode == "msgstr") msgstr = msgstr getstring();
744 if (mode == "msgid_plural") msgid_plural = msgid_plural getstring();
745 if (mode == "msgstr0") msgstr0 = msgstr0 getstring();
746 if (mode == "msgstr1") msgstr1 = msgstr1 getstring();
747 if (mode == "msgstr2") msgstr2 = msgstr2 getstring();
748 if (mode == "msgstr3") msgstr3 = msgstr3 getstring();
749 if (mode == "msgstr4") msgstr4 = msgstr4 getstring();
750 if (mode == "msgstr5") msgstr5 = msgstr5 getstring();
752 if (! $0) {
753 if (msgid != msgstr) {
754 if (msgctxt) printf("msgctxt \"%s\"\n", msgctxt);
755 printf("msgid \"%s\"\n", msgid);
756 if (msgid_plural) printf("msgid_plural \"%s\"\n", msgid_plural);
757 if (msgstr) printf("msgstr \"%s\"\n", msgstr);
758 if (msgstr0) printf("msgstr[0] \"%s\"\n", msgstr0);
759 if (msgstr1) printf("msgstr[1] \"%s\"\n", msgstr1);
760 if (msgstr2) printf("msgstr[2] \"%s\"\n", msgstr2);
761 if (msgstr3) printf("msgstr[3] \"%s\"\n", msgstr3);
762 if (msgstr4) printf("msgstr[4] \"%s\"\n", msgstr4);
763 if (msgstr5) printf("msgstr[5] \"%s\"\n", msgstr5);
764 printf("\n");
765 }
766 clean();
767 }
768 }
769 if ($0 == "") skip = "";
770 }
771 ' "$tmpfile" > "$tmpfile.awk"
773 msgfmt "$tmpfile.awk" -o "$tmpfile.mo"
775 if [ -s "$tmpfile.mo" ]; then
776 rm "$mo"; mv "$tmpfile.mo" "$mo"
777 else
778 _ 'Error processing %s' "$mo"
779 [ -e "$tmpfile.mo" ] && rm "$tmpfile.mo"
780 fi
782 # Clean
783 rm "$tmpfile" "$tmpfile.pf" "$tmpfile.awk"
784 done
786 local size1=$(find $install -type f -name '*.mo' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
787 local time1=$(date +%s)
788 status
789 comp_summary "$time0" "$time1" "$size0" "$size1"
790 }
793 # Remove files provided by split packages
794 # For example:
795 # 1. Package "pkg-main":
796 # SPLIT="pkg-1 pkg-2 pkg-extra"
797 # 2. Package="pkg-extra":
798 # WANTED="pkg-main"
799 # BUILD_DEPENDS="pkg-1 pkg-2"
800 # cook_copy_folders usr
801 # cook_split_rm $BUILD_DEPENDS
803 cook_split_rm() {
804 for i in $@; do
805 action 'Remove files provided by split package %s...' "$i"
806 while read j; do
807 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
808 rmdir "$(dirname "$fs$j")" 2>/dev/null
809 done < $WOK/$i/taz/$i-$VERSION/files.list
810 :; status
811 done
812 }
815 # Update installed.cook.diff
817 update_installed_cook_diff() {
818 # If a cook failed deps are removed.
819 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
820 cd $CACHE
821 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
822 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
823 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
824 }
827 # Remove installed deps.
829 remove_deps() {
830 # Now remove installed build deps.
831 diff='/tmp/installed.cook.diff'
832 if [ -s $diff ]; then
833 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
834 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
835 _n 'Build dependencies to remove:'; echo " $nb"
836 [ -n "$root" ] && echo "root=\"$root\""
837 _n 'Removing:'
838 for dep in $deps; do
839 echo -n " $dep"
840 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
841 done
842 newline; newline
843 # Keep the last diff for debug and info.
844 mv -f $diff $CACHE/installed.diff
845 fi
846 }
849 # Function to compress all man pages
850 # Compressing can be disabled with COOKOPTS="!manz"
852 compress_manpages() {
853 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
855 case "$ARCH" in
856 arm*) return;; # While SliTaz-arm miss `advancecomp`
857 esac
858 local manpath="$install/usr/share/man" dest link
859 [ -d "$manpath" ] || return
861 action 'Compressing man pages...'
863 local size0=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
864 local time0=$(date +%s)
865 # We'll use only Gzip compression, so decompress other formats first
866 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
867 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
869 # Fast compress with gzip
870 find $manpath -type f -name '*.[1-9]*' -exec gzip \{\} \;
872 # Fix symlinks
873 for i in $(find $install/usr/share/man -type l); do
874 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
875 link=$(echo $i | sed 's|\.[gbx]z2*$||')
876 rm $i; ln -s $dest.gz $link.gz
877 done
879 # Recompress with advdef (it can't compress, only recompress)
880 tazpkg -gi advancecomp --quiet
881 for i in $(find $install/usr/share/man -type f); do
882 advdef -z4q $i
883 done
885 local size1=$(find $install/usr/share/man -type f -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
886 local time1=$(date +%s)
887 status
888 comp_summary "$time0" "$time1" "$size0" "$size1"
889 }
892 # Function used after compile_rules() to compress all png images
893 # Compressing can be disabled with COOKOPTS="!pngz"
895 compress_png() {
896 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
897 case "$ARCH" in
898 arm*) return;; # While SliTaz-arm miss `pngquant` and `optipng`
899 esac
900 [ -z "$(find $install -type f -name '*.png')" ] && return
902 action 'Compressing png images...'
903 local size0=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
904 local time0=$(date +%s)
906 local use_pq=true use_op=true
907 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
908 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
910 $use_pq && tazpkg -gi pngquant --quiet
911 $use_op && tazpkg -gi optipng --quiet
913 local oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
914 [ -z "$oplevel" ] && oplevel='2'
915 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
917 for i in $(find $install -type f -name '*.png'); do
918 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
919 $use_op && optipng -quiet -strip all -o$oplevel "$i"
920 done
922 local size1=$(find $install -type f -name '*.png' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
923 local time1=$(date +%s)
924 status
925 comp_summary "$time0" "$time1" "$size0" "$size1"
926 }
929 # Function used after compile_rules() to compress all svg images
930 # Compressing can be disabled with COOKOPTS="!svgz"
932 compress_svg() {
933 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
934 case "$ARCH" in
935 arm*) return;; # While SliTaz-arm miss `svgcleaner`
936 esac
937 [ -z "$(find $install -type f -name '*.svg')" ] && return
939 action 'Compressing svg images...'
940 local size0=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
941 local time0=$(date +%s)
942 tazpkg -gi svgcleaner --quiet
943 cleaner_log="$(mktemp)"
944 for i in $(find $install -type f -name '*.svg'); do
945 echo -n "$i: " >> "$cleaner_log"
946 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
947 done
948 local size1=$(find $install -type f -name '*.svg' -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
949 local time1=$(date +%s)
950 status
951 comp_summary "$time0" "$time1" "$size0" "$size1"
952 sed -i '/: $/d' "$cleaner_log"
953 if [ -s "$cleaner_log" ]; then
954 echo 'Cleaner warnings and errors:'
955 awk '{printf " %s\n", $0;}' "$cleaner_log"
956 echo
957 fi
958 rm "$cleaner_log"
959 }
962 # Function used after compile_rules() to shrink all *.ui and *.glade files:
963 # remove insignificant spaces and comments
964 # Compressing can be disabled with COOKOPTS="!uiz"
966 compress_ui() {
967 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
968 case "$ARCH" in
969 arm*) return;; # While SliTaz-arm miss `xmlstarlet`
970 esac
971 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
973 action 'Compressing ui files...'
974 local size0=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
975 local time0=$(date +%s)
976 tazpkg -gi xmlstarlet --quiet
977 temp_ui="$(mktemp)"
978 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
979 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
980 cat "$temp_ui" > "$ui"
981 done
982 local size1=$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; | awk '{s+=$5}END{print s}')
983 local time1=$(date +%s)
984 status
985 comp_summary "$time0" "$time1" "$size0" "$size1"
986 rm "$temp_ui"
987 }
990 # The main cook function.
992 cookit() {
993 title 'Cook: %s' "$PACKAGE $VERSION"
994 set_paths
996 # Handle cross-tools.
997 case "$ARCH" in
998 arm*|x86_64)
999 # CROSS_COMPILE is used by at least Busybox and the kernel to set
1000 # the cross-tools prefix. Sysroot is the root of our target arch
1001 sysroot="$CROSS_TREE/sysroot"
1002 tools="$CROSS_TREE/tools"
1003 # Set root path when cross compiling. ARM tested but not x86_64
1004 # When cross compiling we must install build deps in $sysroot.
1005 arch="-$ARCH"
1006 root="$sysroot"
1007 _ '%s sysroot: %s' "$ARCH" "$sysroot"
1008 _ 'Adding "%s" to PATH' "$tools/bin"
1009 export PATH="$PATH:$tools/bin"
1010 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
1011 export CROSS_COMPILE="$HOST_SYSTEM-"
1012 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
1013 if [ "$ARCH" == 'x86_64' ]; then
1014 export CC="$HOST_SYSTEM-gcc -m64"
1015 export CXX="$HOST_SYSTEM-g++ -m64"
1016 else
1017 export CC="$HOST_SYSTEM-gcc"
1018 export CXX="$HOST_SYSTEM-g++"
1019 fi
1020 export AR="$HOST_SYSTEM-ar"
1021 export AS="$HOST_SYSTEM-as"
1022 export RANLIB="$HOST_SYSTEM-ranlib"
1023 export LD="$HOST_SYSTEM-ld"
1024 export STRIP="$HOST_SYSTEM-strip"
1025 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
1026 esac
1028 [ -n "$QA" ] && receipt_quality
1029 cd $pkgdir
1030 [ -z "$continue" ] && rm -rf source 2>/dev/null
1031 rm -rf install taz 2>/dev/null
1033 # Disable -pipe if less than 512 MB free RAM.
1034 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
1035 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
1036 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
1037 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
1038 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
1039 fi
1040 unset free
1042 # Export flags and path to be used by make and receipt.
1043 DESTDIR="$pkgdir/install"
1044 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
1045 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
1046 #LDFLAGS
1048 # Check for build deps and handle implicit depends of *-dev packages
1049 # (ex: libusb-dev :: libusb).
1050 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
1051 touch $CACHE/installed.local $CACHE/installed.web
1052 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
1053 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
1054 for dep in $BUILD_DEPENDS; do
1055 implicit="${dep%-dev}"
1056 # Don't add implicit dependency if it defined in DEPENDS
1057 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
1058 for i in $dep $implicit; do
1059 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
1060 # Try local package first. In some cases implicit doesn't exist, ex:
1061 # libboost-dev exists but not libboost, so check if we got vers.
1062 unset vers
1063 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
1064 # We may have a local package.
1065 if [ -z "$vers" ]; then
1066 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
1067 fi
1068 debug "bdep: $i version: $vers"
1069 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
1070 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
1071 else
1072 # Priority to package version in wok (maybe more up-to-date)
1073 # than the mirrored one.
1074 if [ -n "$vers" ]; then
1075 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
1076 echo $i >> $CACHE/installed.web
1077 else
1078 # So package exists in wok but not available.
1079 _ 'Missing dep (wok/pkg): %s' "$i $vers"
1080 echo $i >> $CACHE/missing.dep
1081 fi
1082 else
1083 # Package is not in wok but may be in online repo.
1084 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
1085 echo $i >> $CACHE/installed.web
1086 else
1087 _ 'ERROR: unknown dep "%s"' "$i"
1088 exit 1
1089 fi
1090 fi
1091 fi
1092 fi
1093 done
1094 done
1096 # Get the list of installed packages
1097 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
1099 # Have we a missing build dep to cook?
1100 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
1101 _ 'Auto cook config is set: %s' "$AUTO_COOK"
1102 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
1103 for i in $(uniq $CACHE/missing.dep); do
1104 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
1105 tee -a $LOGS/$PACKAGE.log.$$
1106 # programmers: next two messages are exact copy from remove_deps()
1107 togrep1=$(_n 'Build dependencies to remove:')
1108 togrep2=$(_n 'Removing:')
1109 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
1110 fgrep $togrep1 $LOGS/$i.log && \
1111 fgrep $togrep2 $LOGS/$i.log && newline) | \
1112 tee -a $LOGS/$PACKAGE.log.$$ && break
1113 done
1114 rm -f $CACHE/missing.dep
1115 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
1116 fi
1118 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
1119 # is enabled and cook fails we have ERROR in log, if no auto cook we have
1120 # missing dep in cached file.
1121 lerror=$(_n 'ERROR')
1122 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
1123 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
1124 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
1125 exit 1
1126 fi
1128 # Install local packages: package-version$arch
1129 cd $PKGS
1130 for i in $(uniq $CACHE/installed.local); do
1131 _ 'Installing dep (pkg/local): %s' "$i"
1132 tazpkg install $i --root=$root --local --quiet
1133 done
1135 # Install web or cached packages (if mirror is set to $PKGS we only
1136 # use local packages).
1137 for i in $(uniq $CACHE/installed.web); do
1138 _ 'Installing dep (web/cache): %s' "$i"
1139 tazpkg get-install $i --root=$root --quiet
1140 done
1142 update_installed_cook_diff
1144 # Get source tarball and make sure we have source dir named:
1145 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
1146 # tarball if it exists.
1147 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
1148 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
1149 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
1150 LZMA_SRC=''
1151 else
1152 get_source || exit 1
1153 fi
1154 fi
1155 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
1156 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
1157 if ! extract_source ; then
1158 get_source
1159 extract_source || exit 1
1160 fi
1161 if [ -n "$LZMA_SRC" ]; then
1162 cd $pkgdir/source
1163 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
1164 mv tmp tmp-1; mkdir tmp
1165 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
1166 fi
1167 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
1168 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
1169 fi
1170 fi
1171 cd $pkgdir/source/tmp
1172 # Some archives are not well done and don't extract to one dir (ex lzma).
1173 files=$(ls | wc -l)
1174 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
1175 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
1176 mv * ../$PACKAGE-$VERSION/$TARBALL
1177 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
1178 mv * ../$PACKAGE-$VERSION
1179 cd ..; rm -rf tmp
1180 fi
1182 # Libtool shared libs path hack.
1183 case "$ARCH" in
1184 arm*) cross libhack ;;
1185 esac
1187 # Execute receipt rules.
1188 if grep -q ^compile_rules $receipt; then
1189 _ 'Executing: %s' 'compile_rules'
1190 echo "CFLAGS : $CFLAGS"
1191 #echo "LDFLAGS : $LDFLAGS"
1192 [ -d "$src" ] && cd $src
1193 compile_rules $@ || exit 1
1194 # Stay compatible with _pkg
1195 [ -d "$src/_pkg" ] && mv $src/_pkg $install
1196 # QA: compile_rules success so valid.
1197 mkdir -p $install
1198 else
1199 # QA: no compile_rules so no error, valid.
1200 mkdir -p $install
1201 fi
1203 # Actions to do after compiling the package
1204 # Skip all for split packages (already done in main package)
1205 if [ -z "$WANTED" ]; then
1206 footer
1207 compress_manpages
1208 compress_png
1209 compress_svg
1210 compress_ui
1211 fix_desktop_files
1212 normalize_mo
1213 fi
1214 footer
1216 # Execute testsuite.
1217 if grep -q ^testsuite $receipt; then
1218 title 'Running testsuite'
1219 testsuite $@ || exit 1
1220 footer
1221 fi
1223 update_installed_cook_diff force
1227 # Cook quality assurance.
1229 cookit_quality() {
1230 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
1231 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
1232 fi
1233 # ERROR can be echoed any time in cookit()
1234 lerror=$(_n 'ERROR')
1235 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
1236 grep -Eq "(^$lerror|undefined reference to)" ; then
1237 debug_info | tee -a $LOGS/$pkg.log
1238 rm -f $command
1239 exit 1
1240 fi
1244 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
1245 # but it doesn't handle EXTRAVERSION.
1247 packit() {
1248 set_paths
1250 # Handle cross compilation
1251 case "$ARCH" in
1252 arm*|x86_64) arch="-$ARCH" ;;
1253 esac
1255 title 'Pack: %s' "$PACKAGE $VERSION$arch"
1257 if grep -q ^genpkg_rules $receipt; then
1258 _ 'Executing: %s' 'genpkg_rules'
1259 set -e; cd $pkgdir; mkdir -p $fs
1260 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
1261 $LOGS/$pkg.log
1262 else
1263 _ 'No packages rules: meta package'
1264 mkdir -p $fs
1265 fi
1267 # Check CONFIG_FILES
1268 if [ -n "$CONFIG_FILES" ]; then
1269 for i in $CONFIG_FILES; do
1270 if [ ! -e $fs$i ]; then
1271 case $i in
1272 */) mkdir -p $fs$i ;;
1273 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
1274 esac
1275 fi
1276 done
1277 fi
1279 # First QA check to stop now if genpkg_rules failed.
1280 lerror=$(_n 'ERROR')
1281 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1282 exit 1
1283 fi
1285 cd $taz
1286 for file in receipt description.txt; do
1287 [ ! -f "../$file" ] && continue
1288 action 'Copying "%s"...' "$file"
1289 cp -f ../$file $pack; chown 0.0 $pack/$file; status
1290 done
1291 copy_generic_files
1293 # Strip and stuff files.
1294 strip_package
1295 strip_mo_i18n
1297 # Create files.list with redirecting find output.
1298 action 'Creating the list of files...'
1299 cd $fs
1300 find . -type f -print > ../files.list
1301 find . -type l -print >> ../files.list
1302 cd ..; sed -i s/'^.'/''/ files.list
1303 status
1305 # Md5sum of files.
1306 action 'Creating md5sum of files...'
1307 while read file; do
1308 [ -L "fs$file" ] && continue
1309 [ -f "fs$file" ] || continue
1310 case "$file" in
1311 /lib/modules/*/modules.*|*.pyc) continue ;;
1312 esac
1313 md5sum "fs$file" | sed 's/ fs/ /'
1314 done < files.list > md5sum
1315 status
1317 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
1318 2>/dev/null | awk 'END{ print $1 }')
1320 # Build cpio archives.
1321 action 'Compressing the FS...'
1322 find fs -newer $receipt -exec touch -r $receipt {} \;
1323 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
1324 rm -rf fs
1325 status
1327 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1328 2>/dev/null | awk 'END{ print $1 }')
1330 action 'Updating receipt sizes...'
1331 sed -i s/^PACKED_SIZE.*$// receipt
1332 sed -i s/^UNPACKED_SIZE.*$// receipt
1333 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
1334 status
1336 # Set extra version.
1337 if [ -n "$EXTRAVERSION" ]; then
1338 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1339 sed -i s/^EXTRAVERSION.*$// receipt
1340 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
1341 status
1342 fi
1344 # Compress.
1345 action 'Creating full cpio archive...'
1346 find . -print | cpio -o -H newc --quiet > \
1347 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1348 status
1350 action 'Restoring original package tree...'
1351 unlzma -c fs.cpio.lzma | cpio -idm --quiet
1352 status
1354 rm fs.cpio.lzma; cd ..
1356 # QA and give info.
1357 tazpkg=$(ls *.tazpkg)
1358 packit_quality
1359 footer "$(_ 'Package "%s" created' "$tazpkg")"
1363 # Verify package quality and consistency.
1365 packit_quality() {
1366 #action 'QA: checking for broken link...'
1367 #link=$(find $fs/usr -type l -follow)
1368 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1369 #status
1371 # Exit if any error found in log file.
1372 lerror=$(_n 'ERROR')
1373 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1374 rm -f $command
1375 exit 1
1376 fi
1378 action 'QA: checking for empty package...'
1379 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
1380 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1381 newline; _ 'ERROR: empty package'
1382 rm -f $command
1383 exit 1
1384 else
1385 :; status
1386 # Find and remove old package(s)
1387 tempd="$(mktemp -d)"; cd "$tempd"
1388 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
1389 # Extract receipt from each matched package
1390 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1391 name=$(. receipt; echo $PACKAGE)
1392 rm receipt
1393 if [ "$name" == "$pkg" ]; then
1394 action 'Removing old package "%s"' "$(basename "$testpkg")"
1395 rm -f "$testpkg"
1396 status
1397 fi
1398 done
1399 rm -r "$tempd"
1400 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
1401 sed -i /^${pkg}$/d $broken
1402 #action 'Removing source tree...'
1403 #rm -f $WOK/$pkg/source; status
1404 fi
1408 # Reverse "cat" command: prints input lines in the reverse order
1410 tac() {
1411 sed '1!G;h;$!d' $1
1415 # Install package on --install or update the chroot.
1417 install_package() {
1418 case "$ARCH" in
1419 arm*|x86_64)
1420 arch="-$ARCH"
1421 root="$CROSS_TREE/sysroot" ;;
1422 esac
1423 # Install package if requested but skip install if target host doesn't
1424 # match build system or it will break the build chroot.
1425 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1426 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1427 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1428 cd $PKGS
1429 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1430 else
1431 _ 'Unable to install package, build has failed.'; newline
1432 exit 1
1433 fi
1434 fi
1436 # Install package if part of the chroot to keep env up-to-date.
1437 if [ -d "$root$INSTALLED/$pkg" ]; then
1438 . /etc/slitaz/cook.conf
1439 . $WOK/$pkg/taz/$pkg-*/receipt
1440 _ 'Updating %s chroot environment...' "$ARCH"
1441 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1442 cd $PKGS
1443 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1444 fi
1448 # remove chroot jail
1450 umount_aufs() {
1451 tac ${1}rw/aufs-umount.sh | sh
1452 rm -rf ${1}rw
1453 umount ${1}root
1454 rmdir ${1}r*
1458 # Launch the cook command into a chroot jail protected by aufs.
1459 # The current filesystems are used read-only and updates are
1460 # stored in a separate branch.
1462 try_aufs_chroot() {
1464 base="/dev/shm/aufsmnt$$"
1466 # Can we setup the chroot? Is it already done?
1467 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1468 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1469 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1470 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1471 mkdir ${base}root ${base}rw || return
1473 _ 'Setup aufs chroot...'
1475 # Sanity check
1476 for i in / /proc /sys /dev/shm /home ; do
1477 case " $AUFS_MOUNTS " in
1478 *\ $i\ *) ;;
1479 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1480 esac
1481 done
1482 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1483 mount --bind $mnt ${base}root$mnt
1484 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1485 _ 'Aufs mount failure'
1486 umount ${base}root
1487 rm -rf ${base}r*
1488 return
1489 fi
1490 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1491 done
1492 trap "umount_aufs ${base}" INT
1494 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1495 status=$?
1497 _ 'Leaving aufs chroot...'
1498 umount_aufs $base
1499 # Install package outside the aufs jail
1500 install_package
1501 exit $status
1505 # Encode predefined XML entities
1507 xml_ent() {
1508 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1512 # Create a XML feed for freshly built packages.
1514 gen_rss() {
1515 pubdate=$(date '+%a, %d %b %Y %X')
1516 cat > $FEEDS/$pkg.xml <<EOT
1517 <item>
1518 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1519 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1520 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1521 <pubDate>$pubdate</pubDate>
1522 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1523 </item>
1524 EOT
1528 # Truncate stdout log file to $1 Mb.
1530 loglimit() {
1531 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1532 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1533 else
1534 tee /dev/stderr
1535 fi
1539 # Search file in mirrored packages
1541 search_file_mirror() {
1542 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1546 # Search file in local wok packages
1548 search_file_local() {
1549 # existing packages have precedence over the package/taz folder
1550 srch=$1
1551 { for package in $(find $PKGS -name '*.tazpkg'); do
1552 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1553 grep /$srch\$)" ]; then
1554 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1555 fi
1556 done } | sort -u
1560 # Ask in multiple choice
1562 ask_multiple() {
1563 local multiples first my_choice
1564 multiples="$1"
1565 first=$(echo "$multiples" | head -n1)
1566 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1567 _ 'Select one [%s]: ' "$first"; read my_choice
1568 found="${my_choice:-$first}"
1572 # Search file in local cache (fast), local wok packages, mirrored packages
1574 search_file() {
1575 local srch cache missing
1576 srch="$1"
1577 cache='/var/cache/ldsearch.cache'
1578 missing='/var/cache/missing.file'
1579 touch $cache $missing
1580 found=$(grep $srch $cache | cut -d$'\t' -f2)
1581 if [ -z "$found" ]; then
1582 found=$(search_file_local $srch)
1583 if [ -n "$found" ]; then
1584 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1585 ask_multiple "$found"
1586 fi
1587 echo -e "$srch\t$found" >> $cache
1588 else
1589 found=$(search_file_mirror $srch)
1590 if [ -n "$found" ]; then
1591 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1592 ask_multiple "$found"
1593 fi
1594 echo -e "$srch\t$found" >> $cache
1595 else
1596 echo "$srch" >> $missing
1597 fi
1598 fi
1599 fi
1604 # Receipt functions to ease packaging
1607 get_dev_files() {
1608 action 'Getting standard devel files...'
1609 mkdir -p $fs/usr/lib
1610 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1611 cp -a $install/usr/lib/*a $fs/usr/lib
1612 cp -a $install/usr/include $fs/usr
1613 status
1617 # Function to use in compile_rules() to copy man page from $src to $install
1619 cook_pick_manpages() {
1620 local name section
1621 action 'Copying man pages...'
1623 for i in $@; do
1624 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1625 section=${name##*/}; section=${section##*.}
1626 mkdir -p $install/usr/share/man/man$section
1627 cp -a $i $install/usr/share/man/man$section
1628 done
1629 status
1633 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1635 cook_copy_files() {
1636 action 'Copying files...'
1637 cd $install
1638 local i j
1639 for i in $@; do
1640 for j in $(find . -name $i ! -type d); do
1641 mkdir -p $fs$(dirname ${j#.})
1642 cp -a $j $fs/${j#.}
1643 done
1644 done
1645 cd - >/dev/null
1646 status
1650 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1652 cook_copy_folders() {
1653 action 'Copying folders...'
1654 cd $install
1655 local i j
1656 for i in $@; do
1657 for j in $(find . -name $i -type d); do
1658 mkdir -p $fs$(dirname ${j#.})
1659 cp -a $j $fs/${j#.}
1660 done
1661 done
1662 cd - >/dev/null
1663 status
1667 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1668 # (default: 16 and 48) from $install to $fs
1670 cook_copy_icons() {
1671 local sizes=$@
1672 action 'Copying hicolor icons...'
1673 mkdir -p $fs/usr/share/icons/hicolor
1674 for i in ${sizes:-16 48}; do
1675 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1676 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1677 $fs/usr/share/icons/hicolor
1678 done
1679 status
1686 # Commands
1689 case "$1" in
1690 usage|help|-u|-h)
1691 usage ;;
1693 list-wok)
1694 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1695 cd $WOK
1696 if [ "$ARCH" != 'i486' ]; then
1697 count=0
1698 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1699 do
1700 unset HOST_ARCH
1701 . $pkg
1702 count=$(($count + 1))
1703 colorize 34 "$PACKAGE"
1704 done
1705 else
1706 count=$(ls | wc -l)
1707 ls -1
1708 fi
1709 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1710 ;;
1712 activity)
1713 cat $activity ;;
1715 search)
1716 # Just a simple search function, we dont need more actually.
1717 query="$2"
1718 title 'Search results for "%s"' "$query"
1719 cd $WOK; ls -1 | grep "$query"
1720 footer ;;
1722 setup)
1723 # Setup a build environment
1724 check_root
1725 _ 'Cook: setup environment' | log
1726 title 'Setting up your environment'
1727 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1728 cd $SLITAZ
1729 init_db_files
1730 _ 'Checking for packages to install...'
1731 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1732 # ARCH-setup or 'cross check' should be used before: cook setup
1733 case "$ARCH" in
1734 arm*|x86_64)
1735 if [ ! -x '/usr/bin/cross' ]; then
1736 _ 'ERROR: %s is not installed' 'cross'
1737 exit 1
1738 fi
1739 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1740 . /etc/slitaz/cross.conf ;;
1741 esac
1742 for pkg in $SETUP_PKGS; do
1743 if [ -n "$forced" ]; then
1744 tazpkg -gi $pkg --forced
1745 else
1746 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1747 fi
1748 done
1750 # Handle --options
1751 case "$2" in
1752 --wok) hg clone $WOK_URL wok || exit 1 ;;
1753 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1754 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1755 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1756 esac
1758 # SliTaz group and permissions
1759 if ! grep -q ^slitaz /etc/group; then
1760 _ 'Adding group "%s"' 'slitaz'
1761 addgroup slitaz
1762 fi
1763 _ 'Setting permissions for group "%s"...' 'slitaz'
1764 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1765 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1766 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1768 *-setup)
1769 # Setup for cross compiling.
1770 arch="${1%-setup}"
1771 check_root
1772 . /etc/slitaz/cook.conf
1773 for pkg in $CROSS_SETUP; do
1774 if [ -n "$forced" ]; then
1775 tazpkg -gi $pkg --forced
1776 else
1777 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1778 fi
1779 done
1781 _ 'Cook: setup %s cross environment' "$arch" | log
1782 title 'Setting up your %s cross environment' "$arch"
1783 init_db_files
1784 sed -i \
1785 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1786 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1787 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1788 /etc/slitaz/cook.conf
1789 case "$arch" in
1790 arm)
1791 flags='-O2 -march=armv6'
1792 host="$ARCH-slitaz-linux-gnueabi" ;;
1793 armv6hf)
1794 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1795 host="$ARCH-slitaz-linux-gnueabi" ;;
1796 armv7)
1797 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1798 host="$ARCH-slitaz-linux-gnueabi" ;;
1799 x86_64)
1800 flags='-O2 -mtune=generic -pipe'
1801 host="$ARCH-slitaz-linux" ;;
1802 esac
1803 sed -i \
1804 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1805 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1806 . /etc/slitaz/cook.conf
1807 sysroot="$CROSS_TREE/sysroot"
1808 tools="/cross/$arch/tools"
1809 root="$sysroot"
1810 # L10n: keep the same width of translations to get a consistent view
1811 _ 'Target arch : %s' "$ARCH"
1812 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1813 _ 'Build flags : %s' "$flags"
1814 _ 'Arch sysroot : %s' "$sysroot"
1815 _ 'Tools prefix : %s' "$tools/bin"
1816 # Tell the packages manager where to find packages.
1817 _ 'Packages DB : %s' "$root$DB"
1818 mkdir -p $root$INSTALLED
1819 cd $root$DB; rm -f *.bak
1820 for list in packages.list packages.desc packages.equiv packages.md5; do
1821 rm -f $list
1822 ln -s $SLITAZ/packages/$list $list
1823 done
1824 # We must have the cross compiled glibc-base installed or default
1825 # i486 package will be used as dep by tazpkg and then break the
1826 # cross environment
1827 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1828 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1829 fi
1830 # Show GCC version or warn if not yet compiled.
1831 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1832 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1833 else
1834 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1835 _ 'Run "%s" to cook a toolchain' 'cross compile'
1836 fi
1837 footer ;;
1839 test)
1840 # Test a cook environment.
1841 _ 'Cook test: testing the cook environment' | log
1842 [ ! -d "$WOK" ] && exit 1
1843 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1844 cook cooktest ;;
1846 new)
1847 # Create the package folder and an empty receipt.
1848 pkg="$2"
1849 [ -z "$pkg" ] && usage
1850 newline
1851 if [ -d "$WOK/$pkg" ]; then
1852 _ 'Package "%s" already exists.' "$pkg"
1853 exit 1
1854 fi
1856 action 'Creating folder "%s"' "$WOK/$pkg"
1857 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1859 action 'Preparing the package receipt...'
1860 cp $DATA/receipt .
1861 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1862 status; newline
1864 # Interactive mode, asking and seding.
1865 case "$3" in
1866 --interactive|-x)
1867 _ 'Entering interactive mode...'
1868 separator
1869 _ 'Package : %s' "$pkg"
1871 _n 'Version : ' ; read answer
1872 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1874 _n 'Category : ' ; read answer
1875 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1877 # L10n: Short description
1878 _n 'Short desc : ' ; read answer
1879 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1881 _n 'Maintainer : ' ; read answer
1882 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1884 _n 'License : ' ; read answer
1885 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1887 _n 'Web site : ' ; read answer
1888 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1889 newline
1891 # Wget URL.
1892 _ 'Wget URL to download source tarball.'
1893 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1894 _n 'Wget url : ' ; read answer
1895 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1897 # Ask for a stuff dir.
1898 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1899 if [ "$?" -eq 0 ]; then
1900 action 'Creating the stuff directory...'
1901 mkdir $WOK/$pkg/stuff; status
1902 fi
1904 # Ask for a description file.
1905 confirm "$(_n 'Are you going to write a description? (y/N)')"
1906 if [ "$?" -eq 0 ]; then
1907 action 'Creating the "%s" file...' 'description.txt'
1908 touch $WOK/$pkg/description.txt; status
1909 fi
1911 footer "$(_ 'Receipt is ready to use.')" ;;
1912 esac ;;
1914 list)
1915 # Cook a list of packages (better use the Cooker since it will order
1916 # packages before executing cook).
1917 check_root
1918 if [ -z "$2" ]; then
1919 newline; _ 'No list in argument.'; newline
1920 exit 1
1921 fi
1922 if [ ! -f "$2" ]; then
1923 newline; _ 'List "%s" not found.' "$2"; newline
1924 exit 1
1925 fi
1927 _ 'Starting cooking the list "%s"' "$2" | log
1929 for pkg in $(cat $2); do
1930 cook $pkg || broken
1931 done ;;
1933 clean-wok)
1934 check_root
1935 newline; action 'Cleaning all packages files...'
1936 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1937 status; newline ;;
1939 clean-src)
1940 check_root
1941 newline; action 'Cleaning all packages sources...'
1942 rm -rf $WOK/*/source
1943 status; newline ;;
1945 uncook)
1946 cd $WOK
1947 count=0
1948 title 'Checking for uncooked packages'
1950 for pkg in *; do
1951 unset HOST_ARCH EXTRAVERSION
1952 [ ! -e $pkg/receipt ] && continue
1953 . $pkg/receipt
1954 # Source cooked pkg receipt to get EXTRAVERSION
1955 if [ -d "$WOK/$pkg/taz" ]; then
1956 cd $WOK/$pkg/taz/$pkg-*
1957 . receipt; cd $WOK
1958 fi
1959 case "$ARCH" in
1960 i486)
1961 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1962 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1963 count=$(($count + 1))
1964 colorize 34 "$pkg"
1965 fi ;;
1966 arm*)
1967 # Check only packages included in arch
1968 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1969 # *.tazpkg
1970 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1971 count=$(($count + 1))
1972 colorize 34 "$pkg"
1973 fi
1974 fi ;;
1975 esac
1976 done
1978 if [ "$count" -gt "0" ]; then
1979 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1980 else
1981 _ 'All packages are cooked :-)'
1982 newline
1983 fi
1984 ;;
1986 pkgdb)
1987 # Create suitable packages list for TazPkg and only for built packages
1988 # as well as flavors files for TazLiTo. We don't need logs since we do it
1989 # manually to ensure everything is fine before syncing the mirror.
1990 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1991 ;;
1993 *)
1994 # Just cook and generate a package.
1995 check_root
1996 time=$(date +%s)
1997 pkg="$1"
1998 [ -z "$pkg" ] && usage
1999 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
2000 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
2001 receipt="$WOK/$pkg/receipt"
2002 check_pkg_in_wok
2003 newline
2005 unset inst
2006 unset_receipt
2007 . $receipt
2009 # Handle cross compilation.
2010 case "$ARCH" in
2011 arm*)
2012 if [ -z "$HOST_ARCH" ]; then
2013 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2014 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2015 _ 'cook: %s' "$error"
2016 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2017 _ 'Cook skip: %s' "$error" | log
2018 newline
2019 exit 1
2020 fi ;;
2021 esac
2023 # Some packages are not included in some arch or fail to cross compile.
2024 : ${HOST_ARCH=i486}
2025 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2026 # Handle arm{v6hf,v7,..}
2027 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2028 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2029 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2030 _ 'cook: %s' "error"
2031 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2032 _ 'Cook skip: %s' "$error" | log
2033 sed -i /^${pkg}$/d $broken
2034 newline
2035 exit 0
2036 fi
2038 # Skip blocked, 3 lines also for the Cooker.
2039 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
2040 _ 'Package "%s" is blocked' "$pkg"; newline
2041 exit 0
2042 fi
2044 try_aufs_chroot "$@"
2046 # Log and source receipt.
2047 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
2048 echo "cook:$pkg" > $command
2049 [ "$lastcooktime" ] &&
2050 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2051 while read cmd duration start; do
2052 [ $(($start + $duration)) -lt $(date +%s) ] &&
2053 echo "sed -i '/^$cmd $duration/d' $cooktime"
2054 done < $cooktime | sh
2056 # Display and log info if cook process stopped.
2057 # FIXME: gettext not working (in single quotes) here!
2058 trap '_ "\n\nCook stopped: control-C\n\n" | \
2059 tee -a $LOGS/$pkg.log' INT
2061 # Handle --options
2062 case "$2" in
2063 --clean|-c)
2064 action 'Cleaning "%s"' "$pkg"
2065 cd $WOK/$pkg; rm -rf install taz source
2066 status; newline
2067 exit 0 ;;
2069 --install|-i)
2070 inst='yes' ;;
2072 --getsrc|-gs)
2073 title 'Getting source for "%s"' "$pkg"
2074 get_source
2075 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
2076 exit 0 ;;
2078 --block|-b)
2079 action 'Blocking package "%s"' "$pkg"
2080 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
2081 status; newline
2082 exit 0 ;;
2084 --unblock|-ub)
2085 action 'Unblocking package "%s"' "$pkg"
2086 sed -i "/^${pkg}$/"d $blocked
2087 status; newline
2088 exit 0 ;;
2090 --pack)
2091 if [ -d $WOK/$pkg/taz ]; then
2092 rm -rf $WOK/$pkg/taz
2093 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
2094 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
2095 clean_log
2096 else
2097 _ 'Need to build "%s"' "$pkg"
2098 exit 0
2099 fi
2100 exit 0 ;;
2102 --cdeps)
2103 if [ ! -d $WOK/$pkg/taz ]; then
2104 _ 'Need to build "%s"' "$pkg"
2105 exit 0
2106 fi
2108 title 'Checking depends'
2109 lddlist='/tmp/lddlist'; touch $lddlist
2110 missing='/var/cache/missing.file'
2112 # find all deps using ldd
2113 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
2114 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
2115 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
2116 done #"
2118 # remove exe/so duplicates
2119 sort -u $lddlist > $lddlist.sorted
2121 # search packages
2122 for exefile in $(cat $lddlist.sorted); do
2123 search_file $exefile
2124 echo "$found" >> $lddlist.pkgs
2125 echo -n '.'
2126 done
2127 echo
2129 # remove packages duplicates
2130 sort -u $lddlist.pkgs > $lddlist.final
2131 sort -u $missing > $missing.final
2132 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
2133 exit 0 ;;
2134 esac
2136 # Rotate log
2137 for i in $(seq 9 -1 1); do
2138 j=$(($i - 1))
2139 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2140 done
2141 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2143 # Check if wanted is built now so we have separate log files.
2144 for wanted in $WANTED ; do
2145 if grep -q "^$wanted$" $blocked; then
2146 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
2147 newline
2148 rm -f $command
2149 exit 1
2150 fi
2151 if grep -q "^$wanted$" $broken; then
2152 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
2153 newline
2154 rm -f $command
2155 exit 1
2156 fi
2157 if [ ! -d "$WOK/$wanted/install" ]; then
2158 cook "$wanted" || exit 1
2159 fi
2160 done
2162 # Cook and pack or exit on error and log everything.
2163 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
2164 remove_deps | tee -a $LOGS/$pkg.log
2165 cookit_quality
2166 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2167 clean_log
2169 # Exit if any error in packing.
2170 lerror=$(_n 'ERROR')
2171 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2172 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2173 debug_info | tee -a $LOGS/$pkg.log
2174 rm -f $command
2175 exit 1
2176 fi
2178 # Create an XML feed
2179 gen_rss
2181 # Time and summary
2182 time=$(($(date +%s) - $time))
2183 summary | tee -a $LOGS/$pkg.log
2184 newline
2186 # We may want to install/update (outside aufs jail !).
2187 [ -s /aufs-umount.sh ] ||
2188 install_package
2190 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2191 # You want automation: use the Cooker Build Bot.
2192 rm -f $command ;;
2193 esac
2195 exit 0