cookutils annotate cook @ rev 992

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