cookutils annotate cook @ rev 1051

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