cookutils view cook @ rev 885

cook: fix copy_generic_files (for double copy)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 28 18:32:09 2017 +0100 (2017-02-28)
parents 30ca1ab8368a
children 9b02985442a0
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 if [ ! -d "$WOK/$pkg" ]; then
84 newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
85 exit 1
86 fi
87 }
90 if_empty_value() {
91 if [ -z "$value" ]; then
92 # L10n: QA is quality assurance
93 _ 'QA: empty variable: %s' "$var=\"\""; newline
94 exit 1
95 fi
96 }
99 # Initialize files used in $CACHE
101 init_db_files() {
102 _ 'Creating directories structure in "%s"' "$SLITAZ"
103 mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
104 _ 'Creating DB files in "%s"' "$CACHE"
105 for f in $activity $command $broken $blocked; do
106 touch $f
107 done
108 }
111 # QA: check a receipt consistency before building.
113 receipt_quality() {
114 _ 'QA: checking package receipt...'
115 unset online
116 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
117 online='online'
118 fi
119 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE; do
120 unset value
121 value="$(. $receipt; eval echo \$$var)"
122 case "$var" in
123 PACKAGE|VERSION|SHORT_DESC)
124 if_empty_value ;;
125 CATEGORY)
126 value="${value:-empty}"
127 valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
128 if ! echo " $valid " | grep -q " $value "; then
129 _ 'QA: unknown category "%s"' "$value"
130 longline "$(_ 'Please, use one of: %s' "$valid")"
131 newline
132 exit 1
133 fi ;;
134 WEB_SITE)
135 # We don't check WGET_URL since if dl is needed it will fail.
136 # Break also if we're not online. Here error is not fatal.
137 if_empty_value
138 [ -z "$online" ] && break
139 if ! busybox wget -T 12 -s $value 2>/dev/null; then
140 _ 'QA: unable to reach "%s"' "$value"
141 fi ;;
142 esac
143 done
144 }
147 # Paths used in receipt and by cook itself.
149 set_paths() {
150 pkgdir="$WOK/$PACKAGE"
151 . "$pkgdir/receipt"
152 basesrc="$pkgdir/source"
153 tmpsrc="$basesrc/tmp"
154 src="$basesrc/$PACKAGE-$VERSION"
155 taz="$pkgdir/taz"
156 pack="$taz/$PACKAGE-$VERSION$EXTRAVERSION"
157 fs="$pack/fs"
158 stuff="$pkgdir/stuff"
159 install="$pkgdir/install"
160 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
161 lzma_tarball="$pkgsrc.tar.lzma"
162 if [ -n "$PATCH" ]; then
163 [ -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
164 fi
165 if [ -n "$WANTED" ]; then
166 basesrc="$WOK/$WANTED/source"
167 src="$basesrc/$WANTED-$VERSION"
168 install="$WOK/$WANTED/install"
169 wanted_stuff="$WOK/$WANTED/stuff"
170 fi
171 if [ -n "$SOURCE" ]; then
172 source_stuff="$WOK/$SOURCE/stuff"
173 fi
174 # Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
175 if [ -f "$WOK/linux/receipt" ]; then
176 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d\" -f2)
177 kbasevers=${kvers:0:3}
178 elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
179 kvers=$(grep ^VERSION= $INSTALLED/linux-api-headers/receipt | cut -d\" -f2)
180 kbasevers=${kvers:0:3}
181 fi
182 # Python version
183 if [ -f "$WOK/python/receipt" ]; then
184 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d\" -f2)
185 fi
186 # Perl version for some packages needed it
187 if [ -f "$WOK/perl/receipt" ]; then
188 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d\" -f2)
189 fi
190 # Old way compatibility.
191 _pkg="$install"
192 }
195 # Create source tarball when URL is a SCM.
197 create_tarball() {
198 local tarball
199 tarball="$pkgsrc.tar.bz2"
200 [ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
201 _ 'Creating tarball "%s"' "$tarball"
202 if [ -n "$LZMA_SRC" ]; then
203 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
204 LZMA_SRC=''
205 else
206 tar -cjf $tarball $pkgsrc || exit 1
207 mv $tarball $SRC; rm -rf $pkgsrc
208 fi
209 TARBALL="$tarball"
210 }
213 # Get package source. For SCM we are in cache so clone here and create a
214 # tarball here.
216 get_source() {
217 local url
218 url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
219 set_paths
220 pwd=$(pwd)
221 case "$WGET_URL" in
222 http://*|ftp://*)
223 # Busybox Wget is better!
224 busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
225 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
226 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
228 https://*)
229 wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
230 busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
231 (_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
233 hg*|mercurial*)
234 if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
235 url=${WGET_URL#hg|}
236 else
237 url=${WGET_URL#mercurial|}
238 fi
239 _ 'Getting source from %s...' 'Hg'
240 _ 'URL: %s' "$url"
241 _ 'Cloning to "%s"' "$pwd/$pkgsrc"
242 if [ -n "$BRANCH" ]; then
243 _ 'Hg branch: %s' "$BRANCH"
244 hg clone $url --rev $BRANCH $pkgsrc || \
245 (_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
246 else
247 hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
248 fi
249 rm -rf $pkgsrc/.hg
250 create_tarball ;;
252 git*)
253 url=${WGET_URL#git|}
254 _ 'Getting source from %s...' 'Git'
255 _ 'URL: %s' "$url"
256 cd $SRC
257 git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
258 if [ -n "$BRANCH" ]; then
259 _ 'Git branch: %s' "$BRANCH"
260 cd $pkgsrc; git checkout $BRANCH; cd ..
261 fi
262 cd $SRC
263 create_tarball ;;
265 cvs*)
266 url=${WGET_URL#cvs|}
267 mod=$PACKAGE
268 [ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
269 _ 'Getting source from %s...' 'CVS'
270 _ 'URL: %s' "$url"
271 [ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
272 _ 'Cloning to "%s"' "$pwd/$mod"
273 cvs -d:$url co $mod && mv $mod $pkgsrc
274 create_tarball ;;
276 svn*|subversion*)
277 if $(echo "$WGET_URL" | fgrep -q "svn|"); then
278 url=${WGET_URL#svn|}
279 else
280 url=${WGET_URL#subversion|}
281 fi
282 _ 'Getting source from %s...' 'SVN'
283 _ 'URL: %s' "$url"
284 if [ -n "$BRANCH" ]; then
285 echo t | svn co $url -r $BRANCH $pkgsrc
286 else
287 echo t | svn co $url $pkgsrc
288 fi
289 create_tarball ;;
291 bzr*)
292 url=${WGET_URL#bzr|}
293 _ 'Getting source from %s...' 'bazaar'
294 cd $SRC
295 pkgsrc=${url#*:}
296 if [ -n "$BRANCH" ]; then
297 echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
298 bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
299 else
300 echo "bzr -Ossl.cert_reqs=none branch $url"
301 bzr -Ossl.cert_reqs=none branch $url
302 cd $pkgsrc; BRANCH=$(bzr revno); cd ..
303 _ "Don't forget to add to receipt:"
304 echo -e "BRANCH=\"$BRANCH\"\n"
305 fi
306 mv $pkgsrc $pkgsrc-$BRANCH
307 pkgsrc="$pkgsrc-$BRANCH"
308 create_tarball ;;
310 *)
311 (newline; _ 'ERROR: Unable to handle "%s"' "$WGET_URL"; newline) | \
312 tee -a $LOGS/$PACKAGE.log
313 exit 1 ;;
314 esac
315 }
318 # Extract source package.
320 extract_source() {
321 if [ ! -s "$SRC/$TARBALL" ]; then
322 local url
323 url="$MIRROR_URL/sources/packages"
324 url="$url/${TARBALL:0:1}/$TARBALL"
325 _ 'Getting source from %s...' 'mirror'
326 _ 'URL: %s' "$url"
327 busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
328 fi
329 _ 'Extracting source archive "%s"' "$TARBALL"
330 case "$TARBALL" in
331 *.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
332 *.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
333 *.tar.lzma) tar -xaf $SRC/$TARBALL ;;
334 *.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
335 *.tar) tar -xf $SRC/$TARBALL ;;
336 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
337 *.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
338 tar -xf $SRC/$TARBALL 2>/dev/null;;
339 *.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
340 *.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
341 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
342 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
343 *) cp $SRC/$TARBALL $(pwd) ;;
344 esac
345 }
348 # Display time.
350 disp_time() {
351 local sec div min
352 sec="$1"
353 div=$(( ($1 + 30) / 60))
354 case $div in
355 0) min='';;
356 # L10n: 'm' is for minutes (approximate cooking time)
357 *) min=$(_n ' ~ %dm' "$div");;
358 esac
360 # L10n: 's' is for seconds (cooking time)
361 _ '%ds%s' "$sec" "$min"
362 }
365 # Display cooked package summary.
367 summary() {
368 set_paths
369 cd $WOK/$pkg
370 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
371 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
372 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
373 size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
374 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
375 [ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
377 _ 'Summary for: %s' "$PACKAGE $VERSION"
378 separator
380 # L10n: keep the same width of translations to get a consistent view
381 [ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
382 [ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
383 [ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
384 [ -n "$prod" ] && _ 'Produced : %s' "$prod"
385 _ 'Packed : %s' "$fs"
386 _ 'Compressed : %s' "$size"
387 _ 'Files : %s' "$files"
388 _ 'Cook time : %s' "$(disp_time "$time")"
389 _ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
390 _ 'Host arch : %s' "$ARCH"
391 separator
392 }
395 # Display debugging error info.
397 debug_info() {
398 title 'Debug information'
399 # L10n: specify your format of date and time (to help: man date)
400 # L10n: not bad one is '+%x %R'
401 _ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
402 [ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
403 # L10n: Please, translate all messages beginning with ERROR in a same way
404 lerror=$(_n 'ERROR')
405 for error in \
406 ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
407 'error:' 'fatal error:' 'undefined reference to' \
408 'Unable to connect to' 'link: cannot find the library' \
409 'CMake Error' ': No such file or directory' \
410 'Could not read symbols: File in wrong format'
411 do
412 fgrep "$error" $LOGS/$pkg.log
413 done > $LOGS/$pkg.log.debug_info 2>&1
414 cat $LOGS/$pkg.log.debug_info
415 rm -f $LOGS/$pkg.log.debug_info
416 footer
417 }
420 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
421 # so some packages need to copy these files with the receipt and genpkg_rules.
423 copy_generic_files() {
424 # $LOCALE is set in cook.conf
425 if [ -n "$LOCALE" -a -z "$WANTED" ]; then
426 if [ -d "$install/usr/share/locale" ]; then
427 mkdir -p $fs/usr/share/locale
428 for i in $LOCALE; do
429 if [ -d "$install/usr/share/locale/$i" ]; then
430 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
431 fi
432 done
433 fi
434 fi
436 # Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
437 if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
438 if [ -d "$install/usr/share/pixmaps" ]; then
439 mkdir -p $fs/usr/share/pixmaps
440 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
441 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
442 $fs/usr/share/pixmaps
443 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
444 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
445 $fs/usr/share/pixmaps
446 fi
447 fi
449 # Custom or homemade PNG pixmap can be in stuff.
450 if [ -f "$stuff/$PACKAGE.png" ]; then
451 mkdir -p $fs/usr/share/pixmaps
452 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
453 fi
454 fi
456 # Desktop entry (.desktop).
457 # Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
458 if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
459 if [ -d "$install/usr/share/applications" ] && [ -z "$WANTED" ]; then
460 mkdir -p $fs/usr/share
461 cp -a $install/usr/share/applications $fs/usr/share
462 fi
463 fi
465 # Homemade desktop file(s) can be in stuff.
466 if [ -d "$stuff/applications" ]; then
467 mkdir -p $fs/usr/share
468 cp -a $stuff/applications $fs/usr/share
469 fi
470 if [ -f "$stuff/$PACKAGE.desktop" ]; then
471 mkdir -p $fs/usr/share/applications
472 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
473 fi
475 # Add custom licenses
476 if [ -d "$stuff/licenses" ]; then
477 mkdir -p $fs/usr/share/licenses
478 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
479 fi
480 }
483 # Remove files provided by split packages
484 # For example:
485 # 1. Package "pkg-main":
486 # SPLIT="pkg-1 pkg-2 pkg-extra"
487 # 2. Package="pkg-extra":
488 # WANTED="pkg-main"
489 # BUILD_DEPENDS="pkg-1 pkg-2"
490 # cook_copy_folders usr
491 # cook_split_rm $BUILD_DEPENDS
493 cook_split_rm() {
494 for i in $@; do
495 action 'Remove files provided by split package %s...' "$i"
496 while read j; do
497 [ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
498 rmdir "$(dirname "$fs$j")" 2>/dev/null
499 done < $WOK/$i/taz/$i-$VERSION/files.list
500 :; status
501 done
502 }
505 # Update installed.cook.diff
507 update_installed_cook_diff() {
508 # If a cook failed deps are removed.
509 cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
510 cd $CACHE
511 [ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
512 busybox diff installed.list installed.cook > /tmp/installed.cook.diff
513 deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
514 }
517 # Remove installed deps.
519 remove_deps() {
520 # Now remove installed build deps.
521 diff='/tmp/installed.cook.diff'
522 if [ -s $diff ]; then
523 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
524 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
525 _n 'Build dependencies to remove:'; echo " $nb"
526 [ -n "$root" ] && echo "root=\"$root\""
527 _n 'Removing:'
528 for dep in $deps; do
529 echo -n " $dep"
530 echo 'y' | tazpkg remove $dep --root=$root >/dev/null
531 done
532 newline; newline
533 # Keep the last diff for debug and info.
534 mv -f $diff $CACHE/installed.diff
535 fi
536 }
539 # The main cook function.
541 cookit() {
542 if [ -n "$SETUP_MD5" ] && [ "$SETUP_MD5" != "$(ls $root$INSTALLED | \
543 md5sum | cut -c1-32)" ]; then
544 _ 'ERROR: Broken setup. Abort.'
545 return
546 fi
548 title 'Cook: %s' "$PACKAGE $VERSION"
549 set_paths
551 # Handle cross-tools.
552 case "$ARCH" in
553 arm*|x86_64)
554 # CROSS_COMPILE is used by at least Busybox and the kernel to set
555 # the cross-tools prefix. Sysroot is the root of our target arch
556 sysroot="$CROSS_TREE/sysroot"
557 tools="$CROSS_TREE/tools"
558 # Set root path when cross compiling. ARM tested but not x86_64
559 # When cross compiling we must install build deps in $sysroot.
560 arch="-$ARCH"
561 root="$sysroot"
562 _ '%s sysroot: %s' "$ARCH" "$sysroot"
563 _ 'Adding "%s" to PATH' "$tools/bin"
564 export PATH="$PATH:$tools/bin"
565 export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
566 export CROSS_COMPILE="$HOST_SYSTEM-"
567 _ 'Using cross-tools: %s' "$CROSS_COMPILE"
568 if [ "$ARCH" == 'x86_64' ]; then
569 export CC="$HOST_SYSTEM-gcc -m64"
570 export CXX="$HOST_SYSTEM-g++ -m64"
571 else
572 export CC="$HOST_SYSTEM-gcc"
573 export CXX="$HOST_SYSTEM-g++"
574 fi
575 export AR="$HOST_SYSTEM-ar"
576 export AS="$HOST_SYSTEM-as"
577 export RANLIB="$HOST_SYSTEM-ranlib"
578 export LD="$HOST_SYSTEM-ld"
579 export STRIP="$HOST_SYSTEM-strip"
580 export LIBTOOL="$HOST_SYSTEM-libtool" ;;
581 esac
583 [ -n "$QA" ] && receipt_quality
584 cd $pkgdir
585 [ -z "$continue" ] && rm -rf source 2>/dev/null
586 rm -rf install taz 2>/dev/null
588 # Disable -pipe if less than 512 MB free RAM.
589 free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
590 if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
591 _ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
592 CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
593 CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
594 fi
595 unset free
597 # Export flags and path to be used by make and receipt.
598 DESTDIR="$pkgdir/install"
599 # FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
600 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
601 #LDFLAGS
603 # Check for build deps and handle implicit depends of *-dev packages
604 # (ex: libusb-dev :: libusb).
605 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
606 touch $CACHE/installed.local $CACHE/installed.web
607 [ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
608 [ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
609 for dep in $BUILD_DEPENDS; do
610 implicit="${dep%-dev}"
611 # Don't add implicit dependency if it defined in DEPENDS
612 # echo '' $DEPENDS '' | fgrep -q " $implicit " && implicit=''
613 for i in $dep $implicit; do
614 if [ ! -f "$root$INSTALLED/$i/receipt" ]; then
615 # Try local package first. In some cases implicit doesn't exist, ex:
616 # libboost-dev exists but not libboost, so check if we got vers.
617 unset vers
618 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
619 # We may have a local package.
620 if [ -z "$vers" ]; then
621 vers=$(awk -F$'\t' -vp="$i" '$1==p{print $2; quit}' $PKGS/packages.info 2> /dev/null)
622 fi
623 debug "bdep: $i version: $vers"
624 if [ -f "$PKGS/$i-$vers$arch.tazpkg" ]; then
625 echo $i-$vers$arch.tazpkg >> $CACHE/installed.local
626 else
627 # Priority to package version in wok (maybe more up-to-date)
628 # than the mirrored one.
629 if [ -n "$vers" ]; then
630 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
631 echo $i >> $CACHE/installed.web
632 else
633 # So package exists in wok but not available.
634 _ 'Missing dep (wok/pkg): %s' "$i $vers"
635 echo $i >> $CACHE/missing.dep
636 fi
637 else
638 # Package is not in wok but may be in online repo.
639 if fgrep -q $i-$vers$arch $root$DB/packages.list; then
640 echo $i >> $CACHE/installed.web
641 else
642 _ 'ERROR: unknown dep "%s"' "$i"
643 exit 1
644 fi
645 fi
646 fi
647 fi
648 done
649 done
651 # Get the list of installed packages
652 cd $root$INSTALLED; ls -1 > $CACHE/installed.list
654 # Have we a missing build dep to cook?
655 if [ -s "$CACHE/missing.dep" ] && [ -n "$AUTO_COOK" ]; then
656 _ 'Auto cook config is set: %s' "$AUTO_COOK"
657 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
658 for i in $(uniq $CACHE/missing.dep); do
659 (_ 'Building dep (wok/pkg) : %s' "$i $vers") | \
660 tee -a $LOGS/$PACKAGE.log.$$
661 # programmers: next two messages are exact copy from remove_deps()
662 togrep1=$(_n 'Build dependencies to remove:')
663 togrep2=$(_n 'Removing:')
664 cook $i || (_ "ERROR: can't cook dep \"%s\"" "$i" && newline && \
665 fgrep $togrep1 $LOGS/$i.log && \
666 fgrep $togrep2 $LOGS/$i.log && newline) | \
667 tee -a $LOGS/$PACKAGE.log.$$ && break
668 done
669 rm -f $CACHE/missing.dep
670 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
671 fi
673 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
674 # is enabled and cook fails we have ERROR in log, if no auto cook we have
675 # missing dep in cached file.
676 lerror=$(_n 'ERROR')
677 if fgrep -q ^$lerror $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
678 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
679 _p 'ERROR: missing %d dependency' 'ERROR: missing %d dependencies' "$nb" "$nb"
680 exit 1
681 fi
683 # Install local packages: package-version$arch
684 cd $PKGS
685 for i in $(uniq $CACHE/installed.local); do
686 # _ 'Installing dep (pkg/local): %s' "$i"
687 tazpkg install $i --root=$root --local --quiet --cookmode
688 done
690 # Install web or cached packages (if mirror is set to $PKGS we only
691 # use local packages).
692 for i in $(uniq $CACHE/installed.web); do
693 # _ 'Installing dep (web/cache): %s' "$i"
694 tazpkg get-install $i --root=$root --quiet --cookmode
695 done
697 update_installed_cook_diff
699 # Get source tarball and make sure we have source dir named:
700 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
701 # tarball if it exists.
702 if [ -n "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
703 if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
704 TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
705 LZMA_SRC=''
706 else
707 get_source || exit 1
708 fi
709 fi
710 if [ -z "$WANTED" ] && [ -n "$TARBALL" ] && [ ! -d "$src" ]; then
711 mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
712 if ! extract_source ; then
713 get_source
714 extract_source || exit 1
715 fi
716 if [ -n "$LZMA_SRC" ]; then
717 cd $pkgdir/source
718 if [ "$(ls -A tmp | wc -l)" -gl 1 ] || [ -f "$(echo tmp/*)" ]; then
719 mv tmp tmp-1; mkdir tmp
720 mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
721 fi
722 if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
723 cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
724 fi
725 fi
726 cd $pkgdir/source/tmp
727 # Some archives are not well done and don't extract to one dir (ex lzma).
728 files=$(ls | wc -l)
729 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
730 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
731 mv * ../$PACKAGE-$VERSION/$TARBALL
732 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
733 mv * ../$PACKAGE-$VERSION
734 cd ..; rm -rf tmp
735 fi
737 # Libtool shared libs path hack.
738 case "$ARCH" in
739 arm*) cross libhack ;;
740 esac
742 # Execute receipt rules.
743 if grep -q ^compile_rules $receipt; then
744 _ 'Executing: %s' 'compile_rules'
745 echo "CFLAGS : $CFLAGS"
746 #echo "LDFLAGS : $LDFLAGS"
747 [ -d "$src" ] && cd $src
748 compile_rules $@ || exit 1
749 # Stay compatible with _pkg
750 [ -d "$src/_pkg" ] && mv $src/_pkg $install
751 # QA: compile_rules success so valid.
752 mkdir -p $install
753 else
754 # QA: no compile_rules so no error, valid.
755 mkdir -p $install
756 fi
758 # Actions to do after compiling the package
759 # Skip all for split packages (already done in main package)
760 if [ -z "$WANTED" ]; then
761 footer
762 export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
763 fi
764 footer
766 # Execute testsuite.
767 if grep -q ^testsuite $receipt; then
768 title 'Running testsuite'
769 testsuite $@ || exit 1
770 footer
771 fi
773 update_installed_cook_diff force
774 }
777 # Cook quality assurance.
779 cookit_quality() {
780 if [ ! -d "$WOK/$pkg/install" ] && [ -z "$WANTED" ]; then
781 _ 'ERROR: cook failed' | tee -a $LOGS/$pkg.log
782 fi
783 # ERROR can be echoed any time in cookit()
784 lerror=$(_n 'ERROR')
785 if grep -Ev "(conftest|configtest)" $LOGS/$pkg.log | \
786 grep -Eq "(^$lerror|undefined reference to)" ; then
787 debug_info | tee -a $LOGS/$pkg.log
788 rm -f $command
789 exit 1
790 fi
791 }
794 # Create the package. Wanted to use TazPkg to create a tazpkg package at first,
795 # but it doesn't handle EXTRAVERSION.
797 packit() {
798 set_paths
800 # Handle cross compilation
801 case "$ARCH" in
802 arm*|x86_64) arch="-$ARCH" ;;
803 esac
805 title 'Pack: %s' "$PACKAGE $VERSION$arch"
807 if grep -q ^genpkg_rules $receipt; then
808 _ 'Executing: %s' 'genpkg_rules'
809 set -e; cd $pkgdir; mkdir -p $fs
810 genpkg_rules || (newline; _ 'ERROR: genpkg_rules failed'; newline) >> \
811 $LOGS/$pkg.log
812 else
813 _ 'No packages rules: meta package'
814 mkdir -p $fs
815 fi
817 # Check CONFIG_FILES
818 if [ -n "$CONFIG_FILES" ]; then
819 for i in $CONFIG_FILES; do
820 if [ ! -e $fs$i ]; then
821 case $i in
822 */) mkdir -p $fs$i ;;
823 *) mkdir -p $fs$(dirname $i); touch $fs$i ;;
824 esac
825 fi
826 done
827 fi
829 # First QA check to stop now if genpkg_rules failed.
830 lerror=$(_n 'ERROR')
831 if fgrep -q ^$lerror $LOGS/$pkg.log; then
832 exit 1
833 fi
835 cd $taz
836 for file in receipt description.txt; do
837 [ ! -f "../$file" ] && continue
838 action 'Copying "%s"...' "$file"
839 cp -f ../$file $pack; chown 0.0 $pack/$file; status
840 done
841 copy_generic_files
843 # Strip and stuff files.
844 export COOKOPTS ARCH HOST_SYSTEM LOCALE fs; @@PREFIX@@/libexec/cookutils/compressor fs
846 # Create files.list with redirecting find output.
847 action 'Creating the list of files...'
848 cd $fs
849 find . -type f -print > ../files.list
850 find . -type l -print >> ../files.list
851 cd ..; sed -i s/'^.'/''/ files.list
852 status
854 # Md5sum of files.
855 action 'Creating md5sum of files...'
856 while read file; do
857 [ -L "fs$file" ] && continue
858 [ -f "fs$file" ] || continue
859 case "$file" in
860 /lib/modules/*/modules.*|*.pyc) continue ;;
861 esac
862 md5sum "fs$file" | sed 's/ fs/ /'
863 done < files.list > md5sum
864 status
866 UNPACKED_SIZE=$(du -chs fs receipt files.list md5sum description.txt \
867 2>/dev/null | awk 'END{ print $1 }')
869 # Build cpio archives.
870 action 'Compressing the FS...'
871 find fs -newer $receipt -exec touch -hr $receipt {} \;
872 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si
873 rm -rf fs
874 status
876 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list md5sum description.txt \
877 2>/dev/null | awk 'END{ print $1 }')
879 action 'Updating receipt sizes...'
880 sed -i s/^PACKED_SIZE.*$// receipt
881 sed -i s/^UNPACKED_SIZE.*$// receipt
882 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
883 status
885 # Set extra version.
886 if [ -n "$EXTRAVERSION" ]; then
887 action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
888 sed -i s/^EXTRAVERSION.*$// receipt
889 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
890 status
891 fi
893 # Compress.
894 action 'Creating full cpio archive...'
895 find . -print | cpio -o -H newc --quiet > \
896 ../$PACKAGE-$VERSION$EXTRAVERSION$arch.tazpkg
897 status
899 action 'Restoring original package tree...'
900 unlzma -c fs.cpio.lzma | cpio -idm --quiet
901 status
903 rm fs.cpio.lzma; cd ..
905 # QA and give info.
906 tazpkg=$(ls *.tazpkg)
907 packit_quality
908 footer "$(_ 'Package "%s" created' "$tazpkg")"
909 }
912 # Verify package quality and consistency.
914 packit_quality() {
915 #action 'QA: checking for broken link...'
916 #link=$(find $fs/usr -type l -follow)
917 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
918 #status
920 # Exit if any error found in log file.
921 lerror=$(_n 'ERROR')
922 if fgrep -q ^$lerror $LOGS/$pkg.log; then
923 rm -f $command
924 exit 1
925 fi
927 action 'QA: checking for empty package...'
928 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
929 if [ "$files" -eq 0 -a "$CATEGORY" != 'meta' ]; then
930 newline; _ 'ERROR: empty package'
931 rm -f $command
932 exit 1
933 else
934 :; status
935 # Find and remove old package(s)
936 tempd="$(mktemp -d)"; cd "$tempd"
937 for testpkg in $(ls $PKGS/$pkg-*.tazpkg 2> /dev/null); do
938 # Extract receipt from each matched package
939 cpio -F "$testpkg" -i receipt >/dev/null 2>&1
940 name=$(. receipt; echo $PACKAGE)
941 rm receipt
942 if [ "$name" == "$pkg" ]; then
943 action 'Removing old package "%s"' "$(basename "$testpkg")"
944 rm -f "$testpkg"
945 status
946 fi
947 done
948 rm -r "$tempd"
949 mv -f $pkgdir/taz/$pkg-*.tazpkg $PKGS
950 sed -i /^${pkg}$/d $broken
951 #action 'Removing source tree...'
952 #rm -f $WOK/$pkg/source; status
953 fi
954 }
957 # Reverse "cat" command: prints input lines in the reverse order
959 tac() {
960 sed '1!G;h;$!d' $1
961 }
964 # Install package on --install or update the chroot.
966 install_package() {
967 case "$ARCH" in
968 arm*|x86_64)
969 arch="-$ARCH"
970 root="$CROSS_TREE/sysroot" ;;
971 esac
972 # Install package if requested but skip install if target host doesn't
973 # match build system or it will break the build chroot.
974 build=$(echo $BUILD_SYSTEM | cut -d- -f1)
975 if [ -n "$inst" ] && [ "$build" == "$ARCH" ]; then
976 if [ -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
977 cd $PKGS
978 tazpkg install $PACKAGE-$VERSION$EXTRAVERSION.tazpkg --forced
979 else
980 _ 'Unable to install package, build has failed.'; newline
981 exit 1
982 fi
983 fi
985 # Install package if part of the chroot to keep env up-to-date.
986 if [ -d "$root$INSTALLED/$pkg" ]; then
987 . /etc/slitaz/cook.conf
988 . $WOK/$pkg/taz/$pkg-*/receipt
989 _ 'Updating %s chroot environment...' "$ARCH"
990 _ 'Updating chroot: %s' "$pkg ($VERSION$EXTRAVERSION$arch)" | log
991 cd $PKGS
992 tazpkg install $pkg-$VERSION$EXTRAVERSION$arch.tazpkg --forced --root=$root
993 fi
994 }
997 # remove chroot jail
999 umount_aufs() {
1000 tac ${1}rw/aufs-umount.sh | sh
1001 rm -rf ${1}rw
1002 umount ${1}root
1003 rmdir ${1}r*
1007 # Launch the cook command into a chroot jail protected by aufs.
1008 # The current filesystems are used read-only and updates are
1009 # stored in a separate branch.
1011 try_aufs_chroot() {
1013 base="/dev/shm/aufsmnt$$"
1015 # Can we setup the chroot? Is it already done?
1016 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1017 grep -q ^AUFS_NOT_RAMFS $receipt && base="/mnt/aufsmnt$$"
1018 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1019 grep -q ^aufs /proc/modules || modprobe aufs 2> /dev/null || return
1020 mkdir ${base}root ${base}rw || return
1022 _ 'Setup aufs chroot...'
1024 # Sanity check
1025 for i in / /proc /sys /dev/shm /home ; do
1026 case " $AUFS_MOUNTS " in
1027 *\ $i\ *) ;;
1028 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1029 esac
1030 done
1031 for mnt in $(ls -d $AUFS_MOUNTS | sort | uniq); do
1032 mount --bind $mnt ${base}root$mnt
1033 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1034 _ 'Aufs mount failure'
1035 umount ${base}root
1036 rm -rf ${base}r*
1037 return
1038 fi
1039 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1040 done
1041 trap "umount_aufs ${base}" INT
1043 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1044 status=$?
1046 _ 'Leaving aufs chroot...'
1047 umount_aufs $base
1048 # Install package outside the aufs jail
1049 install_package
1050 exit $status
1054 # Encode predefined XML entities
1056 xml_ent() {
1057 sed -e 's|&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g' -e "s|'|\&apos;|g"
1061 # Create a XML feed for freshly built packages.
1063 gen_rss() {
1064 pubdate=$(date '+%a, %d %b %Y %X')
1065 cat > $FEEDS/$pkg.xml <<EOT
1066 <item>
1067 <title>$PACKAGE $VERSION$EXTRAVERSION</title>
1068 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1069 <guid>$PACKAGE-$VERSION$EXTRAVERSION</guid>
1070 <pubDate>$pubdate</pubDate>
1071 <description>$(echo -n "$SHORT_DESC" | xml_ent)</description>
1072 </item>
1073 EOT
1077 # Truncate stdout log file to $1 Mb.
1079 loglimit() {
1080 if [ -n "$DEFAULT_LOG_LIMIT" ]; then
1081 tee /dev/stderr | head -qc ${1:-$DEFAULT_LOG_LIMIT}m
1082 else
1083 tee /dev/stderr
1084 fi
1088 # Search file in mirrored packages
1090 search_file_mirror() {
1091 busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
1095 # Search file in local wok packages
1097 search_file_local() {
1098 # existing packages have precedence over the package/taz folder
1099 srch=$1
1100 { for package in $(find $PKGS -name '*.tazpkg'); do
1101 if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
1102 grep /$srch\$)" ]; then
1103 busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
1104 fi
1105 done } | sort -u
1109 # Ask in multiple choice
1111 ask_multiple() {
1112 local multiples first my_choice
1113 multiples="$1"
1114 first=$(echo "$multiples" | head -n1)
1115 newline; _ 'Multiple choice:'; echo "$multiples"; newline
1116 _ 'Select one [%s]: ' "$first"; read my_choice
1117 found="${my_choice:-$first}"
1121 # Search file in local cache (fast), local wok packages, mirrored packages
1123 search_file() {
1124 local srch cache missing
1125 srch="$1"
1126 cache='/var/cache/ldsearch.cache'
1127 missing='/var/cache/missing.file'
1128 touch $cache $missing
1129 found=$(grep $srch $cache | cut -d$'\t' -f2)
1130 if [ -z "$found" ]; then
1131 found=$(search_file_local $srch)
1132 if [ -n "$found" ]; then
1133 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1134 ask_multiple "$found"
1135 fi
1136 echo -e "$srch\t$found" >> $cache
1137 else
1138 found=$(search_file_mirror $srch)
1139 if [ -n "$found" ]; then
1140 if [ $(echo "$found" | wc -l) -gt 1 ]; then
1141 ask_multiple "$found"
1142 fi
1143 echo -e "$srch\t$found" >> $cache
1144 else
1145 echo "$srch" >> $missing
1146 fi
1147 fi
1148 fi
1153 # Receipt functions to ease packaging
1156 get_dev_files() {
1157 action 'Getting standard devel files...'
1158 mkdir -p $fs/usr/lib
1159 cp -a $install/usr/lib/pkgconfig $fs/usr/lib
1160 cp -a $install/usr/lib/*a $fs/usr/lib
1161 cp -a $install/usr/include $fs/usr
1162 status
1166 # Function to use in compile_rules() to copy man page from $src to $install
1168 cook_pick_manpages() {
1169 local name section
1170 action 'Copying man pages...'
1172 for i in $@; do
1173 name=$(echo $i | sed 's|\.[gbx]z2*$||')
1174 section=${name##*/}; section=${section##*.}
1175 mkdir -p $install/usr/share/man/man$section
1176 cp -a $i $install/usr/share/man/man$section
1177 done
1178 status
1182 # Function to use in genpkg_rules() to copy specified files from $install to $fs
1184 cook_copy_files() {
1185 action 'Copying files...'
1186 cd $install
1187 local i j
1188 IFS=$'\n'
1189 for i in $@; do
1190 for j in $(find . -name $i ! -type d); do
1191 mkdir -p $fs$(dirname ${j#.})
1192 cp -a $j $fs$(dirname ${j#.})
1193 done
1194 done
1195 cd - >/dev/null
1196 status
1200 # Function to use in genpkg_rules() to copy specified folders from $install to $fs
1202 cook_copy_folders() {
1203 action 'Copying folders...'
1204 cd $install
1205 local i j
1206 IFS=$'\n'
1207 for i in $@; do
1208 for j in $(find . -name $i -type d); do
1209 mkdir -p $fs$(dirname ${j#.})
1210 cp -a $j $fs$(dirname ${j#.})
1211 done
1212 done
1213 cd - >/dev/null
1214 status
1218 # Function to use in genpkg_rules() to copy hicolor icons in specified sizes
1219 # (default: 16 and 48) from $install to $fs
1221 cook_copy_icons() {
1222 local sizes=$@
1223 action 'Copying hicolor icons...'
1224 mkdir -p $fs/usr/share/icons/hicolor
1225 for i in ${sizes:-16 48}; do
1226 [ -e "$install/usr/share/icons/hicolor/${i}x$i" ] &&
1227 cp -a $install/usr/share/icons/hicolor/${i}x$i \
1228 $fs/usr/share/icons/hicolor
1229 done
1230 status
1237 # Commands
1240 case "$1" in
1241 usage|help|-u|-h)
1242 usage ;;
1244 list-wok)
1245 title 'List of %s packages in "%s"' "$ARCH" "$WOK"
1246 cd $WOK
1247 if [ "$ARCH" != 'i486' ]; then
1248 count=0
1249 for pkg in $(fgrep 'HOST_ARCH=' */receipt | egrep "$ARCH|any" | cut -d: -f1)
1250 do
1251 unset HOST_ARCH
1252 . $pkg
1253 count=$(($count + 1))
1254 colorize 34 "$PACKAGE"
1255 done
1256 else
1257 count=$(ls | wc -l)
1258 ls -1
1259 fi
1260 footer "$(_p '%s package' '%s packages' "$count" "$(colorize 32 "$count")")"
1261 ;;
1263 activity)
1264 cat $activity ;;
1266 search)
1267 # Just a simple search function, we dont need more actually.
1268 query="$2"
1269 title 'Search results for "%s"' "$query"
1270 cd $WOK; ls -1 | grep "$query"
1271 footer ;;
1273 setup)
1274 # Setup a build environment
1275 check_root
1276 _ 'Cook: setup environment' | log
1277 title 'Setting up your environment'
1278 [ -d $SLITAZ ] || mkdir -p $SLITAZ
1279 cd $SLITAZ
1280 init_db_files
1281 _ 'Checking for packages to install...'
1282 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1283 # ARCH-setup or 'cross check' should be used before: cook setup
1284 case "$ARCH" in
1285 arm*|x86_64)
1286 if [ ! -x '/usr/bin/cross' ]; then
1287 _ 'ERROR: %s is not installed' 'cross'
1288 exit 1
1289 fi
1290 _ 'Using config file: %s' '/etc/slitaz/cross.conf'
1291 . /etc/slitaz/cross.conf ;;
1292 esac
1293 for pkg in $SETUP_PKGS; do
1294 if [ -n "$forced" ]; then
1295 tazpkg -gi $pkg --forced
1296 else
1297 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg
1298 fi
1299 done
1301 # Handle --options
1302 case "$2" in
1303 --wok) hg clone $WOK_URL wok || exit 1 ;;
1304 --stable) hg clone $WOK_URL-stable wok || exit 1 ;;
1305 --undigest) hg clone $WOK_URL-undigest wok || exit 1 ;;
1306 --tiny) hg clone $WOK_URL-tiny wok || exit 1 ;;
1307 esac
1309 # SliTaz group and permissions
1310 if ! grep -q ^slitaz /etc/group; then
1311 _ 'Adding group "%s"' 'slitaz'
1312 addgroup slitaz
1313 fi
1314 _ 'Setting permissions for group "%s"...' 'slitaz'
1315 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1316 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1317 footer "$(_ 'All done, ready to cook packages :-)')" ;;
1319 *-setup)
1320 # Setup for cross compiling.
1321 arch="${1%-setup}"
1322 check_root
1323 . /etc/slitaz/cook.conf
1324 for pkg in $CROSS_SETUP; do
1325 if [ -n "$forced" ]; then
1326 tazpkg -gi $pkg --forced
1327 else
1328 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
1329 fi
1330 done
1332 _ 'Cook: setup %s cross environment' "$arch" | log
1333 title 'Setting up your %s cross environment' "$arch"
1334 init_db_files
1335 sed -i \
1336 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1337 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1338 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1339 /etc/slitaz/cook.conf
1340 case "$arch" in
1341 arm)
1342 flags='-O2 -march=armv6'
1343 host="$ARCH-slitaz-linux-gnueabi" ;;
1344 armv6hf)
1345 flags='-O2 -march=armv6j -mfpu=vfp -mfloat-abi=hard'
1346 host="$ARCH-slitaz-linux-gnueabi" ;;
1347 armv7)
1348 flags='-Os -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp -pipe'
1349 host="$ARCH-slitaz-linux-gnueabi" ;;
1350 x86_64)
1351 flags='-O2 -mtune=generic -pipe'
1352 host="$ARCH-slitaz-linux" ;;
1353 esac
1354 sed -i \
1355 -e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
1356 -e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
1357 . /etc/slitaz/cook.conf
1358 sysroot="$CROSS_TREE/sysroot"
1359 tools="/cross/$arch/tools"
1360 root="$sysroot"
1361 # L10n: keep the same width of translations to get a consistent view
1362 _ 'Target arch : %s' "$ARCH"
1363 _ 'Configure args : %s' "$CONFIGURE_ARGS"
1364 _ 'Build flags : %s' "$flags"
1365 _ 'Arch sysroot : %s' "$sysroot"
1366 _ 'Tools prefix : %s' "$tools/bin"
1367 # Tell the packages manager where to find packages.
1368 _ 'Packages DB : %s' "$root$DB"
1369 mkdir -p $root$INSTALLED
1370 cd $root$DB; rm -f *.bak
1371 for list in packages.list packages.desc packages.equiv packages.md5; do
1372 rm -f $list
1373 ln -s $SLITAZ/packages/$list $list
1374 done
1375 # We must have the cross compiled glibc-base installed or default
1376 # i486 package will be used as dep by tazpkg and then break the
1377 # cross environment
1378 if [ ! -f "$root$INSTALLED/glibc-base/receipt" ]; then
1379 colorize 36 $(_ 'WARNING: %s is not installed in sysroot' '(e)glibc-base')
1380 fi
1381 # Show GCC version or warn if not yet compiled.
1382 if [ -x "$tools/bin/$HOST_SYSTEM-gcc" ]; then
1383 _ 'Cross compiler : %s' "$HOST_SYSTEM-gcc"
1384 else
1385 colorize 36 $(_ 'C compiler "%s" is missing' "$HOST_SYSTEM-gcc")
1386 _ 'Run "%s" to cook a toolchain' 'cross compile'
1387 fi
1388 footer ;;
1390 test)
1391 # Test a cook environment.
1392 _ 'Cook test: testing the cook environment' | log
1393 [ ! -d "$WOK" ] && exit 1
1394 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1395 cook cooktest ;;
1397 new)
1398 # Create the package folder and an empty receipt.
1399 pkg="$2"
1400 [ -z "$pkg" ] && usage
1401 newline
1402 if [ -d "$WOK/$pkg" ]; then
1403 _ 'Package "%s" already exists.' "$pkg"
1404 exit 1
1405 fi
1407 action 'Creating folder "%s"' "$WOK/$pkg"
1408 mkdir $WOK/$pkg; cd $WOK/$pkg; status
1410 action 'Preparing the package receipt...'
1411 cp $DATA/receipt .
1412 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1413 status; newline
1415 # Interactive mode, asking and seding.
1416 case "$3" in
1417 --interactive|-x)
1418 _ 'Entering interactive mode...'
1419 separator
1420 _ 'Package : %s' "$pkg"
1422 _n 'Version : ' ; read answer
1423 sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
1425 _n 'Category : ' ; read answer
1426 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
1428 # L10n: Short description
1429 _n 'Short desc : ' ; read answer
1430 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
1432 _n 'Maintainer : ' ; read answer
1433 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
1435 _n 'License : ' ; read answer
1436 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
1438 _n 'Web site : ' ; read answer
1439 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
1440 newline
1442 # Wget URL.
1443 _ 'Wget URL to download source tarball.'
1444 _n 'Example : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
1445 _n 'Wget url : ' ; read answer
1446 sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
1448 # Ask for a stuff dir.
1449 confirm "$(_n 'Do you need a stuff directory? (y/N)')"
1450 if [ "$?" -eq 0 ]; then
1451 action 'Creating the stuff directory...'
1452 mkdir $WOK/$pkg/stuff; status
1453 fi
1455 # Ask for a description file.
1456 confirm "$(_n 'Are you going to write a description? (y/N)')"
1457 if [ "$?" -eq 0 ]; then
1458 action 'Creating the "%s" file...' 'description.txt'
1459 touch $WOK/$pkg/description.txt; status
1460 fi
1462 footer "$(_ 'Receipt is ready to use.')" ;;
1463 esac ;;
1465 list)
1466 # Cook a list of packages (better use the Cooker since it will order
1467 # packages before executing cook).
1468 check_root
1469 if [ -z "$2" ]; then
1470 newline; _ 'No list in argument.'; newline
1471 exit 1
1472 fi
1473 if [ ! -f "$2" ]; then
1474 newline; _ 'List "%s" not found.' "$2"; newline
1475 exit 1
1476 fi
1478 _ 'Starting cooking the list "%s"' "$2" | log
1480 for pkg in $(cat $2); do
1481 cook $pkg || broken
1482 done ;;
1484 clean-wok)
1485 check_root
1486 newline; action 'Cleaning all packages files...'
1487 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1488 status; newline ;;
1490 clean-src)
1491 check_root
1492 newline; action 'Cleaning all packages sources...'
1493 rm -rf $WOK/*/source
1494 status; newline ;;
1496 uncook)
1497 cd $WOK
1498 count=0
1499 title 'Checking for uncooked packages'
1501 for pkg in *; do
1502 unset HOST_ARCH EXTRAVERSION
1503 [ ! -e $pkg/receipt ] && continue
1504 . $pkg/receipt
1505 # Source cooked pkg receipt to get EXTRAVERSION
1506 if [ -d "$WOK/$pkg/taz" ]; then
1507 cd $WOK/$pkg/taz/$pkg-*
1508 . receipt; cd $WOK
1509 fi
1510 case "$ARCH" in
1511 i486)
1512 debug "$(_ 'Package "%s"' "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg")"
1513 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then
1514 count=$(($count + 1))
1515 colorize 34 "$pkg"
1516 fi ;;
1517 arm*)
1518 # Check only packages included in arch
1519 if echo "$HOST_ARCH" | egrep -q "$ARCH|any"; then
1520 # *.tazpkg
1521 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION-$ARCH.tazpkg" ]; then
1522 count=$(($count + 1))
1523 colorize 34 "$pkg"
1524 fi
1525 fi ;;
1526 esac
1527 done
1529 if [ "$count" -gt "0" ]; then
1530 footer "$(_p '%s uncooked package' '%s uncooked packages' "$count" "$(colorize 31 "$count")")"
1531 else
1532 _ 'All packages are cooked :-)'
1533 newline
1534 fi
1535 ;;
1537 pkgdb)
1538 # Create suitable packages list for TazPkg and only for built packages
1539 # as well as flavors files for TazLiTo. We don't need logs since we do it
1540 # manually to ensure everything is fine before syncing the mirror.
1541 @@PREFIX@@/libexec/cookutils/pkgdb "$2"
1542 ;;
1544 *)
1545 # Just cook and generate a package.
1546 check_root
1547 time=$(date +%s)
1548 pkg="$1"
1549 [ -z "$pkg" ] && usage
1550 lastcooktime=$(sed '/^Cook time/!d;s|.*: *\([0-9]*\)s.*|\1|' \
1551 $LOGS/$pkg.log 2> /dev/null | sed '$!d')
1552 receipt="$WOK/$pkg/receipt"
1553 check_pkg_in_wok
1554 newline
1556 unset inst
1557 unset_receipt
1558 . $receipt
1560 # Handle cross compilation.
1561 case "$ARCH" in
1562 arm*)
1563 if [ -z "$HOST_ARCH" ]; then
1564 _ 'cook: HOST_ARCH is not set in "%s" receipt' "$pkg"
1565 error="$(_ 'package "%s" is not included in %s' "$pkg" "$ARCH")"
1566 _ 'cook: %s' "$error"
1567 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1568 _ 'Cook skip: %s' "$error" | log
1569 newline
1570 exit 1
1571 fi ;;
1572 esac
1574 # Some packages are not included in some arch or fail to cross compile.
1575 : ${HOST_ARCH=i486}
1576 debug "$(_ 'Host arch %s' "$HOST_ARCH")"
1577 # Handle arm{v6hf,v7,..}
1578 if ! $(echo "$HOST_ARCH" | egrep -q "${ARCH%v[0-9]*}|any"); then
1579 _ 'cook: %s' "HOST_ARCH=$HOST_ARCH"
1580 error="$(_ "package \"%s\" doesn't cook or is not included in %s" "$pkg" "$ARCH")"
1581 _ 'cook: %s' "error"
1582 [ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
1583 _ 'Cook skip: %s' "$error" | log
1584 sed -i /^${pkg}$/d $broken
1585 newline
1586 exit 0
1587 fi
1589 # Skip blocked, 3 lines also for the Cooker.
1590 if grep -q "^$pkg$" $blocked && [ "$2" != '--unblock' ]; then
1591 _ 'Package "%s" is blocked' "$pkg"; newline
1592 exit 0
1593 fi
1595 try_aufs_chroot "$@"
1597 # Log and source receipt.
1598 _ 'Cook started for: %s' "<a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1599 echo "cook:$pkg" > $command
1600 [ "$lastcooktime" ] &&
1601 echo "cook:$pkg $lastcooktime $(date +%s)" >> $cooktime
1602 while read cmd duration start; do
1603 [ $(($start + $duration)) -lt $(date +%s) ] &&
1604 echo "sed -i '/^$cmd $duration/d' $cooktime"
1605 done < $cooktime | sh
1607 # Display and log info if cook process stopped.
1608 # FIXME: gettext not working (in single quotes) here!
1609 trap '_ "\n\nCook stopped: control-C\n\n" | \
1610 tee -a $LOGS/$pkg.log' INT
1612 # Handle --options
1613 case "$2" in
1614 --clean|-c)
1615 action 'Cleaning "%s"' "$pkg"
1616 cd $WOK/$pkg; rm -rf install taz source
1617 status; newline
1618 exit 0 ;;
1620 --install|-i)
1621 inst='yes' ;;
1623 --getsrc|-gs)
1624 title 'Getting source for "%s"' "$pkg"
1625 get_source
1626 _ 'Tarball: %s' "$SRC/$TARBALL"; newline
1627 exit 0 ;;
1629 --block|-b)
1630 action 'Blocking package "%s"' "$pkg"
1631 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1632 status; newline
1633 exit 0 ;;
1635 --unblock|-ub)
1636 action 'Unblocking package "%s"' "$pkg"
1637 sed -i "/^${pkg}$/"d $blocked
1638 status; newline
1639 exit 0 ;;
1641 --pack)
1642 if [ -d $WOK/$pkg/taz ]; then
1643 rm -rf $WOK/$pkg/taz
1644 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1645 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1646 clean_log
1647 else
1648 _ 'Need to build "%s"' "$pkg"
1649 exit 0
1650 fi
1651 exit 0 ;;
1653 --cdeps)
1654 if [ ! -d $WOK/$pkg/taz ]; then
1655 _ 'Need to build "%s"' "$pkg"
1656 exit 0
1657 fi
1659 title 'Checking depends'
1660 lddlist='/tmp/lddlist'; touch $lddlist
1661 missing='/var/cache/missing.file'
1663 # find all deps using ldd
1664 for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
1665 [ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
1666 ldd $exe | sed 's| ||' | cut -d' ' -f1 >> $lddlist
1667 done #"
1669 # remove exe/so duplicates
1670 sort -u $lddlist > $lddlist.sorted
1672 # search packages
1673 for exefile in $(cat $lddlist.sorted); do
1674 search_file $exefile
1675 echo "$found" >> $lddlist.pkgs
1676 echo -n '.'
1677 done
1678 echo
1680 # remove packages duplicates
1681 sort -u $lddlist.pkgs > $lddlist.final
1682 sort -u $missing > $missing.final
1683 rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
1684 exit 0 ;;
1685 esac
1687 # Rotate log
1688 for i in $(seq 9 -1 1); do
1689 j=$(($i - 1))
1690 [ -e $LOGS/$pkg.log.$j ] && mv -f $LOGS/$pkg.log.$j $LOGS/$pkg.log.$i
1691 done
1692 [ -e $LOGS/$pkg.log ] && mv $LOGS/$pkg.log $LOGS/$pkg.log.0
1694 # Check if wanted is built now so we have separate log files.
1695 for wanted in $WANTED ; do
1696 if grep -q "^$wanted$" $blocked; then
1697 _ 'WANTED package "%s" is blocked' "$wanted" | tee $LOGS/$pkg.log
1698 newline
1699 rm -f $command
1700 exit 1
1701 fi
1702 if grep -q "^$wanted$" $broken; then
1703 _ 'WANTED package "%s" is broken' "$wanted" | tee $LOGS/$pkg.log
1704 newline
1705 rm -f $command
1706 exit 1
1707 fi
1708 if [ ! -d "$WOK/$wanted/install" ]; then
1709 cook "$wanted" || exit 1
1710 fi
1711 done
1713 # Cook and pack or exit on error and log everything.
1714 cookit $@ 2>&1 | loglimit 50 > $LOGS/$pkg.log
1715 remove_deps | tee -a $LOGS/$pkg.log
1716 cookit_quality
1717 packit 2>&1 | loglimit 5 >> $LOGS/$pkg.log
1718 clean_log
1720 # Exit if any error in packing.
1721 lerror=$(_n 'ERROR')
1722 if grep -Ev "(/root/.cvspass|conftest|df: /|rm: can't remove)" $LOGS/$pkg.log | \
1723 grep -Eq "(^$lerror|: No such file or directory|not remade because of errors|ake: \*\*\* .* Error)"; then
1724 debug_info | tee -a $LOGS/$pkg.log
1725 rm -f $command
1726 exit 1
1727 fi
1729 # Create an XML feed
1730 gen_rss
1732 # Time and summary
1733 time=$(($(date +%s) - $time))
1734 summary | tee -a $LOGS/$pkg.log
1735 newline
1737 # We may want to install/update (outside aufs jail !).
1738 [ -s /aufs-umount.sh ] ||
1739 install_package
1741 # Finally we DON'T WANT to build the *-dev or packages with WANTED="$pkg"
1742 # You want automation: use the Cooker Build Bot.
1743 rm -f $command ;;
1744 esac
1746 exit 0