cookutils annotate cook @ rev 1058

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