mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1437 lines
43 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Build-Pkg
  11. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. exec 2>&1
  25. buildstart="`date "+%m/%d/%Y from %T"`"
  26. options=''
  27. config=default
  28. clear_src=1
  29. norebuild=0
  30. nopostinst=0
  31. update=0
  32. make_tar=''
  33. prefix="usr"
  34. prefix_auto=1
  35. pkgdir=""
  36. download=0
  37. verbose=0
  38. xtrace=0
  39. debug=0
  40. chroot=0
  41. root=""
  42. id=''
  43. desktopfiles=''
  44. desktopauto=1
  45. stagelevel=9
  46. this_is_the_2nd_run=0
  47. #
  48. # ---- Functions
  49. #
  50. help_msg() {
  51. spacer=" "
  52. echo
  53. echo "Usage: ./scripts/Build-Pkg" \
  54. "[ -0 | -1 | -2 ... | -8 | -9 ] \\"
  55. echo "$spacer [ -v ] [ -xtrace ] [ -chroot ] \\"
  56. echo "$spacer [ -root { <rootdir> | auto } ] [ -update ] \\"
  57. echo "$spacer [ -cfg <config> ] [ -nopostinst ] \\"
  58. echo "$spacer [ -prefix <prefix-dir> ] [ -norebuild ] \\"
  59. echo "$spacer [ -noclearsrc ] [ -pkgdir <pkgdir> ] \\"
  60. echo "$spacer [ -id <id> ] [ -debug ] pkg-name(s)"
  61. echo
  62. echo " Build a single package. Warning: Re-building a package might overwrite or"
  63. echo " remove configuration files; with the -update option modified files are backed"
  64. echo " up and restored after the package build. In most cases the other options are"
  65. echo " only needed by ./scripts/Build-Target when building the entire distribution."
  66. echo
  67. echo " -0, -1, ..., -9 set build stage to 0, 1, ..., 9, respectively"
  68. echo " -v be verbose"
  69. echo " -xtrace print additional xtrace (debug-)output to the"
  70. echo " build log file"
  71. echo " -chroot create and use a chroot environment"
  72. echo " -root { <rootdir> | auto } the root build directory to use;"
  73. echo " defaults to automatic setting"
  74. echo " -update backup/restore modified package files"
  75. echo " -cfg <config> the build configuration to use"
  76. echo " -nopostinst do not create postinstall files"
  77. echo " -prefix <prefix-dir> the installation prefix for packages;"
  78. echo " defaults to automatic setting"
  79. echo " -norebuild don't rebuild a previously successfully built package;"
  80. echo " if the \"retry broken\" Config option is set, don't"
  81. echo " rebuild unsuccessfully built packages, too"
  82. echo " -noclearsrc don't delete the package build directory (src.*)"
  83. echo " -pkgdir <pkgdir> path to package build config (package/..),"
  84. echo " either absolute or relative to ROCK Linux"
  85. echo " sources directory"
  86. echo " -id <id> use the given build id"
  87. echo " -debug enable debug mode: setup everything and exit before"
  88. echo " the actual build"
  89. echo " -download download missing source files"
  90. echo
  91. echo "Type './scripts/Help Build-Pkg' for details."
  92. echo
  93. }
  94. #
  95. # ---- Parse options + config and make Build-Pkg sub-calls
  96. #
  97. while [ "$1" ] ; do
  98. case "$1" in
  99. -this_is_the_2nd_run) this_is_the_2nd_run=1 ;;
  100. -[0-9]) options="$options $1" ; stagelevel=${1#-} ;;
  101. -v) options="$options $1" ; verbose=1 ;;
  102. -xtrace) options="$options $1" ; xtrace=1 ;;
  103. -debug) options="$options $1" ; debug=1 ; clear_src=0 ;;
  104. -update) options="$options $1" ; update=1 ;;
  105. -chroot) options="$options $1" ; chroot=1 ;;
  106. -chr-sub) options="$options $1" ; chroot=0 ;;
  107. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  108. -root) options="$options $1 $2" ; root="$2" ; shift ;;
  109. -prefix) options="$options $1 $2" ;
  110. prefix_auto=0 ; prefix="$2" ; shift ;;
  111. -id) options="$options $1 $2" ; id="$2" ; shift ;;
  112. -pkgdir) options="$options $1 $2" ; pkgdir="$2" ; shift ;;
  113. -noclearsrc) options="$options $1" ; clear_src=0 ;;
  114. -norebuild) options="$options $1" ; norebuild=1 ;;
  115. -nopostinst) options="$options $1" ; nopostinst=1 ;;
  116. -download) options="$options $1" ; download=1 ;;
  117. -*) help_msg ; exit 1 ;;
  118. *) break ;;
  119. esac
  120. shift
  121. done
  122. # check if arguments are left as package names
  123. if [ $# = 0 ] ; then
  124. help_msg ; exit 1
  125. fi
  126. ./scripts/Check-System || exit 1
  127. export ROCK_CHECK_SYSTEM_OK=1
  128. . ./scripts/functions
  129. . ./scripts/parse-config
  130. if [ -z "$root" -a $stagelevel -le 2 ] || \
  131. [ -z "$root" -a $chroot -eq 1 ] || \
  132. [ "$root" = auto ]; then
  133. root="build/$ROCKCFG_ID"
  134. fi
  135. [ "$pkgdir" -a "${pkgdir#/}" = "$pkgdir" ] && pkgdir="$base/$pkgdir"
  136. [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
  137. root=${root%/} ; xroot="$root" ; [ $stagelevel -ge 3 ] && root=""
  138. if [ -z "$id" ] ; then
  139. id=`get_unique`
  140. options="$options -id $id"
  141. fi
  142. ./scripts/Build-Tools -$stagelevel -cfg $config || exit 1
  143. # more than one package are passed
  144. if [ $# -gt 1 ] ; then
  145. for x ; do
  146. if ! ./scripts/Build-Pkg $options $x && \
  147. [ "$ROCKCFG_ABORT_ON_ERROR" = 1 ] ; then
  148. exit 1
  149. fi
  150. done
  151. exit 0
  152. fi
  153. # parameter 1 has $pkg=$xpkg
  154. pkg="${1%=*}"; xpkg="${1#*=}"
  155. builddir="$base/src.$xpkg.$id"
  156. # get real pkg name for mapped packages
  157. . build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkgmapper
  158. if [ $stagelevel -le 1 ] ; then
  159. prefix="$tools"
  160. fi
  161. prefix=${prefix%/} ; prefix=${prefix#/}
  162. # set desktop file name
  163. desktopfiles="$( echo ${base}/package/*/${pkg} )/*.desktop"
  164. export ROCK_PKG=$pkg
  165. export ROCK_XPKG=$xpkg
  166. # Set permissions and ownership of $buildir; $base/build might have different ones.
  167. mkdir -p "$builddir"; chmod 700 "$builddir" ; chown 0:0 "$builddir"
  168. if [ "$xroot" ] ; then
  169. pushd "$xroot/" >/dev/null || exit 1
  170. realconf=$(cd $base/config; pwd -P)
  171. realdown=$(cd $base/download; pwd -P)
  172. realbase=$(dirname $(cd $base/scripts; pwd -P))
  173. if [ ! -e ROCK/loop/scripts ]; then
  174. mkdir -p ROCK/{loop,config,download}
  175. mount --bind $realbase $PWD/ROCK/loop
  176. mount --bind $realconf $PWD/ROCK/config
  177. mount --bind $realdown $PWD/ROCK/download
  178. fi
  179. for x in Documentation architecture misc package scripts target; do
  180. if [ ! -e ROCK/$x ]; then ln -s "loop/$x" "ROCK/$x"; fi
  181. done
  182. if [ ! -e "ROCK/build/$ROCKCFG_ID" ]; then
  183. mkdir -p "ROCK/build"
  184. ln -snf ../.. "ROCK/build/$ROCKCFG_ID"
  185. fi
  186. # If build is a symlink to somewhere else (NFS share for clusterbuild
  187. # usually) we do _not_ want to extract our stuff there.
  188. # Network latency!
  189. ln -sf loop/src.$xpkg.$id ROCK/src.$xpkg.$id
  190. popd >/dev/null
  191. fi
  192. if [ "$chroot" = 1 ] ; then
  193. cd "$xroot" || exit 1
  194. x_mknod() {
  195. if [ ! -e "$1" ]; then
  196. mknod "$@"
  197. fi
  198. }
  199. mkdir -p dev/loop
  200. x_mknod dev/null c 1 3
  201. x_mknod dev/zero c 1 5
  202. x_mknod dev/random c 1 8
  203. x_mknod dev/urandom c 1 9
  204. x_mknod dev/loop/0 b 7 0
  205. x_mknod dev/loop/1 b 7 1
  206. x_mknod dev/loop/2 b 7 2
  207. x_mknod dev/loop/3 b 7 3
  208. x_mknod dev/tty c 5 0
  209. x_mknod dev/ptmx c 5 2
  210. if [ ! -L dev/fd ]; then
  211. ln -s /proc/self/fd dev/fd
  212. fi
  213. if [ "$ROCKCFG_PSEUDONATIVE" = 1 -a ! -f pseudonative_handler ]
  214. then
  215. echo_header "Preparing chroot dir for pseudonative build:"
  216. echo_status "Building pseudonative_handler."
  217. cc -static -o pseudonative_handler \
  218. $base/misc/tools-source/pseudonative_handler.c
  219. if [ ! -f /proc/sys/fs/binfmt_misc/register ] ; then
  220. echo_status "Mounting /proc/sys/fs/binfmt_misc."
  221. mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
  222. fi
  223. echo_status "Registering pseudonative_handler."
  224. sign="$( hexdump bin/bash | head -n2 | cut -f2- -d' ' | tr -d ' \n' | \
  225. cut -c 1-40 | sed -e 's,\(..\)\(..\),\\x\2\\x\1,g' )"
  226. echo ":${arch_machine}_rock_bin:M::$sign::/pseudonative_handler:" > /proc/sys/fs/binfmt_misc/register
  227. sign="$( hexdump lib/libc.so.[0-9] | head -n2 | cut -f2- -d' ' | tr -d ' \n' | \
  228. cut -c 1-40 | sed -e 's,\(..\)\(..\),\\x\2\\x\1,g' )"
  229. echo ":${arch_machine}_rock_lib:M::$sign::/pseudonative_handler:" > /proc/sys/fs/binfmt_misc/register
  230. echo_status "Creating pseudonative bindir."
  231. rm -rf ROCK/tools.cross/pseudonative.bin
  232. mkdir -p ROCK/tools.cross/pseudonative.bin
  233. cd ROCK/tools.cross
  234. while read f
  235. do
  236. b=$(basename $f)
  237. a=${b#$arch_target-}
  238. ln -sf ../$f pseudonative.bin/$b
  239. if [ "$a" != "$b" ]; then
  240. ln -sf ../$f pseudonative.bin/$a
  241. fi
  242. done < <(
  243. find crosscc lib libexec $arch_target wrapper -xtype f -perm +111 | \
  244. xargs file -L | grep ELF.*executable | cut -f1 -d:
  245. )
  246. echo_status "Applying some bin hotfixes."
  247. ln -s ../bin/true pseudonative.bin/umount
  248. ln -s ../bin/true pseudonative.bin/mount
  249. rm -f bin/uname pseudonative.bin/uname
  250. echo_status "Creating pseudonative libdir."
  251. rm -rf pseudonative.lib; mkdir -p pseudonative.lib
  252. cp /lib/ld-linux.so.* /lib/libc.so.* pseudonative.lib/
  253. cp /lib/libnss_compat.so.* pseudonative.lib/
  254. cp /lib/libnss_files.so.* pseudonative.lib/
  255. cd ../..
  256. echo_status "Creating fake rootdir-symlink."
  257. mkdir -p $( dirname ${xroot#/} )
  258. rm -f ${xroot#/}; ln -s / ${xroot#/}
  259. fi
  260. if [ ! -f proc/mounts ]; then
  261. mount -t proc proc $PWD/proc
  262. fi
  263. # A /dev with working PTYs is essential for make check in
  264. # binutils and gcc.
  265. if ! grep -q "$( pwd -P )/dev" /etc/mtab ; then
  266. mount --rbind /dev $PWD/dev
  267. fi
  268. cat > "$builddir/chroot.sh" <<- EOT
  269. #!/bin/bash
  270. export ROCK_THIS_IS_CHROOT=1; cd /ROCK
  271. ./scripts/Build-Pkg $options -chr-sub -root "/" "$1"
  272. EOT
  273. cat > "$builddir/debug.sh" <<- EOT
  274. #!/bin/bash
  275. export ROCK_THIS_IS_CHROOT=1
  276. if [ ! -e $PWD/ROCK/loop/scripts ]; then
  277. mount --bind $realbase $PWD/ROCK/loop
  278. mount --bind $realconf $PWD/ROCK/config
  279. mount --bind $realdown $PWD/ROCK/download
  280. fi
  281. if [ ! -e $PWD/ROCK/src.$xpkg.$id ]; then
  282. ln -s loop/src.$xpkg.$id $PWD/ROCK/src.$xpkg.$id
  283. fi
  284. chroot "$xroot" /bin/bash /ROCK/src.$xpkg.$id/debug_x.sh
  285. rm -f $PWD/ROCK/src.$xpkg.$id
  286. EOT
  287. chmod +x "$builddir/debug.sh"
  288. if [ "$TZ" ] ; then
  289. if [ "${TZ#/}" != "$TZ" ] ; then
  290. cp $TZ ROCK/localtime
  291. else
  292. cp /usr/share/zoneinfo/$TZ ROCK/localtime
  293. fi
  294. else
  295. if [ -f /etc/localtime ] ; then
  296. cp /etc/localtime ROCK/localtime
  297. else
  298. ln -s /usr/share/zoneinfo/Factory ROCK/localtime
  299. fi
  300. fi
  301. TZ="/ROCK/localtime" chroot . bin/bash ROCK/src.$xpkg.$id/chroot.sh
  302. returncode=$?
  303. # Only remove $builddir if it is empty.
  304. rmdir --ignore-fail-on-non-empty "$realbase/src.$xpkg.$id"
  305. exit $returncode
  306. fi
  307. if [ "$ROCKCFG_FLIST" = "flwrapper" -a -z "$FLWRAPPER" ] ; then
  308. export FLWRAPPER_WLOG="$builddir/fl_wrapper.wlog"
  309. export FLWRAPPER_RLOG="$builddir/fl_wrapper.rlog"
  310. export FLWRAPPER_BASEPID=$$
  311. [ "$LD_PRELOAD" ] && LD_PRELOAD="${LD_PRELOAD}:"
  312. export FLWRAPPER="$base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/fl_wrapper.so"
  313. export LD_PRELOAD="${LD_PRELOAD}$FLWRAPPER"
  314. fi
  315. export INSTALL_WRAPPER_LOGFILE="$builddir/install_wrapper.log"
  316. export CMD_WRAPPER_LOGFILE="$builddir/cmd_wrapper.log"
  317. if [ $norebuild = 1 -a -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  318. echo_pkg_deny $stagelevel $pkg "already built"
  319. exit 0
  320. fi
  321. if [ "$ROCKCFG_RETRY_BROKEN" = 0 -a $norebuild = 1 -a \
  322. -f $root/var/adm/logs/$stagelevel-$xpkg.err ] ; then
  323. echo_pkg_deny $stagelevel $pkg "already failed"
  324. exit 1
  325. fi
  326. confdir=""
  327. archdir="$builddir/archdir"
  328. if [ -z "$pkgdir" ] ; then
  329. for x in package/*/$pkg/$pkg.desc ; do
  330. if [ -f "$x" ] ; then
  331. if [ "$confdir" ] ; then
  332. echo_pkg_deny $stagelevel $pkg "in multiple trees"
  333. echo "Package in multiple trees: $pkg !" \
  334. > $root/var/adm/logs/$stagelevel-$xpkg.err
  335. exit 1
  336. fi
  337. x=${x#package/}; x=${x%%/*}
  338. confdir="$base/package/$x/$pkg"
  339. repository=$x
  340. fi
  341. done
  342. else
  343. if [ -f "$pkgdir/$pkg.desc" ] ; then
  344. confdir="$pkgdir"
  345. repository=extern
  346. fi
  347. fi
  348. if [ -z "$confdir" ] ; then
  349. echo_pkg_deny $stagelevel $pkg "does not exist" ; exit 1
  350. fi
  351. mkdir -p $root/var/adm/{logs,flists,cksums,md5sums,packages,dependencies}
  352. mkdir -p $root/var/adm/{dep-debug,parse-config,cache,descs,rock-debug}
  353. mkdir -p $root/var/adm/{provides,requires,conflicts}
  354. [ "$root" ] && chmod 700 $root
  355. rm -f $root/var/adm/logs/$stagelevel-$xpkg.{out,log,err}
  356. if [ $this_is_the_2nd_run = 0 ] ; then
  357. options="-this_is_the_2nd_run $options $pkg=$xpkg"
  358. if [ "$ROCKCFG_CREATE_CACHE" = 1 -a $stagelevel -ge 3 ] ; then
  359. mkdir -p $root/var/adm/cache
  360. touch $root/var/adm/cache/$xpkg
  361. rm -f $root/var/adm/cache/$xpkg.tm
  362. /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
  363. -f 'buildtime=$(qcalc %U + %S)' \
  364. env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' PATH="$PATH" \
  365. TZ="$TZ" ROCK_BUILD_TARGET=$ROCK_BUILD_TARGET \
  366. build_root="$build_root" build_rock="$build_rock" \
  367. build_logs="$build_logs" build_pkgs="$build_pkgs" \
  368. ROCK_THIS_IS_CHROOT="$ROCK_THIS_IS_CHROOT" \
  369. FLWRAPPER_WLOG="$FLWRAPPER_WLOG" FLWRAPPER_RLOG="$FLWRAPPER_RLOG" \
  370. FLWRAPPER_BASEPID="$FLWRAPPER_BASEPID" FLWRAPPER="$FLWRAPPER" \
  371. LD_PRELOAD="${LD_PRELOAD}" \
  372. $0 $options
  373. returncode=$?
  374. [ ! -e "$root/var/adm/cache/$xpkg.tm" ] && exit $returncode
  375. qcalc() { gawk "BEGIN { printf(\"%d\n\", ($*)*100); }"; }
  376. eval "`grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm`"
  377. rm -f $root/var/adm/cache/$xpkg.tm
  378. {
  379. errortag=""
  380. if [ -f "$root/var/adm/logs/$stagelevel-$xpkg.err" ] ; then
  381. errortag=" ERROR"
  382. fi
  383. if [ -f $confdir/$pkg.desc ] ; then
  384. grep '^\[COPY\] ' $confdir/$pkg.desc | \
  385. sed "s,/$pkg.desc\$,/$pkg.cache,"
  386. fi
  387. echo
  388. grep '^\[TIMESTAMP\]' $root/var/adm/cache/$xpkg
  389. date "+[TIMESTAMP] %s %c ($stagelevel)$errortag"
  390. echo
  391. echo "[CONFIG-ID] ${ROCKCFG_ID#*-}"
  392. echo -e "[ROCKVER] $rockver\n"
  393. echo "[LOGS]" $( cd $root/var/adm/logs ; \
  394. ls ?-$xpkg.* 2> /dev/null )
  395. echo
  396. grep '^\[BUILDTIME\]' $root/var/adm/cache/$xpkg
  397. echo "[BUILDTIME] $buildtime ($stagelevel)$errortag"
  398. x="$root/var/adm/packages/$xpkg"
  399. if [ -f $x ]; then
  400. echo "[SIZE] `grep "^Package Size: " \
  401. $x | cut -f3- -d' '`"
  402. fi
  403. echo
  404. x="$root/var/adm/dependencies/$xpkg"
  405. if [ "$pkg" != "rock-debug" -a -f $x ]; then
  406. cut -f2- -d' ' "$x" | \
  407. fmt -70 | sed 's,^,[DEP] ,'
  408. echo
  409. fi
  410. cat $root/var/adm/flists/$xpkg{,:*} 2> /dev/null | \
  411. sed -r '\,(bin/[^/]+|lib/.+\.(so|a))$, { s,.*/,,; p; };d' | \
  412. sort -u | fmt -w65 | sed 's,^,[PROVIDES] ,'
  413. echo
  414. for stagelevel in 0 1 2 3 4 5 6 7 8 9 ; do
  415. x="$root/var/adm/logs/$stagelevel-$xpkg.err"
  416. if [ -f "$x" ] ; then
  417. tail -n 50 "$x" | \
  418. sed "s,^,[$stagelevel-ERROR] ,"
  419. echo
  420. fi
  421. done
  422. } > $root/var/adm/cache/$xpkg.new
  423. mv $root/var/adm/cache/$xpkg.new $root/var/adm/cache/$xpkg
  424. exit $returncode
  425. else
  426. exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' PATH="$PATH" \
  427. TZ="$TZ" ROCK_BUILD_TARGET=$ROCK_BUILD_TARGET \
  428. build_root="$build_root" build_rock="$build_rock" \
  429. build_logs="$build_logs" build_pkgs="$build_pkgs" \
  430. ROCK_THIS_IS_CHROOT="$ROCK_THIS_IS_CHROOT" \
  431. FLWRAPPER_WLOG="$FLWRAPPER_WLOG" FLWRAPPER_RLOG="$FLWRAPPER_RLOG" \
  432. FLWRAPPER_BASEPID="$FLWRAPPER_BASEPID" FLWRAPPER="$FLWRAPPER" \
  433. LD_PRELOAD="${LD_PRELOAD}" \
  434. $0 $options
  435. fi
  436. fi
  437. #
  438. # ---- Setting Build Variables
  439. #
  440. if [ -z "$root" ] ; then
  441. dummydir="$builddir/rootdummy"
  442. else
  443. dummydir="${root}/ROCK/${builddir#$base/}/rootdummy"
  444. fi
  445. mkdir -p "$dummydir"
  446. if [[ "$xpkg" = *-32bit ]] ; then
  447. instroot="$dummydir"
  448. libs_only=1
  449. else
  450. instroot="$root"
  451. libs_only=0
  452. fi
  453. #
  454. if [[ -z "$arch_target32" || "$xpkg" = *-32bit ]] ; then
  455. multilib="lib"
  456. else
  457. multilib="lib64"
  458. fi
  459. flistroot="bin boot etc lib $multilib sbin usr var opt"
  460. flistrfilter="ldconfig\..*: .*|.*: /var/adm/.*"
  461. flistdel="var/adm/.*|var/tmp/.*|var/lock/.*|var/run/.*|etc/ld.so.cache|usr/tmp/.*|.*\\.old"
  462. pkgsplits=""
  463. if [ "$ROCKCFG_SPLIT_DEV" != 0 ]; then
  464. # this doesn't affect files in /lib, just /.../lib
  465. # so there needn't be an exception for linux kernel modules
  466. splitreg 40 dev "(/(lib|$multilib)/.*\.(la|a|o)\$|/include/|/man[23]/)"
  467. splitdesc_dev() { desc_I="$desc_I (development files)"; }
  468. fi
  469. if [ "$ROCKCFG_SPLIT_DOC" != 0 ]; then
  470. # only move doc/ to :doc, not man and info pages
  471. splitreg 60 doc '/share/doc/'
  472. splitdesc_doc() { desc_I="$desc_I (documentation)"; }
  473. fi
  474. makeopt='CC="$CC" CXX="$CXX"'
  475. if [ $stagelevel -le 2 ] ; then
  476. var_append makeopt ' ' 'CC_FOR_BUILD="$BUILDCC"'
  477. var_append makeopt ' ' 'BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
  478. var_append makeopt ' ' 'HOSTCC="$HOSTCC" HOST_CC="$HOST_CC"'
  479. var_append makeopt ' ' 'STRIP="$STRIP" AR="$AR" LD="$LD"'
  480. var_append makeopt ' ' 'RANLIB="$RANLIB" NM="$NM"'
  481. fi
  482. makeinstopt="$makeopt install"
  483. [ "$root" ] && var_append makeinstopt ' ' 'DESTDIR=$root'
  484. if [ $stagelevel -ge 3 ] ; then
  485. flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
  486. fi
  487. prepare="" ; hook_add prepare 5 'eval "$prepare"'
  488. prepatch="" ; hook_add prepatch 5 'eval "$prepatch"'
  489. postpatch="" ; hook_add postpatch 5 'eval "$postpatch"'
  490. postdoc="" ; hook_add postdoc 5 'eval "$postdoc"'
  491. preconf="" ; hook_add preconf 5 'eval "$preconf"'
  492. premake="" ; hook_add premake 5 'eval "$premake"'
  493. inmake="" ; hook_add inmake 5 'eval "$inmake"'
  494. postmake="" ; hook_add postmake 5 'eval "$postmake"'
  495. postinstall="" ; hook_add postinstall 5 'eval "$postinstall"'
  496. postflist="" ; hook_add postflist 5 'eval "$postflist"'
  497. finish="" ; hook_add finish 5 'eval "$finish"'
  498. [ "$ROCKCFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
  499. hook_add postflist 3 'postflist_libs'
  500. configprefix="" ; autogen=0 ; automakever=""
  501. configscript="./configure" ; extraconfopt=""
  502. configexec="bash"
  503. srcdir=auto ; srctar=auto
  504. taropt="--use-compress-program=bzip2 -xf"
  505. mainfunction="build_this_package"
  506. runconf=1 ; runxmkmf=1 ; runmkpl=1 ; runpysetup=1 ; runcmake=1 ; autopatch=1
  507. autoextract=1 ; chownsrcdir=1 ; nocvsinsrcdir=1; patchopt="-bfp1 -z .orig"
  508. createprefix=1 ; createdocs="" ; rmemptydir="" ; autoso2a=0 ; forcefpic=""
  509. cmakesrcdir=.
  510. check_shared=1
  511. check_usrlocal=1
  512. check_badfiles=1
  513. badfiles="" badfiles_nr=0
  514. declare -a badfiles_desc
  515. #
  516. # ---- Read various config files
  517. #
  518. parse_desc $confdir/$pkg.desc
  519. ver="`echo "$desc_V" | tail -n 1 | cut -f1 -d' '`"
  520. extraver="`echo "$desc_V" | tail -n 1 | cut -s -f2- -d' '`"
  521. [ -z "$extraver" ] && extraver="0"
  522. if [ "$pkg" = "$xpkg" ]; then
  523. echo_pkg_start $stagelevel $repository $xpkg $ver $extraver
  524. else
  525. echo_pkg_start $stagelevel $repository $pkg=$xpkg $ver $extraver
  526. fi
  527. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 -a -z "$pkgdir" ] ; then
  528. x="`./scripts/Check-PkgFormat $pkg`"
  529. [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
  530. `option to ignore such errors."
  531. fi
  532. targetdir="$base/target/$target"
  533. patchfiles="`ls $confdir/*.patch $confdir/*.patch.$arch \
  534. $confdir/*.patch_$xpkg $confdir/*.patch_$xpkg.$arch \
  535. $targetdir/pkg_$pkg.patch $targetdir/pkg_$pkg.patch.$arch \
  536. $targetdir/xpkg_$xpkg.patch $targetdir/xpkg_$xpkg.patch.$arch \
  537. 2>/dev/null | tr '\n' ' '`"
  538. if [ $stagelevel -le 2 ]; then
  539. patchfiles="`ls $patchfiles $confdir/*.patch.cross \
  540. $confdir/*.patch.cross.$arch 2>/dev/null | tr '\n' ' '`"
  541. fi
  542. if [ $stagelevel -le 1 -o "$ROCKCFG_CROSSBUILD" = 0 -a $stagelevel -eq 2 ] ; then
  543. createdocs=0
  544. fi
  545. if [ -f $confdir/$pkg.cache ]; then
  546. if ! egrep -q '^\[PROVIDES].*\.(so|a)( |$)' $confdir/$pkg.cache; then
  547. forcefpic="0"
  548. fi
  549. fi
  550. if [ $stagelevel -le 1 ] ; then
  551. var_append flistroot " " "$tools"
  552. flistdel="$flistdel|$tools/info/(dir|standards.info)"
  553. else
  554. flistdel="$flistdel|$tools(/.*|)"
  555. fi
  556. if [ $stagelevel -ge 3 ]; then
  557. for pc_file in $xroot/var/adm/parse-config/* ; do
  558. if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
  559. then . "$pc_file" ; fi
  560. done
  561. unset pc_file
  562. fi
  563. . $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config
  564. set_confopt
  565. if [ $stagelevel -eq 0 -a "$ROCKCFG_PSEUDONATIVE" = 1 ]; then
  566. echo_status "Building this package statically for pseudo native build."
  567. var_insert extraconfopt " " "--enable-static --disable-shared"
  568. for x in BUILDCC_WRAPPER_INSERT LDFLAGS LD CFLAGS CC; do
  569. var_append $x " " "-static"
  570. done
  571. fi
  572. eval "$desc_O"
  573. # include package pre config - if any
  574. if [ -f $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_pre.conf ] ; then
  575. echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
  576. . $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_pre.conf
  577. fi
  578. if [ -f $targetdir/pkg_$pkg.conf ] ; then
  579. echo_status "Reading package configuration from target directory."
  580. . $targetdir/pkg_$pkg.conf
  581. elif [ -f $confdir/$pkg.conf ] ; then
  582. echo_status "Reading package configuration from package directory."
  583. . $confdir/$pkg.conf
  584. fi
  585. # include package post config - if any
  586. if [ -f $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_post.conf ] ; then
  587. echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
  588. . $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_post.conf
  589. fi
  590. if [ -f $base/architecture/$arch/pkg-header ] ; then
  591. echo_status "Reading overwrites from architecture/$arch/pkg-header."
  592. . $base/architecture/$arch/pkg-header
  593. fi
  594. if [ -f $base/target/$target/pkg-header ] ; then
  595. echo_status "Reading overwrites from target/$target/pkg-header."
  596. . $base/target/$target/pkg-header
  597. fi
  598. #
  599. # ---- Variable updates based on the configuration files read
  600. #
  601. if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ] ; then
  602. flistdel="$flistdel|usr/share/info/(dir|standards.info)"
  603. if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  604. flistdel="$flistdel|usr/share/locale/..[/_].*"
  605. flistdel="$flistdel|usr/share/man/..[/_].*"
  606. fi
  607. if [ $stagelevel = 0 ] ; then
  608. flistdel="${flistdel//usr\//}|${flistdel//usr\/share\//}"
  609. fi
  610. else
  611. flistdel="$flistdel|$prefix/info/(dir|standards.info)"
  612. if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  613. flistdel="$flistdel|$prefix/share/locale/..[/_].*"
  614. flistdel="$flistdel|$prefix/man/..[/_].*"
  615. fi
  616. fi
  617. #
  618. # ---- Build Package
  619. #
  620. echo_status "Preparing build in src.$xpkg.$id"
  621. if [ "$ROCKCFG_SRC_TMPFS" = 1 ]; then
  622. echo_status "Mounting tmpfs on src.$xpkg.$id"
  623. mount -t tmpfs -o $ROCKCFG_SRC_TMPFS_OPT tmpfs "$builddir"
  624. fi
  625. if [ "$xroot" != "$root" ] ; then
  626. for x in $flistroot ; do
  627. [ -d $xroot/$x ] || mkdir -p $xroot/$x
  628. [ -d $root/$x ] || ln -sf $xroot/$x $root/
  629. done
  630. fi
  631. if [ $update = 1 ] ; then
  632. echo_status "Creating backup of old package data (running in update mode)."
  633. (
  634. cd $xroot/
  635. grep -v "^X" var/adm/md5sums/$xpkg var/adm/md5sums/$xpkg:* 2> /dev/null |
  636. md5sum --check - 2>&1 | grep ': FAILED$' | cut -f1 -d:
  637. ) > "$builddir/backup_files.txt"
  638. if [ -s "$builddir/backup_files.txt" ] ; then
  639. mkdir -p "$xroot/var/adm/backup"
  640. chmod 700 "$xroot/var/adm/backup"
  641. backup_tar="$xroot/var/adm/backup/$(
  642. date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
  643. ( cd $xroot/; tar --no-recursion --force-local -cf - -T "$builddir/`
  644. `backup_files.txt" || true; ) | bzip2 > $backup_tar
  645. else
  646. update=0
  647. fi
  648. fi
  649. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  650. rm -f "$builddir/"fl_wrapper.{r,w}log
  651. touch "$builddir/"fl_wrapper.{r,w}log
  652. elif [ "$ROCKCFG_FLIST" = "find" ] ; then
  653. touch "$builddir/temp.time_stamp"
  654. sleep 2
  655. fi
  656. if [ $stagelevel -gt 1 -a "$autoso2a" = 1 ]; then
  657. export AUTOSO2A_DIR="$builddir/autoso2a"
  658. export AUTOSO2A_AR="$AR" AUTOSO2A_RANLIB="$RANLIB"
  659. var_insert CC_WRAPPER_OTHERS ":" "so2a_wrapper"
  660. var_insert CXX_WRAPPER_OTHERS ":" "so2a_wrapper"
  661. fi
  662. i=0
  663. mkdir -p "$builddir/wrappers"
  664. for x in "${wrapper_data[@]}"; do
  665. echo "$x" | (
  666. read n; o="$n"
  667. if [ -f "$builddir/wrappers/$n" ]; then
  668. mv "$builddir/wrappers/$n" "$builddir/wrappers/$n.$i"
  669. o="$n.$i"; (( i++ ))
  670. fi
  671. {
  672. echo '#!/bin/bash'
  673. echo 'echo "$PWD: $0 $*" >> "'"$builddir/wrappers.log"'"'
  674. echo 'PATH="$PATH_WRBACKUP"'
  675. echo "orig='$o'"
  676. cat
  677. } > "$builddir/wrappers/$n"
  678. chmod +x "$builddir/wrappers/$n"
  679. )
  680. done
  681. export PATH_WRBACKUP="$PATH"
  682. PATH="$builddir/wrappers:$PATH"
  683. unset i
  684. # make sure we don't create an flist with just an
  685. # empty docdir in it if the package build fails..
  686. flistdel="$flistdel|${docdir#$root/}"
  687. # define new abort function for errors while building
  688. #
  689. abort() {
  690. [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
  691. rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
  692. false
  693. }
  694. # FD 202 can be used to write output to console instead of build log
  695. exec 202>&1
  696. {
  697. (
  698. set -e
  699. set +h
  700. echo "Build-Pkg exec $PATH"
  701. echo -e "\n--- ENVIRONMENT Variables ---"
  702. set | grep "^[^ ]*="
  703. echo -e "--- ENVIRONMENT Variables ---\n"
  704. if [ $xtrace -eq 1 -o $ROCKCFG_XTRACE -eq 1 ] ; then
  705. PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> '
  706. set -o xtrace
  707. fi
  708. trap 'echo "Got SIGINT (Crtl-C). Aborting build." ; exit 1' INT
  709. exec < /dev/null
  710. hook_eval prepare
  711. mkdir -p "$builddir/archdir"
  712. # Download archives files and link to them in $archdir.
  713. while read l_cksum l_srctar l_url l_flags ; do
  714. [ -z "$l_cksum" ] && continue
  715. x=`source_file l_cksum $l_srctar l_url $l_flags`
  716. if [ ! -f $x ]; then
  717. if [ $download = 1 ] ; then
  718. echo_status "Running ./scripts/Download for this package..."
  719. echo_status "----- DOWNLOAD LOG -----"
  720. echo; ./scripts/Download $xpkg; echo
  721. echo_status "------------------------"
  722. download=0
  723. fi >&202 2>&1
  724. if [ ! -f $x ]; then
  725. echo "File not found: ${x#$base/}"
  726. abort "Did you run ./scripts/Download for this package?"
  727. fi
  728. fi
  729. ln -vs $x "$builddir/archdir/"
  730. done < <( echo "$desc_D" | column_clean )
  731. echo_status "Building. Writing output to" \
  732. "\$root/var/adm/logs/$stagelevel-$xpkg.out" >&202
  733. # Makes debugging build problems easier
  734. #
  735. hook_dump > "$builddir/debug.hooks"
  736. #
  737. {
  738. dump_env
  739. cat <<- EOT
  740. PS1='\\[\\e[00m\\e[01;31m\\]debug-`
  741. `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
  742. alias cp="cp -i" ; alias mv="mv -i"
  743. alias rm="rm -i" ; alias ls="ls --color=auto -a"
  744. alias ..="cd .." ; alias ...="cd ../.."
  745. alias xdiff="sh $base/misc/archive/xdiff.sh"
  746. alias bked="sh $base/misc/archive/bked.sh"
  747. fixfile () {
  748. # we use .vanilla to not rediff backup .orig from patch
  749. [ -f \$1.vanilla ] || cp \$1 \$1.vanilla
  750. \$EDITOR \$1
  751. }
  752. fixfilediff() {
  753. find -name '*.vanilla' | while read x ; do
  754. diff -u \$x \${x/.vanilla/}
  755. done
  756. }
  757. EOT
  758. } > "$builddir/debug.buildenv"
  759. #
  760. cat > "$builddir/debug_x.sh" <<- EOT
  761. #!/bin/bash
  762. # export PROMPT_COMMAND='. debug.buildenv; cd .; unset PROMPT_COMMAND'
  763. cd "$root"
  764. if [ -e $PWD/ROCK ]; then
  765. if [ ! -e $PWD/ROCK/loop/scripts ]; then
  766. mount --bind $realbase $PWD/ROCK/loop
  767. mount --bind $realconf $PWD/ROCK/config
  768. mount --bind $realdown $PWD/ROCK/download
  769. fi
  770. if [ ! -e $PWD/ROCK/src.$xpkg.$id ]; then
  771. ln -s loop/src.$xpkg.$id $PWD/ROCK/src.$xpkg.$id
  772. fi
  773. fi
  774. cd "$builddir" ; exec env -i bash --init-file debug.buildenv 200>> build.pid
  775. EOT
  776. #
  777. if [ "$ROCK_THIS_IS_CHROOT" != 1 ]; then
  778. mv "$builddir/debug_x.sh" "$builddir/debug.sh"
  779. chmod +x "$builddir/debug.sh"
  780. fi
  781. # Create PID file
  782. #
  783. # The builtin variable '$$' is not this pid because this proc
  784. # is just a sub-proc of $$. That's why the $builddir/strace.tmp
  785. # hack is required to get the right pid to trace.
  786. #
  787. # We also connect file descriptor 3 with the pid file. So the command
  788. # 'fuser' can be used to create a list of all processes which are part
  789. # of this build process.
  790. #
  791. sh -c 'echo $PPID' > "$builddir/build.pid"
  792. exec 200>> "$builddir/build.pid"
  793. echo "Command Wrapper Debug: running '${CC} --version' .."
  794. type ${CC%% *}; CMD_WRAPPER_DEBUG=1 ${CC} --version
  795. echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
  796. if [ "$debug" = 1 ] ; then
  797. echo "Everything is set up." \
  798. "We are in debug mode - so exit now."
  799. exit
  800. fi
  801. if [ "$ROCKCFG_FLIST" = "strace" ] ; then
  802. if [ "$(uname -m)" = "ppc" ]; then
  803. SYSEXIT="exit"
  804. else
  805. SYSEXIT="_exit"
  806. fi
  807. strace -o "$builddir/strace.out" -F -f -q -e open,creat,mkdir,`
  808. `mknod,link,symlink,rename,utime,chdir,execve,`
  809. `fork,clone,vfork,`
  810. `$SYSEXIT,exit_group -p `cat "$builddir/build.pid"` &
  811. strace_pid=$! ; sleep 1 ; cd $base
  812. fi
  813. echo "Running main build function '$mainfunction' ..."
  814. cd "$builddir" ; eval "$mainfunction"
  815. hook_eval postinstall
  816. echo "Creating file list and doing final adaptions ... "
  817. #
  818. cd $xroot/
  819. #
  820. if [ "$ROCKCFG_FLIST" = "strace" ] ; then
  821. sleep 1 ; kill -INT $strace_pid ; sleep 1
  822. fl_stparse -w "$builddir/fl_wrapper.wlog" \
  823. -r "$builddir/fl_wrapper.rlog" < "$builddir/strace.out"
  824. fi
  825. if [ "$ROCKCFG_FLIST" = "flwrapper" -o \
  826. "$ROCKCFG_FLIST" = "strace" ] ; then
  827. if [ "$stagelevel" -le 2 ]
  828. then
  829. xbase="$( cd $xroot/ 2> /dev/null ; pwd -P )"
  830. egrepexp="[ ]($base|$xbase|$builddir|/tmp|/usr/lib/(conftest|cf)[0-9]*|/usr/tmp|/var/tmp|/var/backups|/proc|/dev)(/|$)"
  831. if cat $builddir/fl_wrapper.wlog | sed 's,//*,/,g' | \
  832. egrep -qv "$egrepexp"
  833. then
  834. x="Created file outside basedir: "
  835. cat $builddir/fl_wrapper.wlog | sed 's,//*,/,g' | \
  836. egrep -v "$egrepexp" | cut -f2- | \
  837. sort -u | sed "s,^,$x,"
  838. echo "base #1: $base"
  839. echo "base #2: $xbase"
  840. abort
  841. fi
  842. fi
  843. if fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog | \
  844. egrep "^(${flistroot// /|})(/|$)" >> \
  845. $builddir/flist.txt
  846. then : ; fi
  847. elif [ "$ROCKCFG_FLIST" = "find" ] ; then
  848. if find $flistroot \
  849. \( -not -type d -or -type d -empty \) \
  850. -and \( -newer $builddir/temp.time_stamp -or \
  851. -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
  852. $builddir/flist.txt
  853. then : ; fi
  854. fi
  855. # evaluate flistdel (1/2)
  856. egrep -v "^($flistdel)\$" $builddir/flist.txt | sort -u > $builddir/flist.txt.new
  857. mv $builddir/flist.txt.new $builddir/flist.txt
  858. # copy over missing *.a files
  859. if [ "$autoso2a" = 1 ]; then
  860. echo "Checking for missing .a files ..."
  861. while read d s; do
  862. grep -q "/${s%.so}.a$" $builddir/flist.txt && continue
  863. [ "$d" = "lib" ] && d="usr/lib"
  864. if [ -f "$AUTOSO2A_DIR/${s%.so}.a" ]; then
  865. echo "Installing automatically created $d/${s%.so}.a."
  866. cp "$AUTOSO2A_DIR/${s%.so}.a" "$root/$d/${s%.so}.a"
  867. add_flist "$root/$d/${s%.so}.a"
  868. else
  869. echo "Not found: $AUTOSO2A_DIR/${s%.so}.a"
  870. fi
  871. done < <( egrep '(^|/)lib/[^/]*\.so$' "$builddir/flist.txt" | sed 's,\(.*\)/,\1 ,' )
  872. fi
  873. # merge flist of previous build
  874. for x in var/adm/flists/$xpkg var/adm/flists/$xpkg:*; do
  875. [ -f $x ] && cut -f2- -d' ' $x >> "$builddir/flist.txt"
  876. done
  877. # evaluate flistdel (2/2)
  878. egrep -v "^($flistdel)\$" "$builddir/flist.txt" | sort -u > "$builddir/flist.txt.new"
  879. mv "$builddir/flist.txt.new" "$builddir/flist.txt"
  880. hook_eval postflist
  881. fl_wrparse -D -p "$xpkg" -r "$xroot/" < "$builddir/flist.txt" | sort -u > "$builddir/flist.split"
  882. echo Found `wc -l < "$builddir/flist.split"` "files for this package."
  883. splitapply $xpkg "$builddir/flist.split"
  884. if [ "$ROCKCFG_FLIST" = "flwrapper" -o \
  885. "$ROCKCFG_FLIST" = "strace" ] && [ $stagelevel -ge 3 ] ; then
  886. echo "Calculating build-time package dependencies ..."
  887. ! egrep -v "^($flistrfilter)\$" "$builddir"/fl_wrapper.[rw]log |
  888. sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | \
  889. grep -v ' var/adm/' | awk '
  890. ARGIND < ARGC-1 {
  891. if ( index($1, "'$xpkg':") != 1 )
  892. f[$2] = $1 " " f[$2];
  893. }
  894. ARGIND == ARGC-1 {
  895. file = $2;
  896. while ( file != "" ) {
  897. if ( f[file] ) {
  898. split(f[file], a);
  899. for (i in a)
  900. if (! d[a[i] " " file]) {
  901. d[a[i] " " file] = 1;
  902. print a[i] " " file;
  903. }
  904. }
  905. sub("/?[^/]*$", "", file)
  906. }
  907. }
  908. ' var/adm/flists/* - > "$builddir/dependencies.debug"
  909. awk 'BEGIN { FS=": "; } { print "'$xpkg': " $1; }' \
  910. < "$builddir/dependencies.debug" > "$builddir/dependencies.txt"
  911. if [ -f var/adm/dep-debug/$xpkg ] ; then
  912. cat var/adm/dep-debug/$xpkg >> "$builddir/dependencies.debug"
  913. fi
  914. sort -u "$builddir/dependencies.debug" > var/adm/dep-debug/$xpkg
  915. # add debug info for known false dependencies
  916. if egrep -q "^[^#].* $xpkg( |$)" $base/scripts/dep_fixes.txt; then
  917. echo "--- $xpkg [$stagelevel] ---" >> $root/var/adm/rock-debug/falsedeps.txt
  918. fi
  919. while read x; do
  920. grep "^$x: " "$builddir/dependencies.debug" | sort -u | \
  921. sed "s,:, -> $xpkg [$stagelevel]:," >> $root/var/adm/rock-debug/falsedeps.txt
  922. done < <( egrep "^$xpkg +del +" $base/scripts/dep_fixes.txt | \
  923. tr ' ' '\t' | tr -s '\t' | cut -f3- | tr '\t' '\n' )
  924. # merge the dependencies defined by the package
  925. for x in `echo "$desc_E" | egrep '^add ' | sed 's/^add //' ` ; do
  926. echo "Adding dependency: $x ..."
  927. echo "$xpkg: $x" >> "$builddir/dependencies.txt"
  928. done
  929. # remove dependencies as requested by the package
  930. # TODO: groups are not used yet (and it is not easy here)
  931. del_pattern=""
  932. for x in `echo "$desc_E" | egrep '^del ' | sed 's/^del //' ` ; do
  933. del_pattern="$del_pattern -e \".*: $x(:.*|)\$\""
  934. done
  935. if [ -n "$del_pattern" ] ; then
  936. echo "Deleting dependencies, pattern: $del_pattern ..."
  937. eval "egrep -v $del_pattern \"$builddir/dependencies.txt\"" > "$builddir/dependencies.txt.new"
  938. mv "$builddir/dependencies.txt.new" "$builddir/dependencies.txt"
  939. fi
  940. if [ -f var/adm/dependencies/$xpkg ] ; then
  941. cat var/adm/dependencies/$xpkg >> "$builddir/dependencies.txt"
  942. fi
  943. sort -u "$builddir/dependencies.txt" > "$builddir/dependencies.txt.new"
  944. mv "$builddir/dependencies.txt.new" "$builddir/dependencies.txt"
  945. fi
  946. echo "Calculating run-time package dependencies from pkg-config files..."
  947. grep "\.pc$" "$builddir/flist.split" | while read dummy x ; do
  948. x="$root/$x"
  949. # Only three tags are of interest here. Version: is mandatory.
  950. version="`grep -e"^Version:" $x | cut -f2- -d' '`"
  951. [ "$version" ] || continue
  952. # Set the variables defined in the .pc file.
  953. eval $( sed 's,^\([a-zA-Z0-9_]*\)=\(.*\),\1="\2",p ; d' $x )
  954. echo "`basename ${x%.pc}` $version" >> $builddir/provides.tmp
  955. for tag in Requires Conflicts ; do
  956. case "$tag" in
  957. "Requires") tmpfile="$builddir/requires.tmp" ;;
  958. "Conflicts") tmpfile="$builddir/conflicts.tmp" ;;
  959. esac
  960. # Set positional parameters to the tag values.
  961. set $( sed -e"/^$tag: / { s,^$tag: ,, ; s/,/ /g ; p } ; d" $x ) ""
  962. while [ "$1" ] ; do
  963. eval echo -n "$1"
  964. case "$2" in
  965. "<"|">"|"<="|">="|"=")
  966. echo " $2 $3" ; shift 2 ;;
  967. *) echo ;;
  968. esac ; shift
  969. done >> $tmpfile
  970. done
  971. done
  972. for spkg in $( sed 's,: .*,,' < "$builddir/flist.split" | sort -u )
  973. do
  974. (
  975. if [ -z "${spkg##*:*}" ]; then
  976. splitdesc_${spkg#*:}
  977. fi
  978. echo "<$spkg> Calculating run-time package dependencies from ELF files..."
  979. grep "^$spkg: " "$builddir/flist.split" | while read dummy x ; do
  980. x="$root/$x"
  981. # Symbolic links (to ELF files) and non-regular files
  982. # are ignored.
  983. [ -L "$x" -o ! -f "$x" ] && continue
  984. # Strip most values from ELF dynamic and version
  985. # sections as they don't contain useful info.
  986. readelf -dV $x 2>/dev/null | sed -e '
  987. /^Version definition section /,/^Version needs section / {
  988. s,.* Flags: BASE .* Name: \(.*\),provides \1,p
  989. }
  990. /^Version needs section /,$ {
  991. s,.* File: \([^ ]*\) .*,requires \1,p
  992. }
  993. # in dynamic section
  994. s,.* (SONAME) .* Library soname: \[\(.*\)\]$,provides \1,p
  995. s,.* (NEEDED) .* Shared library: \[\(.*\)\]$,requires \1,p
  996. # in version sections
  997. s,.* Name: \([^ ]*\).*,\1,p ; d
  998. ' | while read a b ; do
  999. case "$a" in
  1000. "provides"|"requires")
  1001. pref="$b" ; tmpfile="$builddir/$a.tmp"
  1002. [ "$a" == provides ] && cmp_op=" " || cmp_op=" @ "
  1003. echo "$pref" >> $tmpfile ;;
  1004. *) echo "$pref${cmp_op}$a" >> $tmpfile ;;
  1005. esac
  1006. done
  1007. done
  1008. for x in {provides,requires,conflicts} ; do
  1009. if [ -f "$builddir/$x.tmp" ] ; then
  1010. echo "<$spkg> Creating var/adm/$x/$spkg"
  1011. sort -u "$builddir/$x.tmp" > var/adm/$x/$spkg
  1012. rm -f "$builddir/$x.tmp"
  1013. else
  1014. rm -f var/adm/$x/$spkg
  1015. fi
  1016. done
  1017. echo "<$spkg> Creating flist file ..."
  1018. {
  1019. grep "^$spkg: " "$builddir/flist.split"
  1020. for x in var/adm/{parse-config,provides,requires,conflicts}/$spkg ; do
  1021. [ -s "$x" ] && echo "$spkg: $x"
  1022. done
  1023. for x in var/adm/{flists,md5sums,cksums,packages,descs,dependencies}/$spkg ; do
  1024. touch $x ; echo "$spkg: $x"
  1025. done
  1026. } | sort -u > var/adm/flists/$spkg
  1027. if [ -f "$builddir/dependencies.txt" ] ; then
  1028. echo "<$spkg> Creating package dependencies file ..."
  1029. sed "s,^[^ ]*,$spkg:," < "$builddir/dependencies.txt" > var/adm/dependencies/$spkg
  1030. fi
  1031. echo "<$spkg> Creating package description ..."
  1032. #
  1033. rocksrcck=$(cd $base; md5sum package/*/$pkg/* 2> /dev/null | \
  1034. grep -v '\.cache$' | md5sum | cut -f1 -d' ')
  1035. buildlist="$( grep "^Build \[.\] at " var/adm/packages/$spkg || true
  1036. echo "Build [$stagelevel] at $buildstart to `date "+%T %Z"`")"
  1037. #
  1038. cat > var/adm/packages/$spkg << EOT
  1039. Package Name and Version: $spkg $ver $extraver
  1040. Package Size: `getdu $root/ < var/adm/flists/$spkg`, `
  1041. wc -l < var/adm/flists/$spkg | tr -d ' '` files
  1042. ROCK Linux Package Source Checksum: $rocksrcck
  1043. ROCK Linux Version and Architecture: $rockver $arch
  1044. Build on `uname -m -n -r -s -p`
  1045. $buildlist
  1046. Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
  1047. ${desc_I:-$spkg}
  1048. $( echo "${desc_T:-No description available.}" | sed 's,^, ,' )
  1049. URL(s):
  1050. $( echo "${desc_U:-http://www.rocklinux.net/packages/$pkg.html}" | sed 's,^, ,' )
  1051. Original Author(s):
  1052. $( echo "${desc_A:-Unknown}" | sed 's,^, ,' )
  1053. ROCK Package Maintainer(s):
  1054. $( echo "${desc_M:-Unknown}" | sed 's,^, ,' )
  1055. Download URL(s):
  1056. $( echo "${desc_D:-None}" | awk '{ print " " $3 $2; }' )
  1057. EOT
  1058. {
  1059. echo "[CONFIG] ${ROCKCFG_ID#*-}"
  1060. while read x; do
  1061. if [ "${x#\[}" != "$x" ]; then # "]}"
  1062. x="`echo ${x// /|} | tr -d '[]'`"
  1063. y="${x%%|*}" ; x="(${x%|(*)})"
  1064. case "$y" in
  1065. V) echo "[V] $ver $extraver" ;;
  1066. *) echo "$descfile" | egrep "^\[$x\]" | expand | sed "s,^[^ ]*,[$y]," ;;
  1067. esac
  1068. fi
  1069. done < $base/Documentation/Developers/PKG-DESC-FORMAT
  1070. } > var/adm/descs/$spkg
  1071. # Create them last so checksums of other var/adm files are correct.
  1072. echo "<$spkg> Creating md5sum and cksum files ..."
  1073. echo -n > var/adm/cksums/$spkg
  1074. echo -n > var/adm/md5sums/$spkg
  1075. # getfiles only returns non-directories, suitable for checksum creation.
  1076. getfiles < var/adm/flists/$spkg > "$builddir/files.lst"
  1077. if [ -s "$builddir/files.lst" ] ; then
  1078. while read file ; do
  1079. [ -z "${file//[ ]/}" ] && continue
  1080. # Checksums on these files are volatile.
  1081. if [ "$file" = "var/adm/cksums/$spkg" -o \
  1082. "$file" = "var/adm/md5sums/$spkg" -o \
  1083. -b "$file" -o -c "$file" -o -p "$file" -o \
  1084. -L "$file" -o -S "$file" ] ; then
  1085. echo "X ${file}" >> var/adm/md5sums/$spkg
  1086. echo "X $( stat -c %s ${file} ) ${file}" \
  1087. >> var/adm/cksums/$spkg
  1088. elif [ ${ROCKCFG_CREATE_CKSUM} -eq 1 ] ; then
  1089. md5sum "${file}" >> var/adm/md5sums/$spkg
  1090. cksum "${file}" >> var/adm/cksums/$spkg
  1091. else
  1092. echo "0 ${file}" >> var/adm/md5sums/$spkg
  1093. echo "0 $( stat -c %s ${file} ) ${file}" \
  1094. >> var/adm/cksums/$spkg
  1095. fi
  1096. done < "$builddir/files.lst"
  1097. fi
  1098. if [ $stagelevel -ge 3 -a $nopostinst = 0 -a -d /var/adm/postinstall ]; then
  1099. cp var/adm/flists/$spkg "$(mktemp var/adm/postinstall/${spkg}-install.XXXXXX)"
  1100. fi
  1101. )
  1102. done
  1103. echo "Making post-install adaptions."
  1104. if [ $stagelevel -ge 3 -a -f /sbin/ldconfig ] ; then ldconfig ; fi
  1105. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 ] ; then
  1106. found_errors=0
  1107. found_dups=0
  1108. # check for files which are 'shared' with other packages
  1109. if [ "$check_shared" != "0" ]; then
  1110. while read dummy file; do
  1111. if [ $found_dups = 0 ] ; then
  1112. echo "Found shared files with other packages:"
  1113. found_errors=1; found_dups=1
  1114. fi
  1115. echo "$file:" $( cd $root/var/adm/flists
  1116. grep -l " $file\$" * )
  1117. done < <( find $root/var/adm/flists/ -maxdepth 1 -type f | \
  1118. xargs -n100 sed "s,^$xpkg:[^ ]*,.," | \
  1119. sort -k2 | uniq -d -f1 | grep '^\. ' )
  1120. fi
  1121. found_local=0
  1122. # check for files in /usr/local
  1123. if [ "$check_usrlocal" != "0" ]; then
  1124. while read file ; do
  1125. if [ $found_local = 0 ] ; then
  1126. echo "Found files in /usr/local:"
  1127. found_errors=1; found_local=1
  1128. fi
  1129. echo $file
  1130. done < <( sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg \
  1131. $root/var/adm/flists/$xpkg:* 2> /dev/null | egrep "^/usr/local" )
  1132. fi
  1133. found_bad=0
  1134. # check for registered 'bad files'
  1135. if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
  1136. echo "$badfiles" > "$builddir/badfiles.txt"
  1137. while read x file; do
  1138. if [ $found_bad = 0 ]; then
  1139. echo "Found registered 'bad files' in package:"
  1140. found_errors=1; found_bad=1
  1141. fi
  1142. desc="No description found!"
  1143. for ((x=0; x<badfiles_nr; x++)); do
  1144. if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
  1145. then desc="${badfiles_desc[x]#*$'\n'}"; fi
  1146. done
  1147. echo "$file: $desc"
  1148. done < <( grep -f "$builddir/badfiles.txt" $root/var/adm/flists/$xpkg \
  1149. $root/var/adm/flists/$xpkg:* 2> /dev/null )
  1150. fi
  1151. [ $found_errors != 0 ] && abort
  1152. fi
  1153. touch $root/var/adm/logs/$stagelevel-$xpkg.log
  1154. echo "Finished building $pkg=$xpkg."
  1155. hook_eval finish
  1156. )
  1157. if [ ! -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  1158. abort
  1159. fi
  1160. } 2>&1 | {
  1161. trap '' INT
  1162. if [ "$ROCKCFG_VERBOSE" = 1 -o "$verbose" = 1 ] ; then
  1163. tee $root/var/adm/logs/$stagelevel-$xpkg.out
  1164. else
  1165. cat > $root/var/adm/logs/$stagelevel-$xpkg.out
  1166. fi
  1167. }
  1168. if [ $update = 1 ] ; then
  1169. echo_status "Restoring backup of old package data."
  1170. while read fn ; do
  1171. [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
  1172. done < "$builddir/backup_files.txt"
  1173. tar --force-local --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
  1174. while read fn ; do
  1175. cmp -s $fn $fn.new && rm -f $fn.new
  1176. done < "$builddir/backup_files.txt"
  1177. fi
  1178. cd $base
  1179. umount -r -d -f "$builddir"/* 2> /dev/null
  1180. umount -r -d -f -l "$builddir"/* 2> /dev/null
  1181. if [ "$ROCKCFG_SRC_TMPFS_LOG" = 1 -a -n "$( type -p df )" ]; then
  1182. if [ ! -f $root/var/adm/rock-debug/tmpfslog.txt ] ; then
  1183. echo -e "# Config\tPackage\tInodes\tKB" | \
  1184. expand -t20 > $root/var/adm/rock-debug/tmpfslog.txt
  1185. fi
  1186. echo -e "$config\t$stagelevel-$xpkg\t$(
  1187. df 2> /dev/null -Pi "$builddir" | tail -n 1 | tr -s ' ' | cut -f3 -d' '
  1188. )\t$(
  1189. df 2> /dev/null -Pk "$builddir" | tail -n 1 | tr -s ' ' | cut -f3 -d' ')" | \
  1190. expand -t20 >> $root/var/adm/rock-debug/tmpfslog.txt
  1191. fi
  1192. if [ "$ROCKCFG_PSEUDONATIVE" = 1 -a $stagelevel -eq 0 ]; then
  1193. rm -f $base/build/$ROCKCFG_ID/pseudonative_handler
  1194. fi
  1195. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  1196. export LD_PRELOAD="${LD_PRELOAD//${FLWRAPPER}/}"
  1197. export LD_PRELOAD="${LD_PRELOAD//::/:}"
  1198. fi
  1199. if [ "$ROCKCFG_SRC_TMPFS" = 1 ]; then
  1200. umount -l "$builddir"
  1201. fi
  1202. if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  1203. if [ $clear_src = 1 ] ; then
  1204. rm -rf "$builddir"/* "$builddir"
  1205. else
  1206. cp $root/var/adm/logs/$stagelevel-$xpkg.out "$builddir/BUILD-LOG"
  1207. fi
  1208. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  1209. "-> $stagelevel-$xpkg.log"
  1210. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  1211. $root/var/adm/logs/$stagelevel-$xpkg.log
  1212. echo_pkg_finish $stagelevel $repository $xpkg
  1213. exit 0
  1214. else
  1215. if [ $clear_src = 1 -a "$ROCKCFG_ALWAYS_CLEAN" = 1 ] ; then
  1216. rm -rf "$builddir"/* "$builddir"
  1217. else
  1218. cp $root/var/adm/logs/$stagelevel-$xpkg.out "$builddir/ERROR-LOG"
  1219. fi
  1220. if [ "$ROCKCFG_VERBOSE" != 1 -a "$verbose" != 1 ] ; then
  1221. echo_errorquote "$( grep -B7 -- '--- BUILD ERROR ---' \
  1222. $root/var/adm/logs/$stagelevel-$xpkg.out | \
  1223. sed '$ s,--- BUILD ERROR ---,,' | \
  1224. grep . | grep -vx -- -- )"
  1225. fi
  1226. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  1227. "-> $stagelevel-$xpkg.err"
  1228. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  1229. $root/var/adm/logs/$stagelevel-$xpkg.err
  1230. echo_pkg_abort $stagelevel $repository $xpkg
  1231. exit 1
  1232. fi
  1233. # ---- EOF