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.

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