cookutils view cook @ rev 887

cook: make function copy(), use it to copy files to $fs (thanks Pascal for having pointed out the problem); fix cook_copy_icons() status.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Mar 03 02:37:16 2017 +0200 (2017-03-03)
parents 9b02985442a0
children 2cb347d1b668
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 # A bit smarter function than the classic `cp` command
422 copy() {
423 if [ "$(stat -c %h -- "$1")" -gt 1 ]; then
424 cp -al "$1" "$2" # copy hardlinks
425 else
426 cp -a "$1" "$2" # copy generic files
427 fi
428 }
431 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
432 # so some packages need to copy these files with the receipt and genpkg_rules.
434 copy_generic_files() {
435 # $LOCALE is set in cook.conf
436 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
437 if [ -d "$install/usr/share/locale" ]; then
438 mkdir -p $fs/usr/share/locale
439 for i in $LOCALE; do
440 if [ -d "$install/usr/share/locale/$i" ]; then
441 copy $install/usr/share/locale/$i $fs/usr/share/locale
442 fi
443 done
444 fi
445 fi
447 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
448 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
449 if [ -d "$install/usr/share/pixmaps" ]; then
450 mkdir -p $fs/usr/share/pixmaps
451 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
452 copy $install/usr/share/pixmaps/$PACKAGE.png \
453 $fs/usr/share/pixmaps
454 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
455 copy $install/usr/share/pixmaps/$PACKAGE.xpm \
456 $fs/usr/share/pixmaps
457 fi
458 fi
460 # Custom or homemade PNG pixmap can be in stuff.
461 if [ -f "$stuff/$PACKAGE.png" ]; then
462 mkdir -p $fs/usr/share/pixmaps
463 copy $stuff/$PACKAGE.png $fs/usr/share/pixmaps
464 fi
465 fi
467 # Desktop entry (.desktop).
468 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
469 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
470 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
471 mkdir -p $fs/usr/share
472 copy $install/usr/share/applications $fs/usr/share
473 fi
474 fi
476 # Homemade desktop file(s) can be in stuff.
477 if [ -d "$stuff/applications" ]; then
478 mkdir -p $fs/usr/share
479 copy $stuff/applications $fs/usr/share
480 fi
481 if [ -f "$stuff/$PACKAGE.desktop" ]; then
482 mkdir -p $fs/usr/share/applications
483 copy $stuff/$PACKAGE.desktop $fs/usr/share/applications
484 fi
486 # Add custom licenses
487 if [ -d "$stuff/licenses" ]; then
488 mkdir -p $fs/usr/share/licenses
489 copy $stuff/licenses $fs/usr/share/licenses/$PACKAGE
490 fi
491 }
494 # Remove files provided by split packages
495 # For example:
496 # 1. Package "pkg-main":
497 # SPLIT="pkg-1 pkg-2 pkg-extra"
498 # 2. Package="pkg-extra":
499 # WANTED="pkg-main"
500 # BUILD_DEPENDS="pkg-1 pkg-2"
501 # cook_copy_folders usr
502 # cook_split_rm $BUILD_DEPENDS
504 cook_split_rm() {
505 for i in $@; do
506 action 'Remove files provided by split package %s...' "$i"
507 while read j; do
508 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
509 rmdir "$(dirname "$fs$j")" 2>/dev/null
510 done < $WOK/$i/taz/$i-$VERSION/files.list
511 :; status
512 done
513 }
516 # Update installed.cook.diff
518 update_installed_cook_diff() {
519 # If a cook failed deps are removed.
520 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
521 cd $CACHE
522 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
523 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
524 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
525 }
528 # Remove installed deps.
530 remove_deps() {
531 # Now remove installed build deps.
532 diff='/tmp/installed.cook.diff'
533 if [ -s $diff ]; then
534 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
535 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
536 _n 'Build dependencies to remove:'; echo " $nb"
537 [ -n "$root" ] && echo "root=\"$root\""
538 _n 'Removing:'
539 for dep in $deps; do
540 echo -n " $dep"
541 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
542 done
543 newline; newline
544 # Keep the last diff for debug and info.
545 mv -f $diff $CACHE/installed.diff
546 fi | fold -sw80
547 }
550 # The main cook function.
552 cookit() {
553 if [ -n "$SETUP_MD5" ] && [ "$SETUP_MD5" != "$(ls $root$INSTALLED | \
554 md5sum | cut -c1-32)" ]; then
555 _ 'ERROR: Broken setup. Abort.'
556 return
557 fi
559 title 'Cook: %s' "$PACKAGE $VERSION"
560 set_paths
562 # Handle cross-tools.
563 case "$ARCH" in
564 arm*|x86_64)
565 # CROSS_COMPILE is used by at least Busybox and the kernel to set
566 # the cross-tools prefix. Sysroot is the root of our target arch
567 sysroot="$CROSS_TREE/sysroot"
568 tools="$CROSS_TREE/tools"
569 # Set root path when cross compiling. ARM tested but not x86_64
570 # When cross compiling we must install build deps in $sysroot.
571 arch="-$ARCH"
572 root="$sysroot"
573 _ '%s sysroot: %s' "$ARCH" "$sysroot"
574 _ 'Adding "%s" to PATH' "$tools/bin"
575 export PATH="$PATH:$tools/bin"
576 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
577 export CROSS_COMPILE="$HOST_SYSTEM-"
578 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
579 if [ "$ARCH" == 'x86_64' ]; then
580 export CC="$HOST_SYSTEM-gcc -m64"
581 export CXX="$HOST_SYSTEM-g++ -m64"
582 else
583 export CC="$HOST_SYSTEM-gcc"
584 export CXX="$HOST_SYSTEM-g++"
585 fi
586 export AR="$HOST_SYSTEM-ar"
587 export AS="$HOST_SYSTEM-as"
588 export RANLIB="$HOST_SYSTEM-ranlib"
589 export LD="$HOST_SYSTEM-ld"
590 export STRIP="$HOST_SYSTEM-strip"
591 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
592 esac
594 [ -n "$QA" ] && receipt_quality
595 cd $pkgdir
596 [ -z "$continue" ] && rm -rf source 2>/dev/null
597 rm -rf install taz 2>/dev/null
599 # Disable -pipe if less than 512 MB free RAM.
600 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
601 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
602 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
603 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
604 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
605 fi
606 unset free
608 # Export flags and path to be used by make and receipt.
609 DESTDIR="$pkgdir/install"
610 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
611 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
612 #LDFLAGS
614 # Check for build deps and handle implicit depends of *-dev packages
615 # (ex: libusb-dev :: libusb).
616 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
617 touch $CACHE/installed.local $CACHE/installed.web
618 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
619 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
620 for dep in $BUILD_DEPENDS; do
621 implicit="${dep%-dev}"
622 # Don't add implicit dependency if it defined in DEPENDS
623 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
624 for i in $dep $implicit; do
625 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
626 # Try local package first. In some cases implicit doesn't exist, ex:
627 # libboost-dev exists but not libboost, so check if we got vers.
628 unset vers
629 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
630 # We may have a local package.
631 if [ -z "$vers" ]; then
632 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
633 fi
634 debug "bdep: $i version: $vers"
635 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
636 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
637 else
638 # Priority to package version in wok (maybe more up-to-date)
639 # than the mirrored one.
640 if [ -n "$vers" ]; then
641 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
642 echo $i >> $CACHE/installed.web
643 else
644 # So package exists in wok but not available.
645 _ 'Missing dep (wok/pkg): %s' "$i $vers"
646 echo $i >> $CACHE/missing.dep
647 fi
648 else
649 # Package is not in wok but may be in online repo.
650 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
651 echo $i >> $CACHE/installed.web
652 else
653 _ 'ERROR: unknown dep "%s"' "$i"
654 exit 1
655 fi
656 fi
657 fi
658 fi
659 done
660 done
662 # Get the list of installed packages
663 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
665 # Have we a missing build dep to cook?
666 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
667 _ 'Auto cook config is set: %s' "$AUTO_COOK"
668 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
669 for i in $(uniq $CACHE/missing.dep); do
670 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
671 tee -a $LOGS/$PACKAGE.log.$$
672 # programmers: next two messages are exact copy from remove_deps()
673 togrep1=$(_n 'Build dependencies to remove:')
674 togrep2=$(_n 'Removing:')
675 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
676 fgrep $togrep1 $LOGS/$i.log && \
677 fgrep $togrep2 $LOGS/$i.log && newline) | \
678 tee -a $LOGS/$PACKAGE.log.$$ && break
679 done
680 rm -f $CACHE/missing.dep
681 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
682 fi
684 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
685 # is enabled and cook fails we have ERROR in log, if no auto cook we have
686 # missing dep in cached file.
687 lerror=$(_n 'ERROR')
688 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
689 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
690 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
691 exit 1
692 fi
694 # Install local packages: package-version$arch
695 cd $PKGS
696 for i in $(uniq $CACHE/installed.local); do
697 # _ 'Installing dep (pkg/local): %s' "$i"
698 tazpkg install $i --root=$root --local --quiet --cookmode
699 done
701 # Install web or cached packages (if mirror is set to $PKGS we only
702 # use local packages).
703 for i in $(uniq $CACHE/installed.web); do
704 # _ 'Installing dep (web/cache): %s' "$i"
705 tazpkg get-install $i --root=$root --quiet --cookmode
706 done
708 update_installed_cook_diff
710 # Get source tarball and make sure we have source dir named:
711 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
712 # tarball if it exists.
713 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
714 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
715 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
716 LZMA_SRC=''
717 else
718 get_source || exit 1
719 fi
720 fi
721 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
722 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
723 if ! extract_source ; then
724 get_source
725 extract_source || exit 1
726 fi
727 if [ -n "$LZMA_SRC" ]; then
728 cd $pkgdir/source
729 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
730 mv tmp tmp-1; mkdir tmp
731 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
732 fi
733 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
734 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
735 fi
736 fi
737 cd $pkgdir/source/tmp
738 # Some archives are not well done and don't extract to one dir (ex lzma).
739 files=$(ls | wc -l)
740 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
741 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
742 mv * ../$PACKAGE-$VERSION/$TARBALL
743 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
744 mv * ../$PACKAGE-$VERSION
745 cd ..; rm -rf tmp
746 fi
748 # Libtool shared libs path hack.
749 case "$ARCH" in
750 arm*) cross libhack ;;
751 esac
753 # Execute receipt rules.
754 if grep -q ^compile_rules $receipt; then
755 _ 'Executing: %s' 'compile_rules'
756 echo "CFLAGS : $CFLAGS"
757 #echo "LDFLAGS : $LDFLAGS"
758 [ -d "$src" ] && cd $src
759 compile_rules $@ || exit 1
760 # Stay compatible with _pkg
761 [ -d "$src/_pkg" ] && mv $src/_pkg $install
762 # QA: compile_rules success so valid.
763 mkdir -p $install
764 else
765 # QA: no compile_rules so no error, valid.
766 mkdir -p $install
767 fi
769 # Actions to do after compiling the package
770 # Skip all for split packages (already done in main package)
771 if [ -z "$WANTED" ]; then
772 footer
773 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
774 fi
775 footer
777 # Execute testsuite.
778 if grep -q ^testsuite $receipt; then
779 title 'Running testsuite'
780 testsuite $@ || exit 1
781 footer
782 fi
784 update_installed_cook_diff force
785 }
788 # Cook quality assurance.
790 cookit_quality() {
791 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
792 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
793 fi
794 # ERROR can be echoed any time in cookit()
795 lerror=$(_n 'ERROR')
796 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
797 grep -Eq "(^$lerror|undefined reference to)" ; then
798 debug_info | tee -a $LOGS/$pkg.log
799 rm -f $command
800 exit 1
801 fi
802 }
805 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
806 # but it doesn't handle EXTRAVERSION.
808 packit() {
809 set_paths
811 # Handle cross compilation
812 case "$ARCH" in
813 arm*|x86_64) arch="-$ARCH" ;;
814 esac
816 title 'Pack: %s' "$PACKAGE $VERSION$arch"
818 if grep -q ^genpkg_rules $receipt; then
819 _ 'Executing: %s' 'genpkg_rules'
820 set -e; cd $pkgdir; mkdir -p $fs
821 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
822 $LOGS/$pkg.log
823 else
824 _ 'No packages rules: meta package'
825 mkdir -p $fs
826 fi
828 # Check CONFIG_FILES
829 if [ -n "$CONFIG_FILES" ]; then
830 for i in $CONFIG_FILES; do
831 if [ ! -e $fs$i ]; then
832 case $i in
833 */) mkdir -p $fs$i ;;
834 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
835 esac
836 fi
837 done
838 fi
840 # First QA check to stop now if genpkg_rules failed.
841 lerror=$(_n 'ERROR')
842 if fgrep -q ^$lerror $LOGS/$pkg.log; then
843 exit 1
844 fi
846 cd $taz
847 for file in receipt description.txt; do
848 [ ! -f "../$file" ] && continue
849 action 'Copying "%s"...' "$file"
850 cp -f ../$file $pack; chown 0.0 $pack/$file; status
851 done
852 copy_generic_files
854 # Strip and stuff files.
855 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
857 # Create files.list with redirecting find output.
858 action 'Creating the list of files...'
859 cd $fs
860 find . -type f -print > ../files.list
861 find . -type l -print >> ../files.list
862 cd ..; sed -i s/'^.'/''/ files.list
863 status
865 # Md5sum of files.
866 action 'Creating md5sum of files...'
867 while read file; do
868 [ -L "fs$file" ] && continue
869 [ -f "fs$file" ] || continue
870 case "$file" in
871 /lib/modules/*/modules.*|*.pyc) continue ;;
872 esac
873 md5sum "fs$file" | sed 's/ fs/ /'
874 done < files.list > md5sum
875 status
877 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
878 2>/dev/null | awk 'END{ print $1 }')
880 # Build cpio archives.
881 action 'Compressing the FS...'
882 find fs -newer $receipt -exec touch -hr $receipt {} \;
883 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
884 rm -rf fs
885 status
887 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
888 2>/dev/null | awk 'END{ print $1 }')
890 action 'Updating receipt sizes...'
891 sed -i s/^PACKED_SIZE.*$// receipt
892 sed -i s/^UNPACKED_SIZE.*$// receipt
893 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
894 status
896 # Set extra version.
897 if [ -n "$EXTRAVERSION" ]; then
898 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
899 sed -i s/^EXTRAVERSION.*$// receipt
900 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
901 status
902 fi
904 # Compress.
905 action 'Creating full cpio archive...'
906 find . -print | cpio -o -H newc --quiet > \
907 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
908 status
910 action 'Restoring original package tree...'
911 unlzma -c fs.cpio.lzma | cpio -idm --quiet
912 status
914 rm fs.cpio.lzma; cd ..
916 # QA and give info.
917 tazpkg=$(ls *.tazpkg)
918 packit_quality
919 footer "$(_ 'Package "%s" created' "$tazpkg")"
920 }
923 # Verify package quality and consistency.
925 packit_quality() {
926 #action 'QA: checking for broken link...'
927 #link=$(find $fs/usr -type l -follow)
928 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
929 #status
931 # Exit if any error found in log file.
932 lerror=$(_n 'ERROR')
933 if fgrep -q ^$lerror $LOGS/$pkg.log; then
934 rm -f $command
935 exit 1
936 fi
938 action 'QA: checking for empty package...'
939 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
940 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
941 newline; _ 'ERROR: empty package'
942 rm -f $command
943 exit 1
944 else
945 :; status
946 # Find and remove old package(s)
947 tempd="$(mktemp -d)"; cd "$tempd"
948 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
949 # Extract receipt from each matched package
950 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
951 name=$(. receipt; echo $PACKAGE)
952 rm receipt
953 if [ "$name" == "$pkg" ]; then
954 action 'Removing old package "%s"' "$(basename "$testpkg")"
955 rm -f "$testpkg"
956 status
957 fi
958 done
959 rm -r "$tempd"
960 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
961 sed -i /^${pkg}$/d $broken
962 #action 'Removing source tree...'
963 #rm -f $WOK/$pkg/source; status
964 fi
965 }
968 # Reverse "cat" command: prints input lines in the reverse order
970 tac() {
971 sed '1!G;h;$!d' $1
972 }
975 # Install package on --install or update the chroot.
977 install_package() {
978 case "$ARCH" in
979 arm*|x86_64)
980 arch="-$ARCH"
981 root="$CROSS_TREE/sysroot" ;;
982 esac
983 # Install package if requested but skip install if target host doesn't
984 # match build system or it will break the build chroot.
985 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
986 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
987 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
988 cd $PKGS
989 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
990 else
991 _ 'Unable to install package, build has failed.'; newline
992 exit 1
993 fi
994 fi
996 # Install package if part of the chroot to keep env up-to-date.
997 if [ -d "$root$INSTALLED/$pkg" ]; then
998 . /etc/slitaz/cook.conf
999 . $WOK/$pkg/taz/$pkg-*/receipt
1000 _ 'Updating %s chroot environment...' "$ARCH"
1001 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1002 cd $PKGS
1003 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1004 fi
1008 # remove chroot jail
1010 umount_aufs() {
1011 tac ${1}rw/aufs-umount.sh | sh
1012 rm -rf ${1}rw
1013 umount ${1}root
1014 rmdir ${1}r*
1018 # Launch the cook command into a chroot jail protected by aufs.
1019 # The current filesystems are used read-only and updates are
1020 # stored in a separate branch.
1022 try_aufs_chroot() {
1024 base="/dev/shm/aufsmnt$$"
1026 # Can we setup the chroot? Is it already done?
1027 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1028 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1029 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1030 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1031 mkdir ${base}root ${base}rw || return
1033 _ 'Setup aufs chroot...'
1035 # Sanity check
1036 for i in / /proc /sys /dev/shm /home ; do
1037 case " $AUFS_MOUNTS " in
1038 *\ $i\ *) ;;
1039 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1040 esac
1041 done
1042 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1043 mount --bind $mnt ${base}root$mnt
1044 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1045 _ 'Aufs mount failure'
1046 umount ${base}root
1047 rm -rf ${base}r*
1048 return
1049 fi
1050 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1051 done
1052 trap "umount_aufs ${base}" INT
1054 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1055 status=$?
1057 _ 'Leaving aufs chroot...'
1058 umount_aufs $base
1059 # Install package outside the aufs jail
1060 install_package
1061 exit $status
1065 # Encode predefined XML entities
1067 xml_ent() {
1068 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1072 # Create a XML feed for freshly built packages.
1074 gen_rss() {
1075 pubdate=$(date '+%a, %d %b %Y %X')
1076 cat > $FEEDS/$pkg.xml <<EOT
1077 <item>
1078 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1079 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1080 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1081 <pubDate>$pubdate</pubDate>
1082 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1083 </item>
1084 EOT
1088 # Truncate stdout log file to $1 Mb.
1090 loglimit() {
1091 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1092 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1093 else
1094 tee /dev/stderr
1095 fi
1099 # Search file in mirrored packages
1101 search_file_mirror() {
1102 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1106 # Search file in local wok packages
1108 search_file_local() {
1109 # existing packages have precedence over the package/taz folder
1110 srch=$1
1111 { for package in $(find $PKGS -name '*.tazpkg'); do
1112 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1113 grep /$srch\$)" ]; then
1114 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1115 fi
1116 done } | sort -u
1120 # Ask in multiple choice
1122 ask_multiple() {
1123 local multiples first my_choice
1124 multiples="$1"
1125 first=$(echo "$multiples" | head -n1)
1126 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1127 _ 'Select one [%s]: ' "$first"; read my_choice
1128 found="${my_choice:-$first}"
1132 # Search file in local cache (fast), local wok packages, mirrored packages
1134 search_file() {
1135 local srch cache missing
1136 srch="$1"
1137 cache='/var/cache/ldsearch.cache'
1138 missing='/var/cache/missing.file'
1139 touch $cache $missing
1140 found=$(grep $srch $cache | cut -d$'\t' -f2)
1141 if [ -z "$found" ]; then
1142 found=$(search_file_local $srch)
1143 if [ -n "$found" ]; then
1144 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1145 ask_multiple "$found"
1146 fi
1147 echo -e "$srch\t$found" >> $cache
1148 else
1149 found=$(search_file_mirror $srch)
1150 if [ -n "$found" ]; then
1151 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1152 ask_multiple "$found"
1153 fi
1154 echo -e "$srch\t$found" >> $cache
1155 else
1156 echo "$srch" >> $missing
1157 fi
1158 fi
1159 fi
1164 # Receipt functions to ease packaging
1167 get_dev_files() {
1168 action 'Getting standard devel files...'
1169 mkdir -p $fs/usr/lib
1170 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1171 cp -a $install/usr/lib/*a $fs/usr/lib
1172 cp -a $install/usr/include $fs/usr
1173 status
1177 # Function to use in compile_rules() to copy man page from $src to $install
1179 cook_pick_manpages() {
1180 local name section
1181 action 'Copying man pages...'
1183 for i in $@; do
1184 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1185 section=${name##*/}; section=${section##*.}
1186 mkdir -p $install/usr/share/man/man$section
1187 copy $i $install/usr/share/man/man$section
1188 done
1189 status
1193 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1195 cook_copy_files() {
1196 action 'Copying files...'
1197 cd $install
1198 local i j
1199 IFS=$'\n'
1200 for i in $@; do
1201 for j in $(find . -name $i ! -type d); do
1202 mkdir -p $fs$(dirname ${j#.})
1203 copy $j $fs$(dirname ${j#.})
1204 done
1205 done
1206 cd - >/dev/null
1207 status
1211 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1213 cook_copy_folders() {
1214 action 'Copying folders...'
1215 cd $install
1216 local i j
1217 IFS=$'\n'
1218 for i in $@; do
1219 for j in $(find . -name $i -type d); do
1220 mkdir -p $fs$(dirname ${j#.})
1221 copy $j $fs$(dirname ${j#.})
1222 done
1223 done
1224 cd - >/dev/null
1225 status
1229 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1230 # (default: 16 and 48) from $install to $fs
1232 cook_copy_icons() {
1233 local sizes=$@
1234 action 'Copying hicolor icons...'
1235 mkdir -p $fs/usr/share/icons/hicolor
1236 for i in ${sizes:-16 48}; do
1237 [ ! -e "$install/usr/share/icons/hicolor/${i}x$i" ] ||
1238 copy $install/usr/share/icons/hicolor/${i}x$i \
1239 $fs/usr/share/icons/hicolor
1240 done
1241 status
1248 # Commands
1251 case "$1" in
1252 usage|help|-u|-h)
1253 usage ;;
1255 list-wok)
1256 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1257 cd $WOK
1258 if [ "$ARCH" != 'i486' ]; then
1259 count=0
1260 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1261 do
1262 unset HOST_ARCH
1263 . $pkg
1264 count=$(($count + 1))
1265 colorize 34 "$PACKAGE"
1266 done
1267 else
1268 count=$(ls | wc -l)
1269 ls -1
1270 fi
1271 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1272 ;;
1274 activity)
1275 cat $activity ;;
1277 search)
1278 # Just a simple search function, we dont need more actually.
1279 query="$2"
1280 title 'Search results for "%s"' "$query"
1281 cd $WOK; ls -1 | grep "$query"
1282 footer ;;
1284 setup)
1285 # Setup a build environment
1286 check_root
1287 _ 'Cook: setup environment' | log
1288 title 'Setting up your environment'
1289 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1290 cd $SLITAZ
1291 init_db_files
1292 _ 'Checking for packages to install...'
1293 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1294 # ARCH-setup or 'cross check' should be used before: cook setup
1295 case "$ARCH" in
1296 arm*|x86_64)
1297 if [ ! -x '/usr/bin/cross' ]; then
1298 _ 'ERROR: %s is not installed' 'cross'
1299 exit 1
1300 fi
1301 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1302 . /etc/slitaz/cross.conf ;;
1303 esac
1304 for pkg in $SETUP_PKGS; do
1305 if [ -n "$forced" ]; then
1306 tazpkg -gi $pkg --forced
1307 else
1308 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1309 fi
1310 done
1312 # Handle --options
1313 case "$2" in
1314 --wok) hg clone $WOK_URL wok || exit 1 ;;
1315 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1316 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1317 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1318 esac
1320 # SliTaz group and permissions
1321 if ! grep -q ^slitaz /etc/group; then
1322 _ 'Adding group "%s"' 'slitaz'
1323 addgroup slitaz
1324 fi
1325 _ 'Setting permissions for group "%s"...' 'slitaz'
1326 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1327 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1328 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1330 *-setup)
1331 # Setup for cross compiling.
1332 arch="${1%-setup}"
1333 check_root
1334 . /etc/slitaz/cook.conf
1335 for pkg in $CROSS_SETUP; do
1336 if [ -n "$forced" ]; then
1337 tazpkg -gi $pkg --forced
1338 else
1339 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1340 fi
1341 done
1343 _ 'Cook: setup %s cross environment' "$arch" | log
1344 title 'Setting up your %s cross environment' "$arch"
1345 init_db_files
1346 sed -i \
1347 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1348 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1349 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1350 /etc/slitaz/cook.conf
1351 case "$arch" in
1352 arm)
1353 flags='-O2 -march=armv6'
1354 host="$ARCH-slitaz-linux-gnueabi" ;;
1355 armv6hf)
1356 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1357 host="$ARCH-slitaz-linux-gnueabi" ;;
1358 armv7)
1359 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1360 host="$ARCH-slitaz-linux-gnueabi" ;;
1361 x86_64)
1362 flags='-O2 -mtune=generic -pipe'
1363 host="$ARCH-slitaz-linux" ;;
1364 esac
1365 sed -i \
1366 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1367 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1368 . /etc/slitaz/cook.conf
1369 sysroot="$CROSS_TREE/sysroot"
1370 tools="/cross/$arch/tools"
1371 root="$sysroot"
1372 # L10n: keep the same width of translations to get a consistent view
1373 _ 'Target arch : %s' "$ARCH"
1374 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1375 _ 'Build flags : %s' "$flags"
1376 _ 'Arch sysroot : %s' "$sysroot"
1377 _ 'Tools prefix : %s' "$tools/bin"
1378 # Tell the packages manager where to find packages.
1379 _ 'Packages DB : %s' "$root$DB"
1380 mkdir -p $root$INSTALLED
1381 cd $root$DB; rm -f *.bak
1382 for list in packages.list packages.desc packages.equiv packages.md5; do
1383 rm -f $list
1384 ln -s $SLITAZ/packages/$list $list
1385 done
1386 # We must have the cross compiled glibc-base installed or default
1387 # i486 package will be used as dep by tazpkg and then break the
1388 # cross environment
1389 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1390 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1391 fi
1392 # Show GCC version or warn if not yet compiled.
1393 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1394 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1395 else
1396 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1397 _ 'Run "%s" to cook a toolchain' 'cross compile'
1398 fi
1399 footer ;;
1401 test)
1402 # Test a cook environment.
1403 _ 'Cook test: testing the cook environment' | log
1404 [ ! -d "$WOK" ] && exit 1
1405 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1406 cook cooktest ;;
1408 new)
1409 # Create the package folder and an empty receipt.
1410 pkg="$2"
1411 [ -z "$pkg" ] && usage
1412 newline
1413 if [ -d "$WOK/$pkg" ]; then
1414 _ 'Package "%s" already exists.' "$pkg"
1415 exit 1
1416 fi
1418 action 'Creating folder "%s"' "$WOK/$pkg"
1419 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1421 action 'Preparing the package receipt...'
1422 cp $DATA/receipt .
1423 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1424 status; newline
1426 # Interactive mode, asking and seding.
1427 case "$3" in
1428 --interactive|-x)
1429 _ 'Entering interactive mode...'
1430 separator
1431 _ 'Package : %s' "$pkg"
1433 _n 'Version : ' ; read answer
1434 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1436 _n 'Category : ' ; read answer
1437 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1439 # L10n: Short description
1440 _n 'Short desc : ' ; read answer
1441 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1443 _n 'Maintainer : ' ; read answer
1444 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1446 _n 'License : ' ; read answer
1447 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1449 _n 'Web site : ' ; read answer
1450 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1451 newline
1453 # Wget URL.
1454 _ 'Wget URL to download source tarball.'
1455 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1456 _n 'Wget url : ' ; read answer
1457 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1459 # Ask for a stuff dir.
1460 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1461 if [ "$?" -eq 0 ]; then
1462 action 'Creating the stuff directory...'
1463 mkdir $WOK/$pkg/stuff; status
1464 fi
1466 # Ask for a description file.
1467 confirm "$(_n 'Are you going to write a description? (y/N)')"
1468 if [ "$?" -eq 0 ]; then
1469 action 'Creating the "%s" file...' 'description.txt'
1470 touch $WOK/$pkg/description.txt; status
1471 fi
1473 footer "$(_ 'Receipt is ready to use.')" ;;
1474 esac ;;
1476 list)
1477 # Cook a list of packages (better use the Cooker since it will order
1478 # packages before executing cook).
1479 check_root
1480 if [ -z "$2" ]; then
1481 newline; _ 'No list in argument.'; newline
1482 exit 1
1483 fi
1484 if [ ! -f "$2" ]; then
1485 newline; _ 'List "%s" not found.' "$2"; newline
1486 exit 1
1487 fi
1489 _ 'Starting cooking the list "%s"' "$2" | log
1491 for pkg in $(cat $2); do
1492 cook $pkg || broken
1493 done ;;
1495 clean-wok)
1496 check_root
1497 newline; action 'Cleaning all packages files...'
1498 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1499 status; newline ;;
1501 clean-src)
1502 check_root
1503 newline; action 'Cleaning all packages sources...'
1504 rm -rf $WOK/*/source
1505 status; newline ;;
1507 uncook)
1508 cd $WOK
1509 count=0
1510 title 'Checking for uncooked packages'
1512 for pkg in *; do
1513 unset HOST_ARCH EXTRAVERSION
1514 [ ! -e $pkg/receipt ] && continue
1515 . $pkg/receipt
1516 # Source cooked pkg receipt to get EXTRAVERSION
1517 if [ -d "$WOK/$pkg/taz" ]; then
1518 cd $WOK/$pkg/taz/$pkg-*
1519 . receipt; cd $WOK
1520 fi
1521 case "$ARCH" in
1522 i486)
1523 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1524 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1525 count=$(($count + 1))
1526 colorize 34 "$pkg"
1527 fi ;;
1528 arm*)
1529 # Check only packages included in arch
1530 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1531 # *.tazpkg
1532 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1533 count=$(($count + 1))
1534 colorize 34 "$pkg"
1535 fi
1536 fi ;;
1537 esac
1538 done
1540 if [ "$count" -gt "0" ]; then
1541 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1542 else
1543 _ 'All packages are cooked :-)'
1544 newline
1545 fi
1546 ;;
1548 pkgdb)
1549 # Create suitable packages list for TazPkg and only for built packages
1550 # as well as flavors files for TazLiTo. We don't need logs since we do it
1551 # manually to ensure everything is fine before syncing the mirror.
1552 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1553 ;;
1555 *)
1556 # Just cook and generate a package.
1557 check_root
1558 time=$(date +%s)
1559 pkg="$1"
1560 [ -z "$pkg" ] && usage
1561 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1562 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1563 receipt="$WOK/$pkg/receipt"
1564 check_pkg_in_wok
1565 newline
1567 unset inst
1568 unset_receipt
1569 . $receipt
1571 # Handle cross compilation.
1572 case "$ARCH" in
1573 arm*)
1574 if [ -z "$HOST_ARCH" ]; then
1575 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1576 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1577 _ 'cook: %s' "$error"
1578 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1579 _ 'Cook skip: %s' "$error" | log
1580 newline
1581 exit 1
1582 fi ;;
1583 esac
1585 # Some packages are not included in some arch or fail to cross compile.
1586 : ${HOST_ARCH=i486}
1587 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1588 # Handle arm{v6hf,v7,..}
1589 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1590 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1591 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1592 _ 'cook: %s' "error"
1593 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1594 _ 'Cook skip: %s' "$error" | log
1595 sed -i /^${pkg}$/d $broken
1596 newline
1597 exit 0
1598 fi
1600 # Skip blocked, 3 lines also for the Cooker.
1601 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1602 _ 'Package "%s" is blocked' "$pkg"; newline
1603 exit 0
1604 fi
1606 try_aufs_chroot "$@"
1608 # Log and source receipt.
1609 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1610 echo "cook:$pkg" > $command
1611 [ "$lastcooktime" ] &&
1612 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1613 while read cmd duration start; do
1614 [ $(($start + $duration)) -lt $(date +%s) ] &&
1615 echo "sed -i '/^$cmd $duration/d' $cooktime"
1616 done < $cooktime | sh
1618 # Display and log info if cook process stopped.
1619 # FIXME: gettext not working (in single quotes) here!
1620 trap '_ "\n\nCook stopped: control-C\n\n" | \
1621 tee -a $LOGS/$pkg.log' INT
1623 # Handle --options
1624 case "$2" in
1625 --clean|-c)
1626 action 'Cleaning "%s"' "$pkg"
1627 cd $WOK/$pkg; rm -rf install taz source
1628 status; newline
1629 exit 0 ;;
1631 --install|-i)
1632 inst='yes' ;;
1634 --getsrc|-gs)
1635 title 'Getting source for "%s"' "$pkg"
1636 get_source
1637 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1638 exit 0 ;;
1640 --block|-b)
1641 action 'Blocking package "%s"' "$pkg"
1642 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1643 status; newline
1644 exit 0 ;;
1646 --unblock|-ub)
1647 action 'Unblocking package "%s"' "$pkg"
1648 sed -i "/^${pkg}$/"d $blocked
1649 status; newline
1650 exit 0 ;;
1652 --pack)
1653 if [ -d $WOK/$pkg/taz ]; then
1654 rm -rf $WOK/$pkg/taz
1655 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1656 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1657 clean_log
1658 else
1659 _ 'Need to build "%s"' "$pkg"
1660 exit 0
1661 fi
1662 exit 0 ;;
1664 --cdeps)
1665 if [ ! -d $WOK/$pkg/taz ]; then
1666 _ 'Need to build "%s"' "$pkg"
1667 exit 0
1668 fi
1670 title 'Checking depends'
1671 lddlist='/tmp/lddlist'; touch $lddlist
1672 missing='/var/cache/missing.file'
1674 # find all deps using ldd
1675 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1676 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1677 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1678 done #"
1680 # remove exe/so duplicates
1681 sort -u $lddlist > $lddlist.sorted
1683 # search packages
1684 for exefile in $(cat $lddlist.sorted); do
1685 search_file $exefile
1686 echo "$found" >> $lddlist.pkgs
1687 echo -n '.'
1688 done
1689 echo
1691 # remove packages duplicates
1692 sort -u $lddlist.pkgs > $lddlist.final
1693 sort -u $missing > $missing.final
1694 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1695 exit 0 ;;
1696 esac
1698 # Rotate log
1699 for i in $(seq 9 -1 1); do
1700 j=$(($i - 1))
1701 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1702 done
1703 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1705 # Check if wanted is built now so we have separate log files.
1706 for wanted in $WANTED ; do
1707 if grep -q "^$wanted$" $blocked; then
1708 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1709 newline
1710 rm -f $command
1711 exit 1
1712 fi
1713 if grep -q "^$wanted$" $broken; then
1714 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1715 newline
1716 rm -f $command
1717 exit 1
1718 fi
1719 if [ ! -d "$WOK/$wanted/install" ]; then
1720 cook "$wanted" || exit 1
1721 fi
1722 done
1724 # Cook and pack or exit on error and log everything.
1725 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1726 remove_deps | tee -a $LOGS/$pkg.log
1727 cookit_quality
1728 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1729 clean_log
1731 # Exit if any error in packing.
1732 lerror=$(_n 'ERROR')
1733 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1734 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1735 debug_info | tee -a $LOGS/$pkg.log
1736 rm -f $command
1737 exit 1
1738 fi
1740 # Create an XML feed
1741 gen_rss
1743 # Time and summary
1744 time=$(($(date +%s) - $time))
1745 summary | tee -a $LOGS/$pkg.log
1746 newline
1748 # We may want to install/update (outside aufs jail !).
1749 [ -s /aufs-umount.sh ] ||
1750 install_package
1752 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1753 # You want automation: use the Cooker Build Bot.
1754 rm -f $command ;;
1755 esac
1757 exit 0