cookutils annotate cook @ rev 1088

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