cookutils annotate cook @ rev 841

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