cookutils view cook @ rev 907
cook: add check_integrity(), fix install_package() to be compatible with receipts v2.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon May 29 01:54:22 2017 +0300 (2017-05-29) |
parents | c711ef2e51a9 |
children | f439bf689ac8 |
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 [ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
84 }
87 # Initialize files used in $CACHE
89 init_db_files() {
90 _ 'Creating directories structure in "%s"' "$SLITAZ"
91 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
92 _ 'Creating DB files in "%s"' "$CACHE"
93 touch $activity $command $broken $blocked
94 }
97 # QA: check a receipt consistency before building.
99 receipt_quality() {
100 _ 'QA: checking package receipt...'
102 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
103 unset value
104 value="$(. $receipt; eval echo \$$var)"
105 # L10n: QA is quality assurance
106 [ -n "$value" ] || die 'QA: empty variable: %s' "$var=\"\""
108 case "$var" in
109 CATEGORY)
110 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
111 if ! echo " $valid " | grep -q " $value "; then
112 _ 'QA: unknown category "%s"' "$value"
113 die 'Please, use one of: %s' "$valid"
114 fi
115 ;;
116 WEB_SITE)
117 # We don't check WGET_URL since if dl is needed it will fail.
118 # Break also if we're not online. Here error is not fatal.
119 if ifconfig | grep -A1 '^[a-z]*[0-9]' | fgrep -q 'addr:' && \
120 ! busybox wget -T 12 --spider $value 2>/dev/null; then
121 _ 'QA: unable to reach "%s"' "$value"
122 fi
123 ;;
124 esac
125 done
126 }
129 # Paths used in receipt and by cook itself.
131 set_paths() {
132 pkgdir="$WOK/$pkg"
133 . "$pkgdir/receipt"
134 basesrc="$pkgdir/source"
135 tmpsrc="$basesrc/tmp"
136 src="$basesrc/$PACKAGE-$VERSION"
137 taz="$pkgdir/taz"
138 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
139 fs="$pack/fs"
140 stuff="$pkgdir/stuff"
141 install="$pkgdir/install"
143 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
144 lzma_tarball="$pkgsrc.tar.lzma"
146 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
148 if [ -n "$WANTED" ]; then
149 basesrc="$WOK/$WANTED/source"
150 src="$basesrc/$WANTED-$VERSION"
151 install="$WOK/$WANTED/install"
152 wanted_stuff="$WOK/$WANTED/stuff"
153 fi
155 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
157 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
158 if [ -f "$WOK/linux/receipt" ]; then
159 kvers=$(. $WOK/linux/receipt; echo $VERSION)
160 kbasevers=$(echo $kvers | cut -d. -f1,2)
161 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
162 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
163 kbasevers=$(echo $kvers | cut -d. -f1,2)
164 fi
166 # Python version
167 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
168 # Perl version for some packages needed it
169 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
171 # Old way compatibility.
172 _pkg="$install"
173 }
176 # Create source tarball when URL is a SCM.
178 create_tarball() {
179 local tarball
180 tarball="$pkgsrc.tar.bz2"
181 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
182 _ 'Creating tarball "%s"' "$tarball"
183 if [ -n "$LZMA_SRC" ]; then
184 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
185 LZMA_SRC=''
186 else
187 tar -cjf $tarball $pkgsrc || exit 1
188 mv $tarball $SRC; rm -rf $pkgsrc
189 fi
190 TARBALL="$tarball"
191 }
194 # Get package source. For SCM we are in cache so clone here and create a
195 # tarball here.
197 get_source() {
198 local url
199 url=${WGET_URL#*|}
200 set_paths
201 pwd=$(pwd)
202 case "$WGET_URL" in
203 http://*|ftp://*|https://*)
204 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
205 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
206 wget -T 60 -c -O $SRC/$TARBALL $url ||
207 die 'ERROR: %s' "wget $WGET_URL"
208 ;;
210 hg*|mercurial*)
211 _ 'Getting source from %s...' 'Hg'
212 _ 'URL: %s' "$url"
213 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
214 if [ -n "$BRANCH" ]; then
215 _ 'Hg branch: %s' "$BRANCH"
216 hg clone $url --rev $BRANCH $pkgsrc ||
217 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
218 else
219 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
220 fi
221 rm -rf $pkgsrc/.hg
222 create_tarball
223 ;;
225 git*)
226 _ 'Getting source from %s...' 'Git'
227 _ 'URL: %s' "$url"
228 cd $SRC
229 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
230 if [ -n "$BRANCH" ]; then
231 _ 'Git branch: %s' "$BRANCH"
232 cd $pkgsrc; git checkout $BRANCH; cd ..
233 fi
234 cd $SRC
235 create_tarball
236 ;;
238 cvs*)
239 mod=$PACKAGE
240 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
241 _ 'Getting source from %s...' 'CVS'
242 _ 'URL: %s' "$url"
243 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
244 _ 'Cloning to "%s"' "$pwd/$mod"
245 cvs -d:$url co $mod && mv $mod $pkgsrc
246 create_tarball
247 ;;
249 svn*|subversion*)
250 _ 'Getting source from %s...' 'SVN'
251 _ 'URL: %s' "$url"
252 if [ -n "$BRANCH" ]; then
253 echo t | svn co $url -r $BRANCH $pkgsrc
254 else
255 echo t | svn co $url $pkgsrc
256 fi
257 create_tarball
258 ;;
260 bzr*)
261 _ 'Getting source from %s...' 'bazaar'
262 cd $SRC
263 pkgsrc=${url#*:}
264 if [ -n "$BRANCH" ]; then
265 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
266 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
267 else
268 echo "bzr -Ossl.cert_reqs=none branch $url"
269 bzr -Ossl.cert_reqs=none branch $url
270 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
271 _ "Don't forget to add to receipt:"
272 echo -e "BRANCH=\"$BRANCH\"\n"
273 fi
274 mv $pkgsrc $pkgsrc-$BRANCH
275 pkgsrc="$pkgsrc-$BRANCH"
276 create_tarball
277 ;;
279 *)
280 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
281 ;;
282 esac
283 }
286 # Extract source package.
288 extract_source() {
289 if [ ! -s "$SRC/$TARBALL" ]; then
290 local url
291 url="$MIRROR_URL/sources/packages"
292 url="$url/${TARBALL:0:1}/$TARBALL"
293 _ 'Getting source from %s...' 'mirror'
294 _ 'URL: %s' "$url"
295 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
296 fi
297 _ 'Extracting source archive "%s"' "$TARBALL"
298 case "$TARBALL" in
299 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
300 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
301 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
302 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
303 *.tar) tar -xf $SRC/$TARBALL ;;
304 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null ;;
305 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
306 tar -xf $SRC/$TARBALL 2>/dev/null;;
307 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
308 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
309 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
310 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
311 *) cp $SRC/$TARBALL $(pwd) ;;
312 esac
313 }
316 # Display time.
318 disp_time() {
319 local sec div min
320 sec="$1"
321 div=$(( ($1 + 30) / 60))
322 case $div in
323 0) min='';;
324 # L10n: 'm' is for minutes (approximate cooking time)
325 *) min=$(_n ' ~ %dm' "$div");;
326 esac
328 # L10n: 's' is for seconds (cooking time)
329 _ '%ds%s' "$sec" "$min"
330 }
333 # Display cooked package summary.
335 summary() {
336 set_paths
337 cd $WOK/$pkg
338 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
339 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
340 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
342 _ 'Summary for: %s' "$PACKAGE $VERSION"
343 separator
345 # L10n: keep the same width of translations to get a consistent view
346 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
347 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
348 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
349 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
350 _ 'Cook time : %s' "$(disp_time "$time")"
351 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
352 _ 'Host arch : %s' "$ARCH"
354 separator -
355 _ ' # : Packed : Compressed : Files : Package name'
356 separator -
357 pkgi=1
358 for i in $PACKAGE $SPLIT; do
359 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION | awk '{print $1}')
360 pkgname="$i-$VERSION.tazpkg"
361 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
362 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION/files.list)
363 printf "%2d : %6s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
364 pkgi=$((pkgi + 1))
365 done
366 separator
367 }
370 # Display debugging error info.
372 debug_info() {
373 title 'Debug information'
374 # L10n: specify your format of date and time (to help: man date)
375 # L10n: not bad one is '+%x %R'
376 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
377 if [ -n "$time" ]; then
378 times="$(($(date +%s) - $time))"
379 _ 'Wasted time : %s' "$(disp_time "$times")"
380 fi
381 for error in \
382 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
383 'error:' 'fatal error:' 'undefined reference to' \
384 'Unable to connect to' 'link: cannot find the library' \
385 'CMake Error' ': No such file or directory' \
386 'Could not read symbols: File in wrong format'
387 do
388 # format "line number:line content"
389 fgrep -n "$error" $LOGS/$pkg.log
390 done > $LOGS/$pkg.log.debug_info 2>&1
391 # sort by line number, remove duplicates
392 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
393 rm -f $LOGS/$pkg.log.debug_info
394 footer
395 }
398 # A bit smarter function than the classic `cp` command
400 scopy() {
401 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
402 cp -a "$1" "$2" # copy generic files
403 else
404 cp -al "$1" "$2" # copy hardlinks
405 fi
406 }
409 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
410 # so some packages need to copy these files with the receipt and genpkg_rules.
412 copy_generic_files() {
413 # $LOCALE is set in cook.conf
414 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
415 if [ -d "$install/usr/share/locale" ]; then
416 mkdir -p $fs/usr/share/locale
417 for i in $LOCALE; do
418 if [ -d "$install/usr/share/locale/$i" ]; then
419 scopy $install/usr/share/locale/$i $fs/usr/share/locale
420 fi
421 done
422 fi
423 fi
425 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
426 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
427 if [ -d "$install/usr/share/pixmaps" ]; then
428 mkdir -p $fs/usr/share/pixmaps
429 for i in png xpm; do
430 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" ] &&
431 scopy $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
432 done
433 fi
435 # Custom or homemade PNG pixmap can be in stuff.
436 if [ -f "$stuff/$PACKAGE.png" ]; then
437 mkdir -p $fs/usr/share/pixmaps
438 scopy $stuff/$PACKAGE.png $fs/usr/share/pixmaps
439 fi
440 fi
442 # Desktop entry (.desktop).
443 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
444 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
445 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
446 mkdir -p $fs/usr/share
447 scopy $install/usr/share/applications $fs/usr/share
448 fi
449 fi
451 # Homemade desktop file(s) can be in stuff.
452 if [ -d "$stuff/applications" ]; then
453 mkdir -p $fs/usr/share
454 scopy $stuff/applications $fs/usr/share
455 fi
456 if [ -f "$stuff/$PACKAGE.desktop" ]; then
457 mkdir -p $fs/usr/share/applications
458 scopy $stuff/$PACKAGE.desktop $fs/usr/share/applications
459 fi
461 # Add custom licenses
462 if [ -d "$stuff/licenses" ]; then
463 mkdir -p $fs/usr/share/licenses
464 scopy $stuff/licenses $fs/usr/share/licenses/$PACKAGE
465 fi
466 }
469 # Remove files provided by split packages
470 # For example:
471 # 1. Package "pkg-main":
472 # SPLIT="pkg-1 pkg-2 pkg-extra"
473 # 2. Package="pkg-extra":
474 # WANTED="pkg-main"
475 # BUILD_DEPENDS="pkg-1 pkg-2"
476 # cook_copy_folders usr
477 # cook_split_rm $BUILD_DEPENDS
479 cook_split_rm() {
480 for i in $@; do
481 action 'Remove files provided by split package %s...' "$i"
482 while read j; do
483 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
484 rmdir "$(dirname "$fs$j")" 2>/dev/null
485 done < $WOK/$i/taz/$i-$VERSION/files.list
486 :; status
487 done
488 }
491 # Update installed.cook.diff
493 update_installed_cook_diff() {
494 # If a cook failed deps are removed.
495 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
496 cd $CACHE
497 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
498 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
499 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
500 }
503 # Remove installed deps.
505 remove_deps() {
506 # Now remove installed build deps.
507 diff='/tmp/installed.cook.diff'
508 [ -s "$diff" ] || return
510 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
511 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
512 newline
513 _n 'Build dependencies to remove:'; echo " $nb"
514 [ -n "$root" ] && echo "root=\"$root\""
515 {
516 _n 'Removing:'
517 for dep in $deps; do
518 echo -n " $dep"
519 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
520 done
521 newline; newline
522 # Keep the last diff for debug and info.
523 mv -f $diff $CACHE/installed.diff
524 } | fold -sw80
525 }
528 # Automatically patch the sources.
530 patchit() {
531 [ -f "$stuff/patches/series" ] || return
533 while read i; do
534 [ -f "$src/done.$i" ] && continue
535 patch -p1 -i $stuff/patches/$i
536 touch $src/done.$i
537 done < $stuff/patches/series
538 }
541 # Check source tarball integrity.
543 check_integrity() {
544 if [ -n "$TARBALL_SHA1" ]; then
545 echo "$TARBALL_SHA1 $SRC/$TARBALL" | sha1sum -c || exit 1
546 fi
547 if [ -n "$TARBALL_SHA256" ]; then
548 echo "$TARBALL_SHA256 $SRC/$TARBALL" | sha256sum -c || exit 1
549 fi
550 if [ -n "$TARBALL_MD5" ]; then
551 echo "$TARBALL_MD5 $SRC/$TARBALL" | md5sum -c || exit 1
552 fi
553 }
556 # The main cook function.
558 cookit() {
559 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
560 _ 'ERROR: Broken setup. Abort.'
561 return
562 fi
564 title 'Cook: %s' "$PACKAGE $VERSION"
565 set_paths
567 # Handle cross-tools.
568 case "$ARCH" in
569 arm*|x86_64)
570 # CROSS_COMPILE is used by at least Busybox and the kernel to set
571 # the cross-tools prefix. Sysroot is the root of our target arch
572 sysroot="$CROSS_TREE/sysroot"
573 tools="$CROSS_TREE/tools"
574 # Set root path when cross compiling. ARM tested but not x86_64
575 # When cross compiling we must install build deps in $sysroot.
576 arch="-$ARCH"
577 root="$sysroot"
578 _ '%s sysroot: %s' "$ARCH" "$sysroot"
579 _ 'Adding "%s" to PATH' "$tools/bin"
580 export PATH="$PATH:$tools/bin"
581 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
582 export CROSS_COMPILE="$HOST_SYSTEM-"
583 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
584 if [ "$ARCH" == 'x86_64' ]; then
585 export CC="$HOST_SYSTEM-gcc -m64"
586 export CXX="$HOST_SYSTEM-g++ -m64"
587 else
588 export CC="$HOST_SYSTEM-gcc"
589 export CXX="$HOST_SYSTEM-g++"
590 fi
591 export AR="$HOST_SYSTEM-ar"
592 export AS="$HOST_SYSTEM-as"
593 export RANLIB="$HOST_SYSTEM-ranlib"
594 export LD="$HOST_SYSTEM-ld"
595 export STRIP="$HOST_SYSTEM-strip"
596 export LIBTOOL="$HOST_SYSTEM-libtool"
597 ;;
598 esac
600 [ -n "$QA" ] && receipt_quality
602 cd $pkgdir
603 [ -z "$continue" ] && rm -rf source 2>/dev/null
604 rm -rf install taz 2>/dev/null
606 # Disable -pipe if less than 512 MB free RAM.
607 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
608 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
609 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
610 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
611 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
612 fi
613 unset free
615 # Export flags and path to be used by make and receipt.
616 DESTDIR="$pkgdir/install"
617 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
618 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
619 #LDFLAGS
621 # BUILD_DEPENDS may vary depending on the ARCH
622 case "$ARCH" in
623 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
624 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
625 esac
627 # Check for build deps and handle implicit depends of *-dev packages
628 # (ex: libusb-dev :: libusb).
629 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
630 touch $CACHE/installed.local $CACHE/installed.web
631 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
632 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
633 for dep in $BUILD_DEPENDS; do
634 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
635 for i in $dep $implicit; do
636 # echo "i='$i'"
637 # Check if package already installed
638 [ -f "$root$INSTALLED/$i/receipt" ] && continue
640 # Try local package first.
641 namever=$(awk -F$'\t' -vpkg="$i" '{
642 # if package-name or provided-package-name matched
643 if (index(" " $1 " " $10 " ", " " pkg " ")) { printf("%s-%s", $1, $2); exit; }
644 }' "$PKGS/packages.info") # <namever> = <package_name>-<package_version>
646 debug "bdep: $i name-version: $namever"
648 # If local package available
649 [ -f "$PKGS/$namever$arch.tazpkg" ] &&
650 echo "$namever$arch.tazpkg" >> $CACHE/installed.local && continue
652 # If package exists in wok but not built
653 [ -d "$WOK/$i" ] &&
654 _ 'Missing dep (wok/pkg): %s' "$i $vers" &&
655 echo $i >> $CACHE/missing.dep && continue
657 # If package available on the mirror
658 [ -n "$(awk -F$'\t' -vi="$i" '$1==i{print $1}' "$root$DB/packages.info")" ] &&
659 echo $i >> $CACHE/installed.web && continue
661 # Give up; skip error for implicit dependency: in some cases
662 # implicit doesn't exist, ex: libboost-dev exists but not libboost.
663 [ "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
664 done
665 done
667 # Get the list of installed packages
668 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
670 # Have we a missing build dep to cook?
671 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
672 _ 'Auto cook config is set: %s' "$AUTO_COOK"
673 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
674 for i in $(uniq $CACHE/missing.dep); do
675 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
676 tee -a $LOGS/$PACKAGE.log.$$
677 # programmers: next two messages are exact copy from remove_deps()
678 togrep1=$(_n 'Build dependencies to remove:')
679 togrep2=$(_n 'Removing:')
680 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
681 fgrep $togrep1 $LOGS/$i.log && \
682 fgrep $togrep2 $LOGS/$i.log && newline) | \
683 tee -a $LOGS/$PACKAGE.log.$$ && break
684 done
685 rm -f $CACHE/missing.dep
686 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
687 fi
689 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
690 # is enabled and cook fails we have ERROR in log, if no auto cook we have
691 # missing dep in cached file.
692 lerror=$(_n 'ERROR')
693 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
694 [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
695 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
696 broken; exit 1
697 fi
699 # Install local packages: package-version$arch
700 cd $PKGS
701 for i in $(uniq $CACHE/installed.local); do
702 # _ 'Installing dep (pkg/local): %s' "$i"
703 tazpkg install $i --root=$root --local --quiet --cookmode
704 done
706 # Install web or cached packages (if mirror is set to $PKGS we only
707 # use local packages).
708 for i in $(uniq $CACHE/installed.web); do
709 # _ 'Installing dep (web/cache): %s' "$i"
710 tazpkg get-install $i --root=$root --local --quiet --cookmode
711 done
713 update_installed_cook_diff
715 # Get source tarball and make sure we have source dir named:
716 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
717 # tarball if it exists.
718 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
719 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
720 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
721 LZMA_SRC=''
722 else
723 get_source || { broken; exit 1; }
724 fi
725 fi
726 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
727 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
728 if ! extract_source ; then
729 get_source
730 extract_source || { broken; exit 1; }
731 fi
732 if [ -n "$LZMA_SRC" ]; then
733 cd $pkgdir/source
734 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
735 mv tmp tmp-1; mkdir tmp
736 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
737 fi
738 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
739 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
740 fi
741 fi
742 cd $pkgdir/source/tmp
743 # Some archives are not well done and don't extract to one dir (ex lzma).
744 files=$(ls | wc -l)
745 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
746 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
747 mv * ../$PACKAGE-$VERSION/$TARBALL
748 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
749 mv * ../$PACKAGE-$VERSION
750 cd ..; rm -rf tmp
751 fi
753 # Libtool shared libs path hack.
754 case "$ARCH" in
755 arm*) cross libhack ;;
756 esac
758 # Execute receipt rules.
759 if grep -q ^compile_rules $receipt; then
760 _ 'Executing: %s' 'compile_rules'
761 echo "CFLAGS : $CFLAGS"
762 #echo "LDFLAGS : $LDFLAGS"
763 [ -d "$src" ] && cd $src
764 patchit
765 compile_rules $@ || { broken; exit 1; }
766 # Stay compatible with _pkg
767 [ -d "$src/_pkg" ] && mv $src/_pkg $install
768 # QA: compile_rules success so valid.
769 mkdir -p $install
770 else
771 # QA: no compile_rules so no error, valid.
772 mkdir -p $install
773 fi
775 # Actions to do after compiling the package
776 # Skip all for split packages (already done in main package)
777 if [ -z "$WANTED" ]; then
778 footer
779 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
780 fi
781 footer
783 # Execute testsuite.
784 if grep -q ^testsuite $receipt; then
785 title 'Running testsuite'
786 testsuite $@ || { broken; exit 1; }
787 footer
788 fi
790 update_installed_cook_diff force
791 }
794 # Cook quality assurance.
796 cookit_quality() {
797 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
798 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
799 fi
800 # ERROR can be echoed any time in cookit()
801 lerror=$(_n 'ERROR')
802 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
803 grep -Eq "(^$lerror|undefined reference to)" ; then
804 debug_info | tee -a $LOGS/$pkg.log
805 sed -i '$ s|$| [ Failed ]|' $activity
806 rm -f $command
807 broken; exit 1
808 fi
809 }
812 # Receipt used for cooking the package is redundant to be included into package.
813 # This script will strip the original receipt to bare minimum: variables,
814 # {pre,post}_{install,remove} functions.
816 mk_pkg_receipt() {
817 orig_receipt="$1"
819 # Receipt's signature is important, although some receipts may miss it
820 signature=$(head -n1 "$orig_receipt")
821 [ "${signature:0:1}" == '#' ] || signature='# SliTaz package receipt.'
823 save_PACKAGE="$PACKAGE"; save_DEPENDS="$DEPENDS"; save_PROVIDE="$PROVIDE"
824 unset_receipt
825 . "$orig_receipt"
826 PACKAGE="$save_PACKAGE"; DEPENDS="$save_DEPENDS"; PROVIDE="$save_PROVIDE"
828 # Manage split packages
829 SPLIT=" $SPLIT "
830 if [ "$SPLIT" != ' ' -a "${SPLIT/ $PACKAGE /}" != "$SPLIT" ]; then
831 # For packages with empty $DEPENDS
832 [ -n "$DEPENDS" ] || DEPENDS="$pkg"
834 # Default $CAT
835 [ -z "$CAT" ] &&
836 case $PACKAGE in
837 *-dev) CAT="development|development files" ;;
838 esac
840 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
841 CATEGORY="${CAT%|*}"
842 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
843 fi
845 # Mandatory variables
846 cat <<EOF
847 $signature
849 PACKAGE="$PACKAGE"
850 VERSION="$VERSION"
851 CATEGORY="$CATEGORY"
852 SHORT_DESC="$SHORT_DESC"
853 MAINTAINER="$MAINTAINER"
854 LICENSE="$LICENSE"
855 WEB_SITE="$WEB_SITE"
856 EOF
858 # Optional variables
859 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\""
860 [ -n "$DEPENDS" ] && echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' '
861 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\""
863 # Extract {pre,post}_{install,remove} functions;
864 # post_install_gtk_() will be copied as post_install() for gtk+ package
865 #
866 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
867 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
868 for i in pre post; do
869 for j in install remove; do
870 if grep -q "^${i}_${j}_$rname()" "$orig_receipt"; then
871 echo
872 sed "/^${i}_${j}_$rname()/,/}/!d" "$orig_receipt" | \
873 sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
874 fi
875 done
876 done
877 }
880 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
881 # but it doesn't handle EXTRAVERSION.
883 packit() {
884 set_paths "$1"
885 PACKAGE="${1:-$PACKAGE}"
887 # Handle cross compilation
888 case "$ARCH" in
889 arm*|x86_64) arch="-$ARCH" ;;
890 esac
892 title 'Pack: %s' "$PACKAGE $VERSION$arch"
894 if grep -q ^genpkg_rules $receipt; then
895 _ 'Executing: %s' 'genpkg_rules'
896 set -e; cd $pkgdir; mkdir -p $fs
897 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
898 $LOGS/$pkg.log
899 else
900 _ 'No packages rules: meta package'
901 mkdir -p $fs
902 fi
904 # Check CONFIG_FILES
905 if [ -n "$CONFIG_FILES" ]; then
906 for i in $CONFIG_FILES; do
907 if [ ! -e $fs$i ]; then
908 case $i in
909 */) mkdir -p $fs$i ;;
910 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
911 esac
912 fi
913 done
914 fi
916 # First QA check to stop now if genpkg_rules failed.
917 lerror=$(_n 'ERROR')
918 if fgrep -q ^$lerror $LOGS/$pkg.log; then
919 broken; exit 1
920 fi
922 cd $taz
923 action 'Copying "%s"...' 'receipt'
924 mk_pkg_receipt ../receipt > $pack/receipt
925 chown 0.0 $pack/receipt; status
927 unset desc
928 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
929 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
930 if [ -n "$desc" ]; then
931 action 'Copying "%s"...' "$(basename "$desc")"
932 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
933 fi
935 copy_generic_files
937 # Strip and stuff files.
938 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
940 # Create files.list with redirecting find output.
941 action 'Creating the list of files...'
942 cd $fs
943 find . -type f -print > ../files.list
944 find . -type l -print >> ../files.list
945 cd ..; sed -i s/'^.'/''/ files.list
946 status
948 # Md5sum of files.
949 action 'Creating md5sum of files...'
950 while read file; do
951 [ -L "fs$file" ] && continue
952 [ -f "fs$file" ] || continue
953 case "$file" in
954 /lib/modules/*/modules.*|*.pyc) continue ;;
955 esac
956 md5sum "fs$file" | sed 's/ fs/ /'
957 done < files.list > md5sum
958 status
960 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
961 2>/dev/null | awk 'END{ print $1 }')
963 # Build cpio archive.
964 action 'Compressing the FS...'
965 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
966 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
967 mv fs ../
968 status
970 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
971 2>/dev/null | awk 'END{ print $1 }')
973 action 'Updating receipt sizes...'
974 sed -i s/^PACKED_SIZE.*$// receipt
975 sed -i s/^UNPACKED_SIZE.*$// receipt
976 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
977 status
979 # Set extra version.
980 if [ -n "$EXTRAVERSION" ]; then
981 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
982 sed -i s/^EXTRAVERSION.*$// receipt
983 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
984 status
985 fi
987 # Compress.
988 action 'Creating full cpio archive...'
989 find . -newer $receipt -exec touch -hr $receipt '{}' \;
990 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
991 status
993 action 'Restoring original package tree...'
994 mv ../fs .
995 status
997 rm fs.cpio.lzma; cd ..
999 # QA and give info.
1000 tazpkg=$(ls *.tazpkg)
1001 packit_quality
1002 footer "$(_ 'Package "%s" created' "$tazpkg")"
1003 update_packages_info
1004 }
1007 # Verify package quality and consistency.
1009 packit_quality() {
1010 #action 'QA: checking for broken link...'
1011 #link=$(find $fs/usr -type l -follow)
1012 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1013 #status
1015 # Exit if any error found in log file.
1016 lerror=$(_n 'ERROR')
1017 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1018 rm -f $command
1019 broken; exit 1
1020 fi
1022 action 'QA: checking for empty package...'
1023 files=$(cat $WOK/$pkg/taz/$PACKAGE-$VERSION/files.list | wc -l)
1024 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1025 broken
1026 rm -f $command
1027 die 'ERROR: empty package'
1028 fi
1030 :; status
1031 # Find and remove old package(s)
1032 tempd="$(mktemp -d)"; cd "$tempd"
1033 for testpkg in $(ls $PKGS/$PACKAGE-*.tazpkg 2> /dev/null); do
1034 # Extract receipt from each matched package
1035 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1036 name=$(. receipt; echo $PACKAGE)
1037 rm receipt
1038 if [ "$name" == "$PACKAGE" ]; then
1039 action 'Removing old package "%s"' "$(basename "$testpkg")"
1040 rm -f "$testpkg"
1041 status
1042 fi
1043 done
1044 rm -r "$tempd"
1045 mv -f $pkgdir/taz/$PACKAGE-$VERSION.tazpkg $PKGS
1046 sed -i /^${pkg}$/d $broken
1047 #action 'Removing source tree...'
1048 #rm -f $WOK/$pkg/source; status
1049 }
1052 # v2: pack all packages using compiled files
1054 packall() {
1055 set_paths
1056 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1057 for i in $PACKAGE $SPLIT; do
1058 unset DEPENDS CAT
1059 packit $i
1060 done
1061 else
1062 packit
1063 fi
1064 }
1067 # Reverse "cat" command: prints input lines in the reverse order
1069 tac() {
1070 sed '1!G;h;$!d' $1
1071 }
1074 # Update chroot with freshly rebuilt package: keep env up-to-date.
1076 update_chroot() {
1077 for i in $pkg $SPLIT; do
1078 if [ -d "$root$INSTALLED/$i" ]; then
1079 . /etc/slitaz/cook.conf
1080 . $WOK/$pkg/taz/$i-$VERSION/receipt
1081 _ 'Updating %s chroot environment...' "$ARCH"
1082 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1083 cd $PKGS
1084 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1085 fi
1086 done
1087 }
1090 # Install package on --inst or update the chroot.
1092 install_package() {
1093 case "$ARCH" in
1094 arm*|x86_64)
1095 arch="-$ARCH"
1096 root="$CROSS_TREE/sysroot" ;;
1097 esac
1098 # Install package if requested but skip install if target host doesn't
1099 # match build system or it will break the build chroot.
1100 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1101 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1102 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1103 cd $PKGS
1104 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1105 else
1106 broken
1107 die 'Unable to install package, build has failed.'
1108 fi
1109 fi
1111 update_chroot
1112 }
1115 # remove chroot jail
1117 umount_aufs() {
1118 tac ${1}rw/aufs-umount.sh | sh
1119 rm -rf ${1}rw
1120 umount ${1}root
1121 rmdir ${1}r*
1122 }
1125 # Launch the cook command into a chroot jail protected by aufs.
1126 # The current filesystems are used read-only and updates are
1127 # stored in a separate branch.
1129 try_aufs_chroot() {
1131 base="/dev/shm/aufsmnt$$"
1133 # Can we setup the chroot? Is it already done?
1134 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1135 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1136 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1137 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1138 mkdir ${base}root ${base}rw || return
1140 _ 'Setup aufs chroot...'
1142 # Sanity check
1143 for i in / /proc /sys /dev/shm /home ; do
1144 case " $AUFS_MOUNTS " in
1145 *\ $i\ *) ;;
1146 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1147 esac
1148 done
1149 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1150 mount --bind $mnt ${base}root$mnt
1151 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1152 _ 'Aufs mount failure'
1153 umount ${base}root
1154 rm -rf ${base}r*
1155 return
1156 fi
1157 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1158 done
1159 trap "umount_aufs ${base}" INT
1161 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1162 status=$?
1164 _ 'Leaving aufs chroot...'
1165 umount_aufs $base
1166 # Install package outside the aufs jail
1167 install_package
1168 exit $status
1169 }
1172 # Encode predefined XML entities
1174 xml_ent() {
1175 sed -e 's|&|\&|g; s|<|\<|g; s|>|\>|g; s|"|\"|g' -e "s|'|\'|g"
1176 }
1179 # Create a XML feed for freshly built packages.
1181 gen_rss() {
1182 pubdate=$(date '+%a, %d %b %Y %X')
1183 cat > $FEEDS/$pkg.xml <<EOT
1184 <item>
1185 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1186 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1187 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1188 <pubDate>$pubdate</pubDate>
1189 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1190 </item>
1191 EOT
1192 }
1195 # Truncate stdout log file to $1 Mb.
1197 loglimit() {
1198 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1199 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1200 else
1201 tee /dev/stderr
1202 fi
1203 }
1206 #
1207 # Receipt functions to ease packaging
1208 #
1210 get_dev_files() {
1211 action 'Getting standard devel files...'
1212 mkdir -p $fs/usr/lib
1213 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1214 cp -a $install/usr/lib/*a $fs/usr/lib
1215 cp -a $install/usr/include $fs/usr
1216 status
1217 }
1220 # Function to use in compile_rules() to copy man page from $src to $install
1222 cook_pick_manpages() {
1223 local name section
1224 action 'Copying man pages...'
1226 for i in $@; do
1227 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1228 section=${name##*/}; section=${section##*.}
1229 mkdir -p $install/usr/share/man/man$section
1230 scopy $i $install/usr/share/man/man$section
1231 done
1232 status
1233 }
1236 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1238 cook_copy_files() {
1239 action 'Copying files...'
1240 cd $install
1241 local i j
1242 IFS=$'\n'
1243 for i in $@; do
1244 for j in $(find . -name $i ! -type d); do
1245 mkdir -p $fs$(dirname ${j#.})
1246 scopy $j $fs$(dirname ${j#.})
1247 done
1248 done
1249 cd - >/dev/null
1250 status
1251 }
1254 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1256 cook_copy_folders() {
1257 action 'Copying folders...'
1258 cd $install
1259 local i j
1260 IFS=$'\n'
1261 for i in $@; do
1262 for j in $(find . -name $i -type d); do
1263 mkdir -p $fs$(dirname ${j#.})
1264 cp -a $j $fs$(dirname ${j#.})
1265 done
1266 done
1267 cd - >/dev/null
1268 status
1269 }
1272 # Common function to copy files, folders and patterns
1274 copy() {
1275 action 'Copying folders and files...'
1276 cd $install
1277 local i j filelist=$(mktemp) tmplist=$(mktemp)
1278 IFS=$'\n'
1279 find ! -type d | sed 's|\.||' > $filelist
1280 for i in $@; do
1281 case $i in
1282 @std)
1283 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1284 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /bin\/.*-config$/d;
1285 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1286 /\/include\//d;
1287 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1288 /\/share\/devhelp\//d; /\/share\/locale\//d;
1289 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1290 ' $filelist > $tmplist
1291 while read j; do
1292 mkdir -p $fs$(dirname $j)
1293 scopy $install$j $fs$(dirname $j)
1294 done < $tmplist
1295 ;;
1296 @dev)
1297 # Copy "developer files"
1298 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /bin\/.*-config$/p;
1299 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1300 /\/include\//p;
1301 ' $filelist | \
1302 while read j; do
1303 mkdir -p $fs$(dirname $j)
1304 scopy $install$j $fs$(dirname $j)
1305 done
1306 ;;
1307 */)
1308 # Copy specified folders
1309 for j in $(find . -name ${i%/} -type d); do
1310 mkdir -p $fs$(dirname ${j#.})
1311 cp -a $j $fs$(dirname ${j#.})
1312 done
1313 ;;
1314 *)
1315 # Copy specified files
1316 for j in $(find . -name $i ! -type d); do
1317 mkdir -p $fs$(dirname ${j#.})
1318 scopy $j $fs$(dirname ${j#.})
1319 done
1320 ;;
1321 esac
1322 done
1323 cd - >/dev/null
1324 rm $filelist $tmplist
1325 status
1326 }
1329 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1330 # (default: 16 and 48) from $install to $fs
1332 cook_copy_icons() {
1333 local sizes=$@
1334 action 'Copying hicolor icons...'
1335 mkdir -p $fs/usr/share/icons/hicolor
1336 for i in ${sizes:-16 48}; do
1337 [ ! -e "$install/usr/share/icons/hicolor/${i}x$i" ] ||
1338 scopy $install/usr/share/icons/hicolor/${i}x$i \
1339 $fs/usr/share/icons/hicolor
1340 done
1341 status
1342 }
1345 # Update packages.info every time after successful build
1347 update_packages_info() {
1348 sed -i "/^$PACKAGE\t/d" $PKGS/packages.info
1349 unset_receipt; . $pack/receipt
1350 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1351 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1352 MD5="$(md5sum "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" | awk '{print $1}')"
1353 cat >> $PKGS/packages.info <<EOT
1354 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 $PROVIDE
1355 EOT
1357 }
1362 #
1363 # Commands
1364 #
1366 case "$1" in
1367 usage|help|-u|-h)
1368 usage ;;
1370 list-wok)
1371 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1372 cd $WOK
1373 if [ "$ARCH" != 'i486' ]; then
1374 count=0
1375 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1376 do
1377 unset HOST_ARCH
1378 . $pkg
1379 count=$(($count + 1))
1380 colorize 34 "$PACKAGE"
1381 done
1382 else
1383 count=$(ls | wc -l)
1384 ls -1
1385 fi
1386 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1387 ;;
1389 activity)
1390 cat $activity ;;
1392 search)
1393 # Just a simple search function, we dont need more actually.
1394 query="$2"
1395 title 'Search results for "%s"' "$query"
1396 cd $WOK; ls -1 | grep "$query"
1397 footer ;;
1399 setup)
1400 # Setup a build environment
1401 check_root
1402 _ 'Cook: setup environment' | log
1403 title 'Setting up your environment'
1404 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1405 cd $SLITAZ
1406 init_db_files
1407 _ 'Checking for packages to install...'
1408 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1409 # ARCH-setup or 'cross check' should be used before: cook setup
1410 case "$ARCH" in
1411 arm*|x86_64)
1412 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1413 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1414 . /etc/slitaz/cross.conf ;;
1415 esac
1416 for pkg in $SETUP_PKGS; do
1417 if [ -n "$forced" ]; then
1418 tazpkg -gi $pkg --forced
1419 else
1420 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1421 fi
1422 done
1424 # Handle --options
1425 case "$2" in
1426 --wok) hg clone $WOK_URL wok || exit 1 ;;
1427 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1428 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1429 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1430 esac
1432 # SliTaz group and permissions
1433 if ! grep -q ^slitaz /etc/group; then
1434 _ 'Adding group "%s"' 'slitaz'
1435 addgroup slitaz
1436 fi
1437 _ 'Setting permissions for group "%s"...' 'slitaz'
1438 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1439 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1440 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1442 *-setup)
1443 # Setup for cross compiling.
1444 arch="${1%-setup}"
1445 check_root
1446 . /etc/slitaz/cook.conf
1447 for pkg in $CROSS_SETUP; do
1448 if [ -n "$forced" ]; then
1449 tazpkg -gi $pkg --forced
1450 else
1451 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1452 fi
1453 done
1455 _ 'Cook: setup %s cross environment' "$arch" | log
1456 title 'Setting up your %s cross environment' "$arch"
1457 init_db_files
1458 sed -i \
1459 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1460 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1461 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1462 /etc/slitaz/cook.conf
1463 case "$arch" in
1464 arm)
1465 flags='-O2 -march=armv6'
1466 host="$ARCH-slitaz-linux-gnueabi" ;;
1467 armv6hf)
1468 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1469 host="$ARCH-slitaz-linux-gnueabi" ;;
1470 armv7)
1471 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1472 host="$ARCH-slitaz-linux-gnueabi" ;;
1473 x86_64)
1474 flags='-O2 -mtune=generic -pipe'
1475 host="$ARCH-slitaz-linux" ;;
1476 esac
1477 sed -i \
1478 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1479 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1480 . /etc/slitaz/cook.conf
1481 sysroot="$CROSS_TREE/sysroot"
1482 tools="/cross/$arch/tools"
1483 root="$sysroot"
1484 # L10n: keep the same width of translations to get a consistent view
1485 _ 'Target arch : %s' "$ARCH"
1486 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1487 _ 'Build flags : %s' "$flags"
1488 _ 'Arch sysroot : %s' "$sysroot"
1489 _ 'Tools prefix : %s' "$tools/bin"
1490 # Tell the packages manager where to find packages.
1491 _ 'Packages DB : %s' "$root$DB"
1492 mkdir -p $root$INSTALLED
1493 cd $root$DB; rm -f *.bak
1494 for list in packages.list packages.desc packages.equiv packages.md5; do
1495 rm -f $list
1496 ln -s $SLITAZ/packages/$list $list
1497 done
1498 # We must have the cross compiled glibc-base installed or default
1499 # i486 package will be used as dep by tazpkg and then break the
1500 # cross environment
1501 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1502 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1503 fi
1504 # Show GCC version or warn if not yet compiled.
1505 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1506 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1507 else
1508 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1509 _ 'Run "%s" to cook a toolchain' 'cross compile'
1510 fi
1511 footer ;;
1513 test)
1514 # Test a cook environment.
1515 _ 'Cook test: testing the cook environment' | log
1516 [ ! -d "$WOK" ] && exit 1
1517 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1518 cook cooktest ;;
1520 new)
1521 # Create the package folder and an empty receipt.
1522 pkg="$2"
1523 [ -z "$pkg" ] && usage
1524 newline
1525 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1527 action 'Creating folder "%s"' "$WOK/$pkg"
1528 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1530 action 'Preparing the package receipt...'
1531 cp $DATA/receipt .
1532 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1533 status; newline
1535 # Interactive mode, asking and seding.
1536 case "$3" in
1537 --interactive|-x)
1538 _ 'Entering interactive mode...'
1539 separator
1540 _ 'Package : %s' "$pkg"
1542 _n 'Version : ' ; read answer
1543 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1545 _n 'Category : ' ; read answer
1546 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1548 # L10n: Short description
1549 _n 'Short desc : ' ; read answer
1550 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1552 _n 'Maintainer : ' ; read answer
1553 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1555 _n 'License : ' ; read answer
1556 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1558 _n 'Web site : ' ; read answer
1559 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1560 newline
1562 # Wget URL.
1563 _ 'Wget URL to download source tarball.'
1564 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1565 _n 'Wget url : ' ; read answer
1566 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1568 # Ask for a stuff dir.
1569 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1570 if [ "$?" -eq 0 ]; then
1571 action 'Creating the stuff directory...'
1572 mkdir $WOK/$pkg/stuff; status
1573 fi
1575 # Ask for a description file.
1576 confirm "$(_n 'Are you going to write a description? (y/N)')"
1577 if [ "$?" -eq 0 ]; then
1578 action 'Creating the "%s" file...' 'description.txt'
1579 touch $WOK/$pkg/description.txt; status
1580 fi
1582 footer "$(_ 'Receipt is ready to use.')" ;;
1583 esac ;;
1585 list)
1586 # Cook a list of packages (better use the Cooker since it will order
1587 # packages before executing cook).
1588 check_root
1589 [ -z "$2" ] && die 'No list in argument.'
1590 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1592 _ 'Starting cooking the list "%s"' "$2" | log
1594 for pkg in $(cat $2); do
1595 cook $pkg || broken
1596 done ;;
1598 clean-wok)
1599 check_root
1600 newline; action 'Cleaning all packages files...'
1601 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1602 status; newline ;;
1604 clean-src)
1605 check_root
1606 newline; action 'Cleaning all packages sources...'
1607 rm -rf $WOK/*/source
1608 status; newline ;;
1610 uncook)
1611 cd $WOK
1612 count=0
1613 title 'Checking for uncooked packages'
1615 for pkg in *; do
1616 unset HOST_ARCH EXTRAVERSION
1617 [ ! -e $pkg/receipt ] && continue
1618 . $pkg/receipt
1619 # Source cooked pkg receipt to get EXTRAVERSION
1620 if [ -d "$WOK/$pkg/taz" ]; then
1621 cd $WOK/$pkg/taz/$pkg-*
1622 . receipt; cd $WOK
1623 fi
1624 case "$ARCH" in
1625 i486)
1626 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1627 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1628 count=$(($count + 1))
1629 colorize 34 "$pkg"
1630 fi ;;
1631 arm*)
1632 # Check only packages included in arch
1633 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1634 # *.tazpkg
1635 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1636 count=$(($count + 1))
1637 colorize 34 "$pkg"
1638 fi
1639 fi ;;
1640 esac
1641 done
1643 if [ "$count" -gt 0 ]; then
1644 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1645 else
1646 _ 'All packages are cooked :-)'
1647 newline
1648 fi
1649 ;;
1651 pkgdb)
1652 # Create suitable packages list for TazPkg and only for built packages
1653 # as well as flavors files for TazLiTo. We don't need logs since we do it
1654 # manually to ensure everything is fine before syncing the mirror.
1655 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1656 ;;
1658 *)
1659 # Just cook and generate a package.
1660 check_root
1661 time=$(date +%s)
1662 pkg="$1"
1663 [ -z "$pkg" ] && usage
1665 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1666 $LOGS/$pkg.log 2>/dev/null | sed '$!d')
1667 receipt="$WOK/$pkg/receipt"
1668 check_pkg_in_wok
1669 newline
1671 unset inst
1672 unset_receipt
1673 . $receipt
1675 # Handle cross compilation.
1676 case "$ARCH" in
1677 arm*)
1678 if [ -z "$HOST_ARCH" ]; then
1679 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1680 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1681 _ 'cook: %s' "$error"
1682 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1683 _ 'Cook skip: %s' "$error" | log
1684 newline
1685 broken; exit 1
1686 fi ;;
1687 esac
1689 # Some packages are not included in some arch or fail to cross compile.
1690 : ${HOST_ARCH=i486}
1691 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1692 # Handle arm{v6hf,v7,..}
1693 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1694 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1695 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1696 _ 'cook: %s' "error"
1697 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1698 _ 'Cook skip: %s' "$error" | log
1699 sed -i /^${pkg}$/d $broken
1700 newline
1701 exit 0
1702 fi
1704 # Skip blocked, 3 lines also for the Cooker.
1705 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1706 die 'Package "%s" is blocked' "$pkg"
1708 try_aufs_chroot "$@"
1710 # Log and source receipt.
1711 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1712 echo "cook:$pkg" > $command
1714 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1716 while read cmd duration start; do
1717 [ $(($start + $duration)) -lt $(date +%s) ] &&
1718 echo "sed -i '/^$cmd $duration/d' $cooktime"
1719 done < $cooktime | sh
1721 # Display and log info if cook process stopped.
1722 # FIXME: gettext not working (in single quotes) here!
1723 trap '_ "\n\nCook stopped: control-C\n\n" | \
1724 tee -a $LOGS/$pkg.log' INT
1726 # Handle --options
1727 case "$2" in
1728 --clean|-c)
1729 action 'Cleaning "%s"' "$pkg"
1730 cd $WOK/$pkg; rm -rf install taz source
1731 status; newline
1732 exit 0 ;;
1734 --install|-i)
1735 inst='yes' ;;
1737 --getsrc|-gs)
1738 title 'Getting source for "%s"' "$pkg"
1739 get_source
1740 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1741 exit 0 ;;
1743 --block|-b)
1744 action 'Blocking package "%s"' "$pkg"
1745 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1746 status; newline
1747 exit 0 ;;
1749 --unblock|-ub)
1750 action 'Unblocking package "%s"' "$pkg"
1751 sed -i "/^${pkg}$/"d $blocked
1752 status; newline
1753 exit 0 ;;
1755 --pack)
1756 [ -d $WOK/$pkg/taz ] || die 'Need to build "%s"' "$pkg"
1757 rm -rf $WOK/$pkg/taz
1758 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1759 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1760 clean_log
1761 rm -f $command
1762 exit 0 ;;
1764 --cdeps)
1765 @@PREFIX@@/libexec/cookutils/cdeps $pkg
1766 esac
1768 # Rotate log
1769 for i in $(seq 9 -1 1); do
1770 j=$(($i - 1))
1771 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1772 done
1773 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1775 # Check if wanted is built now so we have separate log files.
1776 for wanted in $WANTED ; do
1777 if grep -q "^$wanted$" $blocked; then
1778 broken
1779 rm -f $command
1780 die 'WANTED package "%s" is blocked' "$wanted"
1781 fi
1782 if grep -q "^$wanted$" $broken; then
1783 broken
1784 rm -f $command
1785 die 'WANTED package "%s" is broken' "$wanted"
1786 fi
1787 if [ ! -d "$WOK/$wanted/install" ]; then
1788 cook "$wanted" || { broken; exit 1; }
1789 fi
1790 done
1792 # Cook and pack or exit on error and log everything.
1793 check_integrity
1794 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1795 remove_deps | tee -a $LOGS/$pkg.log
1796 cookit_quality
1797 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1798 clean_log
1800 # Exit if any error in packing.
1801 lerror=$(_n 'ERROR')
1802 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1803 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1804 debug_info | tee -a $LOGS/$pkg.log
1805 sed -i '$ s|$| [ Failed ]|' $activity
1806 rm -f $command
1807 broken; exit 1
1808 fi
1810 # Create an XML feed
1811 gen_rss
1813 # Time and summary
1814 time=$(($(date +%s) - $time))
1815 summary | tee -a $LOGS/$pkg.log
1816 newline
1818 # We may want to install/update (outside aufs jail!).
1819 [ -s /aufs-umount.sh ] || install_package
1821 sed -i '$ s|$| [ Done ]|' $activity
1823 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1824 # If you want automation, use the Cooker Build Bot.
1825 rm -f $command
1826 ;;
1827 esac
1829 exit 0