cookutils view cook @ rev 554

Update Makefile to include the exclude.txt file.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Oct 20 19:50:42 2012 +0000 (2012-10-20)
parents 6ff62c90dd29
children 2afacf0c3875
line source
1 #!/bin/sh
2 #
3 # Cook - A tool to cook and generate SliTaz packages. Read the README
4 # before adding or modifing any code in cook!
5 #
6 # Copyright (C) SliTaz GNU/Linux - GNU gpl v3
7 # Author: Christophe Lincoln <pankso@slitaz.org>
8 #
9 . /usr/lib/slitaz/libcook.sh
10 . /usr/lib/slitaz/libcookorder.sh
11 . /usr/lib/slitaz/libcookiso.sh
13 COMMAND="$1"
15 #
16 # Functions
17 #
19 usage() {
20 cat << EOT
22 $(echo -e "\033[1m$(gettext "Usage:")\033[0m") cook [package|command] [list|--option]
24 $(echo -e "\033[1m$(gettext "Commands:")\033[0m")
25 usage|help $(gettext "Display this short usage.")
26 setup $(gettext "Setup your build environment.")
27 *-setup $(gettext "Setup a cross environment.")
28 test $(gettext "Test environment and cook a package.")
29 list-wok $(gettext "List packages in the wok.")
30 search $(gettext "Simple packages search function.")
31 new $(gettext "Create a new package with a receipt".)
32 list $(gettext "Cook a list of packages.")
33 clean-wok $(gettext "Clean-up all packages files.")
34 clean-src $(gettext "Clean-up all packages sources.")
35 upwok $(gettext "Update wok.")
36 gen-wok-db $(gettext "Build cook order files.")
37 gen-src $(gettext "Build source list.")
38 check-incoming $(gettext "Move incoming packages to packages folder.")
39 gen-cooklist $(gettext "Make cook order list.")
40 check-src $(gettext "Check upstream tarball for package in the wok.")
41 maintainers $(gettext "List all maintainers in the wok.")
42 maintained-by $(gettext "List packages maintained by a contributor.")
43 tags $(gettext "List all tags used in wok receipts.")
44 pkgdb $(gettext "Create packages DB lists and flavors.")
45 unbuild $(gettext "List all unbuild packages.")
47 $(echo -e "\033[1m$(gettext "Options:")\033[0m")
48 --clean|-c Cook : $(gettext "clean the package in the wok.")
49 --install|-i Cook : $(gettext "cook and install the package.")
50 --getsrc|-gs Cook : $(gettext "get the package source tarball.")
51 --block|-b Cook : $(gettext "Block a package so cook will skip it.")
52 --unblock|-ub Cook : $(gettext "Unblock a blocked package.")
53 --interactive|-x New : $(gettext "create a receipt interactively.")
54 --local Upwok : $(gettext "update wok local changes in wok-hg.")
55 --wok|-w Setup : $(gettext "clone the cooking wok from Hg repo.")
56 --stable Setup : $(gettext "clone the stable wok from Hg repo.")
57 --undigest Setup : $(gettext "clone the undigest wok from Hg repo.")
58 --tiny Setup: $(gettext "clone the tiny SliTaz wok from Hg repo.")
59 --forced Setup: $(gettext "force reinstall of chroot packages.")
60 --flavors Pkgdb : $(gettext "create up-to-date flavors files.")
61 --full Unbuild : $(gettext "create a full unbuild list.")
62 --list Unbuild : $(gettext "Copy unbuild list into your cooklist.")
64 EOT
65 exit 0
66 }
68 # We don't want these escapes in web interface.
69 clean_log() {
70 sed -i -e s'|\[70G\[ \[1;32m| |' \
71 -e s'|\[0;39m \]||' $LOGS/$pkg.log
72 }
74 # check if $value is empty
75 if_empty_value() {
76 if [ -z "$value" ]; then
77 gettext "QA: empty variable:"; echo -e " ${var}=\"\"\n"
78 exit 1
79 fi
80 }
82 # QA: check a receipt consistency before building.
83 receipt_quality() {
84 gettext -e "QA: checking package receipt...\n"
85 unset online
86 if ifconfig | grep -q -A 1 "^[a-z]*[0-9]" | fgrep 'addr:'; then
87 online="online"
88 fi
89 for var in PACKAGE VERSION CATEGORY SHORT_DESC MAINTAINER WEB_SITE
90 do
91 unset value
92 value="$(. $receipt ; eval echo \$$var)"
93 case "$var" in
94 PACKAGE|VERSION|SHORT_DESC)
95 if_empty_value ;;
96 CATEGORY)
97 [ -z "$value" ] && value="empty"
98 valid="$PKGS_CATEGORIES"
99 if ! echo "$valid" | grep -q -w "$value"; then
100 gettext "QA: unknown category:"; echo -e " $value\n"
101 exit 1
102 fi ;;
103 WEB_SITE)
104 # We don't check WGET_URL since if dl is needed it will fail.
105 # Break also if we're not online. Here error is not fatal.
106 if_empty_value
107 [ -z "$online" ] || break
108 case $value in
109 https://*)
110 if ! wget -T $TIMEOUT --spider --no-check-certificate $value 2>/dev/null; then
111 gettext "QA: Unable to reach:"; echo -e " $value"
112 fi ;;
113 http://*|ftp://*)
114 if ! busybox wget -T $TIMEOUT -s $value 2>/dev/null; then
115 gettext "QA: Unable to reach:"; echo -e " $value"
116 fi ;;
117 esac
118 esac
119 done
120 }
122 # Paths used in receipt and by cook itself.
123 set_paths() {
124 pkgdir=$WOK/$PACKAGE
125 basesrc=$pkgdir/source
126 tmpsrc=$basesrc/tmp
127 src=$basesrc/$PACKAGE-$VERSION
128 taz=$pkgdir/taz
129 pack=$taz/$PACKAGE-${VERSION}${EXTRAVERSION}
130 fs=$pack/fs
131 stuff=$pkgdir/stuff
132 install=$pkgdir/install
133 pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
134 lzma_tarball="$pkgsrc.tar.lzma"
135 orig_tarball="$TARBALL"
136 if [ "$PATCH" ]; then
137 [ "${PTARBALL}" ] || PTARBALL="$(basename $PATCH)"
138 fi
139 if [ "$WANTED" ]; then
140 basesrc=$WOK/$WANTED/source
141 src=$basesrc/$WANTED-$VERSION
142 install=$WOK/$WANTED/install
143 wanted_stuff=$WOK/$WANTED/stuff
144 fi
145 if [ "$SOURCE" ]; then
146 source_stuff=$WOK/$SOURCE/stuff
147 fi
148 # Kernel version is set from linux
149 if [ -f "$WOK/linux/receipt" ]; then
150 kvers=$(grep ^VERSION= $WOK/linux/receipt | cut -d '"' -f 2)
151 kbasevers=${kvers:0:3}
152 fi
153 # Python version
154 if [ -f "$WOK/python/receipt" ]; then
155 pyvers=$(grep ^VERSION= $WOK/python/receipt | cut -d '"' -f 2)
156 fi
157 # perl version for some packages needed it
158 if [ -f "$WOK/perl/receipt" ]; then
159 perlvers=$(grep ^VERSION= $WOK/perl/receipt | cut -d '"' -f 2)
160 fi
161 # Old way compatibility.
162 _pkg=$install
163 }
165 # Create source tarball when URL is a SCM.
166 create_tarball() {
167 local tarball
168 tarball=$pkgsrc.tar.bz2
169 [ "$LZMA_SRC" ] && tarball=$lzma_tarball
170 gettext "Creating tarball: "; echo "$tarball"
171 if [ "$LZMA_SRC" ]; then
172 tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
173 LZMA_SRC=""
174 else
175 tar cjf $tarball $pkgsrc || exit 1
176 mv $tarball $SRC && rm -rf $pkgsrc
177 fi
178 TARBALL=$tarball
179 }
181 # Get package source. For SCM we are in cache so clone here and create a
182 # tarball here.
183 get_source() {
184 pwd=$(pwd)
185 for file in $@; do
186 gettext "Getting source from url:"; echo " ${file#*|}"
187 if [ "$file" = "$PATCH" -o "$file" = "$orig_url_patch" ]; then
188 SAVE_FILE="$SRC/$PTARBALL"
189 else
190 SAVE_FILE="$SRC/$TARBALL"
191 fi
192 case "$file" in
193 http://*|ftp://*)
194 # Busybox Wget is better!
195 busybox wget $WGET_OPTIONS -T $TIMEOUT -c -O $SAVE_FILE $file || \
196 (echo -e "ERROR: wget $file" && exit 1) ;;
197 https://*)
198 wget $WGET_OPTIONS -T $TIMEOUT -c --no-check-certificate -O $SAVE_FILE $file || \
199 (echo -e "ERROR: wget $file" && exit 1) ;;
200 hg*|mercurial*)
201 if $(echo "$file" | fgrep -q "hg|"); then
202 url=${file#hg|}
203 else
204 url=${file#mercurial|}
205 fi
206 gettext -e "Getting source from Hg...\n"
207 echo "URL: $url"
208 gettext "Cloning to: "; echo "$pwd/$pkgsrc"
209 if [ "$BRANCH" ]; then
210 echo "Hg branch: $BRANCH"
211 hg clone $url --rev $BRANCH $pkgsrc || \
212 (echo "ERROR: hg clone $url --rev $BRANCH" && exit 1)
213 else
214 hg clone $url $pkgsrc || (echo "ERROR: hg clone $url" && exit 1)
215 fi
216 create_tarball ;;
217 git*)
218 url=${file#git|}
219 gettext -e "Getting source from Git...\n"
220 echo "URL: $url"
221 git clone $url $pkgsrc || (echo "ERROR: git clone $url" && exit 1)
222 if [ "$BRANCH" ]; then
223 echo "Git branch: $BRANCH"
224 cd $pkgsrc && git checkout $BRANCH && cd ..
225 fi
226 create_tarball ;;
227 bzr*|bazaar*)
228 if $(echo "$file" | fgrep -q "bzr|"); then
229 url=${file#bzr|}
230 else
231 url=${file#bazaar|}
232 fi
233 gettext -e "Getting source from BZR...\n"
234 echo "URL: $url"
235 bzr branch $url $pkgsrc
236 create_tarball ;;
237 cvs*)
238 url=${file#cvs|}
239 mod=$PACKAGE
240 [ "$CVS_MODULE" ] && mod=$CVS_MODULE
241 gettext -e "Getting source from CVS...\n"
242 echo "URL: $url"
243 [ "$CVS_MODULE" ] && echo "CVS module: $mod"
244 gettext "Cloning to: "; echo "$pwd/$mod"
245 cvs -d:$url co $mod && mv $mod $pkgsrc
246 create_tarball ;;
247 svn*|subversion*)
248 if $(echo "$file" | fgrep -q "svn|"); then
249 url=${file#svn|}
250 else
251 url=${file#subversion|}
252 fi
253 gettext -e "Getting source from SVN...\n"
254 echo "URL: $url"
255 if [ "$BRANCH" ]; then
256 echo t | svn co $url -r $BRANCH $pkgsrc
257 else
258 echo t | svn co $url $pkgsrc
259 fi
260 create_tarball ;;
261 *)
262 gettext -e "\nERROR: Unable to handle:"; echo -e " $file \n" | \
263 tee -a $LOGS/$PACKAGE.log
264 exit 1 ;;
265 esac
266 done
267 }
269 # get source tarball
270 # $1 = --extract
271 getsrc() {
272 gettext "Getting source for:"; echo " $pkg"
273 set_paths
274 [ -f "$SRC/$lzma_tarball" ] && \
275 TARBALL="$lzma_tarball"
277 # Get source tarball and make sure we have source dir named:
278 # $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
279 # tarball if it exists.
280 look_for_cookopt !unpack && unpack="no"
281 look_for_cookopt !repack_src && LZMA_SRC=""
282 if [ ! "$WANTED" ] && [ "$TARBALL" ] && [ ! "$unpack" ] && [ ! "$cook_code" ]; then
283 [ -d $tmpsrc ] && rm -rf $tmpsrc
284 mkdir -p $tmpsrc && cd $tmpsrc
285 fi
287 if [ "$WGET_URL" ] && [ ! -f "$SRC/$TARBALL" ]; then
288 separator && download
289 fi
291 if [ "$WGET_URL" ] && [ -f "$SRC/$TARBALL" ] && [ ! "$unpack" ] && [ ! "$cook_code" ]; then
292 [ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
293 if [ "$1" = "--extract" ]; then
294 extract_source || exit 1
295 if [ ! -f "$SRC/$lzma_tarball" ] && [ "$LZMA_SRC" ]; then
296 echo -e "Repacking source."
297 repack_source || exit 1
298 fi
299 extract_path || exit 1
300 if [ -f $SRC/$TARBALL ]; then
301 [ -d $tmpsrc ] && rm -rf $tmpsrc
302 fi
303 fi
304 fi
306 # This is to make sure if PATCH equals something it will be downloaded
307 # checks are done in download functions
308 if [ "$PATCH" ] && [ ! "$cook_code" ]; then
309 if [ ! -f "$SRC/$PTARBALL" ]; then
310 separator && download
311 fi
312 fi
314 echo -e "Tarball: $SRC/$TARBALL"
315 [ "$PATCH" ] && echo -e "Patch: $SRC/$PTARBALL"
316 }
318 # the base function to download sources when offline
319 # This is to make sure source can be download when local-mirror
320 # script is in use.
321 download_base() {
322 local URLS url alt_url orig_url orig_url_patch
323 url="$ONLINE_SRC_REPOSITORY"
324 if [ "$SOURCE" ]; then
325 alt_url="${url}${SOURCE:0:1}/$SOURCE-${KBASEVER:-$VERSION}.tar.lzma"
326 else
327 alt_url="${url}${PACKAGE:0:1}/$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma"
328 fi
329 orig_url="${url}${TARBALL:0:1}/$TARBALL"
330 [ "$PATCH" ] && orig_url_patch="${url}${PTARBALL:0:1}/$PTARBALL"
331 URLS="$@ $alt_url $orig_url $orig_url_patch"
332 [ "$LAN_MIRROR" ] && URLS="$alt_url $orig_url $orig_url_patch $@"
333 if [ "$WGET_URL" = "$orig_url" ]; then
334 [ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
335 get_source $@
336 elif [ "$WGET_URL" = "$alt_url" ]; then
337 LZMA_SRC=""
338 get_source $@
339 else
340 for i in $URLS; do
341 if [ "$1" = "$PATCH" ]; then
342 [ ! -f "$SRC/$PTARBALL" ] || continue
343 else
344 [ ! -f "$SRC/$TARBALL" ] || continue
345 fi
346 case $i in
347 ${url}*)
348 [ "$i" = "$alt_url" ] && TARBALL="$(basename $alt_url)"
349 [ "$i" = "$alt_url" ] && LZMA_SRC=""
350 get_source $i
351 ;;
352 *)
353 get_source $i ;;
354 esac
355 done
356 fi
357 }
359 # Get source from multible urls
360 download() {
361 if [ ! -s "$SRC/$TARBALL" ]; then
362 download_base $WGET_URL
363 [ -f "$SRC/$TARBALL" ] || broken
364 fi
366 if [ "$PATCH" ]; then
367 if [ ! -s "$SRC/$PTARBALL" ]; then
368 download_base $PATCH
369 [ -f "$SRC/$PTARBALL" ] || broken
370 fi
371 fi
372 }
374 # Extract source package.
375 extract_source() {
376 gettext "Extracting:"; echo " $TARBALL"
377 case "$TARBALL" in
378 *.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
379 *.tar.bz2|*.tbz|*.tbz2) tar xjf $SRC/$TARBALL 2>/dev/null ;;
380 *.tar.lzma) tar xaf $SRC/$TARBALL ;;
381 *.tar) tar xf $SRC/$TARBALL ;;
382 *.zip|*.xpi) unzip -o $SRC/$TARBALL ;;
383 *.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
384 *.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
385 *.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
386 *.deb) ar vx $SRC/$TARBALL
387 [ ! -d $tmpsrc/$PACKAGE-$VERSION ] && mkdir -p $tmpsrc/$PACKAGE-$VERSION
388 cd $tmpsrc/$PACKAGE-$VERSION
389 tar -xvzf $tmpsrc/data.tar.gz
390 [ -f $tmpsrc/data.tar.gz ] && rm -f $tmpsrc/data.tar.gz
391 [ -f $tmpsrc/control.tar.gz ] && rm -f $tmpsrc/control.tar.gz
392 [ -f $tmpsrc/debian-binary ] && rm -f $tmpsrc/debian-binary ;;
393 *.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
394 *.7z) 7zr x $SRC/$TARBALL ;;
395 *) cp $SRC/$TARBALL $(pwd) ;;
396 esac
397 chown -R 0.0 $(pwd)
398 }
400 # Repack source tarball as .tar.lzma
401 # The source tarball is extracted as $tmpsrc/$pkgsrc path
402 # This way the source has a clean path when building
403 repack_source() {
405 # Some archives are not well done and don't extract to one dir (ex lzma).
406 files=$(ls | wc -l)
407 [ "$files" == 1 ] && [ -d "$(ls)" ] && [ ! -d "$pkgsrc" ] && mv * $tmpsrc/$pkgsrc
408 if [ ! -d "$tmpsrc/$pkgsrc" ]; then
409 cd $basesrc
410 if [ "$(ls -A tmp | wc -l)" -gt 1 ] || [ -f "$(echo tmp/*)" ]; then
411 mv tmp tmp-1 && mkdir tmp
412 mv tmp-1 tmp/$pkgsrc
413 fi
414 fi
415 if [ -d "$tmpsrc/$pkgsrc" ]; then
416 gettext "Repacking source is enabled:"; echo " LZMA_SRC"
417 TARBALL=$lzma_tarball
418 cd $tmpsrc
419 if [ -x /usr/bin/optipng ]; then
420 [ "$SHRINKPNG" ] && find -name "*.png" -type f | xargs -i optipng "{}"
421 fi
422 tar -c * | lzma e $SRC/$TARBALL -si $LZMA_SET_DIR
423 if [ $REMOVE_ORIG_TARBALL ]; then
424 if [ -f $SRC/$TARBALL ]; then
425 [ -f $SRC/$orig_tarball ] && rm -f $SRC/$orig_tarball
426 fi
427 fi
428 fi
429 }
431 # Display cooked package summary.
432 summary() {
433 [ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
434 [ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
435 fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
436 size=$(du -sh $INCOMING/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
437 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
438 [ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
439 cookdate=$(date "+%Y-%m-%d %H:%M")
440 sec=$time
441 div=$(( ($time + 30) / 60))
442 [ "$div" != 0 ] && min="~ ${div}m"
443 gettext "Summary for:"; echo " $PACKAGE $VERSION"
444 separator
445 [ "$srcdir" ] && echo "Source dir : $srcdir"
446 [ "$TARBALL" ] && echo "Src file : $TARBALL"
447 [ "$srcsize" ] && echo "Src size : $srcsize"
448 [ "$prod" ] && echo "Produced : $prod"
449 cat << EOT
450 Packed : $fs
451 Compressed : $size
452 Files : $files
453 Cook time : ${sec}s $min
454 Cook date : $cookdate
455 Host arch : $ARCH
456 $(separator)
457 EOT
458 }
460 # Display debugging error info.
461 debug_info() {
462 echo -e "\nDebug information"
463 separator
464 echo "Cook date: $(date '+%Y-%m-%d %H:%M')"
465 for error in \
466 ERROR "No package" "cp: can't" "can't open" "can't cd" \
467 "error:" "fatal error:" "rm: can't remove" "cp: can't stat" \
468 "undefined reference to" "Unable to connect to" \
469 "link: cannot find the library" "CMake Error"
470 do
471 fgrep "$error" $LOGS/$pkg.log
472 done
473 separator && newline
474 }
476 # Copy all generic files (locale, pixmaps, .desktop). We use standard paths,
477 # so some packages need to copy these files with the receipt and genpkg_rules.
478 copy_generic_files()
479 {
480 # $LOCALE is set in cook.conf
481 if [ "$LOCALE" -a "$WANTED" = "" ]; then
482 if [ -d "$install/usr/share/locale" ]; then
483 mkdir -p $fs/usr/share/locale
484 for i in $LOCALE
485 do
486 if [ -d "$install/usr/share/locale/$i" ]; then
487 cp -a $install/usr/share/locale/$i $fs/usr/share/locale
488 fi
489 done
490 fi
491 fi
493 # Generic pixmaps copy can be disabled with GENERIC_PIXMAPS="no"
494 if [ "$GENERIC_PIXMAPS" != "no" ]; then
495 if [ -d "$install/usr/share/pixmaps" ]; then
496 mkdir -p $fs/usr/share/pixmaps
497 if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
498 cp -a $install/usr/share/pixmaps/$PACKAGE.png \
499 $fs/usr/share/pixmaps
500 elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
501 cp -a $install/usr/share/pixmaps/$PACKAGE.xpm \
502 $fs/usr/share/pixmaps
503 fi
504 fi
506 # Custom or homemade PNG pixmap can be in stuff.
507 if [ -f "$stuff/$PACKAGE.png" ]; then
508 mkdir -p $fs/usr/share/pixmaps
509 cp -a $stuff/$PACKAGE.png $fs/usr/share/pixmaps
510 fi
511 fi
513 # Desktop entry (.desktop).
514 # Generic desktop entry copy can be disabled with GENERIC_MENUS="no"
515 if [ "$GENERIC_MENUS" != "no" ]; then
516 if [ -d "$install/usr/share/applications" ] && [ "$WANTED" == "" ]; then
517 mkdir -p $fs/usr/share
518 cp -a $install/usr/share/applications $fs/usr/share
519 fi
520 fi
522 # Homemade desktop file(s) can be in stuff.
523 if [ -d "$stuff/applications" ]; then
524 mkdir -p $fs/usr/share
525 cp -a $stuff/applications $fs/usr/share
526 fi
527 if [ -f "$stuff/$PACKAGE.desktop" ]; then
528 mkdir -p $fs/usr/share/applications
529 cp -a $stuff/$PACKAGE.desktop $fs/usr/share/applications
530 fi
532 # Add custom licenses
533 if [ -d "$stuff/licenses" ]; then
534 mkdir -p $fs/usr/share/licenses
535 cp -a $stuff/licenses $fs/usr/share/licenses/$PACKAGE
536 fi
537 }
539 # Find and strip : --strip-all (-s) or --strip-debug on static libs as well
540 # as removing uneeded files like in Python packages. Cross compiled binaries
541 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
542 strip_package()
543 {
544 case "$ARCH" in
545 arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;;
546 *) export STRIP=strip ;;
547 esac
548 gettext "Executing strip on all files..."
549 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games
550 do
551 if [ -d "$dir" ]; then
552 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
553 fi
554 done
555 find $fs -name "*.so*" -exec $STRIP -s '{}' 2>/dev/null \;
556 find $fs -name "*.a" -exec $STRIP --strip-debug '{}' 2>/dev/null \;
557 status
559 # Remove Python .pyc and .pyo from packages.
560 if echo "$PACKAGE $DEPENDS" | fgrep -q "python"; then
561 gettext "Removing Python compiled files..."
562 find $fs -type f -name "*.pyc" -delete 2>/dev/null
563 find $fs -type f -name "*.pyo" -delete 2>/dev/null
564 status
565 fi
567 # Remove Perl perllocal.pod and .packlist from packages.
568 if echo "$DEPENDS" | fgrep -q "perl"; then
569 gettext "Removing Perl compiled files..."
570 find $fs -type f -name "perllocal.pod" -delete 2>/dev/null
571 find $fs -type f -name ".packlist" -delete 2>/dev/null
572 status
573 fi
574 }
576 # Remove installed deps.
577 remove_deps() {
578 # Now remove installed build deps.
579 diff="$CACHE/installed.cook.diff"
580 if [ -s "$CACHE/installed.cook.diff" ]; then
581 deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
582 nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
583 gettext "Build dependencies to remove:"; echo " $nb"
584 gettext "Removing:"
585 for dep in $deps
586 do
587 echo -n " $dep"
588 tazpkg remove $dep --auto --root=/ >/dev/null
589 done
590 echo -e "\n"
591 # Keep the last diff for debug and info.
592 mv -f $CACHE/installed.cook.diff $CACHE/installed.diff
593 fi
594 }
596 # extract path of source tarball
597 # This is for the getsrc --extract option
598 extract_path()
599 {
600 # Some archives are not well done and don't extract to one dir (ex lzma).
601 files=$(ls | wc -l)
602 [ "$files" == 1 ] && [ -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
603 [ "$files" == 1 ] && [ -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
604 mv * ../$PACKAGE-$VERSION/$TARBALL
605 [ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
606 mv * ../$PACKAGE-$VERSION
607 cd .. && rm -rf tmp
608 if [ "$TOUCH_FILES" ]; then
609 echo "Touching source files to update timestamp"
610 echo "May take a bit"
611 find $src -type f -exec touch "{}" \;
612 fi
613 }
615 # The main cook function.
616 cookit() {
617 echo "Cook: $PACKAGE $VERSION"
618 separator
619 set_paths
621 # Handle cross-tools.
622 case "$ARCH" in
623 arm|x86_64)
624 # CROSS_COMPILE is used by at least Busybox and the kernel to set
625 # the cross-tools prefix but first check if sysroot is used.
626 # the cross-tools prefix. Sysroot the the root of our target arch
627 sysroot=$CROSS_TREE/sysroot
628 tools=$CROSS_TREE/tools
629 # Set root path when cross compiling. ARM tested but not x86_64
630 # When cross compiling we must install build deps in $sysroot.
631 arch="-${ARCH}"
632 root=$sysroot
633 echo "$ARCH sysroot: $sysroot"
634 echo "Adding $tools/bin to PATH"
635 export PATH=$PATH:$tools/bin
636 export PKG_CONFIG_PATH=$sysroot/usr/lib/pkgconfig
637 export CROSS_COMPILE=${HOST_SYSTEM}-
638 echo "Using cross-tools: $CROSS_COMPILE"
639 if [ "$ARCH" == "x86_64" ]; then
640 export CC="${HOST_SYSTEM}-gcc -m64"
641 export CXX="${HOST_SYSTEM}-g++ -m64"
642 else
643 export CC=${HOST_SYSTEM}-gcc
644 export CXX=${HOST_SYSTEM}-g++
645 fi
646 export AR=${HOST_SYSTEM}-ar
647 export AS=${HOST_SYSTEM}-as
648 export RANLIB=${HOST_SYSTEM}-ranlib
649 export LD=${HOST_SYSTEM}-ld
650 export STRIP=${HOST_SYSTEM}-strip ;;
651 *)
652 root="/" ;;
653 esac
655 [ "$QA" ] && receipt_quality
656 cd $pkgdir
657 rm -rf install taz source
659 # Disable -pipe if less than 512Mb free RAM.
660 free=$(free | fgrep '/+ buffers' | tr -s ' ' | cut -f 4 -d ' ')
661 if [ "$free" -lt 524288 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
662 gettext -e "Disabling -pipe compile flag: $free RAM\n"
663 CFLAGS="${CFLAGS/-pipe}" && CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
664 CXXFLAGS="${CXXFLAGS/-pipe}" && \
665 CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
666 fi
667 unset free
669 # Export flags and path to be used by make and receipt.
670 DESTDIR=$pkgdir/install
671 export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C
672 #export LDFLAGS
674 if [ ! "$WANTED" ] && [ "$TARBALL" ]; then
675 getsrc --extract
676 fi
678 # Check for build deps and handle implicit depends of *-dev packages
679 # (ex: libusb-dev :: libusb).
680 rm -f $CACHE/installed.local $CACHE/installed.web $CACHE/missing.dep
681 touch $CACHE/installed.local $CACHE/installed.web
682 look_for_cookopt !auto_dep && AUTO_DEP=""
683 if [ "$AUTO_DEP" -a ! "$WANTED" ]; then
684 BDEPS=$(scan $PACKAGE --look_for=bdep --with_dev | \
685 grep -v $(for i in $(look_for_rwanted) $PACKAGE; do echo " -e ^$i$"; done))
686 else
687 BDEPS="$BUILD_DEPENDS"
688 fi
689 [ "$BDEPS" ] && gettext -e "Checking build dependencies...\n"
690 [ "$root" != "/" ] && echo "Using packages DB: ${root}$DB"
691 for dep in $BDEPS
692 do
693 for i in $dep
694 do
695 if [ ! -f "${root}$INSTALLED/$i/receipt" ]; then
696 # Try local package first. In some cases implicit doesn't exist, ex:
697 # libboost-dev exists but not libboost, so check if we got vers.
698 unset vers
699 [ -f $WOK/$i/receipt ] || continue
700 vers=$(. $WOK/$i/receipt 2>/dev/null ; echo $VERSION)
701 if [ -f "$INCOMING/$i-${vers}_${kbasevers}.tazpkg" ]; then
702 echo $i-${vers}_${kbasevers}.tazpkg >> $CACHE/installed.local
703 elif [ -f "$PKGS/$i-${vers}_${kbasevers}.tazpkg" ]; then
704 echo $i-${vers}_${kbasevers}.tazpkg >> $CACHE/installed.local
705 elif [ -f "$INCOMING/$i-$vers.tazpkg" ]; then
706 echo $i-$vers.tazpkg >> $CACHE/installed.local
707 elif [ -f "$PKGS/$i-$vers.tazpkg" ]; then
708 echo $i-$vers.tazpkg >> $CACHE/installed.local
709 else
710 # Priority to package version in wok (maybe more up-to-date)
711 # than the mirrored one.
712 if [ "$vers" ]; then
713 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
714 echo $i >> $CACHE/installed.web
715 else
716 # So package exists in wok but not available.
717 gettext "Missing dep (wok/pkg):"; echo " $i $vers"
718 echo $i >> $CACHE/missing.dep
719 fi
720 else
721 # Package is not in wok but may be in online repo.
722 if fgrep -q $i-${vers}${arch} ${root}$DB/packages.list; then
723 echo $i >> $CACHE/installed.web
724 else
725 echo "ERROR: unknown dep $i" && exit 1
726 fi
727 fi
728 fi
729 fi
730 done
731 done
733 # Get the list of installed packages
734 ls -1 ${root}$INSTALLED > $CACHE/installed.list
736 # Have we a missing build dep to cook ?
737 if [ -s "$CACHE/missing.dep" ] && [ "$AUTO_COOK" ]; then
738 gettext -e "Auto cook config is set : AUTO_COOK\n"
739 cp -f $LOGS/$PACKAGE.log $LOGS/$PACKAGE.log.$$
740 for i in $(uniq $CACHE/missing.dep)
741 do
742 (gettext "Building dep (wok/pkg) :"; echo " $i $vers") | \
743 tee -a $LOGS/$PACKAGE.log.$$
744 cook $i || (echo -e "ERROR: can't cook dep '$i'\n" && \
745 fgrep "remove: " $LOGS/$i.log && \
746 fgrep "Removing: " $LOGS/$i.log && newline) | \
747 tee -a $LOGS/$PACKAGE.log.$$ && break
748 done
749 rm -f $CACHE/missing.dep
750 mv $LOGS/$PACKAGE.log.$$ $LOGS/$PACKAGE.log
751 fi
753 # QA: Exit on missing dep errors. We exit in both cases, if AUTO_COOK
754 # is enabled and cook fails we have ERROR in log, if no auto cook we have
755 # missing dep in cached file.
756 if fgrep -q "ERROR:" $LOGS/$pkg.log || [ -s "$CACHE/missing.dep" ]; then
757 [ -s "$CACHE/missing.dep" ] && nb=$(cat $CACHE/missing.dep | wc -l)
758 echo "ERROR: missing dep $nb" && exit 1
759 fi
761 # Install local packages: package-version${arch}
762 for i in $(uniq $CACHE/installed.local)
763 do
764 if [ -f "$INCOMING/$i" ]; then
765 gettext "Installing dep (pkg/local):"; echo " $i"
766 tazpkg install $INCOMING/$i --root=$root >/dev/null
767 elif [ -f "$PKGS/$i" ]; then
768 gettext "Installing dep (pkg/local):"; echo " $i"
769 tazpkg install $PKGS/$i --root=$root >/dev/null
770 fi
771 done
773 # Install web or cached packages (if mirror is set to $PKGS we only
774 # use local packages).
775 for i in $(uniq $CACHE/installed.web)
776 do
777 gettext "Installing dep (web/cache):"; echo " $i"
778 tazpkg get-install $i --root=$root >/dev/null
779 done
781 # If a cook failed deps are removed.
782 ls -1 ${root}$INSTALLED > $CACHE/installed.cook
783 [ ! -s "$CACHE/installed.cook.diff" ] && \
784 busybox diff $CACHE/installed.list $CACHE/installed.cook > $CACHE/installed.cook.diff
785 deps=$(cat $CACHE/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
787 # Execute receipt rules.
788 if [ $(grep ^compile_rules $receipt) ] && [ "$cook_code" = "" ]; then
789 echo "Executing: compile_rules"
790 echo "CFLAGS : $CFLAGS"
791 #echo "LDFLAGS : $LDFLAGS"
792 [ -d "$src" ] && cd $src
793 compile_rules $@ || broken
794 [ "$cook_code" ] && exit 1
795 # Stay compatible with _pkg
796 [ -d "$src/_pkg" ] && mv $src/_pkg $install
797 # QA: compile_rules success so valid.
798 mkdir -p $install
799 else
800 # QA: No compile_rules so no error, valid.
801 mkdir -p $install
802 fi
803 separator && newline
805 # Execute testsuite.
806 if grep -q ^testsuite $receipt; then
807 echo "Running testsuite"
808 separator
809 testsuite $@ || exit 1
810 separator && newline
811 fi
812 }
814 # Cook quality assurance.
815 cookit_quality() {
816 if [ ! -d "$WOK/$pkg/install" ] && [ ! "$WANTED" ]; then
817 echo -e "ERROR: cook failed" | tee -a $LOGS/$pkg.log
818 fi
819 # ERROR can be echoed any time in cookit()
820 if fgrep -q ERROR: $LOGS/$pkg.log; then
821 debug_info | tee -a $LOGS/$pkg.log
822 rm -f $command && exit 1
823 fi
824 }
826 # Create the package. Wanted to use Tazpkg to create a tazpkg package at first,
827 # but it doesn't handle EXTRAVERSION.
828 packit() {
829 set_paths
831 # Handle cross compilation
832 case "$ARCH" in
833 arm|x86_64) arch="-$ARCH" ;;
834 esac
836 echo "Pack: $PACKAGE ${VERSION}${arch}"
837 separator
839 if grep -q ^genpkg_rules $receipt; then
840 gettext -e "Executing: genpkg_rules\n"
841 set -e && cd $pkgdir && mkdir -p $fs
842 genpkg_rules || (broken && echo -e "\nERROR: genpkg_rules failed\n" >> \
843 $LOGS/$pkg.log)
844 else
845 gettext "No packages rules: meta package"; echo
846 mkdir -p $fs
847 fi
849 # First QA check to stop now if genpkg_rules failed.
850 if fgrep -q ERROR: $LOGS/$pkg.log; then
851 broken && exit 1
852 fi
854 cd $taz
855 for file in receipt description.txt
856 do
857 [ ! -f "../$file" ] && continue
858 gettext "Copying"; echo -n " $file..."
859 cp -f ../$file $pack && chown 0.0 $pack/$file && status
860 done
861 copy_generic_files
863 # Create files.list with redirecting find output.
864 gettext "Creating the list of files..." && cd $fs
865 find . -type f -print > ../files.list
866 find . -type l -print >> ../files.list
867 cd .. && sed -i s/'^.'/''/ files.list
868 status
870 # Strip and stuff files.
871 look_for_cookopt !strip && STRIP="n"
872 [ "$STRIP" ] || strip_package
874 # Md5sum of files.
875 gettext "Creating $CHECKSUM of files..."
876 while read file; do
877 [ -L "fs$file" ] && continue
878 [ -f "fs$file" ] || continue
879 case "$file" in
880 /lib/modules/*/modules.*|*.pyc) continue ;;
881 esac
882 $CHECKSUM "fs$file" | sed 's/ fs/ /'
883 done < files.list > "$CHECKSUM"
884 status
885 UNPACKED_SIZE=$(du -chs fs receipt files.list $CHECKSUM \
886 description.txt 2> /dev/null | awk \
887 '{ sz=$1 } END { print sz }')
889 if [ "$UPCOOKLIST" ]; then
890 check_so_files
891 fi
893 # Generate md5 of cooking stuff to look for commit later.
894 gen_cookmd5
895 echo -e "\n# md5sum of cooking stuff :" >> receipt
896 cat $WOK/$PACKAGE/md5 | sed 's/^/# /' >> receipt
898 # Build cpio archives.
899 gettext "Compressing the fs... "
900 find fs | cpio -o -H newc --quiet | lzma e fs.cpio.lzma -si $LZMA_SET_DIR
901 rm -rf fs
902 status
903 PACKED_SIZE=$(du -chs fs.cpio.lzma receipt files.list \
904 $CHECKSUM description.txt 2> /dev/null | awk \
905 '{ sz=$1 } END { print sz }')
906 gettext "Updating receipt sizes..."
907 sed -i s/^PACKED_SIZE.*$// receipt
908 sed -i s/^UNPACKED_SIZE.*$// receipt
909 sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
910 status
912 # Set extra version.
913 if [ "$EXTRAVERSION" ]; then
914 gettext "Updating receipt EXTRAVERSION: "; echo -n "$EXTRAVERSION"
915 sed -i s/^EXTRAVERSION.*$// receipt
916 sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
917 status
918 fi
920 # Compress.
921 gettext "Creating full cpio archive... "
922 find . -print | cpio -o -H newc --quiet > \
923 ../$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg
924 status
925 gettext "Restoring original package tree... "
926 unlzma -c fs.cpio.lzma | cpio -idm --quiet
927 status
928 rm fs.cpio.lzma && cd ..
930 if [ "$UPCOOKLIST" ]; then
931 check_recook_rdeps
932 fi
934 # QA and give info.
935 tazpkg=$(ls *.tazpkg)
936 packit_quality
937 separator && gettext "Package:"; echo -e " $tazpkg\n"
938 }
940 # Verify package quality and consistency.
941 packit_quality() {
942 #gettext "QA: Checking for broken link..."
943 #link=$(find $fs/usr -type l -follow)
944 #[ "$link" ] && echo -e "\nERROR: broken link in filesystem"
945 #status
947 # Exit if any error found in log file.
948 if fgrep -q ERROR: $LOGS/$pkg.log; then
949 rm -f $command && exit 1
950 fi
952 gettext "QA: Checking for empty package..."
953 files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
954 if [ "$files" == 0 ] && [ "$CATEGORY" != "meta" ]; then
955 echo -e "\nERROR: empty package"
956 rm -f $command && exit 1
957 else
958 # Ls sort by name so the first file is the one we want.
959 old=$(ls $INCOMING/$pkg-[0-9]*.tazpkg 2>/dev/null | head -n 1)
960 status
961 if [ -f "$old" ]; then
962 gettext "Removing old: $(basename $old)"
963 rm -f $old && status
964 fi
965 mv -f $pkgdir/taz/$pkg-*.tazpkg $INCOMING
966 sed -i /^${pkg}$/d $broken
967 fi
968 }
970 # Install package on --install or update the chroot.
971 install_package()
972 {
973 local pkg build
974 case "$ARCH" in
975 arm|x86_64)
976 arch="-${ARCH}"
977 root=$CROSS_TREE/sysroot ;;
978 *)
979 root="/" ;;
980 esac
981 # Install package if requested but skip install if target host doesn't
982 # match build system or it will break the build chroot.
983 build=$(echo $BUILD_SYSTEM | cut -d "-" -f 1)
984 for pkg in $PACKAGE; do
985 if [ -f "$inst" ] && [ "$build" == "$ARCH" ]; then
986 if [ -f "$INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
987 echo "Updating $ARCH chroot environment..."
988 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION}${arch})" | log
989 tazpkg install \
990 $INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg --root=$root --forced
991 else
992 gettext -e "Unable to install package, build has failed.\n\n"
993 exit 1
994 fi
995 fi
996 done
998 # Install package if part of the chroot to keep env up-to-date.
999 if [ -f "${root}$INSTALLED/$pkg/receipt" ]; then
1000 . /etc/slitaz/cook.conf
1001 . $WOK/$pkg/taz/$pkg-*/receipt
1002 echo "Updating $ARCH chroot environment..."
1003 echo "Updating chroot: $pkg (${VERSION}${EXTRAVERSION}${arch})" | log
1004 if [ -f "$PKGS/$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
1005 tazpkg install \
1006 $PKGS/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
1007 --forced --root=$root
1008 elif [ -f "$INCOMING/$PACKAGE-${VERSION}${EXTRAVERSION}${arch}.tazpkg" ]; then
1009 tazpkg install \
1010 $INCOMING/$pkg-${VERSION}${EXTRAVERSION}${arch}.tazpkg \
1011 --forced --root=$root
1012 fi
1013 fi
1016 tac()
1018 sed '1!G;h;$!d' $1
1021 # this function is to build the unbuild list
1022 unbuild()
1024 check_root
1025 get_options_list="full list"
1026 get_options
1027 [ -f $unbuild ] && rm -rf $unbuild
1028 LIST="$fullco"
1029 [ -f "$1" ] && LIST="$1"
1030 #[ "$full" ] && LIST=$(ls $WOK)
1031 if [ -f "$1" -a "$full" ]; then
1032 COMMAND=gen-cooklist
1033 gen_cook_list
1034 LIST="$tmp/cooklist"
1035 fi
1036 for pkg in $(cat $LIST | grep -v ^#); do
1037 unset VERSION PACKAGE
1038 [ -f $WOK/$pkg/receipt ] || continue
1039 . $WOK/$pkg/receipt
1040 if [ ! -f $INCOMING/$PACKAGE-${VERSION}*.tazpkg -a ! -f $PKGS/$PACKAGE-${VERSION}*.tazpkg ]; then
1041 echo "$PACKAGE" && echo "$PACKAGE" >> $unbuild
1042 fi
1043 done
1044 unset pkg
1045 [ "$list" ] && cp -a $unbuild $cooklist
1048 # Launch the cook command into a chroot jail protected by aufs.
1049 # The current filesystems are used read-only and updates are
1050 # stored in a separate branch.
1051 try_aufs_chroot() {
1053 base=/dev/shm/aufsmnt$$
1055 # Can we setup the chroot ? Is it already done ?
1056 grep -q ^AUFS_NOT_SUPPORTED $receipt && return
1057 [ -n "$AUFS_MOUNTS" -a ! -f /aufs-umount.sh ] || return
1058 lsmod | grep -q aufs || modprobe aufs 2> /dev/null || return
1059 mkdir ${base}root ${base}rw || return
1061 echo "Setup aufs chroot..."
1063 # Sanity check
1064 for i in / /proc /sys /dev/shm /dev/pts /home ; do
1065 case " $AUFS_MOUNTS " in
1066 *\ $i\ *) ;;
1067 *) AUFS_MOUNTS="$AUFS_MOUNTS $i" ;;
1068 esac
1069 done
1070 for mnt in $(echo $AUFS_MOUNTS | sort | uniq); do
1071 mount --bind $mnt ${base}root$mnt
1072 if [ $mnt == / ] && ! mount -t aufs -o br=${base}rw:/ none ${base}root; then
1073 echo "Aufs mountage failure"
1074 umount ${base}root
1075 rmdir ${base}*
1076 return
1077 fi
1078 echo "umount ${base}root$mnt" >> ${base}rw/aufs-umount.sh
1079 done
1081 chroot ${base}root $(cd $(dirname $0); pwd)/$(basename $0) "$@"
1082 status=$?
1084 echo "Leaving aufs chroot..."
1085 tac ${base}rw/aufs-umount.sh | sh
1086 rm -rf ${base}rw
1087 umount ${base}root
1088 rmdir $base*
1090 # Install package if requested
1091 install_package
1092 exit $status
1095 # Create a XML feed for freshly built package.
1096 gen_rss() {
1097 pubdate=$(date "+%a, %d %b %Y %X")
1098 cat > $FEEDS/$pkg.xml << EOT
1099 <item>
1100 <title>$PACKAGE $VERSION${EXTRAVERSION}</title>
1101 <link>${COOKER_URL}?pkg=$PACKAGE</link>
1102 <guid>$PACKAGE-$VERSION${EXTRAVERSION}</guid>
1103 <pubDate>$pubdate</pubDate>
1104 <description>$SHORT_DESC</description>
1105 </item>
1106 EOT
1112 # Commands
1115 case "$COMMAND" in
1116 usage|help|-u|-h)
1117 usage ;;
1118 list-wok)
1119 gettext -e "\nList of packages in:"; echo " $WOK"
1120 separator
1121 cd $WOK && ls -1
1122 separator
1123 echo -n "Packages: " && ls | wc -l
1124 newline ;;
1125 activity)
1126 cat $activity ;;
1127 search)
1128 # Just a simple search function, we dont need more actually.
1129 query="$2"
1130 newline
1131 gettext "Search results for:"; echo " $query"
1132 separator
1133 cd $WOK && ls -1 | grep "$query"
1134 separator && newline ;;
1135 setup)
1136 # Setup a build environment
1137 check_root
1138 echo "Cook: setup environment" | log
1139 newline
1140 gettext "Setting up your environment"; newline
1141 separator && cd $SLITAZ
1142 init_db_files
1143 gettext "Checking for packages to install..."; echo
1144 # Use setup pkgs from cross.conf or cook.conf. When cross compiling
1145 # ARCH-setup or 'cross check-env' should be used before: cook setup
1146 case "$ARCH" in
1147 arm|x86_64)
1148 if [ ! -x "/usr/bin/cross" ]; then
1149 gettext "ERROR: cross is not installed"; echo
1150 exit 1
1151 fi
1152 gettext "Using config file: /etc/slitaz/cross.conf"; echo
1153 . /etc/slitaz/cross.conf ;;
1154 esac
1155 for pkg in $INSTALL_PKGS; do
1156 if [ "$forced" ]; then
1157 tazpkg -gi $pkg --forced
1158 else
1159 [ -f "$INSTALLED/$pkg/receipt" ] || tazpkg get-install $pkg
1160 fi
1161 done
1162 # chroot list
1163 ls -1 "$INSTALLED" > $CACHE/chroot-pkgs
1164 # Handle --options
1165 case "$2" in
1166 --wok)
1167 hg clone $WOK_URL $WOKHG || exit 1 ;;
1168 --stable)
1169 hg clone $WOK_URL-stable $WOKHG || exit 1 ;;
1170 --undigest)
1171 hg clone $WOK_URL-undigest $WOKHG || exit 1 ;;
1172 --tiny)
1173 hg clone $WOK_URL-tiny $WOKHG || exit 1 ;;
1174 esac
1176 rsync_wok
1178 # SliTaz group and permissions
1179 if ! grep -q ^slitaz /etc/group; then
1180 gettext -e "Adding group: slitaz\n"
1181 addgroup slitaz
1182 fi
1183 gettext -e "Setting permissions for slitaz group...\n"
1184 find $SLITAZ -maxdepth 2 -exec chown root.slitaz {} \;
1185 find $SLITAZ -maxdepth 2 -exec chmod g+w {} \;
1186 separator
1187 gettext -e "All done, ready to cook packages :-)\n\n" ;;
1188 *-setup)
1189 # Setup for cross compiling.
1190 arch=${1%-setup}
1191 check_root
1192 echo "Cook: setup $arch cross environment" | log
1193 newline
1194 boldify $(gettext "Setting up your $arch cross environment")
1195 separator
1196 init_db_files
1197 sed -i \
1198 -e s"/ARCH=.*/ARCH=\"$arch\"/" \
1199 -e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
1200 -e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
1201 /etc/slitaz/cook.conf
1202 case "$arch" in
1203 arm)
1204 sed -i \
1205 -e s'/CFLAGS=.*/CFLAGS="-march=armv6 -O2"/' \
1206 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux-gnueabi/' \
1207 -e s'/xorg-dev/""/' \
1208 /etc/slitaz/cook.conf ;;
1209 x86_64)
1210 sed -i \
1211 -e s'/CFLAGS=.*/CFLAGS=""/' \
1212 -e s'/HOST_SYSTEM=.*/HOST_SYSTEM=$ARCH-slitaz-linux/' \
1213 /etc/slitaz/cook.conf ;;
1214 esac
1215 . /etc/slitaz/cook.conf
1216 sysroot=$CROSS_TREE/sysroot
1217 tools=/cross/$arch/tools
1218 root=$sysroot
1219 CC=$tools/bin/${HOST_SYSTEM}-gcc
1220 echo "Target arch : $ARCH"
1221 echo "Configure args : $CONFIGURE_ARGS"
1222 echo "Arch sysroot : $sysroot"
1223 echo "Tools prefix : $tools/bin"
1224 # Tell the packages manager where to find packages.
1225 echo "Packages DB : ${root}$DB"
1226 mkdir -p ${root}$INSTALLED
1227 cd ${root}$DB && rm -f *.bak
1228 for list in packages.list packages.desc packages.equiv packages.md5
1229 do
1230 rm -f $list && ln -s $SLITAZ/packages/$list $list
1231 done
1232 # We must have the cross compiled glibc-base installed or default
1233 # i486 package will be used as dep by tazpkg and then break the
1234 # cross environment
1235 if [ ! -f "${root}$INSTALLED/glibc-base/receipt" ]; then
1236 colorize 36 "WARNING: (e)glibc-base is not installed in sysroot"
1237 fi
1238 # Show GCC version or warn if not yet compiled.
1239 if [ -x $CC ]; then
1240 echo "Cross compiler : ${HOST_SYSTEM}-gcc"
1241 else
1242 colorize 36 "C compiler is missing: ${HOST_SYSTEM}-gcc"
1243 echo "Run 'cross compile' to cook a toolchain"
1244 fi
1245 separator && newline ;;
1246 upwok)
1247 case "$2" in
1248 --local)
1249 gettext -e "Updating local chanages in wok-hg to wok...\n"
1250 rsync_wok || exit 1
1251 exit 1 ;;
1252 esac
1254 gettext -e "Updating wok-hg...\n"
1255 if [ -d $WOKHG/.hg ]; then
1256 cd $WOKHG
1257 hg pull -u || exit 1
1258 fi
1259 cd $SLITAZ
1260 rsync_wok || exit 1 ;;
1261 test)
1262 # Test a cook environment.
1263 echo "Cook test: testing the cook environment" | log
1264 [ ! -d "$WOK" ] && exit 1
1265 [ ! -d "$WOK/cooktest" ] && cp -r $DATA/cooktest $WOK
1266 cook cooktest ;;
1267 new)
1268 # Create the package folder and an empty receipt.
1269 pkg="$2"
1270 [ "$pkg" ] || usage
1271 newline
1272 if [ -d "$WOKHG/$pkg" ]; then
1273 echo -n "$pkg " && gettext "package already exists."
1274 echo -e "\n" && exit 1
1275 fi
1276 gettext "Creating"; echo -n " $WOKHG/$pkg"
1277 mkdir $WOKHG/$pkg && cd $WOKHG/$pkg && status
1278 gettext "Preparing the package receipt..."
1279 cp $DATA/receipt .
1280 sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
1281 status && newline
1283 # Interactive mode, asking and seding.
1284 case "$3" in
1285 --interactive|-x)
1286 gettext -e "Entering interactive mode...\n"
1287 separator
1288 echo "Package : $pkg"
1289 # Version.
1290 echo -n "Version : " ; read anser
1291 sed -i s/'VERSION=\"\"'/"VERSION=\"$anser\""/ receipt
1292 # Category.
1293 echo -n "Category : " ; read anser
1294 sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$anser\""/ receipt
1295 # Short description.
1296 echo -n "Short desc : " ; read anser
1297 sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$anser\""/ receipt
1298 # Maintainer.
1299 echo -n "Maintainer : " ; read anser
1300 sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$anser\""/ receipt
1301 # License.
1302 echo -n "License : " ; read anser
1303 sed -i s/'LICENSE=\"\"'/"LICENSE=\"$anser\""/ receipt
1304 # Web site.
1305 echo -n "Web site : " ; read anser
1306 sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$anser\""# receipt
1307 newline
1308 # Wget URL.
1309 echo "Wget URL to download source tarball."
1310 echo "Example : \$GNU_MIRROR/\$PACKAGE/\$TARBALL"
1311 echo -n "Wget url : " ; read anser
1312 sed -i s#'WGET_URL=\"$TARBALL\"'#"WGET_URL=\"$anser\""# receipt
1313 # Ask for a stuff dir.
1314 echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
1315 if [ "$anser" = "y" ]; then
1316 echo -n "Creating the stuff directory..."
1317 mkdir -p $WOKHG/$pkg/stuff && status
1318 fi
1319 # Ask for a description file.
1320 echo -n "Are you going to write a description ? (y/N) : " ; read anser
1321 if [ "$anser" = "y" ]; then
1322 echo -n "Creating the description.txt file..."
1323 newline > $WOKHG/$pkg/description.txt && status
1324 fi
1325 separator
1326 gettext -e "Receipt is ready to use.\n"
1327 newline ;;
1328 esac ;;
1329 list)
1330 # Cook a list of packages (better use the Cooker since it will order
1331 # packages before executing cook).
1332 check_root
1333 [ -z "$2" ] && gettext -e "\nNo list in argument.\n\n" && exit 1
1334 [ ! -f "$2" ] && gettext -e "\nNo list found:" && \
1335 echo -e " $2\n" && exit 1
1336 echo "Cook list starting: $2" | log
1337 for pkg in $(cat $2)
1338 do
1339 cook $pkg || broken
1340 done ;;
1341 clean-wok)
1342 check_root
1343 gettext -e "\nCleaning all packages files..."
1344 rm -rf $WOK/*/taz $WOK/*/install $WOK/*/source
1345 status && newline ;;
1346 clean-src)
1347 check_root
1348 gettext -e "\nCleaning all packages sources..."
1349 rm -rf $WOK/*/source
1350 status && newline ;;
1351 gen-cooklist)
1352 check_root
1353 [ -f "$2" ] && LIST="$2"
1354 get_options_list="pkg wok missing"
1355 get_options
1356 if ! [ "$pkg" ]; then
1357 if [ ! "$LIST" ] || [ "$LIST" = "toolchain" ]; then
1358 pkg="$TOOLCHAIN $TOOLCHAIN_EXTRA"
1359 else
1360 check_for_list
1361 fi
1362 fi
1363 gen_cook_list
1364 if [ "$missing" ]; then
1365 cooklist=${LIST:-$cooklist}
1366 for pkgname in $(cat $cooklist)
1367 do
1368 unset EXTRAVERSION
1369 [ -f $wok/$pkgname/receipt ] || continue
1370 . $wok/$pkgname/receipt
1371 if [ -f $INCOMING/$PACKAGE-${VERSION}*.tazpkg -o -f $PKGS/$PACKAGE-${VERSION}*.tazpkg ]; then
1372 if grep "^$pkgname" $cooklist; then
1373 sed -i "s|^$pkgname$||g" $cooklist
1374 sed -i /^$/d $cooklist
1375 fi
1376 fi
1377 done
1378 fi
1380 #rm -f $command
1381 ;;
1382 gen-wok-db)
1383 check_root
1384 #echo "cook:gen-wok-db" > $command
1385 [ -d "$WOKHG" ] && WOK="$WOKHG"
1386 [ "$2" ] && WOK="$2"
1387 gen_wok_db ;;
1388 check-incoming)
1389 check_root
1390 get_options_list="forced"
1391 get_options
1392 echo "cook:check-incoming" > $command
1393 check_for_incoming
1394 rm -f $command ;;
1395 gen-src)
1396 check_root
1397 [ "$2" ] && src_repository="$2"
1398 [ -d "$src_repository" ] || src_repository="$SRC"
1399 gettext -e "Rebulding sources.list file: $src_repository"
1400 gen_sources_list $src_repository
1401 status ;;
1402 maintainers)
1403 check_root
1404 newline
1405 echo "List of maintainers for: $WOK"
1406 separator
1407 tmp="/tmp/slitaz-maintainers"
1408 touch $tmp
1409 for pkg in $WOK/*
1410 do
1411 [ -f $pkg/receipt ] || continue
1412 . $pkg/receipt
1413 if ! fgrep -q "$MAINTAINER" $tmp; then
1414 echo "$MAINTAINER" >> $tmp
1415 echo "$MAINTAINER"
1416 fi
1417 done
1418 separator
1419 echo "Maintainers: `cat $tmp | wc -l`"
1420 newline
1421 # Remove tmp files
1422 [ -f $tmp ] && rm -f $tmp
1423 ;;
1424 tags)
1425 check_root
1426 echo -e "\n\033[1mTags list :\033[0m"
1427 separator
1428 tmp="/tmp/tags"
1429 touch $tmp
1430 for pkg in $WOK/*; do
1431 unset TAGS
1432 [ -f $pkg/receipt ] || continue
1433 source $pkg/receipt
1434 for t in $TAGS; do
1435 grep -q ^$t$ $tmp && continue
1436 echo $t | tee -a $tmp
1437 done
1438 done
1439 separator
1440 echo "$(wc -l $tmp | cut -f1 -d ' ') tags listed."
1441 [ -f $tmp ] && rm -rf $tmp
1442 ;;
1443 maintained-by)
1444 # Search for packages maintained by a contributor.
1445 check_root
1446 if [ ! -n "$2" ]; then
1447 echo "Specify a name or email of a maintainer." >&2
1448 exit 1
1449 fi
1450 echo "Maintainer packages"
1451 separator
1452 for pkg in $WOK/*
1453 do
1454 [ -f $pkg/receipt ] || continue
1455 . $pkg/receipt
1456 if echo "$MAINTAINER" | fgrep -q "$2"; then
1457 echo "$PACKAGE"
1458 packages=$(($packages+1))
1459 fi
1460 done
1461 separator
1462 echo "Packages maintained by $2: $packages"
1463 newline
1464 ;;
1465 check-src)
1466 # Verify if upstream package is still available.
1468 check_root
1469 PACKAGE="$2"
1470 receipt="$WOK/$PACKAGE/receipt"
1471 if [ ! -f $receipt ]; then
1472 gettext -e "\nUnable to find package in the wok:"
1473 echo -e " $PACKAGE\n" && exit 1
1474 fi
1475 unset_receipt
1476 source $receipt
1477 check_src()
1479 for url in $@; do
1480 busybox wget -s $url 2>/dev/null && break
1481 done
1483 if [ "$WGET_URL" ];then
1484 echo -n "$PACKAGE : "
1485 check_src $WGET_URL
1486 status
1487 else
1488 echo "No tarball to check for $PACKAGE"
1489 fi
1490 ;;
1491 unbuild)
1492 unbuild "$2" "$3" ;;
1493 pkgdb)
1494 # Create suitable packages list for TazPKG and only for built packages
1495 # as well as flavors files for TazLiTo. We dont need logs since we do it
1496 # manually to ensure everything is fine before syncing the mirror.
1497 pkgdb "$2"
1498 if [ "$3" == "--flavors" ]; then
1499 cook flavors
1500 fi
1501 exit 0 ;;
1502 flavors)
1503 [ -d "$flavors" ] || $(echo -e "Missing flavors: $flavors\n" && exit 1)
1504 [ -d "$live" ] || mkdir -p $live
1505 gettext "Creating flavors files in:"; echo " $live"
1506 echo "Cook pkgdb: Creating all flavors" | log
1507 separator
1508 gettext -e "Recharging lists to use latest packages...\n"
1509 tazpkg recharge >/dev/null 2>/dev/null
1511 if [ ! -f "$live/cookiso.conf" ]; then
1512 echo "Creating configuration file: tazlito.conf"
1513 cp /etc/slitaz/cookiso.conf $live
1514 sed -i "s|WORK_DIR=.*|WORK_DIR="$SLITAZ"|g" $live/cookiso.conf
1515 fi
1517 #[ -d "$flavors/.hg" ] && $flavors && hg pull -u
1519 cd $live
1520 echo "Starting to generate flavors..."
1521 rm -f flavors.list *.flavor
1522 for i in $flavors/*
1523 do
1524 fl=$(basename $i)
1525 echo "Packing flavor: $(basename $i)"
1526 pack_flavor $fl >/dev/null || exit 1
1527 show_flavor $fl --brief --noheader 2> \
1528 /dev/null >> flavors.list
1529 done
1530 cp -f $live/*.flavor $live/flavors.list $PKGS
1531 separator && gettext "Flavors size: "; du -sh $live | awk '{print $1}'
1532 exit 0 ;;
1533 clean-chroot)
1534 clean_chroot ;;
1535 *)
1536 # Just cook and generate a package.
1537 check_root
1538 time=$(date +%s)
1539 pkg="$1"
1540 [ -z "$pkg" ] && usage
1541 receipt="$WOK/$pkg/receipt"
1542 check_pkg_in_wok && newline
1544 unset inst
1545 unset_receipt
1546 . $receipt
1548 # Handle cross compilation.
1550 # CROSS_NOTE: Actually we are running an ARM cooker but running
1551 # the cooker and build each commit in wok is not possible since
1552 # we dont cook the full wok for this arch. For ARM we need a set
1553 # of packages to handle a touch screen desktop, servers but not
1554 # erland.
1556 # The temporary solution is to build only reviewed and tested
1557 # packages with HOST_ARCH set in receipt.
1558 case "$ARCH" in
1559 arm)
1560 if [ ! "$HOST_ARCH" ]; then
1561 echo "cook: HOST_ARCH is not set in $pkg receipt"
1562 echo "cook: This package is not included in: $ARCH"
1563 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1564 echo "Cook skip: $pkg is not included in: $ARCH" | log
1565 newline && exit 1
1566 fi ;;
1567 esac
1569 # Some packages are not included in some arch or fail to cross compile.
1570 : ${HOST_ARCH=i486}
1571 if ! $(echo "$HOST_ARCH" | fgrep -q $ARCH); then
1572 echo "cook: HOST_ARCH=$HOST_ARCH"
1573 echo "cook: $pkg doesn't cook or is not included in: $ARCH"
1574 [ "$CROSS_BUGS" ] && echo "bugs: $CROSS_BUGS"
1575 echo "Cook skip: $pkg doesn't cook or is not included in: $ARCH" | log
1576 newline && exit 1
1577 fi
1579 # Skip blocked, 3 lines also for the Cooker.
1580 if grep -q "^$pkg$" $blocked && [ "$2" != "--unblock" ]; then
1581 gettext -e "Blocked package:"; echo -e " $pkg\n" && exit 0
1582 fi
1584 if [ "$AUFS_MODE" ]; then
1585 try_aufs_chroot "$@"
1586 fi
1588 # Log and source receipt.
1589 echo "Cook started for: <a href='cooker.cgi?pkg=$pkg'>$pkg</a>" | log
1590 echo "cook:$pkg" > $command
1592 # Display and log info if cook process stopped.
1593 trap 'gettext -e "\n\nCook stopped: control-C\n\n" | \
1594 tee -a $LOGS/$pkg.log' INT
1596 set_paths
1598 # Handle --options
1599 case "$2" in
1600 --clean|-c)
1601 gettext -e "Cleaning:"; echo -n " $pkg"
1602 cd $WOK/$pkg && rm -rf install taz source
1603 status && newline && exit 0 ;;
1604 --install|-i)
1605 inst='yes' ;;
1606 --noupdate|-nu)
1607 UPCHROOT="" ;;
1608 --nocleanchroot|-ncc)
1609 CLEAN_CHROOT="" ;;
1610 --getsrc|-gs)
1611 getsrc "$3"
1612 exit 0 ;;
1613 --block|-b)
1614 gettext "Blocking:"; echo -n " $pkg"
1615 [ $(grep "^$pkg$" $blocked) ] || echo "$pkg" >> $blocked
1616 status && newline && exit 0 ;;
1617 --unblock|-ub)
1618 gettext "Unblocking:"; echo -n " $pkg"
1619 sed -i "/^${pkg}$/"d $blocked
1620 status && newline && exit 0 ;;
1621 --pack)
1622 if [ -d $WOK/$pkg/taz ]; then
1623 rm -rf $WOK/$pkg/taz
1624 [ -f $LOGS/$pkg-pack.log ] && rm -rf $LOGS/$pkg-pack.log
1625 packit 2>&1 | tee -a $LOGS/$pkg-pack.log
1626 clean_log
1627 else
1628 gettext "Need to build $pkg." && exit 0
1629 fi
1630 exit 0 ;;
1631 esac
1633 # Check if wanted is built now so we have separate log files.
1634 if [ "$WANTED" ]; then
1635 if grep -q "^$WANTED$" $blocked; then
1636 echo "WANTED package $PACKAGE is blocked: $WANTED" | tee $LOGS/$pkg.log
1637 newline && rm -f $command && exit 1
1638 fi
1639 if grep -q "^$WANTED$" $broken; then
1640 echo "WANTED package $PACKAGE is broken: $WANTED" | tee $LOGS/$pkg.log
1641 newline && rm -f $command && exit 1
1642 fi
1643 if [ ! "$COOK_WANTED" ]; then
1644 if [ ! -d "$WOK/$WANTED/install" ]; then
1645 cook "$WANTED" || exit 1
1646 fi
1647 fi
1648 fi
1650 if [ "$UPCOOKLIST" ]; then
1651 db_md5=$(md5sum $dep_db $wan_db)
1652 echo "update_wok_db"
1653 update_wan_db
1654 echo "check_for_commit"
1655 check_for_commit
1656 sort -o $dep_db $dep_db
1657 sort -o $wan_db $wan_db
1658 if [ "$db_md5" != "$(md5sum $dep_db $wan_db)" ]; then
1659 grep -q "^#" $fullco || sed 1i"#PlanSort" -i $fullco
1660 fi
1661 fi
1663 # Cook and pack or exit on error and log everything.
1664 cookit $@ 2>&1 | tee $LOGS/$pkg.log
1665 remove_deps | tee -a $LOGS/$pkg.log
1666 if [ "$CLEAN_CHROOT" ]; then
1667 clean_chroot | tee -a $LOGS/$pkg.log
1668 fi
1669 cookit_quality
1670 packit 2>&1 | tee -a $LOGS/$pkg.log
1671 clean_log
1673 # Exit if any error in packing.
1674 if grep -q ^ERROR $LOGS/$pkg.log; then
1675 debug_info | tee -a $LOGS/$pkg.log
1676 broken
1677 rm -f $command && exit 1
1678 fi
1680 # This is needed cause unset and source receipt again
1681 if [ -f "$SRC/$lzma_tarball" ]; then
1682 TARBALL="$lzma_tarball"
1683 fi
1685 # Create an XML feed
1686 gen_rss
1688 # Time and summary
1689 time=$(($(date +%s) - $time))
1690 summary | tee -a $LOGS/$pkg.log
1691 newline
1693 if [ "$AUTO_PURGE_SRC" ]; then
1694 if [ -f "$SRC/$TARBALL" ]; then
1695 previous_tarball=$(grep ^$PACKAGE:incoming $SRC/sources.list | cut -f2)
1696 if [ -f "$SRC/$previous_tarball" ]; then
1697 sed "/^$PACKAGE:incoming/ s/.*/$PACKAGE:incoming\t$TARBALL/" \
1698 -i $SRC/sources.list
1699 grep -q $'\t'$previous_tarball$ $SRC/sources.list || \
1700 rm -f $SRC/$previous_tarball
1701 else
1702 echo -e "$PACKAGE:incoming\t$TARBALL" >> $SRC/sources.list
1703 fi
1704 fi
1705 fi
1707 # remove source folder if its not used in
1708 # genpkg_rules in all wanted packages
1709 remove_src
1711 install_package
1713 # Regen the cooklist if it was planned and command is not cook.
1714 [ "$regen_cooklist" -a "$UPCOOKLIST" ] && unset regen_cooklist && sort_cooklist
1716 if [ $(grep -l "^$pkg$" $broken) ]; then
1717 sed -i "^$pkg$" $broken
1718 fi
1719 # Finally we DONT WANT to build the *-dev or packages with WANTED="$pkg"
1720 # You want automation: use the Cooker Build Bot.
1721 rm -f $command ;;
1722 esac
1724 exit 0