cookutils view cook @ rev 1050

cook: fix(): add `fix symlinks` function (for "glusterfs" package, and maybe some other)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 20 13:55:27 2018 +0300 (2018-04-20)
parents 0616fab99da8
children ab62aac645d4
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.')
66 cook splitdb $(_ 'create up-to-date split.db file.')
68 EOT
69 exit 0
70 }
73 # We don't want these escapes in web interface.
75 clean_log() {
76 sed -i -e 's|\[70G\[ \[1;32m| |' \
77 -e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
78 }
81 # Be sure package exists in wok.
83 check_pkg_in_wok() {
84 [ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
85 }
88 # Initialize files used in $CACHE
90 init_db_files() {
91 _ 'Creating directories structure in "%s"' "$SLITAZ"
92 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
93 _ 'Creating DB files in "%s"' "$CACHE"
94 touch $activity $command $broken $blocked $CACHE/webstat
95 chown www:www $cache/webstat
96 }
99 # Paths used in receipt and by cook itself.
101 set_paths() {
102 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
103 if [ -f "$WOK/linux/receipt" ]; then
104 kvers=$(. $WOK/linux/receipt; echo $VERSION)
105 kbasevers=$(echo $kvers | cut -d. -f1,2)
106 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
107 kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
108 kbasevers=$(echo $kvers | cut -d. -f1,2)
109 fi
111 # Python version
112 [ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
113 # Perl version for some packages needed it
114 [ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
116 pkgdir="$WOK/$pkg"
117 . "$pkgdir/receipt"
118 basesrc="$pkgdir/source"
119 tmpsrc="$basesrc/tmp"
120 src="$basesrc/$PACKAGE-$VERSION"
121 taz="$pkgdir/taz"
122 pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
123 fs="$pack/fs"
124 stuff="$pkgdir/stuff"
125 install="$pkgdir/install"
127 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
128 lzma_tarball="$pkgsrc.tar.lzma"
130 [ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
132 if [ -n "$WANTED" ]; then
133 basesrc="$WOK/$WANTED/source"
134 src="$basesrc/$WANTED-$VERSION"
135 install="$WOK/$WANTED/install"
136 wanted_stuff="$WOK/$WANTED/stuff"
137 fi
139 [ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
141 # Old way compatibility.
142 _pkg="$install"
143 }
146 # Create source tarball when URL is a SCM.
148 create_tarball() {
149 local tarball
150 tarball="$pkgsrc.tar.bz2"
151 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
152 _ 'Creating tarball "%s"' "$tarball"
153 if [ -n "$LZMA_SRC" ]; then
154 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
155 LZMA_SRC=''
156 else
157 tar -cjf $tarball $pkgsrc || exit 1
158 mv $tarball $SRC; rm -rf $pkgsrc
159 fi
160 TARBALL="$tarball"
161 }
164 # Get package source. For SCM we are in cache so clone here and create a
165 # tarball here.
167 get_source() {
168 local url
169 url=${WGET_URL#*|}
170 set_paths
171 pwd=$(pwd)
172 case "$WGET_URL" in
173 http://*|ftp://*|https://*)
174 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
175 wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
176 wget -T 60 -c -O $SRC/$TARBALL $url ||
177 die 'ERROR: %s' "wget $WGET_URL"
178 ;;
180 hg*|mercurial*)
181 _ 'Getting source from %s...' 'Hg'
182 _ 'URL: %s' "$url"
183 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
184 if [ -n "$BRANCH" ]; then
185 _ 'Hg branch: %s' "$BRANCH"
186 hg clone $url --rev $BRANCH $pkgsrc ||
187 die 'ERROR: %s' "hg clone $url --rev $BRANCH"
188 else
189 hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
190 fi
191 rm -rf $pkgsrc/.hg
192 create_tarball
193 ;;
195 git*)
196 _ 'Getting source from %s...' 'Git'
197 _ 'URL: %s' "$url"
198 cd $SRC
199 git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
200 if [ -n "$BRANCH" ]; then
201 _ 'Git branch: %s' "$BRANCH"
202 cd $pkgsrc; git checkout $BRANCH; cd ..
203 fi
204 cd $SRC
205 create_tarball
206 ;;
208 cvs*)
209 mod=$PACKAGE
210 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
211 _ 'Getting source from %s...' 'CVS'
212 _ 'URL: %s' "$url"
213 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
214 _ 'Cloning to "%s"' "$pwd/$mod"
215 cvs -d:$url co $mod && mv $mod $pkgsrc
216 create_tarball
217 ;;
219 svn*|subversion*)
220 _ 'Getting source from %s...' 'SVN'
221 _ 'URL: %s' "$url"
222 if [ -n "$BRANCH" ]; then
223 echo t | svn co $url -r $BRANCH $pkgsrc
224 else
225 echo t | svn co $url $pkgsrc
226 fi
227 create_tarball
228 ;;
230 bzr*)
231 _ 'Getting source from %s...' 'bazaar'
232 cd $SRC
233 pkgsrc=${url#*:}
234 if [ -n "$BRANCH" ]; then
235 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
236 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
237 else
238 echo "bzr -Ossl.cert_reqs=none branch $url"
239 bzr -Ossl.cert_reqs=none branch $url
240 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
241 _ "Don't forget to add to receipt:"
242 echo -e "BRANCH=\"$BRANCH\"\n"
243 fi
244 mv $pkgsrc $pkgsrc-$BRANCH
245 pkgsrc="$pkgsrc-$BRANCH"
246 create_tarball
247 ;;
249 *)
250 broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
251 ;;
252 esac
253 }
256 # Extract source package.
258 extract_source() {
259 if [ ! -s "$SRC/$TARBALL" ]; then
260 local url
261 url="$MIRROR_URL/sources/packages"
262 url="$url/${TARBALL:0:1}/$TARBALL"
263 _ 'Getting source from %s...' 'mirror'
264 _ 'URL: %s' "$url"
265 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
266 fi
267 _ 'Extracting source archive "%s"' "$TARBALL"
268 case "$TARBALL" in
269 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
270 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
271 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
272 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
273 *.tar) tar -xf $SRC/$TARBALL ;;
274 *.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
275 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
276 tar -xf $SRC/$TARBALL 2>/dev/null;;
277 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
278 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
279 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
280 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
281 *) cp $SRC/$TARBALL $(pwd) ;;
282 esac
283 }
286 # Display time.
288 disp_time() {
289 local sec div min
290 sec="$1"
291 div=$(( ($1 + 30) / 60))
292 case $div in
293 0) min='';;
294 # L10n: 'm' is for minutes (approximate cooking time)
295 *) min=$(_n ' ~ %dm' "$div");;
296 esac
298 # L10n: 's' is for seconds (cooking time)
299 _ '%ds%s' "$sec" "$min"
300 }
303 # Display cooked package summary.
305 summary() {
306 local arch=''
307 case "$ARCH" in
308 arm*|x86_64) arch="-$ARCH" ;;
309 esac
311 set_paths
312 cd $WOK/$pkg
313 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
314 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
315 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
317 title 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION$arch"
319 # L10n: keep the same width of translations to get a consistent view
320 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
321 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
322 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
323 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
324 _ 'Cook time : %s' "$(disp_time "$time")"
325 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
326 _ 'Target arch : %s' "$ARCH"
328 separator -
329 _ ' # : Packed : Compressed : Files : Package name'
330 separator -
331 pkgi=1
332 for i in $(all_names); do
333 fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
334 pkgname="$i-$VERSION$EXTRAVERSION$arch.tazpkg"
335 size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
336 files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
337 printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
338 pkgi=$((pkgi + 1))
339 done
340 separator
341 }
344 # Display debugging error info.
346 debug_info() {
347 title 'Debug information'
348 # L10n: specify your format of date and time (to help: man date)
349 # L10n: not bad one is '+%x %R'
350 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
351 if [ -n "$time" ]; then
352 times="$(($(date +%s) - $time))"
353 _ 'Wasted time : %s' "$(disp_time "$times")"
354 fi
355 for error in \
356 ERROR 'No package' "cp: can't" "can't open" "can't cd" \
357 'error:' 'fatal error:' 'undefined reference to' \
358 'Unable to connect to' 'link: cannot find the library' \
359 'CMake Error' ': No such file or directory' \
360 'Could not read symbols: File in wrong format'
361 do
362 # format "line number:line content"
363 fgrep -n "$error" $LOGS/$pkg.log
364 done > $LOGS/$pkg.log.debug_info 2>&1
365 # sort by line number, remove duplicates
366 sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
367 rm -f $LOGS/$pkg.log.debug_info
368 footer
369 }
372 # A bit smarter function than the classic `cp` command
374 scopy() {
375 if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
376 cp -a "$1" "$2" # copy generic files
377 else
378 cp -al "$1" "$2" # copy hardlinks
379 fi
380 }
383 # Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
384 # We use standard paths, so some packages need to copy these files with the
385 # receipt and genpkg_rules.
386 # This function executes inside the packaging process, before compressor call.
388 copy_generic_files() {
389 # Proceed only for "main" package (for v2), and for any packages (v1)
390 [ "$pkg" == "$PACKAGE" ] || return 0
392 # $LOCALE is set in cook.conf
393 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
394 if [ -d "$install/usr/share/locale" ]; then
395 mkdir -p "$fs/usr/share/locale"
396 for i in $LOCALE; do
397 if [ -d "$install/usr/share/locale/$i" ]; then
398 cp -r $install/usr/share/locale/$i $fs/usr/share/locale
399 fi
400 done
401 fi
402 fi
404 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
405 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
406 if [ -d "$install/usr/share/pixmaps" ]; then
407 mkdir -p "$fs/usr/share/pixmaps"
408 for i in png xpm; do
409 [ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
410 cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
411 done
412 fi
413 fi
415 # Desktop entry (.desktop).
416 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
417 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
418 if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
419 mkdir -p "$fs/usr/share"
420 cp -r $install/usr/share/applications $fs/usr/share
421 fi
422 fi
423 }
426 # Copy pixmaps, desktop files and licenses from $stuff to $install.
427 # This function executes after the main compile_rules() is done.
429 copy_generic_stuff() {
430 # Custom or homemade PNG pixmap can be in stuff.
431 if [ -f "$stuff/$PACKAGE.png" ]; then
432 mkdir -p $install/usr/share/pixmaps
433 cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
434 fi
436 # Homemade desktop file(s) can be in stuff.
437 if [ -d "$stuff/applications" ]; then
438 mkdir -p $install/usr/share
439 cp -r $stuff/applications $install/usr/share
440 fi
441 if [ -f "$stuff/$PACKAGE.desktop" ]; then
442 mkdir -p $install/usr/share/applications
443 cp $stuff/$PACKAGE.desktop $install/usr/share/applications
444 fi
446 # Add custom licenses
447 if [ -d "$stuff/licenses" ]; then
448 mkdir -p $install/usr/share/licenses
449 cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
450 fi
451 }
454 # Update installed.cook.diff
456 update_installed_cook_diff() {
457 # If a cook failed deps are removed.
458 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
459 cd $CACHE
460 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
461 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
462 deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
463 }
466 # Remove installed deps.
468 remove_deps() {
469 # Now remove installed build deps.
470 diff='/tmp/installed.cook.diff'
471 [ -s "$diff" ] || return
473 deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
474 nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
475 newline
476 _n 'Build dependencies to remove:'; echo " $nb"
477 [ -n "$root" ] && echo "root=\"$root\""
478 {
479 _n 'Removing:'
480 for dep in $deps; do
481 echo -n " $dep"
482 # Do not waste time uninstalling the packages if we are inside
483 # aufs chroot - unmounting chroot will "uninstall" all packages.
484 [ -s /aufs-umount.sh ] ||
485 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
486 done
487 } | busybox fold -sw80
488 newline; newline
489 # Keep the last diff for debug and info.
490 mv -f $diff $CACHE/installed.diff
491 }
494 # Automatically patch the sources.
496 patchit() {
497 [ -f "$stuff/patches/series" ] || return
499 IFS=$'\n'
500 while read i; do
501 patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
502 case $patchname in # allow patch options in form <options_no_spaces>|<file_name>
503 *\|*) patchopts="${patchname%|*}"; patchname="${patchname#*|}";;
504 *) patchopts='-Np1';;
505 esac
506 [ -n "$patchname" ] || continue # allow empty lines
507 [ -f "$src/done.$patchname" ] && continue # already applied (useful with `cook --continue`)
508 newline
509 _ 'Applying patch %s' "$patchname"
510 patch $patchopts -i $stuff/patches/$patchname | sed 's|^| |'
511 touch $src/done.$patchname
512 done < $stuff/patches/series
513 newline
514 unset IFS
515 }
518 # Check source tarball integrity.
520 check_integrity() {
521 for i in sha1 sha3 sha256 sha512 md5; do
522 I=$(echo $i | tr 'a-z' 'A-Z')
523 eval sum=\$TARBALL_$I
524 if [ -n "$sum" ]; then
525 newline
526 _ 'Checking %ssum of source tarball...' "$i"
527 echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
528 fi
529 done
530 newline
531 }
534 # Misc fix functions
536 fix() {
537 case $1 in
538 # https://bugzilla.gnome.org/show_bug.cgi?id=655517
539 # https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
540 ld)
541 export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
542 ;;
543 libtool)
544 if [ -e 'libtool' ]; then
545 sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
546 else
547 echo "fix libtool: warning: libtool absent, nothing to fix."
548 fi
549 ;;
550 math)
551 # fix C++ math issue introduced in Glibc 2.26:
552 # error: '__builtin_isnan' is not a member of 'std'
553 # if (std::isnan(N)) {
554 # ^
555 find $src -type f -exec sed -i '
556 s|std::signbit|__builtin_signbit|g;
557 s|std::isnan|__builtin_isnan|g;
558 s|std::isinf|__builtin_isinf_sign|g;
559 s|std::isfinite|__builtin_isfinite|g;
560 s|std::isnormal|__builtin_isnormal|g
561 ' '{}' \;
562 ;;
563 symlinks)
564 # make absolute symlinks relative
565 echo "fix symlinks"
566 local ifs="$IFS" link target
567 IFS=$'\n'
568 # step 1: fast job, prefix all the absolute symlinks with "$install"
569 for link in $(find $install -type l); do
570 target="$(readlink $link)"
571 case "$target" in
572 /*) ln -sfv "$install$target" "$link";;
573 esac
574 done
575 IFS="$ifs"
576 # step 2: fine tuning, make symlinks relative
577 tazpkg -gi --quiet --local --cookmode symlinks
578 symlinks -cr $install
579 ;;
580 esac
581 }
584 # The main cook function.
586 cookit() {
587 if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
588 _ 'ERROR: Broken setup. Abort.'
589 return
590 fi
592 title 'Cook: %s' "$PACKAGE $VERSION"
593 set_paths
595 # Handle cross-tools.
596 [ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
597 case "$ARCH" in
598 arm*|x86_64)
599 # CROSS_COMPILE is used by at least Busybox and the kernel to set
600 # the cross-tools prefix. Sysroot is the root of our target arch
601 sysroot="$CROSS_TREE/sysroot"
602 tools="$CROSS_TREE/tools"
603 # Set root path when cross compiling. ARM tested but not x86_64
604 # When cross compiling we must install build deps in $sysroot.
605 arch="-$ARCH"
606 root="$sysroot"
607 _ '%s sysroot: %s' "$ARCH" "$sysroot"
608 _ 'Adding "%s" to PATH' "$tools/bin"
609 export PATH="$PATH:$tools/bin"
610 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
611 export CROSS_COMPILE="$HOST_SYSTEM-"
612 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
613 if [ "$ARCH" == 'x86_64' ]; then
614 export CC="$HOST_SYSTEM-gcc -m64"
615 export CXX="$HOST_SYSTEM-g++ -m64"
616 else
617 export CC="$HOST_SYSTEM-gcc"
618 export CXX="$HOST_SYSTEM-g++"
619 fi
620 export AR="$HOST_SYSTEM-ar"
621 export AS="$HOST_SYSTEM-as"
622 export RANLIB="$HOST_SYSTEM-ranlib"
623 export LD="$HOST_SYSTEM-ld"
624 export STRIP="$HOST_SYSTEM-strip"
625 export LIBTOOL="$HOST_SYSTEM-libtool"
626 ;;
627 esac
629 @@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
631 cd $pkgdir
632 [ -z "$continue" ] && rm -rf source 2>/dev/null
633 rm -rf install taz 2>/dev/null
635 # Disable -pipe if less than 512 MB free RAM.
636 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
637 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
638 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
639 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
640 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
641 fi
642 unset free
644 # Export flags and path to be used by make and receipt.
645 DESTDIR="$pkgdir/install"
646 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
647 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
648 LDFLAGS
650 # BUILD_DEPENDS may vary depending on the ARCH
651 case "$ARCH" in
652 arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
653 x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
654 esac
656 # Check for build deps and handle implicit depends of *-dev packages
657 # (ex: libusb-dev :: libusb).
658 # rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
659 # touch $CACHE/installed.local $CACHE/installed.web
660 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
661 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
663 # Get the list of installed packages
664 cd $root$INSTALLED; ls > $CACHE/installed.list
666 for action in check install; do
667 for dep in $BUILD_DEPENDS; do
668 implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
669 for i in $dep $implicit; do
670 # Skip if package already installed
671 [ -f "$root$INSTALLED/$i/receipt" ] && continue
673 case $action in
674 check)
675 # Search for local package or local provided-package
676 name=$(awk -F$'\t' -vpkg="$i" '{
677 if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
678 }' "$PKGS/packages.info")
679 if [ -z "$name" ]; then
680 # Search for package in mirror
681 name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
682 [ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
683 fi
684 ;;
685 install)
686 tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
687 ;;
688 esac
689 done
690 done
691 done
693 # # Have we a missing build dep to cook?
694 # if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
695 # _ 'Auto cook config is set: %s' "$AUTO_COOK"
696 # cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
697 # for i in $(uniq $CACHE/missing.dep); do
698 # (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
699 # tee -a $LOGS/$PACKAGE.log.$$
700 # # programmers: next two messages are exact copy from remove_deps()
701 # togrep1=$(_n 'Build dependencies to remove:')
702 # togrep2=$(_n 'Removing:')
703 # cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
704 # fgrep $togrep1 $LOGS/$i.log && \
705 # fgrep $togrep2 $LOGS/$i.log && newline) | \
706 # tee -a $LOGS/$PACKAGE.log.$$ && break
707 # done
708 # rm -f $CACHE/missing.dep
709 # mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
710 # fi
711 #
712 # # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
713 # # is enabled and cook fails we have ERROR in log, if no auto cook we have
714 # # missing dep in cached file.
715 # lerror=$(_n 'ERROR')
716 # if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
717 # [ -s "$CACHE/missing.dep" ] && nb=$(wc -l < $CACHE/missing.dep)
718 # _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
719 # broken; exit 1
720 # fi
721 #
722 # # Install local packages: package-version$arch
723 # cd $PKGS
724 # for i in $(uniq $CACHE/installed.local); do
725 # # _ 'Installing dep (pkg/local): %s' "$i"
726 # tazpkg install $i --root=$root --local --quiet --cookmode
727 # done
728 #
729 # # Install web or cached packages (if mirror is set to $PKGS we only
730 # # use local packages).
731 # for i in $(uniq $CACHE/installed.web); do
732 # # _ 'Installing dep (web/cache): %s' "$i"
733 # tazpkg get-install $i --root=$root --local --quiet --cookmode
734 # done
736 update_installed_cook_diff
738 # Get source tarball and make sure we have source dir named:
739 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
740 # tarball if it exists.
741 if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
742 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
743 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
744 LZMA_SRC=''
745 else
746 get_source || { broken; exit 1; }
747 fi
748 fi
749 if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
750 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
751 if ! extract_source ; then
752 get_source
753 extract_source || { broken; exit 1; }
754 fi
755 if [ -n "$LZMA_SRC" ]; then
756 cd $pkgdir/source
757 if [ "$(ls -A tmp | wc -l)" -gl 1 -o -f "$(echo tmp/*)" ]; then
758 mv tmp tmp-1; mkdir tmp
759 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
760 fi
761 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
762 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
763 fi
764 fi
766 cd $pkgdir/source/tmp
767 # Some archives are not well done and don't extract to one dir (ex lzma).
768 files=$(ls | wc -l)
769 [ "$files" -eq 1 -a -d "$(ls)" ] &&
770 mv * ../$PACKAGE-$VERSION
771 [ "$files" -eq 1 -a -f "$(ls)" ] &&
772 mkdir -p ../$PACKAGE-$VERSION &&
773 mv * ../$PACKAGE-$VERSION/$TARBALL
774 [ "$files" -gt 1 ] &&
775 mkdir -p ../$PACKAGE-$VERSION &&
776 mv * ../$PACKAGE-$VERSION
777 cd ..; rm -rf tmp
778 fi
780 # Check md5sum (or similar) for sources tarball
781 check_integrity
783 # Libtool shared libs path hack.
784 case "$ARCH" in
785 arm*) cross libhack ;;
786 esac
788 # Compiling all the sets
789 if grep -q ^compile_rules $receipt; then
790 _ 'Executing: %s' 'compile_rules'
791 echo "CFLAGS : $CFLAGS"
792 echo "LDFLAGS : $LDFLAGS"
793 [ -d "$src" ] && cd $src
794 patchit
796 # Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
797 SETS=$(echo $SPLIT \
798 | awk '
799 BEGIN { RS = " "; FS = ":"; }
800 { print $2; }' \
801 | sort -u \
802 | tr '\n' ' ')
803 SETS=${SETS% } # normalize space
804 # Prepare specified source sets using patched sources
805 [ -n "$SETS" ] &&
806 for set in $SETS; do
807 echo "Preparing set $set" # debug
808 cp -a $src $src-$set
809 done
811 for SET in '' $SETS; do
812 # Switch to the specified source set
813 set_paths
814 local suffix=''
815 [ -n "$SET" ] && suffix="-$SET"
816 export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
817 export install="$WOK/$pkg/install$suffix"
818 export DESTDIR="$install"
820 if [ -n "$SETS" ]; then
821 if [ -n "$SET" ]; then
822 title "Switching to the set '$SET'"
823 else
824 title "Switching to the default set"
825 fi
826 echo "src : $src"
827 echo "install: $install"
828 fi
829 [ -d "$src" ] && cd $src # packages without sources exists
830 echo
832 [ -d "$install" ] && rm -r $install
833 #mkdir -p $install
835 compile_rules $@ || { broken; exit 1; }
837 # Stay compatible with _pkg
838 [ -d "$src/_pkg" ] && mv $src/_pkg $install
840 copy_generic_stuff
842 # Actions to do after compiling the package
843 # Skip all for split packages (already done in main package)
844 if [ -z "$WANTED" ]; then
845 footer
846 export COOKOPTS ARCH install
847 @@PREFIX@@/libexec/cookutils/compressor install
848 fi
849 done
850 else
851 mkdir -p $install # allow receipts without `compile_rules()`
852 fi
853 footer
855 # Execute testsuite.
856 if grep -q ^testsuite $receipt; then
857 title 'Running testsuite'
858 testsuite $@ || { broken; exit 1; }
859 footer
860 fi
862 update_installed_cook_diff force
863 }
866 # Cook quality assurance.
868 cookit_quality() {
869 while true; do
870 [ ! -d "$WOK/$pkg/install" -a -z "$WANTED" ] || break
871 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
872 [ "$trials" == 'yes' ] || break
873 title "Interactive mode"
874 # TODO: allow commands:
875 # q - quit; v - edit receipt here using vi;
876 # s - search for package containing package;
877 # <package name> - install package; [Enter] - retry
878 _ 'You may install the packages here and/or edit the receipt there.'
879 newline
880 while true; do
881 _n 'Install the package? [name/N] '; read answer
882 [ -n "$answer" ] || break
883 tazpkg -gi $answer --root=$root --local --quiet --cookmode
884 done
885 newline
886 _n 'Try again? [Y/n] '; read answer
887 [ "$answer" == 'n' ] && break
888 # here you may append log if you want (">>" instead of last ">")
889 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
890 done
892 [ "${COOKOPTS/skip-log-errors/}" != "$COOKOPTS" ] && return 0
894 # ERROR can be echoed any time in cookit()
895 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
896 grep -Eq "(^ERROR|undefined reference to)" ; then
897 debug_info | tee -a $LOGS/$pkg.log
898 put_status $pkg Failed
899 rm -f $command
900 broken; exit 1
901 fi
902 }
905 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
906 # but it doesn't handle EXTRAVERSION.
908 packit() {
909 set_paths "$1"
910 PACKAGE="${1:-$PACKAGE}"
912 # Handle cross compilation
913 case "$ARCH" in
914 arm*|x86_64) arch="-$ARCH" ;;
915 esac
917 title 'Pack: %s' "$PACKAGE $VERSION$arch"
919 # Get set name for specified package from $SPLIT variable
920 local set=$(echo -n $SPLIT \
921 | awk -vpkg="$PACKAGE" '
922 BEGIN { RS = " "; FS = ":"; }
923 { if ($1 == pkg && $2 != "") { print "-" $2; exit; } }')
924 # Change set, make filelist and folderlist for new set
925 export src="$src$set"
926 export install="$install$set"
927 export DESTDIR="$install"
929 if grep -q ^genpkg_rules $receipt; then
930 _ 'Executing: %s' 'genpkg_rules'
931 set -e; cd $pkgdir; mkdir -p $fs
932 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
933 $LOGS/$pkg.log
934 else
935 _ 'No packages rules: meta package'
936 mkdir -p $fs
937 fi
939 # Check CONFIG_FILES
940 if [ -n "$CONFIG_FILES" ]; then
941 unset IFS
942 for i in $CONFIG_FILES; do
943 if [ ! -e $fs$i ]; then
944 case $i in
945 */) mkdir -p $fs$i ;;
946 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
947 esac
948 fi
949 done
950 fi
952 # First QA check to stop now if genpkg_rules failed.
953 lerror=$(_n 'ERROR')
954 if fgrep -q ^$lerror $LOGS/$pkg.log; then
955 broken; exit 1
956 fi
958 cd $taz
959 action 'Copying "%s"...' 'receipt'
960 export PACKAGE DEPENDS PROVIDE SUGGESTED TAZPANEL_DAEMON TAGS CAT CONFIG_FILES
961 @@PREFIX@@/libexec/cookutils/mk_pkg_receipt "$(realpath ../receipt)" > $pack/receipt
962 chown 0.0 $pack/receipt; status
964 unset desc
965 [ "$pkg" == "$PACKAGE" -a -f "../description.txt" ] && desc="../description.txt"
966 [ -f "../description.$PACKAGE.txt" ] && desc="../description.$PACKAGE.txt"
967 if [ -n "$desc" ]; then
968 action 'Copying "%s"...' "$(basename "$desc")"
969 cp -f $desc $pack/description.txt; chown 0.0 $pack/description.txt; status
970 fi
972 copy_generic_files
974 # Strip and stuff files.
975 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
977 # Create files.list with redirecting find output.
978 action 'Creating the list of files...'
979 cd $fs
980 find . -type f -print > ../files.list
981 find . -type l -print >> ../files.list
982 cd ..; sed -i 's|^.||' files.list
983 status
985 # Md5sum of files.
986 action 'Creating md5sum of files...'
987 while read file; do
988 [ -L "fs$file" ] && continue
989 [ -f "fs$file" ] || continue
990 case "$file" in
991 /lib/modules/*/modules.*|*.pyc) continue ;;
992 esac
993 md5sum "fs$file" | sed 's| fs| |'
994 done < files.list | sort -k2 > md5sum
995 status
997 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
998 2>/dev/null | awk 'END{ print $1 }')
1000 # Build cpio archive.
1001 action 'Compressing the FS...'
1002 find fs -newer $receipt -exec touch -hr $receipt '{}' \;
1003 # find fs | cpio -o -H newc --quiet | lzma-alone e fs.cpio.lzma -si
1004 find fs | cpio -o -H newc --quiet | /bin/lzma -qzeT0 >fs.cpio.lzma
1005 mv fs ../
1006 status
1008 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
1009 2>/dev/null | awk 'END{ print $1 }')
1011 action 'Updating receipt sizes...'
1012 sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
1013 sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
1014 status
1016 # Set extra version.
1017 if [ -n "$EXTRAVERSION" ]; then
1018 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
1019 sed -i '/^EXTRAVERSION=/d' receipt
1020 sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
1021 status
1022 fi
1024 # Compress.
1025 action 'Creating full cpio archive...'
1026 find . -newer $receipt -exec touch -hr $receipt '{}' \;
1027 find . | cpio -o -H newc --quiet > ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1028 status
1030 # Restoring original package tree.
1031 mv ../fs .
1033 rm fs.cpio.lzma; cd ..
1035 # QA and give info.
1036 tazpkg=$(ls *.tazpkg)
1037 packit_quality
1038 footer "$(_ 'Package "%s" created' "$tazpkg")"
1042 # Verify package quality and consistency.
1044 packit_quality() {
1045 local arch=''
1046 case "$ARCH" in
1047 arm*|x86_64) arch="-$ARCH" ;;
1048 esac
1050 local rsum rsumold='' rsum_changed old_file
1051 local pi="$PKGS/packages.info" fl="$cache/files.list"
1052 local pkg_file="$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg"
1053 local rsum_file=$(mktemp) rsum_file_old=$(mktemp) tmpdir=$(mktemp -d)
1056 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ]; then
1057 # Exit if any error found in log file.
1058 if fgrep -q ^ERROR $LOGS/$pkg.log; then
1059 rm -f $command
1060 broken; exit 1
1061 fi
1062 fi
1065 [ -n "$CAT" ] && CATEGORY="${CAT%|*}" # allow meta-packages in v2 receipts
1067 if [ "${COOKOPTS/empty-pkg/}" == "$COOKOPTS" ]; then
1068 action 'QA: checking for empty package...'
1069 if [ ! -s "$pack/files.list" -a "$CATEGORY" != 'meta' ]; then
1070 broken
1071 rm -f $command
1072 false; status
1073 die 'ERROR: empty package'
1074 fi
1075 :; status
1076 fi
1079 # Calculate release checksum: usually it does not change on "just recook".
1080 # Release checksum is md5sum of file containing md5sums of:
1081 # a) all files, b) receipt, and c) description.txt.
1082 # Md5sum of the package file will change every time because of embedded timestamps;
1083 # release checksum based only on files content, and will change only when files change.
1084 # (Pitfall: ownership and permissions...)
1086 # Calculate rsum for new package
1087 cp $pack/md5sum $rsum_file
1088 md5sum $pack/receipt | sed 's| [^ ]*/| |' >> $rsum_file
1089 [ -e "$pack/description.txt" ] &&
1090 md5sum $pack/description.txt | sed 's| [^ ]*/| |' >> $rsum_file
1091 rsum=$(md5sum $rsum_file | awk '{print $1}')
1093 # Calculate rsum for existing previous "old" package
1094 if [ -f "$pkg_file" ]; then
1095 # don't trust database entry, check the package file
1096 cd $tmpdir
1097 cpio -F "$pkg_file" -i md5sum receipt description.txt >/dev/null 2>&1
1098 cp ./md5sum $rsum_file_old
1099 md5sum ./receipt | sed 's| [^ ]*/| |' >> $rsum_file_old
1100 [ -e "./description.txt" ] &&
1101 md5sum ./description.txt | sed 's| [^ ]*/| |' >> $rsum_file_old
1102 rsumold=$(md5sum $rsum_file_old | awk '{print $1}')
1103 cd - >/dev/null
1104 fi
1106 # Clean
1107 rm $rsum_file $rsum_file_old
1108 rm -r $tmpdir
1111 touch $pi $broken
1114 # Find and remove old package only if "release checksum" has changed
1116 if [ "$rsum" != "$rsumold" ]; then
1117 old_file=$(awk -F$'\t' -vname="$PACKAGE" -varch="$arch" '{
1118 if ($1 == name) printf("%s-%s%s.tazpkg", $1, $2, arch);
1119 }' $pi) # <name>-<version><extra_version><-arch>.tazpkg
1120 if [ -f "$PKGS/$old_file" ]; then
1121 action 'Removing old package "%s"' "$old_file"
1122 rm -f "$PKGS/$old_file"
1123 status
1124 fi
1125 # package changed, substitute old package by new one
1126 mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg $PKGS
1127 _ 'The release checksum has changed.'
1128 else
1129 # package not changed, remove new package
1130 rm -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
1131 _ 'The release checksum has not changed.'
1132 fi
1135 sed -i "/^${pkg}$/d" $broken
1138 # Update packages database every time after successful build
1140 # packages.info (unsorted, located near to packages)
1141 unset_receipt; . $pack/receipt
1142 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
1143 DEPENDS=$(echo $DEPENDS) # remove newlines, tabs and multiple spaces from variable
1144 sed -i "/^$PACKAGE\t/d" $pi # remove old entry
1145 cat >> $pi <<EOT
1146 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $rsum $PROVIDE
1147 EOT
1149 # files.list (uncompressed, unsorted, located in $cache)
1150 touch $fl
1151 sed -i "/^$PACKAGE: /d" $fl
1152 sed "s/^/$PACKAGE: \0/" $pack/files.list >> $fl
1156 # Return all the names of packages bundled in this receipt
1158 all_names() {
1159 # Get package names from $SPLIT variable
1160 local split=$(echo $SPLIT \
1161 | awk '
1162 BEGIN { RS = " "; FS = ":"; }
1163 { print $1; }' \
1164 | tr '\n' ' ')
1165 local split_space=" $split "
1166 if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
1167 # For receipts v1: $SPLIT may present in the $WANTED package,
1168 # but split packages have their own receipts
1169 echo $PACKAGE
1170 elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
1171 # $PACKAGE included somewhere in $SPLIT (probably in the end).
1172 # We should build packages in the order defined in the $SPLIT.
1173 echo $split
1174 else
1175 # We'll build the $PACKAGE, then all defined in the $SPLIT.
1176 echo $PACKAGE $split
1177 fi
1181 # v2: pack all packages using compiled files
1183 packall() {
1184 set_paths
1185 if head -n1 "$pkgdir/receipt" | fgrep -q 'v2'; then
1186 for i in $(all_names); do
1187 unset TAGS DEPENDS CAT CONFIG_FILES PROVIDE SUGGESTED DATABASE_FILES TAZPANEL_DAEMON
1188 packit $i
1189 done
1190 else
1191 packit
1192 fi
1196 # Reverse "cat" command: prints input lines in the reverse order
1198 tac() {
1199 sed '1!G;h;$!d' $1
1203 # Update chroot with freshly rebuilt package: keep env up-to-date.
1205 update_chroot() {
1206 local PACKAGE="$pkg"
1207 for i in $(all_names); do
1208 if [ -d "$root$INSTALLED/$i" ]; then
1209 . /etc/slitaz/cook.conf
1210 . $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/receipt
1211 _ 'Updating %s chroot environment...' "$ARCH"
1212 _ 'Updating chroot: %s' "$i ($VERSION$EXTRAVERSION$arch)" | log
1213 cd $PKGS
1214 tazpkg -i "$PKGS/$i-$VERSION$EXTRAVERSION$arch.tazpkg" --forced --root=$root
1215 fi
1216 done
1220 # Install package on --inst or update the chroot.
1222 install_package() {
1223 set_paths
1224 case "$ARCH" in
1225 arm*)
1226 arch="-$ARCH"
1227 root="$CROSS_TREE/sysroot"
1228 ;;
1229 x86_64)
1230 arch="-$ARCH"
1231 ;;
1232 esac
1233 # Install package if requested but skip install if target host doesn't
1234 # match build system or it will break the build chroot.
1235 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
1236 if [ -n "$inst" -a "$build" == "$ARCH" ]; then
1237 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" ]; then
1238 cd $PKGS
1239 tazpkg -i "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg" --forced
1240 else
1241 broken
1242 die 'Unable to install package, build has failed.'
1243 fi
1244 fi
1246 update_chroot
1250 # remove chroot jail
1252 umount_aufs() {
1253 tac ${1}rw/aufs-umount.sh | sh
1254 rm -rf ${1}rw
1255 umount ${1}root
1256 rmdir ${1}r*
1260 # Launch the cook command into a chroot jail protected by aufs.
1261 # The current filesystems are used read-only and updates are
1262 # stored in a separate branch.
1264 try_aufs_chroot() {
1266 base="/dev/shm/aufsmnt$$"
1268 # Can we setup the chroot? Is it already done?
1269 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1270 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1271 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1272 grep -q ^aufs /proc/modules || modprobe aufs 2>/dev/null || return
1273 mkdir ${base}root ${base}rw || return
1275 _ 'Setup aufs chroot...'
1277 # Sanity check
1278 for i in / /proc /sys /dev /dev/shm /home; do
1279 case " $AUFS_MOUNTS " in
1280 *\ $i\ *) ;;
1281 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1282 esac
1283 done
1284 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1285 mkdir -p ${base}root$mnt # for `mount -o bind`
1286 mount -o bind $mnt ${base}root$mnt # use `-o bind` instead of `--bind`
1287 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1288 _ 'Aufs mount failure'
1289 umount ${base}root
1290 rm -rf ${base}r*
1291 return
1292 fi
1293 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1294 done
1295 trap "umount_aufs ${base}" INT
1297 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1298 status=$?
1300 _ 'Leaving aufs chroot...'
1301 umount_aufs $base
1302 # Install package outside the aufs jail
1303 install_package
1304 exit $status
1308 # Encode predefined XML entities
1310 xml_ent() {
1311 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1315 # Create a XML feed for freshly built packages.
1317 gen_rss() {
1318 pubdate=$(date '+%a, %d %b %Y %X')
1319 cat > $FEEDS/$pkg.xml <<EOT
1320 <item>
1321 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1322 <link>${COOKER_URL}?pkg=${PACKAGE//+/%2B}</link>
1323 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1324 <pubDate>$pubdate</pubDate>
1325 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1326 </item>
1327 EOT
1331 # Truncate stdout log file to $1 Mb.
1333 loglimit() {
1334 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1335 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1336 else
1337 tee /dev/stderr
1338 fi
1343 # Receipt functions to ease packaging
1346 get_dev_files() {
1347 action 'Getting standard devel files...'
1348 mkdir -p $fs/usr/lib
1349 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1350 cp -a $install/usr/lib/*a $fs/usr/lib
1351 cp -a $install/usr/include $fs/usr
1352 status
1356 # Function to use in compile_rules() to copy man page from $src to $install
1358 cook_pick_manpages() {
1359 local name section
1360 action 'Copying man pages...'
1362 for i in $@; do
1363 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1364 section=${name##*/}; section=${section##*.}
1365 mkdir -p $install/usr/share/man/man$section
1366 scopy $i $install/usr/share/man/man$section
1367 done
1368 status
1372 # Function to use in compile_rules() to copy documentation from $src to $install
1374 cook_pick_docs() {
1375 local docdir="$install/usr/share/doc/$PACKAGE-$VERSION"
1376 action 'Copying documentation...'
1377 mkdir -p $docdir
1378 cp -r $@ $docdir
1379 chmod -R a+r $docdir
1380 status
1384 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1386 cook_copy_files() {
1387 action 'Copying files...'
1388 cd $install
1389 local i j
1390 IFS=$'\n'
1391 for i in $@; do
1392 for j in $(find . -name $i ! -type d); do
1393 mkdir -p $fs$(dirname ${j#.})
1394 scopy $j $fs$(dirname ${j#.})
1395 done
1396 done
1397 cd - >/dev/null
1398 status
1402 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1404 cook_copy_folders() {
1405 action 'Copying folders...'
1406 cd $install
1407 local i j
1408 IFS=$'\n'
1409 for i in $@; do
1410 for j in $(find . -name $i -type d); do
1411 mkdir -p $fs$(dirname ${j#.})
1412 cp -a $j $fs$(dirname ${j#.})
1413 done
1414 done
1415 cd - >/dev/null
1416 status
1420 # Remove from current $fs files that are already packed (for receipts v2).
1421 # Note: the order in $SPLIT is very important.
1422 # Note 2: working in the current set.
1424 remove_already_packed() {
1425 local i j
1426 # $pkg is the name of the main package; $PACKAGE is the name of the current one
1427 # $pkg may (or may not) be included in the $SPLIT
1428 neighbors=$(
1429 echo $pkg $SPLIT" " \
1430 | awk -F$'\t' -vpkg="$PACKAGE" '
1431 BEGIN { RS = " "; FS = ":"; }
1432 { set[$1] = $2; }
1433 END {
1434 current_set = set[pkg];
1435 for (i in set)
1436 { if (i != pkg && set[i] == current_set) print i; }
1438 ')
1439 IFS=$'\n'
1440 for neighbor in $neighbors; do
1441 i="$taz/$neighbor-$VERSION$EXTRAVERSION/files.list"
1442 [ -e "$i" ] || continue
1443 while read j; do
1444 [ -f $fs$j -o -h $fs$j ] || continue
1445 rm $fs$j
1446 rmdir --parents --ignore-fail-on-non-empty $fs$(dirname $j)
1447 done < $i
1448 done
1449 unset IFS
1453 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1454 # (default: 16 and 48) from $install to $fs
1456 cook_copy_icons() {
1457 local sizes=$@ i j ifs="$IFS"
1458 unset IFS
1459 action 'Copying hicolor icons...'
1460 [ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
1461 mkdir -p $fs/usr/share/icons/hicolor
1462 for i in ${sizes:-16 48}; do
1463 j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
1464 [ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
1465 scopy $install/usr/share/icons/hicolor/$j \
1466 $fs/usr/share/icons/hicolor
1467 done
1468 status
1469 IFS="$ifs"
1473 # Common function to copy files, folders and patterns
1475 copy() {
1476 action 'Copying folders and files...'
1477 local i j k filelist=$(mktemp) folderlist=$(mktemp)
1479 IFS=$'\n'
1480 cd $install
1481 find ! -type d | sed 's|\.||' > $filelist
1482 find -type d | sed 's|\.||' > $folderlist
1484 for i in $@; do
1485 case $i in
1486 @std)
1487 # Copy "standard" files (all but "developer files", man pages, documentation, translations)
1488 sed '/\.h$/d; /\.hxx$/d; /\.a$/d; /\.la$/d; /\.pc$/d; /\.pri$/d; /bin\/.*-config$/d;
1489 /\.m4$/d; /\.gir$/d; /\.typelib$/d; /\.vapi$/d; /\.deps$/d; /\.cmake$/d;
1490 /\/Makefile.*/d; /\.inc$/d; /\/include\//d;
1491 /\/share\/man\//d; /\/share\/doc\//d; /\/share\/gtk-doc\//d; /\/share\/info\//d;
1492 /\/share\/devhelp\//d; /\/share\/locale\//d;
1493 /\/share\/bash-completion\//d; /\/etc\/bash_completion\.d\//d; /\/lib\/systemd\//d;
1494 /\/fonts\.scale$/d; /\/fonts\.dir$/d;
1495 /\/share\/appdata\//d; /\/share\/help\//d;
1496 /\/share\/icons\/hicolor\/[12356][1245][268]*x[12356][1245][268]*\//d; # 22, 24, 32, 64, 128, 256, 512
1497 /\.so\.dbg$/d;
1498 ' $filelist
1499 ;;
1500 @dev)
1501 # Copy "developer files"
1502 sed -n '/\.h$/p; /\.hxx$/p; /\.a$/p; /\.pc$/p; /\.pri$/p; /bin\/.*-config$/p;
1503 /\.m4$/p; /\.gir$/p; /\.typelib$/p; /\.vapi$/p; /\.deps$/p; /\.cmake$/p;
1504 /\/Makefile.*/p; /\.inc$/p; /\/include\//p;
1505 /\.so\.dbg$/p;
1506 ' $filelist
1507 ;;
1508 @rm)
1509 # Quick alias
1510 remove_already_packed
1511 ;;
1512 @ico)
1513 # Quick alias
1514 cook_copy_icons >/dev/null
1515 ;;
1516 */)
1517 # Copy specified folders.
1518 i="${i%/}"
1519 find -type d -path "*/${i#/}" | sed 's|^.||'
1520 ;;
1521 *)
1522 # Copy specified files.
1523 find ! -type d -path "*/${i#/}" | sed 's|^.||'
1524 ;;
1525 esac \
1526 | sort -u \
1527 | while read j; do
1528 mkdir -p $fs$(dirname "$j")
1529 if [ -d "$install$j" ]; then
1530 cp -a "$install$j" $fs$(dirname "$j")
1531 else
1532 scopy "$install$j" $fs$(dirname "$j")
1533 fi
1534 done
1535 # Copy empty directories
1536 case $i in
1537 @std)
1538 while read j; do
1539 case $j in
1540 # skip empty man & doc folders
1541 */man/*|*/doc/*) continue;;
1542 esac
1543 [ -z "$(ls -A "$install$j")" ] || continue
1544 # directory $j is empty
1545 k="$j"
1546 # make 'ladder' from directories, from root dir to $j
1547 # /a /a/b /a/b/c etc.
1548 while :; do
1549 [ -z "$k" ] && break
1550 echo "$k"
1551 k="${k%/*}"
1552 done \
1553 | tac \
1554 | while read k; do
1555 # make dir if it does not exist
1556 if [ ! -d "$fs$k" ]; then
1557 # It's like "copy the directory without its underlying content".
1558 # keep original ownership/permissions, access:
1559 keepIFS="$IFS"; unset IFS
1560 install -d $(stat -c'-o%u -g%g -m%a' "$install$k") "$fs$k"
1561 # keep last-modified date:
1562 touch -r "$install$k" "$fs$k"
1563 IFS="$keepIFS"; unset keepIFS
1564 fi
1565 done
1566 done < $folderlist
1567 ;;
1568 esac
1569 done
1570 cd - >/dev/null
1571 unset IFS
1572 rm $filelist $folderlist
1573 status
1577 # Update split.db once for receipt
1579 update_split_db() {
1580 local db="$cache/split.db"
1581 touch $db
1582 sed -i "/^$pkg\t/d" $db
1583 echo -e "$pkg\t$(all_names)" >> $db
1587 # Recreate whole split.db from scratch
1589 recreate_split_db() {
1590 # Clean
1591 local db="$cache/split.db"
1592 touch $db
1593 > $db
1595 cd $WOK
1596 for pkg in *; do
1597 [ -f "$WOK/$pkg/receipt" ] || continue
1598 unset PACKAGE SPLIT
1599 . $WOK/$pkg/receipt
1600 echo -e "$PACKAGE\t$(all_names)" >> $db
1601 done
1605 # Put the status to the activity log
1607 put_status() {
1608 # $1: package, $2: status, one of 'Done', 'Failed'
1609 sed -i "s|>$1</a>$|& [ $2 ]|" $activity
1610 if [ "$2" == 'Done' ]; then
1611 # overstrike all previous 'Failed' to indicate package is OK now
1612 sed -i "/>$1<\/a>/ s|\[ Failed \]|[ -Failed ]|" $activity
1613 fi
1620 # Commands
1623 # cook <package> --deps
1624 [ -n "$deps" ] && {
1625 @@PREFIX@@/libexec/cookutils/deps $1
1626 exit 0
1629 # cook <package> --clean
1630 # cook <package> -c
1631 [ -n "$clean" -o "$2" == '-c' ] && {
1632 action 'Cleaning "%s"' "$1"
1633 cd $WOK/$1; rm -rf install taz source
1634 status; newline
1635 touch $activity # update $activity -> something changed -> update webstat
1636 exit 0
1639 # cook <package> --getsrc
1640 # cook <package> -gs
1641 [ -n "$getsrc" -o "$2" == '-gs' ] && {
1642 title 'Getting source for "%s"' "$1"
1643 receipt="$WOK/$pkg/receipt"
1644 check_pkg_in_wok
1645 unset_receipt
1646 . $receipt
1647 get_source
1648 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1649 exit 0
1652 # cook <package> --block
1653 # cook <package> -b
1654 [ -n "$block" -o "$2" == '-b' ] && {
1655 action 'Blocking package "%s"' "$1"
1656 [ $(grep "^$1$" $blocked) ] || echo "$1" >> $blocked
1657 status; newline
1658 touch $activity
1659 exit 0
1662 # cook <package> --unblock
1663 # cook <package> -ub
1664 [ -n "$unblock" -o "$2" == '-ub' ] && {
1665 action 'Unblocking package "%s"' "$1"
1666 sed -i "/^$1$/d" $blocked
1667 status; newline
1668 touch $activity
1669 exit 0
1675 case "$1" in
1676 usage|help|-u|-h)
1677 usage ;;
1679 list-wok)
1680 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1681 cd $WOK
1682 if [ "$ARCH" != 'i486' ]; then
1683 count=0
1684 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1685 do
1686 unset HOST_ARCH
1687 . ./$pkg
1688 count=$(($count + 1))
1689 colorize 34 "$PACKAGE"
1690 done
1691 else
1692 count=$(ls | wc -l)
1693 ls -1
1694 fi
1695 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1696 ;;
1698 activity)
1699 cat $activity ;;
1701 search)
1702 # Just a simple search function, we don't need more actually.
1703 query="$2"
1704 title 'Search results for "%s"' "$query"
1705 cd $WOK; ls -1 | grep "$query"
1706 footer ;;
1708 setup)
1709 # Setup a build environment
1710 check_root
1711 _ 'Cook: setup environment' | log
1712 title 'Setting up your environment'
1713 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1714 cd $SLITAZ
1715 init_db_files
1716 _ 'Checking for packages to install...'
1717 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1718 # ARCH-setup or 'cross check' should be used before: cook setup
1719 case "$ARCH" in
1720 arm*|x86_64)
1721 [ -x '/usr/bin/cross' ] || die 'ERROR: %s is not installed' 'cross'
1722 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1723 . /etc/slitaz/cross.conf ;;
1724 esac
1725 for pkg in $SETUP_PKGS; do
1726 if [ -n "$forced" ]; then
1727 tazpkg -gi $pkg --forced
1728 else
1729 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1730 fi
1731 done
1733 # Handle --options
1734 case "$2" in
1735 --wok) hg clone $WOK_URL wok || exit 1 ;;
1736 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1737 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1738 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1739 esac
1741 # SliTaz group and permissions
1742 if ! grep -q ^slitaz /etc/group; then
1743 _ 'Adding group "%s"' 'slitaz'
1744 addgroup slitaz
1745 fi
1746 _ 'Setting permissions for group "%s"...' 'slitaz'
1747 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1748 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1749 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1751 *-setup)
1752 # Setup for cross compiling.
1753 arch="${1%-setup}"
1754 check_root
1755 . /etc/slitaz/cook.conf
1756 for pkg in $CROSS_SETUP; do
1757 if [ -n "$forced" ]; then
1758 tazpkg -gi $pkg --forced
1759 else
1760 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1761 fi
1762 done
1764 _ 'Cook: setup %s cross environment' "$arch" | log
1765 title 'Setting up your %s cross environment' "$arch"
1766 init_db_files
1767 sed -i \
1768 -e "s|ARCH=.*|ARCH=\"$arch\"|" \
1769 -e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
1770 -e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
1771 /etc/slitaz/cook.conf
1772 case "$arch" in
1773 arm)
1774 flags='-O2 -march=armv6'
1775 host="$ARCH-slitaz-linux-gnueabi" ;;
1776 armv6hf)
1777 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1778 host="$ARCH-slitaz-linux-gnueabi" ;;
1779 armv7)
1780 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1781 host="$ARCH-slitaz-linux-gnueabi" ;;
1782 x86_64)
1783 flags='-O2 -mtune=generic -pipe'
1784 host="$ARCH-slitaz-linux" ;;
1785 esac
1786 sed -i \
1787 -e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
1788 -e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
1789 . /etc/slitaz/cook.conf
1790 sysroot="$CROSS_TREE/sysroot"
1791 tools="/cross/$arch/tools"
1792 root="$sysroot"
1793 # L10n: keep the same width of translations to get a consistent view
1794 _ 'Target arch : %s' "$ARCH"
1795 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1796 _ 'Build flags : %s' "$flags"
1797 _ 'Arch sysroot : %s' "$sysroot"
1798 _ 'Tools prefix : %s' "$tools/bin"
1799 # Tell the packages manager where to find packages.
1800 _ 'Packages DB : %s' "$root$DB"
1801 mkdir -p $root$INSTALLED
1802 cd $root$DB; rm -f *.bak
1803 for list in packages.list packages.desc packages.equiv packages.md5; do
1804 rm -f $list
1805 ln -s $SLITAZ/packages/$list $list
1806 done
1807 # We must have the cross compiled glibc-base installed or default
1808 # i486 package will be used as dep by tazpkg and then break the
1809 # cross environment
1810 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1811 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1812 fi
1813 # Show GCC version or warn if not yet compiled.
1814 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1815 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1816 else
1817 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1818 _ 'Run "%s" to cook a toolchain' 'cross compile'
1819 fi
1820 footer ;;
1822 test)
1823 # Test a cook environment.
1824 _ 'Cook test: testing the cook environment' | log
1825 [ ! -d "$WOK" ] && exit 1
1826 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1827 cook cooktest ;;
1829 new)
1830 # Create the package folder and an empty receipt.
1831 pkg="$2"
1832 [ -z "$pkg" ] && usage
1833 newline
1834 [ -d "$WOK/$pkg" ] && die 'Package "%s" already exists.' "$pkg"
1836 action 'Creating folder "%s"' "$WOK/$pkg"
1837 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1839 action 'Preparing the package receipt...'
1840 cp $DATA/receipt .
1841 sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
1842 status; newline
1844 # Interactive mode, asking and seding.
1845 case "$3" in
1846 --interactive|-x)
1847 _ 'Entering interactive mode...'
1848 separator
1849 _ 'Package : %s' "$pkg"
1851 _n 'Version : ' ; read answer
1852 sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
1854 _n 'Category : ' ; read answer
1855 sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
1857 # L10n: Short description
1858 _n 'Short desc : ' ; read answer
1859 sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
1861 _n 'Maintainer : ' ; read answer
1862 sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
1864 _n 'License : ' ; read answer
1865 sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
1867 _n 'Web site : ' ; read answer
1868 sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
1869 newline
1871 # Wget URL.
1872 _ 'Wget URL to download source tarball.'
1873 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1874 _n 'Wget url : ' ; read answer
1875 sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1877 # Ask for a stuff dir.
1878 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1879 if [ "$?" -eq 0 ]; then
1880 action 'Creating the stuff directory...'
1881 mkdir $WOK/$pkg/stuff; status
1882 fi
1884 # Ask for a description file.
1885 confirm "$(_n 'Are you going to write a description? (y/N)')"
1886 if [ "$?" -eq 0 ]; then
1887 action 'Creating the "%s" file...' 'description.txt'
1888 touch $WOK/$pkg/description.txt; status
1889 fi
1891 footer "$(_ 'Receipt is ready to use.')" ;;
1892 esac ;;
1894 list)
1895 # Cook a list of packages (better use the Cooker since it will order
1896 # packages before executing cook).
1897 check_root
1898 [ -z "$2" ] && die 'No list in argument.'
1899 [ -f "$2" ] || die 'List "%s" not found.' "$2"
1901 _ 'Starting cooking the list "%s"' "$2" | log
1903 while read pkg; do
1904 cook $pkg || broken
1905 done < $2
1906 ;;
1908 clean-wok)
1909 check_root
1910 newline; action 'Cleaning all packages files...'
1911 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1912 status; newline ;;
1914 clean-src)
1915 check_root
1916 newline; action 'Cleaning all packages sources...'
1917 rm -rf $WOK/*/source
1918 status; newline ;;
1920 uncook)
1921 cd $WOK
1922 count=0
1923 title 'Checking for uncooked packages'
1925 for i in *; do
1926 unset HOST_ARCH EXTRAVERSION
1927 [ ! -e $i/receipt ] && continue
1928 . ./$i/receipt
1929 # Source cooked pkg receipt to get EXTRAVERSION
1930 if [ -d "$WOK/$i/taz" ]; then
1931 cd $WOK/$i/taz/$(ls $WOK/$i/taz/ | head -n1)
1932 . ./receipt; cd $WOK
1933 fi
1934 case "$ARCH" in
1935 i486)
1936 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1937 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1938 count=$(($count + 1))
1939 colorize 34 "$i"
1940 fi ;;
1941 arm*)
1942 # Check only packages included in arch
1943 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1944 # *.tazpkg
1945 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1946 count=$(($count + 1))
1947 colorize 34 "$i"
1948 fi
1949 fi ;;
1950 esac
1951 done
1953 if [ "$count" -gt 0 ]; then
1954 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1955 else
1956 _ 'All packages are cooked :-)'
1957 newline
1958 fi
1959 ;;
1961 pkgdb)
1962 # Create suitable packages list for TazPkg and only for built packages
1963 # as well as flavors files for TazLiTo. We don't need logs since we do it
1964 # manually to ensure everything is fine before syncing the mirror.
1965 recreate_split_db
1966 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1967 ;;
1969 splitdb)
1970 # File split.db is useful for searching for split packages.
1971 recreate_split_db
1972 ;;
1974 *)
1975 # Just cook and generate a package.
1976 check_root
1977 time=$(date +%s)
1978 pkg="$1"
1979 [ -z "$pkg" ] && usage
1981 # Search last successful cook time in all logs from newer to older
1982 for i in '' $(seq 0 9 | sed 's|^|.|'); do
1983 [ -f "$LOGS/$pkg.log$i" ] || break
1984 lastcooktime=$(sed '/^Cook time/!d; s|.*: *\([0-9]*\)s.*|\1|' \
1985 $LOGS/$pkg.log$i 2>/dev/null | sed '$!d')
1986 [ -n "$lastcooktime" ] && break
1987 done
1989 receipt="$WOK/$pkg/receipt"
1990 check_pkg_in_wok
1991 newline
1993 unset inst
1994 unset_receipt
1995 . $receipt
1997 # Handle cross compilation.
1998 case "$ARCH" in
1999 arm*)
2000 if [ -z "$HOST_ARCH" ]; then
2001 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
2002 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
2003 _ 'cook: %s' "$error"
2004 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2005 _ 'Cook skip: %s' "$error" | log
2006 newline
2007 broken; exit 1
2008 fi ;;
2009 esac
2011 # Some packages are not included in some arch or fail to cross compile.
2012 : ${HOST_ARCH=$ARCH}
2013 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
2014 # Handle arm{v6hf,v7,..}
2015 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
2016 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
2017 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
2018 _ 'cook: %s' "error"
2019 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
2020 _ 'Cook skip: %s' "$error" | log
2021 sed -i "/^${pkg}$/d" $broken
2022 newline
2023 exit 0
2024 fi
2026 # Skip blocked, 3 lines also for the Cooker.
2027 grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ] &&
2028 die 'Package "%s" is blocked' "$pkg"
2030 try_aufs_chroot "$@"
2032 # Log and source receipt.
2033 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=${pkg//+/%2B}'>$pkg</a>" | log
2034 echo "cook:$pkg" > $command
2036 [ -n "$lastcooktime" ] && echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
2038 while read cmd duration start; do
2039 [ $(($start + $duration)) -lt $(date +%s) ] &&
2040 echo "sed -i '/^$cmd $duration/d' $cooktime"
2041 done < $cooktime | sh
2043 # Display and log info if cook process stopped.
2044 # FIXME: gettext not working (in single quotes) here!
2045 trap '_ "\n\nCook stopped: control-C\n\n" | \
2046 tee -a $LOGS/$pkg.log' INT
2048 update_split_db
2050 # Handle --options
2051 case "$2" in
2052 --install|-i)
2053 inst='yes' ;;
2055 --pack)
2056 [ -d "$WOK/$pkg/install" ] || die 'Need to build "%s"' "$pkg"
2057 [ ! -d "$WOK/$pkg/taz" ] || rm -rf "$WOK/$pkg/taz"
2058 [ ! -f "$LOGS/$pkg-pack.log" ] || rm -rf $LOGS/$pkg-pack.log
2059 sed -i '$ s|$| (packing)|' $activity
2060 packall 2>&1 | tee -a $LOGS/$pkg-pack.log
2061 clean_log "$pkg-pack"
2062 time=$(($(date +%s) - $time))
2063 summary | sed 's|^Cook |Pack |' | tee -a $LOGS/$pkg-pack.log
2064 put_status $pkg Done
2065 rm -f $command
2066 exit 0 ;;
2068 --trials|-t)
2069 trials='yes' ;;
2070 esac
2072 # Rotate log
2073 for i in $(seq 9 -1 1); do
2074 j=$(($i - 1))
2075 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
2076 done
2077 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
2079 # Check if wanted is built now so we have separate log files.
2080 for wanted in $WANTED ; do
2081 if grep -q "^$wanted$" $blocked; then
2082 broken
2083 rm -f $command
2084 die 'WANTED package "%s" is blocked' "$wanted"
2085 fi
2086 if grep -q "^$wanted$" $broken; then
2087 broken
2088 rm -f $command
2089 die 'WANTED package "%s" is broken' "$wanted"
2090 fi
2091 if [ ! -d "$WOK/$wanted/install" ]; then
2092 cook "$wanted" || { broken; exit 1; }
2093 fi
2094 done
2096 # Cook and pack or exit on error and log everything.
2097 ((((cookit $@ 2>&1; echo $? >&3) | loglimit 50 > $LOGS/$pkg.log) 3>&1) | (read rq; exit $rq))
2098 rq=$? # the return code of `cookit $@` above command
2100 # Remove build dependencies both when `cookit` done or fail
2101 remove_deps | tee -a $LOGS/$pkg.log
2102 cookit_quality
2104 # Log and stop if `cookit` fails
2105 if [ $rq -eq 1 ]; then
2106 debug_info | tee -a $LOGS/$pkg.log
2107 put_status $pkg Failed
2108 rm -f $command
2109 broken; exit 1
2110 fi
2112 # Proceed only if `cookit` return code is zero-OK
2113 packall 2>&1 | loglimit 5 >> $LOGS/$pkg.log
2115 clean_log
2117 # Exit if any error in packing.
2118 if [ "${COOKOPTS/skip-log-errors/}" == "$COOKOPTS" ] &&
2119 grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
2120 grep -Eq "(^ERROR|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
2121 debug_info | tee -a $LOGS/$pkg.log
2122 put_status $pkg Failed
2123 rm -f $command
2124 broken; exit 1
2125 fi
2127 # Create an XML feed
2128 gen_rss
2130 # Time and summary
2131 time=$(($(date +%s) - $time))
2132 summary | tee -a $LOGS/$pkg.log
2133 newline
2135 # We may want to install/update (outside aufs jail!).
2136 [ -s /aufs-umount.sh ] || install_package
2138 put_status $pkg Done
2140 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
2141 # If you want automation, use the Cooker Build Bot.
2142 rm -f $command
2143 ;;
2144 esac
2146 exit 0