cookutils view cook @ rev 900

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