cookutils view cook @ rev 908

cook: support per-package CONFIG_FILES, fix pre_install etc. extracting; lighttpd/index.cgi: display all descriptions.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon May 29 04:48:50 2017 +0300 (2017-05-29)
parents ae08a6458965
children e68dad1ffbff
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\""
862 [ -n "$CONFIG_FILES" ] && echo "CONFIG_FILES=\"$CONFIG_FILES\""
864 # Extract {pre,post}_{install,remove} functions;
865 # post_install_gtk_() will be copied as post_install() for gtk+ package
866 #
867 # restricted name (gtk+ -> gtk_; acl-dev -> acl_dev)
868 rname=$(echo -n $PACKAGE | tr -c 'a-zA-Z0-9' '_')
869 for i in pre post; do
870 for j in install remove; do
871 if grep -q "^${i}_${j}_$rname()" "$orig_receipt"; then
872 echo
873 sed "/^${i}_${j}_$rname()/,/^}/!d" "$orig_receipt" | \
874 sed "s|^${i}_${j}_$rname()|${i}_${j}()|"
875 fi
876 done
877 done
878 }
881 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
882 # but it doesn't handle EXTRAVERSION.
884 packit() {
885 set_paths "$1"
886 PACKAGE="${1:-$PACKAGE}"
888 # Handle cross compilation
889 case "$ARCH" in
890 arm*|x86_64) arch="-$ARCH" ;;
891 esac
893 title 'Pack: %s' "$PACKAGE $VERSION$arch"
895 if grep -q ^genpkg_rules $receipt; then
896 _ 'Executing: %s' 'genpkg_rules'
897 set -e; cd $pkgdir; mkdir -p $fs
898 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
899 $LOGS/$pkg.log
900 else
901 _ 'No packages rules: meta package'
902 mkdir -p $fs
903 fi
905 # Check CONFIG_FILES
906 if [ -n "$CONFIG_FILES" ]; then
907 for i in $CONFIG_FILES; do
908 if [ ! -e $fs$i ]; then
909 case $i in
910 */) mkdir -p $fs$i ;;
911 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
912 esac
913 fi
914 done
915 fi
917 # First QA check to stop now if genpkg_rules failed.
918 lerror=$(_n 'ERROR')
919 if fgrep -q ^$lerror $LOGS/$pkg.log; then
920 broken; exit 1
921 fi
923 cd $taz
924 action 'Copying "%s"...' 'receipt'
925 mk_pkg_receipt ../receipt > $pack/receipt
926 chown 0.0 $pack/receipt; status
928 unset desc
929 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
930 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
931 if [ -n "$desc" ]; then
932 action 'Copying "%s"...' "$(basename "$desc")"
933 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
934 fi
936 copy_generic_files
938 # Strip and stuff files.
939 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
941 # Create files.list with redirecting find output.
942 action 'Creating the list of files...'
943 cd $fs
944 find . -type f -print > ../files.list
945 find . -type l -print >> ../files.list
946 cd ..; sed -i s/'^.'/''/ files.list
947 status
949 # Md5sum of files.
950 action 'Creating md5sum of files...'
951 while read file; do
952 [ -L "fs$file" ] && continue
953 [ -f "fs$file" ] || continue
954 case "$file" in
955 /lib/modules/*/modules.*|*.pyc) continue ;;
956 esac
957 md5sum "fs$file" | sed 's/ fs/ /'
958 done < files.list > md5sum
959 status
961 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
962 2>/dev/null | awk 'END{ print $1 }')
964 # Build cpio archive.
965 action 'Compressing the FS...'
966 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
967 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
968 mv fs ../
969 status
971 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
972 2>/dev/null | awk 'END{ print $1 }')
974 action 'Updating receipt sizes...'
975 sed -i s/^PACKED_SIZE.*$// receipt
976 sed -i s/^UNPACKED_SIZE.*$// receipt
977 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
978 status
980 # Set extra version.
981 if [ -n "$EXTRAVERSION" ]; then
982 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
983 sed -i s/^EXTRAVERSION.*$// receipt
984 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
985 status
986 fi
988 # Compress.
989 action 'Creating full cpio archive...'
990 find . -newer $receipt -exec touch -hr $receipt '{}' \;
991 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
992 status
994 action 'Restoring original package tree...'
995 mv ../fs .
996 status
998 rm fs.cpio.lzma; cd ..
1000 # QA and give info.
1001 tazpkg=$(ls *.tazpkg)
1002 packit_quality
1003 footer "$(_ 'Package "%s" created' "$tazpkg")"
1004 update_packages_info
1008 # Verify package quality and consistency.
1010 packit_quality() {
1011 #action 'QA: checking for broken link...'
1012 #link=$(find $fs/usr -type l -follow)
1013 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
1014 #status
1016 # Exit if any error found in log file.
1017 lerror=$(_n 'ERROR')
1018 if fgrep -q ^$lerror $LOGS/$pkg.log; then
1019 rm -f $command
1020 broken; exit 1
1021 fi
1023 action 'QA: checking for empty package...'
1024 files=$(cat $WOK/$pkg/taz/$PACKAGE-$VERSION/files.list | wc -l)
1025 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1026 broken
1027 rm -f $command
1028 die 'ERROR: empty package'
1029 fi
1031 :; status
1032 # Find and remove old package(s)
1033 tempd="$(mktemp -d)"; cd "$tempd"
1034 for testpkg in $(ls $PKGS/$PACKAGE-*.tazpkg 2>/dev/null); do
1035 # Extract receipt from each matched package
1036 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1037 name=$(. receipt; echo $PACKAGE)
1038 rm receipt
1039 if [ "$name" == "$PACKAGE" ]; then
1040 action 'Removing old package "%s"' "$(basename "$testpkg")"
1041 rm -f "$testpkg"
1042 status
1043 fi
1044 done
1045 rm -r "$tempd"
1046 mv -f $pkgdir/taz/$PACKAGE-$VERSION.tazpkg $PKGS
1047 sed -i /^${pkg}$/d $broken
1048 #action 'Removing source tree...'
1049 #rm -f $WOK/$pkg/source; status
1053 # v2: pack all packages using compiled files
1055 packall() {
1056 set_paths
1057 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1058 for i in $PACKAGE $SPLIT; do
1059 unset DEPENDS CAT CONFIG_FILES
1060 packit $i
1061 done
1062 else
1063 packit
1064 fi
1068 # Reverse "cat" command: prints input lines in the reverse order
1070 tac() {
1071 sed '1!G;h;$!d' $1
1075 # Update chroot with freshly rebuilt package: keep env up-to-date.
1077 update_chroot() {
1078 for i in $pkg $SPLIT; do
1079 if [ -d "$root$INSTALLED/$i" ]; then
1080 . /etc/slitaz/cook.conf
1081 . $WOK/$pkg/taz/$i-$VERSION/receipt
1082 _ 'Updating %s chroot environment...' "$ARCH"
1083 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1084 cd $PKGS
1085 tazpkg install $i-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1086 fi
1087 done
1091 # Install package on --inst or update the chroot.
1093 install_package() {
1094 case "$ARCH" in
1095 arm*|x86_64)
1096 arch="-$ARCH"
1097 root="$CROSS_TREE/sysroot" ;;
1098 esac
1099 # Install package if requested but skip install if target host doesn't
1100 # match build system or it will break the build chroot.
1101 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1102 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1103 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1104 cd $PKGS
1105 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1106 else
1107 broken
1108 die 'Unable to install package, build has failed.'
1109 fi
1110 fi
1112 update_chroot
1116 # remove chroot jail
1118 umount_aufs() {
1119 tac ${1}rw/aufs-umount.sh | sh
1120 rm -rf ${1}rw
1121 umount ${1}root
1122 rmdir ${1}r*
1126 # Launch the cook command into a chroot jail protected by aufs.
1127 # The current filesystems are used read-only and updates are
1128 # stored in a separate branch.
1130 try_aufs_chroot() {
1132 base="/dev/shm/aufsmnt$$"
1134 # Can we setup the chroot? Is it already done?
1135 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1136 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1137 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1138 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1139 mkdir ${base}root ${base}rw || return
1141 _ 'Setup aufs chroot...'
1143 # Sanity check
1144 for i in / /proc /sys /dev/shm /home ; do
1145 case " $AUFS_MOUNTS " in
1146 *\ $i\ *) ;;
1147 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1148 esac
1149 done
1150 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1151 mount --bind $mnt ${base}root$mnt
1152 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1153 _ 'Aufs mount failure'
1154 umount ${base}root
1155 rm -rf ${base}r*
1156 return
1157 fi
1158 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1159 done
1160 trap "umount_aufs ${base}" INT
1162 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1163 status=$?
1165 _ 'Leaving aufs chroot...'
1166 umount_aufs $base
1167 # Install package outside the aufs jail
1168 install_package
1169 exit $status
1173 # Encode predefined XML entities
1175 xml_ent() {
1176 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1180 # Create a XML feed for freshly built packages.
1182 gen_rss() {
1183 pubdate=$(date '+%a, %d %b %Y %X')
1184 cat > $FEEDS/$pkg.xml <<EOT
1185 <item>
1186 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1187 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1188 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1189 <pubDate>$pubdate</pubDate>
1190 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1191 </item>
1192 EOT
1196 # Truncate stdout log file to $1 Mb.
1198 loglimit() {
1199 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1200 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1201 else
1202 tee /dev/stderr
1203 fi
1208 # Receipt functions to ease packaging
1211 get_dev_files() {
1212 action 'Getting standard devel files...'
1213 mkdir -p $fs/usr/lib
1214 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1215 cp -a $install/usr/lib/*a $fs/usr/lib
1216 cp -a $install/usr/include $fs/usr
1217 status
1221 # Function to use in compile_rules() to copy man page from $src to $install
1223 cook_pick_manpages() {
1224 local name section
1225 action 'Copying man pages...'
1227 for i in $@; do
1228 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1229 section=${name##*/}; section=${section##*.}
1230 mkdir -p $install/usr/share/man/man$section
1231 scopy $i $install/usr/share/man/man$section
1232 done
1233 status
1237 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1239 cook_copy_files() {
1240 action 'Copying files...'
1241 cd $install
1242 local i j
1243 IFS=$'\n'
1244 for i in $@; do
1245 for j in $(find . -name $i ! -type d); do
1246 mkdir -p $fs$(dirname ${j#.})
1247 scopy $j $fs$(dirname ${j#.})
1248 done
1249 done
1250 cd - >/dev/null
1251 status
1255 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1257 cook_copy_folders() {
1258 action 'Copying folders...'
1259 cd $install
1260 local i j
1261 IFS=$'\n'
1262 for i in $@; do
1263 for j in $(find . -name $i -type d); do
1264 mkdir -p $fs$(dirname ${j#.})
1265 cp -a $j $fs$(dirname ${j#.})
1266 done
1267 done
1268 cd - >/dev/null
1269 status
1273 # Common function to copy files, folders and patterns
1275 copy() {
1276 action 'Copying folders and files...'
1277 cd $install
1278 local i j filelist=$(mktemp) tmplist=$(mktemp)
1279 IFS=$'\n'
1280 find ! -type d | sed 's|\.||' > $filelist
1281 for i in $@; do
1282 case $i in
1283 @std)
1284 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1285 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /bin\/.*-config$/d;
1286 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1287 /\/include\//d;
1288 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1289 /\/share\/devhelp\//d; /\/share\/locale\//d;
1290 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1291 ' $filelist > $tmplist
1292 while read j; do
1293 mkdir -p $fs$(dirname $j)
1294 scopy $install$j $fs$(dirname $j)
1295 done < $tmplist
1296 ;;
1297 @dev)
1298 # Copy "developer files"
1299 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /bin\/.*-config$/p;
1300 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1301 /\/include\//p;
1302 ' $filelist | \
1303 while read j; do
1304 mkdir -p $fs$(dirname $j)
1305 scopy $install$j $fs$(dirname $j)
1306 done
1307 ;;
1308 */)
1309 # Copy specified folders
1310 for j in $(find . -name ${i%/} -type d); do
1311 mkdir -p $fs$(dirname ${j#.})
1312 cp -a $j $fs$(dirname ${j#.})
1313 done
1314 ;;
1315 *)
1316 # Copy specified files
1317 for j in $(find . -name $i ! -type d); do
1318 mkdir -p $fs$(dirname ${j#.})
1319 scopy $j $fs$(dirname ${j#.})
1320 done
1321 ;;
1322 esac
1323 done
1324 cd - >/dev/null
1325 rm $filelist $tmplist
1326 status
1330 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1331 # (default: 16 and 48) from $install to $fs
1333 cook_copy_icons() {
1334 local sizes=$@
1335 action 'Copying hicolor icons...'
1336 mkdir -p $fs/usr/share/icons/hicolor
1337 for i in ${sizes:-16 48}; do
1338 [ ! -e "$install/usr/share/icons/hicolor/${i}x$i" ] ||
1339 scopy $install/usr/share/icons/hicolor/${i}x$i \
1340 $fs/usr/share/icons/hicolor
1341 done
1342 status
1346 # Update packages.info every time after successful build
1348 update_packages_info() {
1349 sed -i "/^$PACKAGE\t/d" $PKGS/packages.info
1350 unset_receipt; . $pack/receipt
1351 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1352 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1353 MD5="$(md5sum "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" | awk '{print $1}')"
1354 cat >> $PKGS/packages.info <<EOT
1355 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 $PROVIDE
1356 EOT
1364 # Commands
1367 case "$1" in
1368 usage|help|-u|-h)
1369 usage ;;
1371 list-wok)
1372 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1373 cd $WOK
1374 if [ "$ARCH" != 'i486' ]; then
1375 count=0
1376 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1377 do
1378 unset HOST_ARCH
1379 . $pkg
1380 count=$(($count + 1))
1381 colorize 34 "$PACKAGE"
1382 done
1383 else
1384 count=$(ls | wc -l)
1385 ls -1
1386 fi
1387 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1388 ;;
1390 activity)
1391 cat $activity ;;
1393 search)
1394 # Just a simple search function, we dont need more actually.
1395 query="$2"
1396 title 'Search results for "%s"' "$query"
1397 cd $WOK; ls -1 | grep "$query"
1398 footer ;;
1400 setup)
1401 # Setup a build environment
1402 check_root
1403 _ 'Cook: setup environment' | log
1404 title 'Setting up your environment'
1405 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1406 cd $SLITAZ
1407 init_db_files
1408 _ 'Checking for packages to install...'
1409 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1410 # ARCH-setup or 'cross check' should be used before: cook setup
1411 case "$ARCH" in
1412 arm*|x86_64)
1413 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1414 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1415 . /etc/slitaz/cross.conf ;;
1416 esac
1417 for pkg in $SETUP_PKGS; do
1418 if [ -n "$forced" ]; then
1419 tazpkg -gi $pkg --forced
1420 else
1421 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1422 fi
1423 done
1425 # Handle --options
1426 case "$2" in
1427 --wok) hg clone $WOK_URL wok || exit 1 ;;
1428 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1429 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1430 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1431 esac
1433 # SliTaz group and permissions
1434 if ! grep -q ^slitaz /etc/group; then
1435 _ 'Adding group "%s"' 'slitaz'
1436 addgroup slitaz
1437 fi
1438 _ 'Setting permissions for group "%s"...' 'slitaz'
1439 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1440 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1441 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1443 *-setup)
1444 # Setup for cross compiling.
1445 arch="${1%-setup}"
1446 check_root
1447 . /etc/slitaz/cook.conf
1448 for pkg in $CROSS_SETUP; do
1449 if [ -n "$forced" ]; then
1450 tazpkg -gi $pkg --forced
1451 else
1452 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1453 fi
1454 done
1456 _ 'Cook: setup %s cross environment' "$arch" | log
1457 title 'Setting up your %s cross environment' "$arch"
1458 init_db_files
1459 sed -i \
1460 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1461 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1462 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1463 /etc/slitaz/cook.conf
1464 case "$arch" in
1465 arm)
1466 flags='-O2 -march=armv6'
1467 host="$ARCH-slitaz-linux-gnueabi" ;;
1468 armv6hf)
1469 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1470 host="$ARCH-slitaz-linux-gnueabi" ;;
1471 armv7)
1472 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1473 host="$ARCH-slitaz-linux-gnueabi" ;;
1474 x86_64)
1475 flags='-O2 -mtune=generic -pipe'
1476 host="$ARCH-slitaz-linux" ;;
1477 esac
1478 sed -i \
1479 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1480 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1481 . /etc/slitaz/cook.conf
1482 sysroot="$CROSS_TREE/sysroot"
1483 tools="/cross/$arch/tools"
1484 root="$sysroot"
1485 # L10n: keep the same width of translations to get a consistent view
1486 _ 'Target arch : %s' "$ARCH"
1487 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1488 _ 'Build flags : %s' "$flags"
1489 _ 'Arch sysroot : %s' "$sysroot"
1490 _ 'Tools prefix : %s' "$tools/bin"
1491 # Tell the packages manager where to find packages.
1492 _ 'Packages DB : %s' "$root$DB"
1493 mkdir -p $root$INSTALLED
1494 cd $root$DB; rm -f *.bak
1495 for list in packages.list packages.desc packages.equiv packages.md5; do
1496 rm -f $list
1497 ln -s $SLITAZ/packages/$list $list
1498 done
1499 # We must have the cross compiled glibc-base installed or default
1500 # i486 package will be used as dep by tazpkg and then break the
1501 # cross environment
1502 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1503 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1504 fi
1505 # Show GCC version or warn if not yet compiled.
1506 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1507 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1508 else
1509 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1510 _ 'Run "%s" to cook a toolchain' 'cross compile'
1511 fi
1512 footer ;;
1514 test)
1515 # Test a cook environment.
1516 _ 'Cook test: testing the cook environment' | log
1517 [ ! -d "$WOK" ] && exit 1
1518 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1519 cook cooktest ;;
1521 new)
1522 # Create the package folder and an empty receipt.
1523 pkg="$2"
1524 [ -z "$pkg" ] && usage
1525 newline
1526 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1528 action 'Creating folder "%s"' "$WOK/$pkg"
1529 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1531 action 'Preparing the package receipt...'
1532 cp $DATA/receipt .
1533 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1534 status; newline
1536 # Interactive mode, asking and seding.
1537 case "$3" in
1538 --interactive|-x)
1539 _ 'Entering interactive mode...'
1540 separator
1541 _ 'Package : %s' "$pkg"
1543 _n 'Version : ' ; read answer
1544 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1546 _n 'Category : ' ; read answer
1547 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1549 # L10n: Short description
1550 _n 'Short desc : ' ; read answer
1551 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1553 _n 'Maintainer : ' ; read answer
1554 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1556 _n 'License : ' ; read answer
1557 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1559 _n 'Web site : ' ; read answer
1560 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1561 newline
1563 # Wget URL.
1564 _ 'Wget URL to download source tarball.'
1565 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1566 _n 'Wget url : ' ; read answer
1567 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1569 # Ask for a stuff dir.
1570 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1571 if [ "$?" -eq 0 ]; then
1572 action 'Creating the stuff directory...'
1573 mkdir $WOK/$pkg/stuff; status
1574 fi
1576 # Ask for a description file.
1577 confirm "$(_n 'Are you going to write a description? (y/N)')"
1578 if [ "$?" -eq 0 ]; then
1579 action 'Creating the "%s" file...' 'description.txt'
1580 touch $WOK/$pkg/description.txt; status
1581 fi
1583 footer "$(_ 'Receipt is ready to use.')" ;;
1584 esac ;;
1586 list)
1587 # Cook a list of packages (better use the Cooker since it will order
1588 # packages before executing cook).
1589 check_root
1590 [ -z "$2" ] && die 'No list in argument.'
1591 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1593 _ 'Starting cooking the list "%s"' "$2" | log
1595 for pkg in $(cat $2); do
1596 cook $pkg || broken
1597 done ;;
1599 clean-wok)
1600 check_root
1601 newline; action 'Cleaning all packages files...'
1602 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1603 status; newline ;;
1605 clean-src)
1606 check_root
1607 newline; action 'Cleaning all packages sources...'
1608 rm -rf $WOK/*/source
1609 status; newline ;;
1611 uncook)
1612 cd $WOK
1613 count=0
1614 title 'Checking for uncooked packages'
1616 for pkg in *; do
1617 unset HOST_ARCH EXTRAVERSION
1618 [ ! -e $pkg/receipt ] && continue
1619 . $pkg/receipt
1620 # Source cooked pkg receipt to get EXTRAVERSION
1621 if [ -d "$WOK/$pkg/taz" ]; then
1622 cd $WOK/$pkg/taz/$pkg-*
1623 . receipt; cd $WOK
1624 fi
1625 case "$ARCH" in
1626 i486)
1627 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1628 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1629 count=$(($count + 1))
1630 colorize 34 "$pkg"
1631 fi ;;
1632 arm*)
1633 # Check only packages included in arch
1634 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1635 # *.tazpkg
1636 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1637 count=$(($count + 1))
1638 colorize 34 "$pkg"
1639 fi
1640 fi ;;
1641 esac
1642 done
1644 if [ "$count" -gt 0 ]; then
1645 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1646 else
1647 _ 'All packages are cooked :-)'
1648 newline
1649 fi
1650 ;;
1652 pkgdb)
1653 # Create suitable packages list for TazPkg and only for built packages
1654 # as well as flavors files for TazLiTo. We don't need logs since we do it
1655 # manually to ensure everything is fine before syncing the mirror.
1656 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1657 ;;
1659 *)
1660 # Just cook and generate a package.
1661 check_root
1662 time=$(date +%s)
1663 pkg="$1"
1664 [ -z "$pkg" ] && usage
1666 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1667 $LOGS/$pkg.log 2>/dev/null | sed '$!d')
1668 receipt="$WOK/$pkg/receipt"
1669 check_pkg_in_wok
1670 newline
1672 unset inst
1673 unset_receipt
1674 . $receipt
1676 # Handle cross compilation.
1677 case "$ARCH" in
1678 arm*)
1679 if [ -z "$HOST_ARCH" ]; then
1680 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1681 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1682 _ 'cook: %s' "$error"
1683 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1684 _ 'Cook skip: %s' "$error" | log
1685 newline
1686 broken; exit 1
1687 fi ;;
1688 esac
1690 # Some packages are not included in some arch or fail to cross compile.
1691 : ${HOST_ARCH=i486}
1692 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1693 # Handle arm{v6hf,v7,..}
1694 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1695 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1696 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1697 _ 'cook: %s' "error"
1698 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1699 _ 'Cook skip: %s' "$error" | log
1700 sed -i /^${pkg}$/d $broken
1701 newline
1702 exit 0
1703 fi
1705 # Skip blocked, 3 lines also for the Cooker.
1706 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1707 die 'Package "%s" is blocked' "$pkg"
1709 try_aufs_chroot "$@"
1711 # Log and source receipt.
1712 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1713 echo "cook:$pkg" > $command
1715 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1717 while read cmd duration start; do
1718 [ $(($start + $duration)) -lt $(date +%s) ] &&
1719 echo "sed -i '/^$cmd $duration/d' $cooktime"
1720 done < $cooktime | sh
1722 # Display and log info if cook process stopped.
1723 # FIXME: gettext not working (in single quotes) here!
1724 trap '_ "\n\nCook stopped: control-C\n\n" | \
1725 tee -a $LOGS/$pkg.log' INT
1727 # Handle --options
1728 case "$2" in
1729 --clean|-c)
1730 action 'Cleaning "%s"' "$pkg"
1731 cd $WOK/$pkg; rm -rf install taz source
1732 status; newline
1733 exit 0 ;;
1735 --install|-i)
1736 inst='yes' ;;
1738 --getsrc|-gs)
1739 title 'Getting source for "%s"' "$pkg"
1740 get_source
1741 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1742 exit 0 ;;
1744 --block|-b)
1745 action 'Blocking package "%s"' "$pkg"
1746 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1747 status; newline
1748 exit 0 ;;
1750 --unblock|-ub)
1751 action 'Unblocking package "%s"' "$pkg"
1752 sed -i "/^${pkg}$/"d $blocked
1753 status; newline
1754 exit 0 ;;
1756 --pack)
1757 [ -d $WOK/$pkg/taz ] || die 'Need to build "%s"' "$pkg"
1758 rm -rf $WOK/$pkg/taz
1759 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1760 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1761 clean_log
1762 rm -f $command
1763 exit 0 ;;
1765 --cdeps)
1766 @@PREFIX@@/libexec/cookutils/cdeps $pkg
1767 esac
1769 # Rotate log
1770 for i in $(seq 9 -1 1); do
1771 j=$(($i - 1))
1772 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1773 done
1774 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1776 # Check if wanted is built now so we have separate log files.
1777 for wanted in $WANTED ; do
1778 if grep -q "^$wanted$" $blocked; then
1779 broken
1780 rm -f $command
1781 die 'WANTED package "%s" is blocked' "$wanted"
1782 fi
1783 if grep -q "^$wanted$" $broken; then
1784 broken
1785 rm -f $command
1786 die 'WANTED package "%s" is broken' "$wanted"
1787 fi
1788 if [ ! -d "$WOK/$wanted/install" ]; then
1789 cook "$wanted" || { broken; exit 1; }
1790 fi
1791 done
1793 # Cook and pack or exit on error and log everything.
1794 check_integrity
1795 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1796 remove_deps | tee -a $LOGS/$pkg.log
1797 cookit_quality
1798 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1799 clean_log
1801 # Exit if any error in packing.
1802 lerror=$(_n 'ERROR')
1803 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1804 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1805 debug_info | tee -a $LOGS/$pkg.log
1806 sed -i '$ s|$| [ Failed ]|' $activity
1807 rm -f $command
1808 broken; exit 1
1809 fi
1811 # Create an XML feed
1812 gen_rss
1814 # Time and summary
1815 time=$(($(date +%s) - $time))
1816 summary | tee -a $LOGS/$pkg.log
1817 newline
1819 # We may want to install/update (outside aufs jail!).
1820 [ -s /aufs-umount.sh ] || install_package
1822 sed -i '$ s|$| [ Done ]|' $activity
1824 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1825 # If you want automation, use the Cooker Build Bot.
1826 rm -f $command
1827 ;;
1828 esac
1830 exit 0