cookutils annotate cook @ rev 1044

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