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.

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