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.

1443 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/cache/$xpkg"
  405. if [ -f "$x" ]; then
  406. grep -e"\[DEP-[0-9]\]" "$x"
  407. fi
  408. x="$root/var/adm/dependencies/$xpkg"
  409. if [ "$pkg" != "rock-debug" -a -f $x ]; then
  410. cut -f2- -d' ' "$x" | \
  411. fmt -70 | sed "s,^,[DEP-$stagelevel] ,"
  412. cut -f2- -d' ' "$x" | \
  413. fmt -70 | sed 's,^,[DEP] ,'
  414. echo
  415. fi
  416. cat $root/var/adm/flists/$xpkg{,:*} 2> /dev/null | \
  417. sed -r '\,(bin/[^/]+|lib/.+\.(so|a))$, { s,.*/,,; p; };d' | \
  418. sort -u | fmt -w65 | sed 's,^,[PROVIDES] ,'
  419. echo
  420. for stagelevel in 0 1 2 3 4 5 6 7 8 9 ; do
  421. x="$root/var/adm/logs/$stagelevel-$xpkg.err"
  422. if [ -f "$x" ] ; then
  423. tail -n 50 "$x" | \
  424. sed "s,^,[$stagelevel-ERROR] ,"
  425. echo
  426. fi
  427. done
  428. } > $root/var/adm/cache/$xpkg.new
  429. mv $root/var/adm/cache/$xpkg.new $root/var/adm/cache/$xpkg
  430. exit $returncode
  431. else
  432. exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' PATH="$PATH" \
  433. TZ="$TZ" ROCK_BUILD_TARGET=$ROCK_BUILD_TARGET \
  434. build_root="$build_root" build_rock="$build_rock" \
  435. build_logs="$build_logs" build_pkgs="$build_pkgs" \
  436. ROCK_THIS_IS_CHROOT="$ROCK_THIS_IS_CHROOT" \
  437. FLWRAPPER_WLOG="$FLWRAPPER_WLOG" FLWRAPPER_RLOG="$FLWRAPPER_RLOG" \
  438. FLWRAPPER_BASEPID="$FLWRAPPER_BASEPID" FLWRAPPER="$FLWRAPPER" \
  439. LD_PRELOAD="${LD_PRELOAD}" \
  440. $0 $options
  441. fi
  442. fi
  443. #
  444. # ---- Setting Build Variables
  445. #
  446. if [ -z "$root" ] ; then
  447. dummydir="$builddir/rootdummy"
  448. else
  449. dummydir="${root}/ROCK/${builddir#$base/}/rootdummy"
  450. fi
  451. mkdir -p "$dummydir"
  452. if [[ "$xpkg" = *-32bit ]] ; then
  453. instroot="$dummydir"
  454. libs_only=1
  455. else
  456. instroot="$root"
  457. libs_only=0
  458. fi
  459. #
  460. if [[ -z "$arch_target32" || "$xpkg" = *-32bit ]] ; then
  461. multilib="lib"
  462. else
  463. multilib="lib64"
  464. fi
  465. flistroot="bin boot etc lib $multilib sbin usr var opt"
  466. flistrfilter="ldconfig\..*: .*|.*: /var/adm/.*"
  467. flistdel="var/adm/.*|var/tmp/.*|var/lock/.*|var/run/.*|etc/ld.so.cache|usr/tmp/.*|.*\\.old"
  468. pkgsplits=""
  469. if [ "$ROCKCFG_SPLIT_DEV" != 0 ]; then
  470. # this doesn't affect files in /lib, just /.../lib
  471. # so there needn't be an exception for linux kernel modules
  472. splitreg 40 dev "(/(lib|$multilib)/.*\.(la|a|o)\$|/include/|/man[23]/)"
  473. splitdesc_dev() { desc_I="$desc_I (development files)"; }
  474. fi
  475. if [ "$ROCKCFG_SPLIT_DOC" != 0 ]; then
  476. # only move doc/ to :doc, not man and info pages
  477. splitreg 60 doc '/share/doc/'
  478. splitdesc_doc() { desc_I="$desc_I (documentation)"; }
  479. fi
  480. makeopt='CC="$CC" CXX="$CXX"'
  481. if [ $stagelevel -le 2 ] ; then
  482. var_append makeopt ' ' 'CC_FOR_BUILD="$BUILDCC"'
  483. var_append makeopt ' ' 'BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
  484. var_append makeopt ' ' 'HOSTCC="$HOSTCC" HOST_CC="$HOST_CC"'
  485. var_append makeopt ' ' 'STRIP="$STRIP" AR="$AR" LD="$LD"'
  486. var_append makeopt ' ' 'RANLIB="$RANLIB" NM="$NM"'
  487. fi
  488. makeinstopt="$makeopt install"
  489. [ "$root" ] && var_append makeinstopt ' ' 'DESTDIR=$root'
  490. if [ $stagelevel -ge 3 ] ; then
  491. flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
  492. fi
  493. prepare="" ; hook_add prepare 5 'eval "$prepare"'
  494. prepatch="" ; hook_add prepatch 5 'eval "$prepatch"'
  495. postpatch="" ; hook_add postpatch 5 'eval "$postpatch"'
  496. postdoc="" ; hook_add postdoc 5 'eval "$postdoc"'
  497. preconf="" ; hook_add preconf 5 'eval "$preconf"'
  498. premake="" ; hook_add premake 5 'eval "$premake"'
  499. inmake="" ; hook_add inmake 5 'eval "$inmake"'
  500. postmake="" ; hook_add postmake 5 'eval "$postmake"'
  501. postinstall="" ; hook_add postinstall 5 'eval "$postinstall"'
  502. postflist="" ; hook_add postflist 5 'eval "$postflist"'
  503. finish="" ; hook_add finish 5 'eval "$finish"'
  504. [ "$ROCKCFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
  505. hook_add postflist 3 'postflist_libs'
  506. configprefix="" ; autogen=0 ; automakever=""
  507. configscript="./configure" ; extraconfopt=""
  508. configexec="bash"
  509. srcdir=auto ; srctar=auto
  510. taropt="--use-compress-program=bzip2 -xf"
  511. mainfunction="build_this_package"
  512. runconf=1 ; runxmkmf=1 ; runmkpl=1 ; runpysetup=1 ; runcmake=1 ; autopatch=1
  513. autoextract=1 ; chownsrcdir=1 ; nocvsinsrcdir=1; patchopt="-bfp1 -z .orig"
  514. createprefix=1 ; createdocs="" ; rmemptydir="" ; autoso2a=0 ; forcefpic=""
  515. cmakesrcdir=.
  516. check_shared=1
  517. check_usrlocal=1
  518. check_badfiles=1
  519. badfiles="" badfiles_nr=0
  520. declare -a badfiles_desc
  521. #
  522. # ---- Read various config files
  523. #
  524. parse_desc $confdir/$pkg.desc
  525. ver="`echo "$desc_V" | tail -n 1 | cut -f1 -d' '`"
  526. extraver="`echo "$desc_V" | tail -n 1 | cut -s -f2- -d' '`"
  527. [ -z "$extraver" ] && extraver="0"
  528. if [ "$pkg" = "$xpkg" ]; then
  529. echo_pkg_start $stagelevel $repository $xpkg $ver $extraver
  530. else
  531. echo_pkg_start $stagelevel $repository $pkg=$xpkg $ver $extraver
  532. fi
  533. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 -a -z "$pkgdir" ] ; then
  534. x="`./scripts/Check-PkgFormat $pkg`"
  535. [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
  536. `option to ignore such errors."
  537. fi
  538. targetdir="$base/target/$target"
  539. patchfiles="`ls $confdir/*.patch $confdir/*.patch.$arch \
  540. $confdir/*.patch_$xpkg $confdir/*.patch_$xpkg.$arch \
  541. $targetdir/pkg_$pkg.patch $targetdir/pkg_$pkg.patch.$arch \
  542. $targetdir/xpkg_$xpkg.patch $targetdir/xpkg_$xpkg.patch.$arch \
  543. 2>/dev/null | tr '\n' ' '`"
  544. if [ $stagelevel -le 2 ]; then
  545. patchfiles="`ls $patchfiles $confdir/*.patch.cross \
  546. $confdir/*.patch.cross.$arch 2>/dev/null | tr '\n' ' '`"
  547. fi
  548. if [ $stagelevel -le 1 -o "$ROCKCFG_CROSSBUILD" = 0 -a $stagelevel -eq 2 ] ; then
  549. createdocs=0
  550. fi
  551. if [ -f $confdir/$pkg.cache ]; then
  552. if ! egrep -q '^\[PROVIDES].*\.(so|a)( |$)' $confdir/$pkg.cache; then
  553. forcefpic="0"
  554. fi
  555. fi
  556. if [ $stagelevel -le 1 ] ; then
  557. var_append flistroot " " "$tools"
  558. flistdel="$flistdel|$tools/info/(dir|standards.info)"
  559. else
  560. flistdel="$flistdel|$tools(/.*|)"
  561. fi
  562. if [ $stagelevel -ge 3 ]; then
  563. for pc_file in $xroot/var/adm/parse-config/* ; do
  564. if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
  565. then . "$pc_file" ; fi
  566. done
  567. unset pc_file
  568. fi
  569. . $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/parse-config
  570. set_confopt
  571. if [ $stagelevel -eq 0 -a "$ROCKCFG_PSEUDONATIVE" = 1 ]; then
  572. echo_status "Building this package statically for pseudo native build."
  573. var_insert extraconfopt " " "--enable-static --disable-shared"
  574. for x in BUILDCC_WRAPPER_INSERT LDFLAGS LD CFLAGS CC; do
  575. var_append $x " " "-static"
  576. done
  577. fi
  578. eval "$desc_O"
  579. # include package pre config - if any
  580. if [ -f $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_pre.conf ] ; then
  581. echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
  582. . $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_pre.conf
  583. fi
  584. if [ -f $targetdir/pkg_$pkg.conf ] ; then
  585. echo_status "Reading package configuration from target directory."
  586. . $targetdir/pkg_$pkg.conf
  587. elif [ -f $confdir/$pkg.conf ] ; then
  588. echo_status "Reading package configuration from package directory."
  589. . $confdir/$pkg.conf
  590. fi
  591. # include package post config - if any
  592. if [ -f $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_post.conf ] ; then
  593. echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
  594. . $base/build/$ROCKCFG_ID/ROCK/$toolsdir/lib/pkg_${pkg}_post.conf
  595. fi
  596. if [ -f $base/architecture/$arch/pkg-header ] ; then
  597. echo_status "Reading overwrites from architecture/$arch/pkg-header."
  598. . $base/architecture/$arch/pkg-header
  599. fi
  600. if [ -f $base/target/$target/pkg-header ] ; then
  601. echo_status "Reading overwrites from target/$target/pkg-header."
  602. . $base/target/$target/pkg-header
  603. fi
  604. #
  605. # ---- Variable updates based on the configuration files read
  606. #
  607. if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ] ; then
  608. flistdel="$flistdel|usr/share/info/(dir|standards.info)"
  609. if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  610. flistdel="$flistdel|usr/share/locale/..[/_].*"
  611. flistdel="$flistdel|usr/share/man/..[/_].*"
  612. fi
  613. if [ $stagelevel = 0 ] ; then
  614. flistdel="${flistdel//usr\//}|${flistdel//usr\/share\//}"
  615. fi
  616. else
  617. flistdel="$flistdel|$prefix/info/(dir|standards.info)"
  618. if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  619. flistdel="$flistdel|$prefix/share/locale/..[/_].*"
  620. flistdel="$flistdel|$prefix/man/..[/_].*"
  621. fi
  622. fi
  623. #
  624. # ---- Build Package
  625. #
  626. echo_status "Preparing build in src.$xpkg.$id"
  627. if [ "$ROCKCFG_SRC_TMPFS" = 1 ]; then
  628. echo_status "Mounting tmpfs on src.$xpkg.$id"
  629. mount -t tmpfs -o $ROCKCFG_SRC_TMPFS_OPT tmpfs "$builddir"
  630. fi
  631. if [ "$xroot" != "$root" ] ; then
  632. for x in $flistroot ; do
  633. [ -d $xroot/$x ] || mkdir -p $xroot/$x
  634. [ -d $root/$x ] || ln -sf $xroot/$x $root/
  635. done
  636. fi
  637. if [ $update = 1 ] ; then
  638. echo_status "Creating backup of old package data (running in update mode)."
  639. (
  640. cd $xroot/
  641. grep -v "^X" var/adm/md5sums/$xpkg var/adm/md5sums/$xpkg:* 2> /dev/null |
  642. md5sum --check - 2>&1 | grep ': FAILED$' | cut -f1 -d:
  643. ) > "$builddir/backup_files.txt"
  644. if [ -s "$builddir/backup_files.txt" ] ; then
  645. mkdir -p "$xroot/var/adm/backup"
  646. chmod 700 "$xroot/var/adm/backup"
  647. backup_tar="$xroot/var/adm/backup/$(
  648. date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
  649. ( cd $xroot/; tar --no-recursion --force-local -cf - -T "$builddir/`
  650. `backup_files.txt" || true; ) | bzip2 > $backup_tar
  651. else
  652. update=0
  653. fi
  654. fi
  655. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  656. rm -f "$builddir/"fl_wrapper.{r,w}log
  657. touch "$builddir/"fl_wrapper.{r,w}log
  658. elif [ "$ROCKCFG_FLIST" = "find" ] ; then
  659. touch "$builddir/temp.time_stamp"
  660. sleep 2
  661. fi
  662. if [ $stagelevel -gt 1 -a "$autoso2a" = 1 ]; then
  663. export AUTOSO2A_DIR="$builddir/autoso2a"
  664. export AUTOSO2A_AR="$AR" AUTOSO2A_RANLIB="$RANLIB"
  665. var_insert CC_WRAPPER_OTHERS ":" "so2a_wrapper"
  666. var_insert CXX_WRAPPER_OTHERS ":" "so2a_wrapper"
  667. fi
  668. i=0
  669. mkdir -p "$builddir/wrappers"
  670. for x in "${wrapper_data[@]}"; do
  671. echo "$x" | (
  672. read n; o="$n"
  673. if [ -f "$builddir/wrappers/$n" ]; then
  674. mv "$builddir/wrappers/$n" "$builddir/wrappers/$n.$i"
  675. o="$n.$i"; (( i++ ))
  676. fi
  677. {
  678. echo '#!/bin/bash'
  679. echo 'echo "$PWD: $0 $*" >> "'"$builddir/wrappers.log"'"'
  680. echo 'PATH="$PATH_WRBACKUP"'
  681. echo "orig='$o'"
  682. cat
  683. } > "$builddir/wrappers/$n"
  684. chmod +x "$builddir/wrappers/$n"
  685. )
  686. done
  687. export PATH_WRBACKUP="$PATH"
  688. PATH="$builddir/wrappers:$PATH"
  689. unset i
  690. # make sure we don't create an flist with just an
  691. # empty docdir in it if the package build fails..
  692. flistdel="$flistdel|${docdir#$root/}"
  693. # define new abort function for errors while building
  694. #
  695. abort() {
  696. [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
  697. rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
  698. false
  699. }
  700. # FD 202 can be used to write output to console instead of build log
  701. exec 202>&1
  702. {
  703. (
  704. set -e
  705. set +h
  706. echo "Build-Pkg exec $PATH"
  707. echo -e "\n--- ENVIRONMENT Variables ---"
  708. set | grep "^[^ ]*="
  709. echo -e "--- ENVIRONMENT Variables ---\n"
  710. if [ $xtrace -eq 1 -o $ROCKCFG_XTRACE -eq 1 ] ; then
  711. PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> '
  712. set -o xtrace
  713. fi
  714. trap 'echo "Got SIGINT (Crtl-C). Aborting build." ; exit 1' INT
  715. exec < /dev/null
  716. hook_eval prepare
  717. mkdir -p "$builddir/archdir"
  718. # Download archives files and link to them in $archdir.
  719. while read l_cksum l_srctar l_url l_flags ; do
  720. [ -z "$l_cksum" ] && continue
  721. x=`source_file l_cksum $l_srctar l_url $l_flags`
  722. if [ ! -f $x ]; then
  723. if [ $download = 1 ] ; then
  724. echo_status "Running ./scripts/Download for this package..."
  725. echo_status "----- DOWNLOAD LOG -----"
  726. echo; ./scripts/Download $xpkg; echo
  727. echo_status "------------------------"
  728. download=0
  729. fi >&202 2>&1
  730. if [ ! -f $x ]; then
  731. echo "File not found: ${x#$base/}"
  732. abort "Did you run ./scripts/Download for this package?"
  733. fi
  734. fi
  735. ln -vs $x "$builddir/archdir/"
  736. done < <( echo "$desc_D" | column_clean )
  737. echo_status "Building. Writing output to" \
  738. "\$root/var/adm/logs/$stagelevel-$xpkg.out" >&202
  739. # Makes debugging build problems easier
  740. #
  741. hook_dump > "$builddir/debug.hooks"
  742. #
  743. {
  744. dump_env
  745. cat <<- EOT
  746. PS1='\\[\\e[00m\\e[01;31m\\]debug-`
  747. `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
  748. alias cp="cp -i" ; alias mv="mv -i"
  749. alias rm="rm -i" ; alias ls="ls --color=auto -a"
  750. alias ..="cd .." ; alias ...="cd ../.."
  751. alias xdiff="sh $base/misc/archive/xdiff.sh"
  752. alias bked="sh $base/misc/archive/bked.sh"
  753. fixfile () {
  754. # we use .vanilla to not rediff backup .orig from patch
  755. [ -f \$1.vanilla ] || cp \$1 \$1.vanilla
  756. \$EDITOR \$1
  757. }
  758. fixfilediff() {
  759. find -name '*.vanilla' | while read x ; do
  760. diff -u \$x \${x/.vanilla/}
  761. done
  762. }
  763. EOT
  764. } > "$builddir/debug.buildenv"
  765. #
  766. cat > "$builddir/debug_x.sh" <<- EOT
  767. #!/bin/bash
  768. # export PROMPT_COMMAND='. debug.buildenv; cd .; unset PROMPT_COMMAND'
  769. cd "$root"
  770. if [ -e $PWD/ROCK ]; then
  771. if [ ! -e $PWD/ROCK/loop/scripts ]; then
  772. mount --bind $realbase $PWD/ROCK/loop
  773. mount --bind $realconf $PWD/ROCK/config
  774. mount --bind $realdown $PWD/ROCK/download
  775. fi
  776. if [ ! -e $PWD/ROCK/src.$xpkg.$id ]; then
  777. ln -s loop/src.$xpkg.$id $PWD/ROCK/src.$xpkg.$id
  778. fi
  779. fi
  780. cd "$builddir" ; exec env -i bash --init-file debug.buildenv 200>> build.pid
  781. EOT
  782. #
  783. if [ "$ROCK_THIS_IS_CHROOT" != 1 ]; then
  784. mv "$builddir/debug_x.sh" "$builddir/debug.sh"
  785. chmod +x "$builddir/debug.sh"
  786. fi
  787. # Create PID file
  788. #
  789. # The builtin variable '$$' is not this pid because this proc
  790. # is just a sub-proc of $$. That's why the $builddir/strace.tmp
  791. # hack is required to get the right pid to trace.
  792. #
  793. # We also connect file descriptor 3 with the pid file. So the command
  794. # 'fuser' can be used to create a list of all processes which are part
  795. # of this build process.
  796. #
  797. sh -c 'echo $PPID' > "$builddir/build.pid"
  798. exec 200>> "$builddir/build.pid"
  799. echo "Command Wrapper Debug: running '${CC} --version' .."
  800. type ${CC%% *}; CMD_WRAPPER_DEBUG=1 ${CC} --version
  801. echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
  802. if [ "$debug" = 1 ] ; then
  803. echo "Everything is set up." \
  804. "We are in debug mode - so exit now."
  805. exit
  806. fi
  807. if [ "$ROCKCFG_FLIST" = "strace" ] ; then
  808. if [ "$(uname -m)" = "ppc" ]; then
  809. SYSEXIT="exit"
  810. else
  811. SYSEXIT="_exit"
  812. fi
  813. strace -o "$builddir/strace.out" -F -f -q -e open,creat,mkdir,`
  814. `mknod,link,symlink,rename,utime,chdir,execve,`
  815. `fork,clone,vfork,`
  816. `$SYSEXIT,exit_group -p `cat "$builddir/build.pid"` &
  817. strace_pid=$! ; sleep 1 ; cd $base
  818. fi
  819. echo "Running main build function '$mainfunction' ..."
  820. cd "$builddir" ; eval "$mainfunction"
  821. hook_eval postinstall
  822. echo "Creating file list and doing final adaptions ... "
  823. #
  824. cd $xroot/
  825. #
  826. if [ "$ROCKCFG_FLIST" = "strace" ] ; then
  827. sleep 1 ; kill -INT $strace_pid ; sleep 1
  828. fl_stparse -w "$builddir/fl_wrapper.wlog" \
  829. -r "$builddir/fl_wrapper.rlog" < "$builddir/strace.out"
  830. fi
  831. if [ "$ROCKCFG_FLIST" = "flwrapper" -o \
  832. "$ROCKCFG_FLIST" = "strace" ] ; then
  833. if [ "$stagelevel" -le 2 ]
  834. then
  835. xbase="$( cd $xroot/ 2> /dev/null ; pwd -P )"
  836. egrepexp="[ ]($base|$xbase|$builddir|/tmp|/usr/lib/(conftest|cf)[0-9]*|/usr/tmp|/var/tmp|/var/backups|/proc|/dev)(/|$)"
  837. if cat $builddir/fl_wrapper.wlog | sed 's,//*,/,g' | \
  838. egrep -qv "$egrepexp"
  839. then
  840. x="Created file outside basedir: "
  841. cat $builddir/fl_wrapper.wlog | sed 's,//*,/,g' | \
  842. egrep -v "$egrepexp" | cut -f2- | \
  843. sort -u | sed "s,^,$x,"
  844. echo "base #1: $base"
  845. echo "base #2: $xbase"
  846. abort
  847. fi
  848. fi
  849. if fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog | \
  850. egrep "^(${flistroot// /|})(/|$)" >> \
  851. $builddir/flist.txt
  852. then : ; fi
  853. elif [ "$ROCKCFG_FLIST" = "find" ] ; then
  854. if find $flistroot \
  855. \( -not -type d -or -type d -empty \) \
  856. -and \( -newer $builddir/temp.time_stamp -or \
  857. -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
  858. $builddir/flist.txt
  859. then : ; fi
  860. fi
  861. # evaluate flistdel (1/2)
  862. egrep -v "^($flistdel)\$" $builddir/flist.txt | sort -u > $builddir/flist.txt.new
  863. mv $builddir/flist.txt.new $builddir/flist.txt
  864. # copy over missing *.a files
  865. if [ "$autoso2a" = 1 ]; then
  866. echo "Checking for missing .a files ..."
  867. while read d s; do
  868. grep -q "/${s%.so}.a$" $builddir/flist.txt && continue
  869. [ "$d" = "lib" ] && d="usr/lib"
  870. if [ -f "$AUTOSO2A_DIR/${s%.so}.a" ]; then
  871. echo "Installing automatically created $d/${s%.so}.a."
  872. cp "$AUTOSO2A_DIR/${s%.so}.a" "$root/$d/${s%.so}.a"
  873. add_flist "$root/$d/${s%.so}.a"
  874. else
  875. echo "Not found: $AUTOSO2A_DIR/${s%.so}.a"
  876. fi
  877. done < <( egrep '(^|/)lib/[^/]*\.so$' "$builddir/flist.txt" | sed 's,\(.*\)/,\1 ,' )
  878. fi
  879. # merge flist of previous build
  880. for x in var/adm/flists/$xpkg var/adm/flists/$xpkg:*; do
  881. [ -f $x ] && cut -f2- -d' ' $x >> "$builddir/flist.txt"
  882. done
  883. # evaluate flistdel (2/2)
  884. egrep -v "^($flistdel)\$" "$builddir/flist.txt" | sort -u > "$builddir/flist.txt.new"
  885. mv "$builddir/flist.txt.new" "$builddir/flist.txt"
  886. hook_eval postflist
  887. fl_wrparse -D -p "$xpkg" -r "$xroot/" < "$builddir/flist.txt" | sort -u > "$builddir/flist.split"
  888. echo Found `wc -l < "$builddir/flist.split"` "files for this package."
  889. splitapply $xpkg "$builddir/flist.split"
  890. if [ "$ROCKCFG_FLIST" = "flwrapper" -o \
  891. "$ROCKCFG_FLIST" = "strace" ] && [ $stagelevel -ge 3 ] ; then
  892. echo "Calculating build-time package dependencies ..."
  893. ! egrep -v "^($flistrfilter)\$" "$builddir"/fl_wrapper.[rw]log |
  894. sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | \
  895. grep -v ' var/adm/' | awk '
  896. ARGIND < ARGC-1 {
  897. if ( index($1, "'$xpkg':") != 1 )
  898. f[$2] = $1 " " f[$2];
  899. }
  900. ARGIND == ARGC-1 {
  901. file = $2;
  902. while ( file != "" ) {
  903. if ( f[file] ) {
  904. split(f[file], a);
  905. for (i in a)
  906. if (! d[a[i] " " file]) {
  907. d[a[i] " " file] = 1;
  908. print a[i] " " file;
  909. }
  910. }
  911. sub("/?[^/]*$", "", file)
  912. }
  913. }
  914. ' var/adm/flists/* - > "$builddir/dependencies.debug"
  915. awk 'BEGIN { FS=": "; } { print "'$xpkg': " $1; }' \
  916. < "$builddir/dependencies.debug" > "$builddir/dependencies.txt"
  917. if [ -f var/adm/dep-debug/$xpkg ] ; then
  918. cat var/adm/dep-debug/$xpkg >> "$builddir/dependencies.debug"
  919. fi
  920. sort -u "$builddir/dependencies.debug" > var/adm/dep-debug/$xpkg
  921. # add debug info for known false dependencies
  922. if egrep -q "^[^#].* $xpkg( |$)" $base/scripts/dep_fixes.txt; then
  923. echo "--- $xpkg [$stagelevel] ---" >> $root/var/adm/rock-debug/falsedeps.txt
  924. fi
  925. while read x; do
  926. grep "^$x: " "$builddir/dependencies.debug" | sort -u | \
  927. sed "s,:, -> $xpkg [$stagelevel]:," >> $root/var/adm/rock-debug/falsedeps.txt
  928. done < <( egrep "^$xpkg +del +" $base/scripts/dep_fixes.txt | \
  929. tr ' ' '\t' | tr -s '\t' | cut -f3- | tr '\t' '\n' )
  930. # merge the dependencies defined by the package
  931. for x in `echo "$desc_E" | egrep '^add ' | sed 's/^add //' ` ; do
  932. echo "Adding dependency: $x ..."
  933. echo "$xpkg: $x" >> "$builddir/dependencies.txt"
  934. done
  935. # remove dependencies as requested by the package
  936. # TODO: groups are not used yet (and it is not easy here)
  937. del_pattern=""
  938. for x in `echo "$desc_E" | egrep '^del ' | sed 's/^del //' ` ; do
  939. del_pattern="$del_pattern -e \".*: $x(:.*|)\$\""
  940. done
  941. if [ -n "$del_pattern" ] ; then
  942. echo "Deleting dependencies, pattern: $del_pattern ..."
  943. eval "egrep -v $del_pattern \"$builddir/dependencies.txt\"" > "$builddir/dependencies.txt.new"
  944. mv "$builddir/dependencies.txt.new" "$builddir/dependencies.txt"
  945. fi
  946. if [ -f var/adm/dependencies/$xpkg ] ; then
  947. cat var/adm/dependencies/$xpkg >> "$builddir/dependencies.txt"
  948. fi
  949. sort -u "$builddir/dependencies.txt" > "$builddir/dependencies.txt.new"
  950. mv "$builddir/dependencies.txt.new" "$builddir/dependencies.txt"
  951. fi
  952. echo "Calculating run-time package dependencies from pkg-config files..."
  953. grep "\.pc$" "$builddir/flist.split" | while read dummy x ; do
  954. x="$root/$x"
  955. # Only three tags are of interest here. Version: is mandatory.
  956. version="`grep -e"^Version:" $x | cut -f2- -d' '`"
  957. [ "$version" ] || continue
  958. # Set the variables defined in the .pc file.
  959. eval $( sed 's,^\([a-zA-Z0-9_]*\)=\(.*\),\1="\2",p ; d' $x )
  960. echo "`basename ${x%.pc}` $version" >> $builddir/provides.tmp
  961. for tag in Requires Conflicts ; do
  962. case "$tag" in
  963. "Requires") tmpfile="$builddir/requires.tmp" ;;
  964. "Conflicts") tmpfile="$builddir/conflicts.tmp" ;;
  965. esac
  966. # Set positional parameters to the tag values.
  967. set $( sed -e"/^$tag: / { s,^$tag: ,, ; s/,/ /g ; p } ; d" $x ) ""
  968. while [ "$1" ] ; do
  969. eval echo -n "$1"
  970. case "$2" in
  971. "<"|">"|"<="|">="|"=")
  972. echo " $2 $3" ; shift 2 ;;
  973. *) echo ;;
  974. esac ; shift
  975. done >> $tmpfile
  976. done
  977. done
  978. for spkg in $( sed 's,: .*,,' < "$builddir/flist.split" | sort -u )
  979. do
  980. (
  981. if [ -z "${spkg##*:*}" ]; then
  982. splitdesc_${spkg#*:}
  983. fi
  984. echo "<$spkg> Calculating run-time package dependencies from ELF files..."
  985. grep "^$spkg: " "$builddir/flist.split" | while read dummy x ; do
  986. x="$root/$x"
  987. # Symbolic links (to ELF files) and non-regular files
  988. # are ignored.
  989. [ -L "$x" -o ! -f "$x" ] && continue
  990. # Strip most values from ELF dynamic and version
  991. # sections as they don't contain useful info.
  992. readelf -dV $x 2>/dev/null | sed -e '
  993. /^Version definition section /,/^Version needs section / {
  994. s,.* Flags: BASE .* Name: \(.*\),provides \1,p
  995. }
  996. /^Version needs section /,$ {
  997. s,.* File: \([^ ]*\) .*,requires \1,p
  998. }
  999. # in dynamic section
  1000. s,.* (SONAME) .* Library soname: \[\(.*\)\]$,provides \1,p
  1001. s,.* (NEEDED) .* Shared library: \[\(.*\)\]$,requires \1,p
  1002. # in version sections
  1003. s,.* Name: \([^ ]*\).*,\1,p ; d
  1004. ' | while read a b ; do
  1005. case "$a" in
  1006. "provides"|"requires")
  1007. pref="$b" ; tmpfile="$builddir/$a.tmp"
  1008. [ "$a" == provides ] && cmp_op=" " || cmp_op=" @ "
  1009. echo "$pref" >> $tmpfile ;;
  1010. *) echo "$pref${cmp_op}$a" >> $tmpfile ;;
  1011. esac
  1012. done
  1013. done
  1014. for x in {provides,requires,conflicts} ; do
  1015. if [ -f "$builddir/$x.tmp" ] ; then
  1016. echo "<$spkg> Creating var/adm/$x/$spkg"
  1017. sort -u "$builddir/$x.tmp" > var/adm/$x/$spkg
  1018. rm -f "$builddir/$x.tmp"
  1019. else
  1020. rm -f var/adm/$x/$spkg
  1021. fi
  1022. done
  1023. echo "<$spkg> Creating flist file ..."
  1024. {
  1025. grep "^$spkg: " "$builddir/flist.split"
  1026. for x in var/adm/{parse-config,provides,requires,conflicts}/$spkg ; do
  1027. [ -s "$x" ] && echo "$spkg: $x"
  1028. done
  1029. for x in var/adm/{flists,md5sums,cksums,packages,descs,dependencies}/$spkg ; do
  1030. touch $x ; echo "$spkg: $x"
  1031. done
  1032. } | sort -u > var/adm/flists/$spkg
  1033. if [ -f "$builddir/dependencies.txt" ] ; then
  1034. echo "<$spkg> Creating package dependencies file ..."
  1035. sed "s,^[^ ]*,$spkg:," < "$builddir/dependencies.txt" > var/adm/dependencies/$spkg
  1036. fi
  1037. echo "<$spkg> Creating package description ..."
  1038. #
  1039. rocksrcck=$(cd $base; md5sum package/*/$pkg/* 2> /dev/null | \
  1040. grep -v '\.cache$' | md5sum | cut -f1 -d' ')
  1041. buildlist="$( grep "^Build \[.\] at " var/adm/packages/$spkg || true
  1042. echo "Build [$stagelevel] at $buildstart to `date "+%T %Z"`")"
  1043. #
  1044. cat > var/adm/packages/$spkg << EOT
  1045. Package Name and Version: $spkg $ver $extraver
  1046. Package Size: `getdu $root/ < var/adm/flists/$spkg`, `
  1047. wc -l < var/adm/flists/$spkg | tr -d ' '` files
  1048. ROCK Linux Package Source Checksum: $rocksrcck
  1049. ROCK Linux Version and Architecture: $rockver $arch
  1050. Build on `uname -m -n -r -s -p`
  1051. $buildlist
  1052. Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
  1053. ${desc_I:-$spkg}
  1054. $( echo "${desc_T:-No description available.}" | sed 's,^, ,' )
  1055. URL(s):
  1056. $( echo "${desc_U:-http://www.rocklinux.net/packages/$pkg.html}" | sed 's,^, ,' )
  1057. Original Author(s):
  1058. $( echo "${desc_A:-Unknown}" | sed 's,^, ,' )
  1059. ROCK Package Maintainer(s):
  1060. $( echo "${desc_M:-Unknown}" | sed 's,^, ,' )
  1061. Download URL(s):
  1062. $( echo "${desc_D:-None}" | awk '{ print " " $3 $2; }' )
  1063. EOT
  1064. {
  1065. echo "[CONFIG] ${ROCKCFG_ID#*-}"
  1066. while read x; do
  1067. if [ "${x#\[}" != "$x" ]; then # "]}"
  1068. x="`echo ${x// /|} | tr -d '[]'`"
  1069. y="${x%%|*}" ; x="(${x%|(*)})"
  1070. case "$y" in
  1071. V) echo "[V] $ver $extraver" ;;
  1072. *) echo "$descfile" | egrep "^\[$x\]" | expand | sed "s,^[^ ]*,[$y]," ;;
  1073. esac
  1074. fi
  1075. done < $base/Documentation/Developers/PKG-DESC-FORMAT
  1076. } > var/adm/descs/$spkg
  1077. # Create them last so checksums of other var/adm files are correct.
  1078. echo "<$spkg> Creating md5sum and cksum files ..."
  1079. echo -n > var/adm/cksums/$spkg
  1080. echo -n > var/adm/md5sums/$spkg
  1081. # getfiles only returns non-directories, suitable for checksum creation.
  1082. getfiles < var/adm/flists/$spkg > "$builddir/files.lst"
  1083. if [ -s "$builddir/files.lst" ] ; then
  1084. while read file ; do
  1085. [ -z "${file//[ ]/}" ] && continue
  1086. # Checksums on these files are volatile.
  1087. if [ "$file" = "var/adm/cksums/$spkg" -o \
  1088. "$file" = "var/adm/md5sums/$spkg" -o \
  1089. -b "$file" -o -c "$file" -o -p "$file" -o \
  1090. -L "$file" -o -S "$file" ] ; then
  1091. echo "X ${file}" >> var/adm/md5sums/$spkg
  1092. echo "X $( stat -c %s ${file} ) ${file}" \
  1093. >> var/adm/cksums/$spkg
  1094. elif [ ${ROCKCFG_CREATE_CKSUM} -eq 1 ] ; then
  1095. md5sum "${file}" >> var/adm/md5sums/$spkg
  1096. cksum "${file}" >> var/adm/cksums/$spkg
  1097. else
  1098. echo "0 ${file}" >> var/adm/md5sums/$spkg
  1099. echo "0 $( stat -c %s ${file} ) ${file}" \
  1100. >> var/adm/cksums/$spkg
  1101. fi
  1102. done < "$builddir/files.lst"
  1103. fi
  1104. if [ $stagelevel -ge 3 -a $nopostinst = 0 -a -d /var/adm/postinstall ]; then
  1105. cp var/adm/flists/$spkg "$(mktemp var/adm/postinstall/${spkg}-install.XXXXXX)"
  1106. fi
  1107. )
  1108. done
  1109. echo "Making post-install adaptions."
  1110. if [ $stagelevel -ge 3 -a -f /sbin/ldconfig ] ; then ldconfig ; fi
  1111. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 ] ; then
  1112. found_errors=0
  1113. found_dups=0
  1114. # check for files which are 'shared' with other packages
  1115. if [ "$check_shared" != "0" ]; then
  1116. while read dummy file; do
  1117. if [ $found_dups = 0 ] ; then
  1118. echo "Found shared files with other packages:"
  1119. found_errors=1; found_dups=1
  1120. fi
  1121. echo "$file:" $( cd $root/var/adm/flists
  1122. grep -l " $file\$" * )
  1123. done < <( find $root/var/adm/flists/ -maxdepth 1 -type f | \
  1124. xargs -n100 sed "s,^$xpkg:[^ ]*,.," | \
  1125. sort -k2 | uniq -d -f1 | grep '^\. ' )
  1126. fi
  1127. found_local=0
  1128. # check for files in /usr/local
  1129. if [ "$check_usrlocal" != "0" ]; then
  1130. while read file ; do
  1131. if [ $found_local = 0 ] ; then
  1132. echo "Found files in /usr/local:"
  1133. found_errors=1; found_local=1
  1134. fi
  1135. echo $file
  1136. done < <( sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg \
  1137. $root/var/adm/flists/$xpkg:* 2> /dev/null | egrep "^/usr/local" )
  1138. fi
  1139. found_bad=0
  1140. # check for registered 'bad files'
  1141. if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
  1142. echo "$badfiles" > "$builddir/badfiles.txt"
  1143. while read x file; do
  1144. if [ $found_bad = 0 ]; then
  1145. echo "Found registered 'bad files' in package:"
  1146. found_errors=1; found_bad=1
  1147. fi
  1148. desc="No description found!"
  1149. for ((x=0; x<badfiles_nr; x++)); do
  1150. if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
  1151. then desc="${badfiles_desc[x]#*$'\n'}"; fi
  1152. done
  1153. echo "$file: $desc"
  1154. done < <( grep -f "$builddir/badfiles.txt" $root/var/adm/flists/$xpkg \
  1155. $root/var/adm/flists/$xpkg:* 2> /dev/null )
  1156. fi
  1157. [ $found_errors != 0 ] && abort
  1158. fi
  1159. touch $root/var/adm/logs/$stagelevel-$xpkg.log
  1160. echo "Finished building $pkg=$xpkg."
  1161. hook_eval finish
  1162. )
  1163. if [ ! -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  1164. abort
  1165. fi
  1166. } 2>&1 | {
  1167. trap '' INT
  1168. if [ "$ROCKCFG_VERBOSE" = 1 -o "$verbose" = 1 ] ; then
  1169. tee $root/var/adm/logs/$stagelevel-$xpkg.out
  1170. else
  1171. cat > $root/var/adm/logs/$stagelevel-$xpkg.out
  1172. fi
  1173. }
  1174. if [ $update = 1 ] ; then
  1175. echo_status "Restoring backup of old package data."
  1176. while read fn ; do
  1177. [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
  1178. done < "$builddir/backup_files.txt"
  1179. tar --force-local --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
  1180. while read fn ; do
  1181. cmp -s $fn $fn.new && rm -f $fn.new
  1182. done < "$builddir/backup_files.txt"
  1183. fi
  1184. cd $base
  1185. umount -r -d -f "$builddir"/* 2> /dev/null
  1186. umount -r -d -f -l "$builddir"/* 2> /dev/null
  1187. if [ "$ROCKCFG_SRC_TMPFS_LOG" = 1 -a -n "$( type -p df )" ]; then
  1188. if [ ! -f $root/var/adm/rock-debug/tmpfslog.txt ] ; then
  1189. echo -e "# Config\tPackage\tInodes\tKB" | \
  1190. expand -t20 > $root/var/adm/rock-debug/tmpfslog.txt
  1191. fi
  1192. echo -e "$config\t$stagelevel-$xpkg\t$(
  1193. df 2> /dev/null -Pi "$builddir" | tail -n 1 | tr -s ' ' | cut -f3 -d' '
  1194. )\t$(
  1195. df 2> /dev/null -Pk "$builddir" | tail -n 1 | tr -s ' ' | cut -f3 -d' ')" | \
  1196. expand -t20 >> $root/var/adm/rock-debug/tmpfslog.txt
  1197. fi
  1198. if [ "$ROCKCFG_PSEUDONATIVE" = 1 -a $stagelevel -eq 0 ]; then
  1199. rm -f $base/build/$ROCKCFG_ID/pseudonative_handler
  1200. fi
  1201. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  1202. export LD_PRELOAD="${LD_PRELOAD//${FLWRAPPER}/}"
  1203. export LD_PRELOAD="${LD_PRELOAD//::/:}"
  1204. fi
  1205. if [ "$ROCKCFG_SRC_TMPFS" = 1 ]; then
  1206. umount -l "$builddir"
  1207. fi
  1208. if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  1209. if [ $clear_src = 1 ] ; then
  1210. rm -rf "$builddir"/* "$builddir"
  1211. else
  1212. cp $root/var/adm/logs/$stagelevel-$xpkg.out "$builddir/BUILD-LOG"
  1213. fi
  1214. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  1215. "-> $stagelevel-$xpkg.log"
  1216. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  1217. $root/var/adm/logs/$stagelevel-$xpkg.log
  1218. echo_pkg_finish $stagelevel $repository $xpkg
  1219. exit 0
  1220. else
  1221. if [ $clear_src = 1 -a "$ROCKCFG_ALWAYS_CLEAN" = 1 ] ; then
  1222. rm -rf "$builddir"/* "$builddir"
  1223. else
  1224. cp $root/var/adm/logs/$stagelevel-$xpkg.out "$builddir/ERROR-LOG"
  1225. fi
  1226. if [ "$ROCKCFG_VERBOSE" != 1 -a "$verbose" != 1 ] ; then
  1227. echo_errorquote "$( grep -B7 -- '--- BUILD ERROR ---' \
  1228. $root/var/adm/logs/$stagelevel-$xpkg.out | \
  1229. sed '$ s,--- BUILD ERROR ---,,' | \
  1230. grep . | grep -vx -- -- )"
  1231. fi
  1232. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  1233. "-> $stagelevel-$xpkg.err"
  1234. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  1235. $root/var/adm/logs/$stagelevel-$xpkg.err
  1236. echo_pkg_abort $stagelevel $repository $xpkg
  1237. exit 1
  1238. fi
  1239. # ---- EOF