cookutils view cook @ rev 904

Introduce SliTaz packages receipts v2. Tune 'cook' and 'lighttpd/index.cgi' for it. Small improvements to CSS styles.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri May 26 16:22:26 2017 +0300 (2017-05-26)
parents b03ac1e1213d
children c711ef2e51a9
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 # The main cook function.
543 cookit() {
544 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
545 _ 'ERROR: Broken setup. Abort.'
546 return
547 fi
549 title 'Cook: %s' "$PACKAGE $VERSION"
550 set_paths
552 # Handle cross-tools.
553 case "$ARCH" in
554 arm*|x86_64)
555 # CROSS_COMPILE is used by at least Busybox and the kernel to set
556 # the cross-tools prefix. Sysroot is the root of our target arch
557 sysroot="$CROSS_TREE/sysroot"
558 tools="$CROSS_TREE/tools"
559 # Set root path when cross compiling. ARM tested but not x86_64
560 # When cross compiling we must install build deps in $sysroot.
561 arch="-$ARCH"
562 root="$sysroot"
563 _ '%s sysroot: %s' "$ARCH" "$sysroot"
564 _ 'Adding "%s" to PATH' "$tools/bin"
565 export PATH="$PATH:$tools/bin"
566 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
567 export CROSS_COMPILE="$HOST_SYSTEM-"
568 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
569 if [ "$ARCH" == 'x86_64' ]; then
570 export CC="$HOST_SYSTEM-gcc -m64"
571 export CXX="$HOST_SYSTEM-g++ -m64"
572 else
573 export CC="$HOST_SYSTEM-gcc"
574 export CXX="$HOST_SYSTEM-g++"
575 fi
576 export AR="$HOST_SYSTEM-ar"
577 export AS="$HOST_SYSTEM-as"
578 export RANLIB="$HOST_SYSTEM-ranlib"
579 export LD="$HOST_SYSTEM-ld"
580 export STRIP="$HOST_SYSTEM-strip"
581 export LIBTOOL="$HOST_SYSTEM-libtool"
582 ;;
583 esac
585 [ -n "$QA" ] && receipt_quality
587 cd $pkgdir
588 [ -z "$continue" ] && rm -rf source 2>/dev/null
589 rm -rf install taz 2>/dev/null
591 # Disable -pipe if less than 512 MB free RAM.
592 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
593 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
594 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
595 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
596 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
597 fi
598 unset free
600 # Export flags and path to be used by make and receipt.
601 DESTDIR="$pkgdir/install"
602 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
603 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
604 #LDFLAGS
606 # BUILD_DEPENDS may vary depending on the ARCH
607 case "$ARCH" in
608 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
609 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
610 esac
612 # Check for build deps and handle implicit depends of *-dev packages
613 # (ex: libusb-dev :: libusb).
614 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
615 touch $CACHE/installed.local $CACHE/installed.web
616 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
617 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
618 for dep in $BUILD_DEPENDS; do
619 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
620 for i in $dep $implicit; do
621 # echo "i='$i'"
622 # Check if package already installed
623 [ -f "$root$INSTALLED/$i/receipt" ] && continue
625 # Try local package first.
626 namever=$(awk -F$'\t' -vpkg="$i" '{
627 # if package-name or provided-package-name matched
628 if (index(" " $1 " " $10 " ", " " pkg " ")) { printf("%s-%s", $1, $2); exit; }
629 }' "$PKGS/packages.info") # <namever> = <package_name>-<package_version>
631 debug "bdep: $i name-version: $namever"
633 # If local package available
634 [ -f "$PKGS/$namever$arch.tazpkg" ] &&
635 echo "$namever$arch.tazpkg" >> $CACHE/installed.local && continue
637 # If package exists in wok but not built
638 [ -d "$WOK/$i" ] &&
639 _ 'Missing dep (wok/pkg): %s' "$i $vers" &&
640 echo $i >> $CACHE/missing.dep && continue
642 # If package available on the mirror
643 [ -n "$(awk -F$'\t' -vi="$i" '$1==i{print $1}' "$root$DB/packages.info")" ] &&
644 echo $i >> $CACHE/installed.web && continue
646 # Give up; skip error for implicit dependency: in some cases
647 # implicit doesn't exist, ex: libboost-dev exists but not libboost.
648 [ "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
649 done
650 done
652 # Get the list of installed packages
653 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
655 # Have we a missing build dep to cook?
656 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
657 _ 'Auto cook config is set: %s' "$AUTO_COOK"
658 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
659 for i in $(uniq $CACHE/missing.dep); do
660 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
661 tee -a $LOGS/$PACKAGE.log.$$
662 # programmers: next two messages are exact copy from remove_deps()
663 togrep1=$(_n 'Build dependencies to remove:')
664 togrep2=$(_n 'Removing:')
665 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
666 fgrep $togrep1 $LOGS/$i.log && \
667 fgrep $togrep2 $LOGS/$i.log && newline) | \
668 tee -a $LOGS/$PACKAGE.log.$$ && break
669 done
670 rm -f $CACHE/missing.dep
671 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
672 fi
674 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
675 # is enabled and cook fails we have ERROR in log, if no auto cook we have
676 # missing dep in cached file.
677 lerror=$(_n 'ERROR')
678 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
679 [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
680 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
681 broken; exit 1
682 fi
684 # Install local packages: package-version$arch
685 cd $PKGS
686 for i in $(uniq $CACHE/installed.local); do
687 # _ 'Installing dep (pkg/local): %s' "$i"
688 tazpkg install $i --root=$root --local --quiet --cookmode
689 done
691 # Install web or cached packages (if mirror is set to $PKGS we only
692 # use local packages).
693 for i in $(uniq $CACHE/installed.web); do
694 # _ 'Installing dep (web/cache): %s' "$i"
695 tazpkg get-install $i --root=$root --local --quiet --cookmode
696 done
698 update_installed_cook_diff
700 # Get source tarball and make sure we have source dir named:
701 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
702 # tarball if it exists.
703 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
704 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
705 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
706 LZMA_SRC=''
707 else
708 get_source || { broken; exit 1; }
709 fi
710 fi
711 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
712 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
713 if ! extract_source ; then
714 get_source
715 extract_source || { broken; exit 1; }
716 fi
717 if [ -n "$LZMA_SRC" ]; then
718 cd $pkgdir/source
719 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
720 mv tmp tmp-1; mkdir tmp
721 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
722 fi
723 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
724 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
725 fi
726 fi
727 cd $pkgdir/source/tmp
728 # Some archives are not well done and don't extract to one dir (ex lzma).
729 files=$(ls | wc -l)
730 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
731 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
732 mv * ../$PACKAGE-$VERSION/$TARBALL
733 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
734 mv * ../$PACKAGE-$VERSION
735 cd ..; rm -rf tmp
736 fi
738 # Libtool shared libs path hack.
739 case "$ARCH" in
740 arm*) cross libhack ;;
741 esac
743 # Execute receipt rules.
744 if grep -q ^compile_rules $receipt; then
745 _ 'Executing: %s' 'compile_rules'
746 echo "CFLAGS : $CFLAGS"
747 #echo "LDFLAGS : $LDFLAGS"
748 [ -d "$src" ] && cd $src
749 patchit
750 compile_rules $@ || { broken; exit 1; }
751 # Stay compatible with _pkg
752 [ -d "$src/_pkg" ] && mv $src/_pkg $install
753 # QA: compile_rules success so valid.
754 mkdir -p $install
755 else
756 # QA: no compile_rules so no error, valid.
757 mkdir -p $install
758 fi
760 # Actions to do after compiling the package
761 # Skip all for split packages (already done in main package)
762 if [ -z "$WANTED" ]; then
763 footer
764 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
765 fi
766 footer
768 # Execute testsuite.
769 if grep -q ^testsuite $receipt; then
770 title 'Running testsuite'
771 testsuite $@ || { broken; exit 1; }
772 footer
773 fi
775 update_installed_cook_diff force
776 }
779 # Cook quality assurance.
781 cookit_quality() {
782 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
783 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
784 fi
785 # ERROR can be echoed any time in cookit()
786 lerror=$(_n 'ERROR')
787 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
788 grep -Eq "(^$lerror|undefined reference to)" ; then
789 debug_info | tee -a $LOGS/$pkg.log
790 sed -i '$ s|$| [ Failed ]|' $activity
791 rm -f $command
792 broken; exit 1
793 fi
794 }
797 # Receipt used for cooking the package is redundant to be included into package.
798 # This script will strip the original receipt to bare minimum: variables,
799 # {pre,post}_{install,remove} functions.
801 mk_pkg_receipt() {
802 orig_receipt="$1"
804 # Receipt's signature is important, although some receipts may miss it
805 signature=$(head -n1 "$orig_receipt")
806 [ "${signature:0:1}" == '#' ] || signature='# SliTaz package receipt.'
808 save_PACKAGE="$PACKAGE"; save_DEPENDS="$DEPENDS"; save_PROVIDE="$PROVIDE"
809 unset_receipt
810 . "$orig_receipt"
811 PACKAGE="$save_PACKAGE"; DEPENDS="$save_DEPENDS"; PROVIDE="$save_PROVIDE"
813 # Manage split packages
814 SPLIT=" $SPLIT "
815 if [ "$SPLIT" != ' ' -a "${SPLIT/ $PACKAGE /}" != "$SPLIT" ]; then
816 # For packages with empty $DEPENDS
817 [ -n "$DEPENDS" ] || DEPENDS="$pkg"
819 # Default $CAT
820 [ -z "$CAT" ] &&
821 case $PACKAGE in
822 *-dev) CAT="development|development files" ;;
823 esac
825 # Manage two-in-one $CAT="$CATEGORY|$SHORT_DESC_ADDITION"
826 CATEGORY="${CAT%|*}"
827 SHORT_DESC="$SHORT_DESC (${CAT#*|})"
828 fi
830 # Mandatory variables
831 cat <<EOF
832 $signature
834 PACKAGE="$PACKAGE"
835 VERSION="$VERSION"
836 CATEGORY="$CATEGORY"
837 SHORT_DESC="$SHORT_DESC"
838 MAINTAINER="$MAINTAINER"
839 LICENSE="$LICENSE"
840 WEB_SITE="$WEB_SITE"
841 EOF
843 # Optional variables
844 [ -n "$TAGS" ] && echo "TAGS=\"$TAGS\""
845 [ -n "$DEPENDS" ] && echo "DEPENDS=\"$DEPENDS\"" | tr -ds '\t' ' '
846 [ -n "$PROVIDE" ] && echo "PROVIDE=\"$PROVIDE\""
848 # Extract {pre,post}_{install,remove} functions
849 for i in pre post; do
850 for j in install remove; do
851 if grep -q "^${i}_$j()" "$orig_receipt"; then
852 echo
853 sed "/^${i}_$j()/,/}/!d" "$orig_receipt"
854 fi
855 done
856 done
857 }
860 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
861 # but it doesn't handle EXTRAVERSION.
863 packit() {
864 set_paths "$1"
865 PACKAGE="${1:-$PACKAGE}"
867 # Handle cross compilation
868 case "$ARCH" in
869 arm*|x86_64) arch="-$ARCH" ;;
870 esac
872 title 'Pack: %s' "$PACKAGE $VERSION$arch"
874 if grep -q ^genpkg_rules $receipt; then
875 _ 'Executing: %s' 'genpkg_rules'
876 set -e; cd $pkgdir; mkdir -p $fs
877 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
878 $LOGS/$pkg.log
879 else
880 _ 'No packages rules: meta package'
881 mkdir -p $fs
882 fi
884 # Check CONFIG_FILES
885 if [ -n "$CONFIG_FILES" ]; then
886 for i in $CONFIG_FILES; do
887 if [ ! -e $fs$i ]; then
888 case $i in
889 */) mkdir -p $fs$i ;;
890 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
891 esac
892 fi
893 done
894 fi
896 # First QA check to stop now if genpkg_rules failed.
897 lerror=$(_n 'ERROR')
898 if fgrep -q ^$lerror $LOGS/$pkg.log; then
899 broken; exit 1
900 fi
902 cd $taz
903 action 'Copying "%s"...' 'receipt'
904 mk_pkg_receipt ../receipt > $pack/receipt
905 chown 0.0 $pack/receipt; status
907 unset desc
908 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
909 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
910 if [ -n "$desc" ]; then
911 action 'Copying "%s"...' "$(basename "$desc")"
912 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
913 fi
915 copy_generic_files
917 # Strip and stuff files.
918 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
920 # Create files.list with redirecting find output.
921 action 'Creating the list of files...'
922 cd $fs
923 find . -type f -print > ../files.list
924 find . -type l -print >> ../files.list
925 cd ..; sed -i s/'^.'/''/ files.list
926 status
928 # Md5sum of files.
929 action 'Creating md5sum of files...'
930 while read file; do
931 [ -L "fs$file" ] && continue
932 [ -f "fs$file" ] || continue
933 case "$file" in
934 /lib/modules/*/modules.*|*.pyc) continue ;;
935 esac
936 md5sum "fs$file" | sed 's/ fs/ /'
937 done < files.list > md5sum
938 status
940 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
941 2>/dev/null | awk 'END{ print $1 }')
943 # Build cpio archive.
944 action 'Compressing the FS...'
945 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
946 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
947 mv fs ../
948 status
950 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
951 2>/dev/null | awk 'END{ print $1 }')
953 action 'Updating receipt sizes...'
954 sed -i s/^PACKED_SIZE.*$// receipt
955 sed -i s/^UNPACKED_SIZE.*$// receipt
956 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
957 status
959 # Set extra version.
960 if [ -n "$EXTRAVERSION" ]; then
961 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
962 sed -i s/^EXTRAVERSION.*$// receipt
963 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
964 status
965 fi
967 # Compress.
968 action 'Creating full cpio archive...'
969 find . -newer $receipt -exec touch -hr $receipt '{}' \;
970 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
971 status
973 action 'Restoring original package tree...'
974 mv ../fs .
975 status
977 rm fs.cpio.lzma; cd ..
979 # QA and give info.
980 tazpkg=$(ls *.tazpkg)
981 packit_quality
982 footer "$(_ 'Package "%s" created' "$tazpkg")"
983 update_packages_info
984 }
987 # Verify package quality and consistency.
989 packit_quality() {
990 #action 'QA: checking for broken link...'
991 #link=$(find $fs/usr -type l -follow)
992 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
993 #status
995 # Exit if any error found in log file.
996 lerror=$(_n 'ERROR')
997 if fgrep -q ^$lerror $LOGS/$pkg.log; then
998 rm -f $command
999 broken; exit 1
1000 fi
1002 action 'QA: checking for empty package...'
1003 files=$(cat $WOK/$pkg/taz/$PACKAGE-$VERSION/files.list | wc -l)
1004 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
1005 broken
1006 rm -f $command
1007 die 'ERROR: empty package'
1008 fi
1010 :; status
1011 # Find and remove old package(s)
1012 tempd="$(mktemp -d)"; cd "$tempd"
1013 for testpkg in $(ls $PKGS/$PACKAGE-*.tazpkg 2> /dev/null); do
1014 # Extract receipt from each matched package
1015 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
1016 name=$(. receipt; echo $PACKAGE)
1017 rm receipt
1018 if [ "$name" == "$PACKAGE" ]; then
1019 action 'Removing old package "%s"' "$(basename "$testpkg")"
1020 rm -f "$testpkg"
1021 status
1022 fi
1023 done
1024 rm -r "$tempd"
1025 mv -f $pkgdir/taz/$PACKAGE-$VERSION.tazpkg $PKGS
1026 sed -i /^${pkg}$/d $broken
1027 #action 'Removing source tree...'
1028 #rm -f $WOK/$pkg/source; status
1032 # v2: pack all packages using compiled files
1034 packall() {
1035 set_paths
1036 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1037 for i in $PACKAGE $SPLIT; do
1038 unset DEPENDS CAT
1039 packit $i
1040 done
1041 else
1042 packit
1043 fi
1047 # Reverse "cat" command: prints input lines in the reverse order
1049 tac() {
1050 sed '1!G;h;$!d' $1
1054 # Install package on --install or update the chroot.
1056 install_package() {
1057 case "$ARCH" in
1058 arm*|x86_64)
1059 arch="-$ARCH"
1060 root="$CROSS_TREE/sysroot" ;;
1061 esac
1062 # Install package if requested but skip install if target host doesn't
1063 # match build system or it will break the build chroot.
1064 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1065 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
1066 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1067 cd $PKGS
1068 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
1069 else
1070 broken
1071 die 'Unable to install package, build has failed.'
1072 fi
1073 fi
1075 # Install package if part of the chroot to keep env up-to-date.
1076 if [ -d "$root$INSTALLED/$pkg" ]; then
1077 . /etc/slitaz/cook.conf
1078 . $WOK/$pkg/taz/$pkg-*/receipt
1079 _ 'Updating %s chroot environment...' "$ARCH"
1080 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
1081 cd $PKGS
1082 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
1083 fi
1087 # remove chroot jail
1089 umount_aufs() {
1090 tac ${1}rw/aufs-umount.sh | sh
1091 rm -rf ${1}rw
1092 umount ${1}root
1093 rmdir ${1}r*
1097 # Launch the cook command into a chroot jail protected by aufs.
1098 # The current filesystems are used read-only and updates are
1099 # stored in a separate branch.
1101 try_aufs_chroot() {
1103 base="/dev/shm/aufsmnt$$"
1105 # Can we setup the chroot? Is it already done?
1106 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1107 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1108 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1109 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1110 mkdir ${base}root ${base}rw || return
1112 _ 'Setup aufs chroot...'
1114 # Sanity check
1115 for i in / /proc /sys /dev/shm /home ; do
1116 case " $AUFS_MOUNTS " in
1117 *\ $i\ *) ;;
1118 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1119 esac
1120 done
1121 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1122 mount --bind $mnt ${base}root$mnt
1123 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1124 _ 'Aufs mount failure'
1125 umount ${base}root
1126 rm -rf ${base}r*
1127 return
1128 fi
1129 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1130 done
1131 trap "umount_aufs ${base}" INT
1133 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1134 status=$?
1136 _ 'Leaving aufs chroot...'
1137 umount_aufs $base
1138 # Install package outside the aufs jail
1139 install_package
1140 exit $status
1144 # Encode predefined XML entities
1146 xml_ent() {
1147 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1151 # Create a XML feed for freshly built packages.
1153 gen_rss() {
1154 pubdate=$(date '+%a, %d %b %Y %X')
1155 cat > $FEEDS/$pkg.xml <<EOT
1156 <item>
1157 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1158 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1159 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1160 <pubDate>$pubdate</pubDate>
1161 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1162 </item>
1163 EOT
1167 # Truncate stdout log file to $1 Mb.
1169 loglimit() {
1170 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1171 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1172 else
1173 tee /dev/stderr
1174 fi
1179 # Receipt functions to ease packaging
1182 get_dev_files() {
1183 action 'Getting standard devel files...'
1184 mkdir -p $fs/usr/lib
1185 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1186 cp -a $install/usr/lib/*a $fs/usr/lib
1187 cp -a $install/usr/include $fs/usr
1188 status
1192 # Function to use in compile_rules() to copy man page from $src to $install
1194 cook_pick_manpages() {
1195 local name section
1196 action 'Copying man pages...'
1198 for i in $@; do
1199 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1200 section=${name##*/}; section=${section##*.}
1201 mkdir -p $install/usr/share/man/man$section
1202 scopy $i $install/usr/share/man/man$section
1203 done
1204 status
1208 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1210 cook_copy_files() {
1211 action 'Copying files...'
1212 cd $install
1213 local i j
1214 IFS=$'\n'
1215 for i in $@; do
1216 for j in $(find . -name $i ! -type d); do
1217 mkdir -p $fs$(dirname ${j#.})
1218 scopy $j $fs$(dirname ${j#.})
1219 done
1220 done
1221 cd - >/dev/null
1222 status
1226 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1228 cook_copy_folders() {
1229 action 'Copying folders...'
1230 cd $install
1231 local i j
1232 IFS=$'\n'
1233 for i in $@; do
1234 for j in $(find . -name $i -type d); do
1235 mkdir -p $fs$(dirname ${j#.})
1236 cp -a $j $fs$(dirname ${j#.})
1237 done
1238 done
1239 cd - >/dev/null
1240 status
1244 # Common function to copy files, folders and patterns
1246 copy() {
1247 action 'Copying folders and files...'
1248 cd $install
1249 local i j filelist=$(mktemp) tmplist=$(mktemp)
1250 IFS=$'\n'
1251 find ! -type d | sed 's|\.||' > $filelist
1252 for i in $@; do
1253 case $i in
1254 @std)
1255 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1256 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /bin\/.*-config$/d;
1257 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d;
1258 /\/include\//d;
1259 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1260 /\/share\/devhelp\//d; /\/share\/locale\//d;
1261 /\/share\/bash-completion\//d; /\/lib\/systemd\//d;
1262 ' $filelist > $tmplist
1263 while read j; do
1264 mkdir -p $fs$(dirname $j)
1265 scopy $install$j $fs$(dirname $j)
1266 done < $tmplist
1267 ;;
1268 @dev)
1269 # Copy "developer files"
1270 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.la$/p; /\.pc$/p; /bin\/.*-config$/p;
1271 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p;
1272 /\/include\//p;
1273 ' $filelist | \
1274 while read j; do
1275 mkdir -p $fs$(dirname $j)
1276 scopy $install$j $fs$(dirname $j)
1277 done
1278 ;;
1279 */)
1280 # Copy specified folders
1281 for j in $(find . -name ${i%/} -type d); do
1282 mkdir -p $fs$(dirname ${j#.})
1283 cp -a $j $fs$(dirname ${j#.})
1284 done
1285 ;;
1286 *)
1287 # Copy specified files
1288 for j in $(find . -name $i ! -type d); do
1289 mkdir -p $fs$(dirname ${j#.})
1290 scopy $j $fs$(dirname ${j#.})
1291 done
1292 ;;
1293 esac
1294 done
1295 cd - >/dev/null
1296 rm $filelist $tmplist
1297 status
1301 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1302 # (default: 16 and 48) from $install to $fs
1304 cook_copy_icons() {
1305 local sizes=$@
1306 action 'Copying hicolor icons...'
1307 mkdir -p $fs/usr/share/icons/hicolor
1308 for i in ${sizes:-16 48}; do
1309 [ ! -e "$install/usr/share/icons/hicolor/${i}x$i" ] ||
1310 scopy $install/usr/share/icons/hicolor/${i}x$i \
1311 $fs/usr/share/icons/hicolor
1312 done
1313 status
1317 # Update packages.info every time after successful build
1319 update_packages_info() {
1320 sed -i "/^$PACKAGE\t/d" $PKGS/packages.info
1321 unset_receipt; . $pack/receipt
1322 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1323 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1324 MD5="$(md5sum "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" | awk '{print $1}')"
1325 cat >> $PKGS/packages.info <<EOT
1326 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 $PROVIDE
1327 EOT
1335 # Commands
1338 case "$1" in
1339 usage|help|-u|-h)
1340 usage ;;
1342 list-wok)
1343 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1344 cd $WOK
1345 if [ "$ARCH" != 'i486' ]; then
1346 count=0
1347 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1348 do
1349 unset HOST_ARCH
1350 . $pkg
1351 count=$(($count + 1))
1352 colorize 34 "$PACKAGE"
1353 done
1354 else
1355 count=$(ls | wc -l)
1356 ls -1
1357 fi
1358 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1359 ;;
1361 activity)
1362 cat $activity ;;
1364 search)
1365 # Just a simple search function, we dont need more actually.
1366 query="$2"
1367 title 'Search results for "%s"' "$query"
1368 cd $WOK; ls -1 | grep "$query"
1369 footer ;;
1371 setup)
1372 # Setup a build environment
1373 check_root
1374 _ 'Cook: setup environment' | log
1375 title 'Setting up your environment'
1376 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1377 cd $SLITAZ
1378 init_db_files
1379 _ 'Checking for packages to install...'
1380 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1381 # ARCH-setup or 'cross check' should be used before: cook setup
1382 case "$ARCH" in
1383 arm*|x86_64)
1384 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1385 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1386 . /etc/slitaz/cross.conf ;;
1387 esac
1388 for pkg in $SETUP_PKGS; do
1389 if [ -n "$forced" ]; then
1390 tazpkg -gi $pkg --forced
1391 else
1392 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1393 fi
1394 done
1396 # Handle --options
1397 case "$2" in
1398 --wok) hg clone $WOK_URL wok || exit 1 ;;
1399 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1400 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1401 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1402 esac
1404 # SliTaz group and permissions
1405 if ! grep -q ^slitaz /etc/group; then
1406 _ 'Adding group "%s"' 'slitaz'
1407 addgroup slitaz
1408 fi
1409 _ 'Setting permissions for group "%s"...' 'slitaz'
1410 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1411 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1412 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1414 *-setup)
1415 # Setup for cross compiling.
1416 arch="${1%-setup}"
1417 check_root
1418 . /etc/slitaz/cook.conf
1419 for pkg in $CROSS_SETUP; do
1420 if [ -n "$forced" ]; then
1421 tazpkg -gi $pkg --forced
1422 else
1423 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1424 fi
1425 done
1427 _ 'Cook: setup %s cross environment' "$arch" | log
1428 title 'Setting up your %s cross environment' "$arch"
1429 init_db_files
1430 sed -i \
1431 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1432 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1433 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1434 /etc/slitaz/cook.conf
1435 case "$arch" in
1436 arm)
1437 flags='-O2 -march=armv6'
1438 host="$ARCH-slitaz-linux-gnueabi" ;;
1439 armv6hf)
1440 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1441 host="$ARCH-slitaz-linux-gnueabi" ;;
1442 armv7)
1443 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1444 host="$ARCH-slitaz-linux-gnueabi" ;;
1445 x86_64)
1446 flags='-O2 -mtune=generic -pipe'
1447 host="$ARCH-slitaz-linux" ;;
1448 esac
1449 sed -i \
1450 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1451 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1452 . /etc/slitaz/cook.conf
1453 sysroot="$CROSS_TREE/sysroot"
1454 tools="/cross/$arch/tools"
1455 root="$sysroot"
1456 # L10n: keep the same width of translations to get a consistent view
1457 _ 'Target arch : %s' "$ARCH"
1458 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1459 _ 'Build flags : %s' "$flags"
1460 _ 'Arch sysroot : %s' "$sysroot"
1461 _ 'Tools prefix : %s' "$tools/bin"
1462 # Tell the packages manager where to find packages.
1463 _ 'Packages DB : %s' "$root$DB"
1464 mkdir -p $root$INSTALLED
1465 cd $root$DB; rm -f *.bak
1466 for list in packages.list packages.desc packages.equiv packages.md5; do
1467 rm -f $list
1468 ln -s $SLITAZ/packages/$list $list
1469 done
1470 # We must have the cross compiled glibc-base installed or default
1471 # i486 package will be used as dep by tazpkg and then break the
1472 # cross environment
1473 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1474 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1475 fi
1476 # Show GCC version or warn if not yet compiled.
1477 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1478 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1479 else
1480 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1481 _ 'Run "%s" to cook a toolchain' 'cross compile'
1482 fi
1483 footer ;;
1485 test)
1486 # Test a cook environment.
1487 _ 'Cook test: testing the cook environment' | log
1488 [ ! -d "$WOK" ] && exit 1
1489 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1490 cook cooktest ;;
1492 new)
1493 # Create the package folder and an empty receipt.
1494 pkg="$2"
1495 [ -z "$pkg" ] && usage
1496 newline
1497 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1499 action 'Creating folder "%s"' "$WOK/$pkg"
1500 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1502 action 'Preparing the package receipt...'
1503 cp $DATA/receipt .
1504 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1505 status; newline
1507 # Interactive mode, asking and seding.
1508 case "$3" in
1509 --interactive|-x)
1510 _ 'Entering interactive mode...'
1511 separator
1512 _ 'Package : %s' "$pkg"
1514 _n 'Version : ' ; read answer
1515 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1517 _n 'Category : ' ; read answer
1518 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1520 # L10n: Short description
1521 _n 'Short desc : ' ; read answer
1522 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1524 _n 'Maintainer : ' ; read answer
1525 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1527 _n 'License : ' ; read answer
1528 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1530 _n 'Web site : ' ; read answer
1531 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1532 newline
1534 # Wget URL.
1535 _ 'Wget URL to download source tarball.'
1536 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1537 _n 'Wget url : ' ; read answer
1538 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1540 # Ask for a stuff dir.
1541 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1542 if [ "$?" -eq 0 ]; then
1543 action 'Creating the stuff directory...'
1544 mkdir $WOK/$pkg/stuff; status
1545 fi
1547 # Ask for a description file.
1548 confirm "$(_n 'Are you going to write a description? (y/N)')"
1549 if [ "$?" -eq 0 ]; then
1550 action 'Creating the "%s" file...' 'description.txt'
1551 touch $WOK/$pkg/description.txt; status
1552 fi
1554 footer "$(_ 'Receipt is ready to use.')" ;;
1555 esac ;;
1557 list)
1558 # Cook a list of packages (better use the Cooker since it will order
1559 # packages before executing cook).
1560 check_root
1561 [ -z "$2" ] && die 'No list in argument.'
1562 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1564 _ 'Starting cooking the list "%s"' "$2" | log
1566 for pkg in $(cat $2); do
1567 cook $pkg || broken
1568 done ;;
1570 clean-wok)
1571 check_root
1572 newline; action 'Cleaning all packages files...'
1573 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1574 status; newline ;;
1576 clean-src)
1577 check_root
1578 newline; action 'Cleaning all packages sources...'
1579 rm -rf $WOK/*/source
1580 status; newline ;;
1582 uncook)
1583 cd $WOK
1584 count=0
1585 title 'Checking for uncooked packages'
1587 for pkg in *; do
1588 unset HOST_ARCH EXTRAVERSION
1589 [ ! -e $pkg/receipt ] && continue
1590 . $pkg/receipt
1591 # Source cooked pkg receipt to get EXTRAVERSION
1592 if [ -d "$WOK/$pkg/taz" ]; then
1593 cd $WOK/$pkg/taz/$pkg-*
1594 . receipt; cd $WOK
1595 fi
1596 case "$ARCH" in
1597 i486)
1598 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1599 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1600 count=$(($count + 1))
1601 colorize 34 "$pkg"
1602 fi ;;
1603 arm*)
1604 # Check only packages included in arch
1605 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1606 # *.tazpkg
1607 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1608 count=$(($count + 1))
1609 colorize 34 "$pkg"
1610 fi
1611 fi ;;
1612 esac
1613 done
1615 if [ "$count" -gt 0 ]; then
1616 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1617 else
1618 _ 'All packages are cooked :-)'
1619 newline
1620 fi
1621 ;;
1623 pkgdb)
1624 # Create suitable packages list for TazPkg and only for built packages
1625 # as well as flavors files for TazLiTo. We don't need logs since we do it
1626 # manually to ensure everything is fine before syncing the mirror.
1627 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1628 ;;
1630 *)
1631 # Just cook and generate a package.
1632 check_root
1633 time=$(date +%s)
1634 pkg="$1"
1635 [ -z "$pkg" ] && usage
1637 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1638 $LOGS/$pkg.log 2>/dev/null | sed '$!d')
1639 receipt="$WOK/$pkg/receipt"
1640 check_pkg_in_wok
1641 newline
1643 unset inst
1644 unset_receipt
1645 . $receipt
1647 # Handle cross compilation.
1648 case "$ARCH" in
1649 arm*)
1650 if [ -z "$HOST_ARCH" ]; then
1651 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1652 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1653 _ 'cook: %s' "$error"
1654 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1655 _ 'Cook skip: %s' "$error" | log
1656 newline
1657 broken; exit 1
1658 fi ;;
1659 esac
1661 # Some packages are not included in some arch or fail to cross compile.
1662 : ${HOST_ARCH=i486}
1663 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1664 # Handle arm{v6hf,v7,..}
1665 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1666 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1667 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1668 _ 'cook: %s' "error"
1669 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1670 _ 'Cook skip: %s' "$error" | log
1671 sed -i /^${pkg}$/d $broken
1672 newline
1673 exit 0
1674 fi
1676 # Skip blocked, 3 lines also for the Cooker.
1677 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
1678 die 'Package "%s" is blocked' "$pkg"
1680 try_aufs_chroot "$@"
1682 # Log and source receipt.
1683 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
1684 echo "cook:$pkg" > $command
1686 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1688 while read cmd duration start; do
1689 [ $(($start + $duration)) -lt $(date +%s) ] &&
1690 echo "sed -i '/^$cmd $duration/d' $cooktime"
1691 done < $cooktime | sh
1693 # Display and log info if cook process stopped.
1694 # FIXME: gettext not working (in single quotes) here!
1695 trap '_ "\n\nCook stopped: control-C\n\n" | \
1696 tee -a $LOGS/$pkg.log' INT
1698 # Handle --options
1699 case "$2" in
1700 --clean|-c)
1701 action 'Cleaning "%s"' "$pkg"
1702 cd $WOK/$pkg; rm -rf install taz source
1703 status; newline
1704 exit 0 ;;
1706 --install|-i)
1707 inst='yes' ;;
1709 --getsrc|-gs)
1710 title 'Getting source for "%s"' "$pkg"
1711 get_source
1712 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1713 exit 0 ;;
1715 --block|-b)
1716 action 'Blocking package "%s"' "$pkg"
1717 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1718 status; newline
1719 exit 0 ;;
1721 --unblock|-ub)
1722 action 'Unblocking package "%s"' "$pkg"
1723 sed -i "/^${pkg}$/"d $blocked
1724 status; newline
1725 exit 0 ;;
1727 --pack)
1728 [ -d $WOK/$pkg/taz ] || die 'Need to build "%s"' "$pkg"
1729 rm -rf $WOK/$pkg/taz
1730 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1731 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1732 clean_log
1733 rm -f $command
1734 exit 0 ;;
1736 --cdeps)
1737 @@PREFIX@@/libexec/cookutils/cdeps $pkg
1738 esac
1740 # Rotate log
1741 for i in $(seq 9 -1 1); do
1742 j=$(($i - 1))
1743 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1744 done
1745 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1747 # Check if wanted is built now so we have separate log files.
1748 for wanted in $WANTED ; do
1749 if grep -q "^$wanted$" $blocked; then
1750 broken
1751 rm -f $command
1752 die 'WANTED package "%s" is blocked' "$wanted"
1753 fi
1754 if grep -q "^$wanted$" $broken; then
1755 broken
1756 rm -f $command
1757 die 'WANTED package "%s" is broken' "$wanted"
1758 fi
1759 if [ ! -d "$WOK/$wanted/install" ]; then
1760 cook "$wanted" || { broken; exit 1; }
1761 fi
1762 done
1764 # Cook and pack or exit on error and log everything.
1765 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1766 remove_deps | tee -a $LOGS/$pkg.log
1767 cookit_quality
1768 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1769 clean_log
1771 # Exit if any error in packing.
1772 lerror=$(_n 'ERROR')
1773 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1774 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1775 debug_info | tee -a $LOGS/$pkg.log
1776 sed -i '$ s|$| [ Failed ]|' $activity
1777 rm -f $command
1778 broken; exit 1
1779 fi
1781 # Create an XML feed
1782 gen_rss
1784 # Time and summary
1785 time=$(($(date +%s) - $time))
1786 summary | tee -a $LOGS/$pkg.log
1787 newline
1789 # We may want to install/update (outside aufs jail!).
1790 [ -s /aufs-umount.sh ] || install_package
1792 sed -i '$ s|$| [ Done ]|' $activity
1794 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1795 # If you want automation, use the Cooker Build Bot.
1796 rm -f $command
1797 ;;
1798 esac
1800 exit 0