OpenSDE Framework (without history before r20070)
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.

1031 lines
29 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Build-Pkg
  6. # Copyright (C) 2006 - 2013 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. exec 2>&1
  18. buildstart="`date "+%m/%d/%Y from %T"`"
  19. sderootdirs="scripts bin etc lib doc src package architecture target"
  20. options=
  21. config=default
  22. clear_src=1
  23. norebuild=0
  24. update=0
  25. make_tar=
  26. prefix="usr"
  27. prefix_auto=1
  28. pkgdir=
  29. verbose=0
  30. xtrace=0
  31. debug=0
  32. chroot=0
  33. root=
  34. id=
  35. build_parallel=
  36. build_debug=
  37. stagelevel=9
  38. this_is_the_2nd_run=0
  39. #
  40. # ---- Functions
  41. #
  42. help_msg() {
  43. spacer=" "
  44. echo
  45. echo "Usage: ./scripts/Build-Pkg" \
  46. "[ -0 | -1 | -2 ... | -8 | -9 ] \\"
  47. echo "$spacer [ -v ] [ -xtrace ] [ -chroot ] \\"
  48. echo "$spacer [ -d ] [ -j <n> ] \\"
  49. echo "$spacer [ -root { <rootdir> | auto } ] \\"
  50. echo "$spacer [ -cfg <config> ] [ -update ] \\"
  51. echo "$spacer [ -prefix <prefix-dir> ] [ -norebuild ] \\"
  52. echo "$spacer [ -noclearsrc ] [ -pkgdir <pkgdir> ] \\"
  53. echo "$spacer [ -id <id> ] [ -debug ] pkg-name(s)"
  54. echo
  55. }
  56. #
  57. # ---- Parse options + config and make Build-Pkg sub-calls
  58. #
  59. while [ "$1" ] ; do
  60. case "$1" in
  61. -this_is_the_2nd_run) this_is_the_2nd_run=1 ;;
  62. -[0-9]) options="$options $1" ; stagelevel=${1#-} ;;
  63. -v) options="$options $1" ; verbose=1 ;;
  64. -xtrace) options="$options $1" ; xtrace=1 ;;
  65. -debug) options="$options $1" ; debug=1 ; clear_src=0 ;;
  66. -j) options="$options $1 $2" ; build_parallel=$2 ; shift ;;
  67. -d) options="$options $1" ; build_debug=1 ;;
  68. -update) options="$options $1" ; update=1 ;;
  69. -chroot) options="$options $1" ; chroot=1 ;;
  70. -chr-sub) options="$options $1" ; chroot=0 ;;
  71. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  72. -root) options="$options $1 $2" ; root="$2" ; shift ;;
  73. -prefix) options="$options $1 $2" ;
  74. prefix_auto=0 ; prefix="$2" ; shift ;;
  75. -id) options="$options $1 $2" ; id="$2" ; shift ;;
  76. -pkgdir) options="$options $1 $2" ; pkgdir="$2" ; shift ;;
  77. -noclearsrc) options="$options $1" ; clear_src=0 ;;
  78. -norebuild) options="$options $1" ; norebuild=1 ;;
  79. -*) help_msg ; exit 1 ;;
  80. *) break ;;
  81. esac
  82. shift
  83. done
  84. # check if arguments are left as package names
  85. if [ $# = 0 ] ; then
  86. help_msg ; exit 1
  87. fi
  88. . lib/functions.in
  89. . lib/parse-config
  90. [ -z "$build_debug" ] || export "SDECFG_DEBUG=$build_debug"
  91. [ -z "$build_parallel" ] || export "SDECFG_PARALLEL_MAX=$build_parallel"
  92. if [ -z "$root" -a $stagelevel -le 1 ] ||
  93. [ -z "$root" -a $chroot -eq 1 ] ||
  94. [ "$root" = auto ]; then
  95. if atstage toolchain; then
  96. root="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
  97. else
  98. # the new systems root
  99. root="build/$SDECFG_ID";
  100. fi
  101. fi
  102. [ "$pkgdir" -a "${pkgdir#/}" = "$pkgdir" ] && pkgdir="$base/$pkgdir"
  103. [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
  104. # remove leading and trailing / on prefix and root
  105. prefix=${prefix%/} ; prefix=${prefix#/} ; root=${root%/}
  106. # xroot is for internal use and always points to the new system
  107. xroot="$root"
  108. if ! atstage native; then
  109. sysroot="$base/build/$SDECFG_ID" # always fresh sandbox
  110. else
  111. root=
  112. sysroot=
  113. fi
  114. if [ -z "$id" ] ; then
  115. id=`get_unique`
  116. options="$options -id $id"
  117. fi
  118. # more than one package is passed
  119. if [ $# -gt 1 ] ; then
  120. for x ; do
  121. if ! ./scripts/Build-Pkg $options $x && \
  122. [ $stagelevel -le "$SDECFG_CONTINUE_ON_ERROR_AFTER" ] ; then
  123. exit 1
  124. fi
  125. done
  126. exit 0
  127. fi
  128. pkg="${1%=*}" ; xpkg="${1#*=}"
  129. builddir="$base/src.$pkg.$config.$id"
  130. if [ "$chroot" = 1 ] ; then
  131. cd "$xroot" || exit 1
  132. x_mknod() {
  133. if [ ! -c "$1" -a ! -b "$1" ]; then
  134. mknod "$@"
  135. fi
  136. }
  137. mkdir -p dev/loop
  138. x_mknod dev/null c 1 3
  139. x_mknod dev/zero c 1 5
  140. x_mknod dev/random c 1 8
  141. x_mknod dev/urandom c 1 9
  142. x_mknod dev/loop/0 b 7 0
  143. x_mknod dev/loop/1 b 7 1
  144. x_mknod dev/loop/2 b 7 2
  145. x_mknod dev/loop/3 b 7 3
  146. #_mknod dev/tty c 5 0
  147. if [ ! -L dev/fd ]; then
  148. ln -s /proc/self/fd dev/fd
  149. fi
  150. realconf=$(cd $base/config; pwd -P)
  151. realdown=$(cd $base/download; pwd -P)
  152. realbase=$(dirname $(cd $base/scripts; pwd -P))
  153. if [ ! -e TOOLCHAIN/loop/scripts ]; then
  154. mkdir -p TOOLCHAIN/{loop,config,download}
  155. mount --bind $realbase TOOLCHAIN/loop
  156. mount --bind $realconf TOOLCHAIN/config
  157. mount --bind $realdown TOOLCHAIN/download
  158. fi
  159. if [ ! -f proc/mounts ]; then
  160. mount -nt proc none proc
  161. fi
  162. for x in $sderootdirs; do
  163. if [ ! -e TOOLCHAIN/$x ]; then ln -s "loop/$x" "TOOLCHAIN/$x"; fi
  164. done
  165. if [ ! -e "TOOLCHAIN/build/$SDECFG_ID" ]; then
  166. mkdir -p "TOOLCHAIN/build"
  167. ln -snf ../.. "TOOLCHAIN/build/$SDECFG_ID"
  168. fi
  169. mkdir -p "TOOLCHAIN/src.$pkg.$config.$id"
  170. ln -s "$PWD/TOOLCHAIN/src.$pkg.$config.$id" "$builddir"
  171. cat > $builddir/chroot.sh <<- EOT
  172. export ROCK_THIS_IS_CHROOT=1; cd /TOOLCHAIN
  173. ./scripts/Build-Pkg $options -chr-sub -root "/" "$1"
  174. EOT
  175. cat > $builddir/debug.sh <<- EOT
  176. #!/bin/bash
  177. if [ ! -f "$xroot/proc/mounts" ]; then
  178. mount -nt proc none "$xroot/proc"
  179. fi
  180. if [ ! -e "$xroot/TOOLCHAIN/loop/scripts" ]; then
  181. mkdir -p "$xroot/"TOOLCHAIN/{loop,config,download}
  182. mount --bind $realbase "$xroot/TOOLCHAIN/loop"
  183. mount --bind $realconf "$xroot/TOOLCHAIN/config"
  184. mount --bind $realdown "$xroot/TOOLCHAIN/download"
  185. fi
  186. export ROCK_THIS_IS_CHROOT=1
  187. /usr/sbin/chroot "$xroot" /bin/bash TOOLCHAIN/src.$pkg.$config.$id/debug_x.sh
  188. if ! fuser -s "$xroot/TOOLCHAIN/" ; then
  189. echo "Loop mounts appear unused - un-mounting ..."
  190. umount -l "$xroot/TOOLCHAIN/"{download,config,loop}
  191. umount -l "$xroot/proc"
  192. fi
  193. EOT
  194. chmod +x $builddir/debug.sh
  195. if [ "$TZ" ] ; then
  196. if [ "${TZ#/}" != "$TZ" ] ; then
  197. cp $TZ TOOLCHAIN/localtime
  198. else
  199. cp /usr/share/zoneinfo/$TZ TOOLCHAIN/localtime
  200. fi
  201. else
  202. if [ -f /etc/localtime ] ; then
  203. cp /etc/localtime TOOLCHAIN/localtime
  204. else
  205. ln -sf /usr/share/zoneinfo/Factory TOOLCHAIN/localtime
  206. fi
  207. fi
  208. if [ "$SDECFG_PKG_DISTCC_HOST_RESOLV" = "1" ]; then
  209. cat /etc/resolv.conf > etc/resolv.conf
  210. fi
  211. TZ="/TOOLCHAIN/localtime" chroot . bin/bash TOOLCHAIN/src.$pkg.$config.$id/chroot.sh
  212. returncode=$?
  213. if [ ! -d "$builddir/." ]; then
  214. rm "$builddir"
  215. fi
  216. exit $returncode
  217. fi
  218. ./bin/sde-build-tools -$stagelevel -c $config || exit 1
  219. if [ "$SDECFG_FLIST" = "flwrapper" -a -z "$FLWRAPPER" ] ; then
  220. export FLWRAPPER_WLOG="$builddir/fl_wrapper.wlog"
  221. export FLWRAPPER_RLOG="$builddir/fl_wrapper.rlog"
  222. export FLWRAPPER_BASEPID=$$
  223. export FLWRAPPER_FILTERDIR="/tmp/:/dev/:/proc/:$builddir"
  224. [ "$LD_PRELOAD" ] && LD_PRELOAD="${LD_PRELOAD}:"
  225. export FLWRAPPER="$base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/fl_wrapper.so"
  226. export LD_PRELOAD="${LD_PRELOAD}$FLWRAPPER"
  227. fi
  228. export INSTALL_WRAPPER_LOGFILE="$builddir/install_wrapper.log"
  229. export CMD_WRAPPER_LOGFILE="$builddir/cmd_wrapper.log"
  230. export UNAME_WRAPPER_LOGFILE="$builddir/uname_wrapper.log"
  231. export HOME=$root/root
  232. if [ $norebuild = 1 -a -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  233. echo_pkg_deny $stagelevel $pkg "already built"
  234. exit 0
  235. fi
  236. # TODO: should i be pedantic and force rebuild of low stages even if $norebuild? /mnemoc
  237. if [ "$SDECFG_RETRY_BROKEN" = 0 -a $norebuild = 1 -a \
  238. -f $root/var/adm/logs/$stagelevel-$xpkg.err ] ; then
  239. echo_pkg_deny $stagelevel $pkg "already failed"
  240. exit 1
  241. fi
  242. archdir="$builddir/archdir"
  243. detect_confdir
  244. if [ -z "$confdir" ] ; then
  245. echo_pkg_deny $stagelevel $pkg "does not exist" ; exit 1
  246. fi
  247. mkdir -p $root/var/adm/logs
  248. mkdir -p $root/var/adm/flists
  249. mkdir -p $root/var/adm/olists
  250. mkdir -p $root/var/adm/cksums
  251. mkdir -p $root/var/adm/md5sums
  252. mkdir -p $root/var/adm/packages
  253. mkdir -p $root/var/adm/dependencies
  254. mkdir -p $root/var/adm/dep-debug
  255. mkdir -p $root/var/adm/parse-config
  256. mkdir -p $root/var/adm/cache
  257. mkdir -p $root/var/adm/descs
  258. [ "$root" ] && chmod 0755 $root
  259. rm -f $root/var/adm/logs/$stagelevel-$xpkg.out
  260. rm -f $root/var/adm/logs/$stagelevel-$xpkg.log
  261. rm -f $root/var/adm/logs/$stagelevel-$xpkg.err
  262. if [ $this_is_the_2nd_run = 0 ] ; then
  263. if [ "$toolsdir" = "tools.chroot" ]; then
  264. . /etc/profile
  265. fi
  266. options="-this_is_the_2nd_run $options $pkg=$xpkg"
  267. if [ "$SDECFG_CREATE_CACHE" = 1 -a "$toolsdir" != "$tools.cross" ] ; then
  268. mkdir -p $root/var/adm/cache
  269. rm -f $root/var/adm/cache/$xpkg
  270. rm -f $root/var/adm/cache/$xpkg.tm
  271. /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
  272. -f 'buildtime=$(qcalc %U + %S)' $0 $options
  273. returncode=$?
  274. [ ! -e "$root/var/adm/cache/$xpkg.tm" ] && exit $returncode
  275. qcalc() { gawk "BEGIN { printf(\"%d\n\", ($*)*100); }"; }
  276. eval "`grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm`"
  277. rm -f $root/var/adm/cache/$xpkg.tm
  278. # store reference time
  279. if [ $pkg = binutils ]; then
  280. echo $buildtime > $sysroot/TOOLCHAIN/reftime
  281. fi
  282. # compute relative build time to binutils (LFS-style)
  283. if [ -e $root/TOOLCHAIN/reftime ]; then
  284. reftime=`cat $root/TOOLCHAIN/reftime`
  285. else
  286. reftime=$buildtime # so until we have a ref all will be 100%
  287. fi
  288. # quantisized to 5% steps
  289. buildtime=`gawk "BEGIN { printf(\"%d\n\", int($buildtime * 20 / $reftime) * 5 ); }"`
  290. {
  291. date '+%n[TIMESTAMP] %s %c'
  292. [ -f $root/var/adm/logs/$stagelevel-$xpkg.err ] &&
  293. x=" ERROR" || x=
  294. echo "[BUILDTIME] $buildtime ($stagelevel)$x"
  295. x="$root/var/adm/packages/$xpkg"
  296. if [ -f $x ]; then
  297. echo "[SIZE] `grep "^Package Size: " \
  298. $x | cut -f3- -d' '`"
  299. fi
  300. echo
  301. x="$root/var/adm/dependencies/$xpkg"
  302. [ "$pkg" != "sde-debug" -a -f $x ] &&
  303. sed 's,^[^:]*:,[DEP],' $x
  304. } > $root/var/adm/cache/$xpkg
  305. exit $returncode
  306. else
  307. exec $0 $options
  308. fi
  309. fi
  310. #
  311. # ---- Setting Build Variables
  312. #
  313. # allowed toplevel directories that will be flisted
  314. flistroot="bin boot etc lib sbin usr var opt"
  315. # additionally allowed toplevel directories for 64 bit architectures
  316. case $arch_machine in
  317. powerpc64|sparc64|x86_64|mips64)
  318. var_append flistroot ' ' "lib64"
  319. if [ "$SDECFG_MULTILIB" = 1 ]; then
  320. var_append flistroot ' ' "lib32"
  321. fi
  322. ;;
  323. esac
  324. # remove the obvious noise: ldconfig and our /var/adm as well as due to
  325. # rare i18n locale directories ...
  326. flistrfilter="ldconfig\..*: .*|.*: /var/adm/.*|.*: .*/share/locale/.*"
  327. flistdel="etc/ld.so.cache|etc/blkid.tab|var/tmp/.*|usr/tmp/.*|var/adm/logs/.*"
  328. flistdel="$flistdel|.*\\.old|.*\\.rej|.*~"
  329. flistvalid="$base|/tmp|/var/backups|/proc|/dev"
  330. foodirlist="bindir sbindir libdir datadir includedir sysconfdir localstatedir docdir"
  331. init_vars_and_hooks
  332. #
  333. # ---- Read various config files
  334. #
  335. parse_desc $pkg
  336. echo_pkg_start $stagelevel $repository $xpkg $ver $extraver
  337. if [ "$SDECFG_PARANOIA_CHECK" = 1 -a -z "$pkgdir" ] ; then
  338. x="`./scripts/Check-PkgFormat $pkg`"
  339. [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
  340. `option to ignore such errors."
  341. fi
  342. targetdir="$base/target/$target"
  343. detect_patchfiles
  344. if atstage toolchain; then
  345. var_append patchfiles ' ' "`ls $confdir/*.patch.toolchain{,.$arch} \
  346. 2>/dev/null | tr '\n' ' '`"
  347. fi
  348. if atstage cross; then
  349. var_append patchfiles ' ' "`ls $confdir/*.patch.cross{,.$arch} \
  350. 2>/dev/null | tr '\n' ' '`"
  351. fi
  352. set_confopt
  353. if atstage native; then
  354. for pc_file in $xroot/var/adm/parse-config/* ; do
  355. if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
  356. then . "$pc_file" ; fi
  357. done
  358. unset pc_file
  359. fi
  360. . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/parse-config
  361. # Erase positional parameters to prevent unintended parameter
  362. # passing. We do not want to pass the current positional parameters
  363. # to the loaded script.
  364. set --
  365. eval "$desc_O"
  366. # include package pre config - if any
  367. if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf ] ; then
  368. # echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_pre.conf"
  369. . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_pre.conf
  370. fi
  371. for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
  372. $confdir/$pkg.conf ; do
  373. if [ -f $x ]; then
  374. # if [[ $x = */$pkg.conf ]]; then
  375. # echo_status "Reading package configuration from package directory."
  376. # else
  377. # echo_status "Reading package configuration from target directory."
  378. # fi
  379. . $x
  380. break
  381. fi
  382. done
  383. # include package post config - if any
  384. if [ -f $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf ] ; then
  385. # echo_status "Reading build/.../$toolsdir/lib/pkg_${pkg}_post.conf"
  386. . $base/build/$SDECFG_ID/TOOLCHAIN/$toolsdir/lib/pkg_${pkg}_post.conf
  387. fi
  388. if [ -f $base/architecture/$arch/pkg-header ] ; then
  389. # echo_status "Reading overwrites from architecture/$arch/pkg-header."
  390. . $base/architecture/$arch/pkg-header
  391. fi
  392. for x in $( get_expanded $base/target/%/pkg-header `get_reverted $targetchain` ); do
  393. if [ -f $x ] ; then
  394. # echo_status "Reading overwrites from ${x#$base/}."
  395. . $x
  396. fi
  397. done
  398. #
  399. # ---- Variable updates based on the configuration files read
  400. #
  401. if [ -z "$prefix" -o "${prefix#usr}" != "$prefix" ] ; then
  402. flistdel="$flistdel|usr/share/info/(dir|standards.info)"
  403. if [ "$SDECFG_DISABLE_NLS" = 1 ] ; then
  404. flistdel="$flistdel|usr/share/locale/..[/_].*"
  405. flistdel="$flistdel|usr/share/man/..[/_].*"
  406. fi
  407. else
  408. flistdel="$flistdel|$prefix/info/(dir|standards.info)"
  409. if [ "$SDECFG_DISABLE_NLS" = 1 ] ; then
  410. flistdel="$flistdel|$prefix/share/locale/..[/_].*"
  411. flistdel="$flistdel|$prefix/man/..[/_].*"
  412. fi
  413. fi
  414. #
  415. # ---- Build Package
  416. #
  417. echo_status "Preparing build in src.$pkg.$config.$id"
  418. if [ $clear_src = 1 ] ; then
  419. mkdir -p $builddir; chmod 0755 $builddir
  420. if [ "$SDECFG_SRC_TMPFS" = 1 ]; then
  421. mount -t tmpfs -n ${SDECFG_SRC_TMPFS_OPT:+-o $SDECFG_SRC_TMPFS_OPT} none $builddir
  422. fi
  423. else
  424. mkdir -p $builddir; chmod 0755 $builddir
  425. fi
  426. if [ $update = 1 -a ! -f $xroot/var/adm/md5sums/$xpkg ] ; then
  427. echo_status "Ignoring update mode since package isn't installed already."
  428. update=0
  429. fi
  430. if [ $update = 1 ] ; then
  431. echo_status "Creating backup of old package data."
  432. (
  433. cd $xroot/
  434. md5sum --check var/adm/md5sums/$xpkg 2>&1 < /dev/null |
  435. grep ': FAILED$' | cut -f1 -d:
  436. ) > $builddir/backup_files.txt
  437. if [ -s $builddir/backup_files.txt ] ; then
  438. mkdir -p "$xroot/var/adm/backup"
  439. chmod 700 "$xroot/var/adm/backup"
  440. backup_tar="$xroot/var/adm/backup/$(
  441. date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
  442. ( cd $xroot/; tar --no-recursion -cf - -T $builddir/`
  443. `backup_files.txt || true; ) | bzip2 > $backup_tar
  444. else
  445. update=0
  446. fi
  447. fi
  448. if [ "$SDECFG_FLIST" = "flwrapper" ] ; then
  449. rm -f $builddir/fl_wrapper.wlog $builddir/fl_wrapper.rlog
  450. touch $builddir/fl_wrapper.wlog $builddir/fl_wrapper.rlog
  451. elif [ "$SDECFG_FLIST" = "find" ] ; then
  452. touch $builddir/temp.time_stamp
  453. sleep 2
  454. fi
  455. hook_eval prepare
  456. # define new abort function for errors while building
  457. #
  458. abort() {
  459. [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
  460. rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
  461. false
  462. }
  463. {
  464. trap 'echo "Got SIGINT (Crtl-C). Aborting build." ; exit 1' INT
  465. exec < /dev/null
  466. # Makes debugging build problems easier
  467. #
  468. hook_dump > $builddir/debug.hooks
  469. #
  470. {
  471. dump_env
  472. cat <<- EOT
  473. PS1='\\[\\e[00m\\e[01;31m\\]debug-`
  474. `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '
  475. alias cp="cp -i" ; alias mv="mv -i"
  476. alias rm="rm -i" ; alias ls="ls --color=auto -a"
  477. alias ..="cd .." ; alias ...="cd ../.."
  478. fixfile () {
  479. # we use .vanilla to not rediff backup .orig from patch
  480. [ -f \$1.vanilla ] || cp \$1 \$1.vanilla
  481. # maybe we do not have the editor yet?
  482. which \$EDITOR > /dev/null || EDITOR=nvi
  483. \$EDITOR \$1
  484. }
  485. fixfilediff() {
  486. find -name '*.vanilla' -printf '%P\n' | while read x ; do
  487. diff -u \$x \${x/.vanilla/}
  488. done
  489. }
  490. EOT
  491. } > $builddir/debug.buildenv
  492. #
  493. cat > $builddir/debug_x.sh <<- EOT
  494. #!/bin/bash
  495. cd $builddir; exec bash --rcfile debug.buildenv 200>> build.pid
  496. EOT
  497. #
  498. if [ "$ROCK_THIS_IS_CHROOT" != 1 ]; then
  499. mv $builddir/debug_x.sh $builddir/debug.sh
  500. chmod +x $builddir/debug.sh
  501. fi
  502. # Create PID file
  503. #
  504. # The builtin-variable '$$' is not this pid because this proc
  505. # is just a sub-proc of $$. That's why the $builddir/strace.tmp
  506. # hack is required to get the right pid to trace.
  507. #
  508. # We also conntect filedescriptor 3 with the pid file. So the command
  509. # 'fuser' can be used to create a list of all processes which are part
  510. # of this build process.
  511. #
  512. sh -c 'echo $PPID' > $builddir/build.pid
  513. exec 200>> $builddir/build.pid
  514. echo "Command Wrapper Debug: running '${CC} --version' .."
  515. type ${CC}; CMD_WRAPPER_DEBUG=1 ${CC} --version
  516. echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
  517. if [ "$debug" = 1 ] ; then
  518. echo "Everything is set up." \
  519. "We are in debug mode - so exit now."
  520. exit
  521. fi
  522. if [ "$SDECFG_FLIST" = "strace" ] ; then
  523. strace -o $builddir/strace.out -F -f -q -e open,creat,mkdir,`
  524. `mknod,link,symlink,rename,utime,chdir,execve,fork,`
  525. `vfork,_exit,exit_group -p `cat $builddir/build.pid` &
  526. strace_pid=$! ; sleep 1 ; cd $base
  527. fi
  528. (
  529. set -e
  530. mkdir -p "$builddir/archdir"
  531. populate_archdir
  532. echo "Running main build function '$mainfunction' ..."
  533. if [ $xtrace -eq 1 -o $SDECFG_XTRACE -eq 1 ] ; then
  534. PS4=$'=[$FUNCNAME:$LINENO (last \\\$?=$?)> ' ; set -o xtrace
  535. cd $builddir ; eval "$mainfunction"
  536. set +o xtrace
  537. else
  538. cd $builddir ; eval "$mainfunction"
  539. fi
  540. touch $root/var/adm/logs/$stagelevel-$xpkg.log
  541. )
  542. [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ||
  543. abort "Due to previous errors, no $stagelevel-$xpkg.log file!
  544. (Try enabling xtrace in the config to track an error inside the build system.)"
  545. hook_eval postinstall
  546. # split debug symbols
  547. if [ "$SDECFG_DEBUG_SPLIT" = 1 ] && ! atstage toolchain; then
  548. if hasflag KERNEL ; then
  549. echo_warning "Disabling debug symbol splitting (kernel package)"
  550. else
  551. split_debug_files
  552. fi
  553. fi
  554. echo "Creating file list and doing final adaptions ... "
  555. #
  556. cd $xroot/
  557. [ -s "var/adm/parse-config/$xpkg" ] &&
  558. echo "var/adm/parse-config/$xpkg" >> $builddir/flist.txt
  559. for x in var/adm/flists/$xpkg var/adm/md5sums/$xpkg \
  560. var/adm/cksums/$xpkg var/adm/packages/$xpkg \
  561. var/adm/descs/$xpkg var/adm/dependencies/$xpkg ; do
  562. touch $x ; echo "$x" >> $builddir/flist.txt
  563. done
  564. #
  565. if [ "$SDECFG_FLIST" = "strace" ] ; then
  566. sleep 1 ; kill -INT $strace_pid ; sleep 1
  567. fl_stparse -w $builddir/fl_wrapper.wlog \
  568. -r $builddir/fl_wrapper.rlog < $builddir/strace.out
  569. fi
  570. if [ "$SDECFG_FLIST" = "flwrapper" -o \
  571. "$SDECFG_FLIST" = "strace" ] ; then
  572. # sanitize accidental //s
  573. sed -i -e 's,//*,/,g' $builddir/fl_wrapper.{w,r}log
  574. if [ "$toolsdir" = "tools.cross" ]; then
  575. xbase="$( cd $xroot/ 2> /dev/null ; pwd -P )"
  576. flistvalid="$xbase|$flistvalid"
  577. if egrep -qv " ($flistvalid)/" $builddir/fl_wrapper.wlog
  578. then
  579. while read file ; do
  580. if [ -e "$file" ] ; then
  581. echo "Created file outside basedir: $file"
  582. abort_soon=1
  583. else # non fatal for now (configure junk)
  584. echo "Created (vanished) file outside basedir (ignored): $file"
  585. fi
  586. done < <( egrep -v " ($flistvalid)/" \
  587. $builddir/fl_wrapper.wlog |
  588. cut -f2- | sort -u )
  589. echo "base #1: $base"
  590. echo "base #2: $xbase"
  591. [ "$abort_soon" = 1 ] && abort
  592. fi
  593. fi
  594. fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog > \
  595. $builddir/flist.txt.tmp
  596. # check for file creation beside the allowed top-level
  597. # directories - allow root since qt, wxwidgets, ... create some
  598. # profile there ... - on stage 0 we have an ugly symlink hack
  599. # so we get doc, $arch_machine, ... in the top level dir :-(
  600. if [ $stagelevel -gt 0 ]; then
  601. fr="$flistroot root TOOLCHAIN"
  602. while read file; do
  603. echo "Created file outside allowed top-level dir: $file"
  604. abort_soon=1
  605. done < <( egrep -v "^(${fr// /|})(/|$)" \
  606. $builddir/flist.txt.tmp )
  607. [ "$abort_soon" = 1 ] && abort
  608. fi
  609. egrep "^(${flistroot// /|})(/|$)" $builddir/flist.txt.tmp >> \
  610. $builddir/flist.txt
  611. elif [ "$SDECFG_FLIST" = "find" ] ; then
  612. find $flistroot \
  613. \( -not -type d -or -type d -empty \) \
  614. -and \( -newer $builddir/temp.time_stamp -or \
  615. -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
  616. $builddir/flist.txt
  617. fi
  618. # evaluate flistdel
  619. egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
  620. mv $builddir/flist.txt{.new,}
  621. hook_eval postflist
  622. # save the old flist for later orphaned file check
  623. [ -e var/adm/flists/$xpkg ] &&
  624. cp -f var/adm/flists/$xpkg $builddir/flist.txt.old
  625. fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt |
  626. sort -u > $builddir/flist.txt.new
  627. # analyze which files have not been reinstalled and thus are (normally)
  628. # no longer needed (orphaned)
  629. if [ -e $builddir/flist.txt.old ]; then
  630. echo "Searching for orphaned files ..."
  631. diff --normal $builddir/flist.txt.{old,new} |
  632. grep '^<' | cut -d ' ' -f 2- > $builddir/olist.txt.new
  633. [ -e var/adm/olists/$xpkg ] &&
  634. cp -f var/adm/olists/$xpkg $builddir/olist.txt.old ||
  635. touch $builddir/olist.txt.old
  636. cat $builddir/olist.txt.{old,new} | sort -u > \
  637. var/adm/olists/$xpkg
  638. fi
  639. # until all olist regressions are fixed merge the two lists ... :-(
  640. touch $builddir/flist.txt.old
  641. cat $builddir/flist.txt.{old,new} | egrep -v "^$xpkg: ($flistdel)\$" |
  642. sort -u > var/adm/flists/$xpkg
  643. echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
  644. echo Found `wc -l < var/adm/olists/$xpkg` "orphaned files for this package."
  645. echo "Clear (old) md5sums and cksums ..."
  646. echo -n > var/adm/md5sums/$xpkg
  647. echo -n > var/adm/cksums/$xpkg
  648. if [ "$SDECFG_FLIST" = "flwrapper" -o \
  649. "$SDECFG_FLIST" = "strace" ] && atstage native ; then
  650. echo "Calculating package dependencies ..."
  651. ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.[rw]log |
  652. sort -u | fl_wrparse -D -s -r "$xroot/" -p '' | sort -u |
  653. grep -v ' var/adm/' | awk '
  654. # read the var/adm/... file content in
  655. ARGIND < ARGC-1 {
  656. if ( $1 != "'$xpkg':" )
  657. f[$2] = $1 " " f[$2];
  658. }
  659. # iterate over the read file list streamed to stdin
  660. ARGIND == ARGC-1 {
  661. file = $2;
  662. if ( f[file] ) {
  663. print f[file] " " file;
  664. }
  665. }
  666. ' var/adm/flists/* - >> $builddir/dependencies.debug
  667. awk 'BEGIN { FS=": "; } { print "'$xpkg': " $1; }' \
  668. < $builddir/dependencies.debug \
  669. >> $builddir/dependencies.txt
  670. sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
  671. # merge the dependencies defined by the package
  672. for x in `echo "$desc_E" | egrep '^add ' | sed 's/^add //' ` ; do
  673. echo "Adding dependency: $x ..."
  674. echo "$xpkg: $x" >> $builddir/dependencies.txt
  675. done
  676. # remove dependencies as requested by the package
  677. # TODO: goups are not used yet (and it is not easy here)
  678. del_pattern=
  679. for x in `echo "$desc_E" | egrep '^del ' | sed 's/^del //' ` ; do
  680. del_pattern="$del_pattern -e \".*: $x\$\""
  681. done
  682. if [ -n "$del_pattern" ] ; then
  683. echo "Deleting dependencies, pattern: $del_pattern ..."
  684. eval egrep -v $del_pattern \
  685. $builddir/dependencies.txt > \
  686. $builddir/dependencies.txt.new
  687. mv $builddir/dependencies.txt{.new,}
  688. fi
  689. sort -u $builddir/dependencies.txt > var/adm/dependencies/$xpkg
  690. fi
  691. echo -n "Creating md5sum and cksum files ..."
  692. getfiles < var/adm/flists/$xpkg > $builddir/files.lst
  693. if [ -s $builddir/files.lst ] ; then
  694. cat $builddir/files.lst | \
  695. grep -v '^var/adm/' | sed -e 's,^.*,"\0",' | \
  696. xargs -r md5sum > var/adm/md5sums/$xpkg
  697. cat $builddir/files.lst | \
  698. grep -v '^var/adm/' | sed -e 's,^.*,"\0",' | \
  699. xargs -r cksum > var/adm/cksums/$xpkg
  700. fi
  701. echo ' done.'
  702. echo "Creating package description ..."
  703. #
  704. rocksrcck=$( pkgchksum $base/package/*/$pkg )
  705. buildlist="$( grep "^Build \[.\] at " var/adm/packages/$xpkg || true
  706. echo "Build [$stagelevel] at $buildstart to `date "+%T %Z"`")"
  707. #
  708. cat > var/adm/packages/$xpkg << EOT
  709. Package Name and Version: $xpkg $ver $extraver
  710. Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
  711. wc -l < var/adm/flists/$xpkg | tr -d ' '` files
  712. OpenSDE Package Source Checksum: $rocksrcck
  713. OpenSDE Version and Architecture: $sdever $arch
  714. $buildlist
  715. Prefix: $prefix
  716. EOT
  717. # Location libdir: /opt/openldap/lib
  718. for x in $foodirlist; do
  719. if [ "`eval echo \\$$x`" != "`pkggetdir $x`" ]; then
  720. echo "Location $x: `eval echo \\$$x`" \
  721. >> var/adm/packages/$xpkg
  722. fi
  723. done
  724. cat >> var/adm/packages/$xpkg << EOT
  725. Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
  726. ${desc_I:-$xpkg}
  727. $( echo "${desc_T:-No description available.}" | sed 's,^, ,' )
  728. URL(s):
  729. $( echo "${desc_U:-No URL available.}" | sed 's,^, ,' )
  730. Original Author(s):
  731. $( echo "${desc_A:-Unknown}" | sed 's,^, ,' )
  732. Package Maintainer(s):
  733. $( echo "${desc_M:-Unknown}" | sed 's,^, ,' )
  734. Download URL(s):
  735. $( echo "${desc_D:-None}" | awk '{ print " " $3 $2; }' )
  736. EOT
  737. {
  738. echo "[CONFIG] ${SDECFG_ID#*-}"
  739. descfile=$base/package/*/$pkg/$pkg.desc
  740. while read x ; do
  741. if [ "${x#\[}" != "$x" ] ; then
  742. x="`echo ${x// /|} | tr -d '[]'`"
  743. y="${x%%|*}" ; x="(${x%|(*)})"
  744. egrep "^\[$x\]" $descfile | expand | sed "s,^[^ ]*,[$y],"
  745. fi
  746. done < $base/etc/desc_format
  747. } > var/adm/descs/$xpkg
  748. echo "Making post-install adaptions."
  749. if [ "$SDECFG_PARANOIA_CHECK" = 1 ] ; then
  750. found_errors=0
  751. found_dups=0
  752. # check for files which are 'shared' with other packages
  753. if [ "$check_shared" != "0" ]; then
  754. while read dummy file; do
  755. if [ $found_dups = 0 ] ; then
  756. echo "Found shared files with other packages:"
  757. found_errors=1; found_dups=1
  758. fi
  759. echo "$file:" $( cd $root/var/adm/flists
  760. grep -l " $file\$" * )
  761. done < <( echo $root/var/adm/flists/* | xargs -n 128 cat | sed "s,^$xpkg:,.," | \
  762. sort -k2 | uniq -d -f1 | grep '^\. ' )
  763. fi
  764. found_local=0
  765. # check for files in /usr/local
  766. if [ "$check_usrlocal" != "0" ]; then
  767. while read file ; do
  768. if [ $found_local = 0 ] ; then
  769. echo "Found files in /usr/local:"
  770. found_errors=1; found_local=1
  771. fi
  772. echo $file
  773. done < <( sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg | \
  774. egrep "^/usr/local" )
  775. fi
  776. found_bad=0
  777. # check for registered 'bad files'
  778. if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
  779. echo "$badfiles" > $builddir/badfiles.txt
  780. while read x file; do
  781. if [ $found_bad = 0 ]; then
  782. echo "Found registered 'bad files' in package:"
  783. found_errors=1; found_bad=1
  784. fi
  785. desc="No description found!"
  786. for ((x=0; x<badfiles_nr; x++)); do
  787. if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
  788. then desc="${badfiles_desc[x]#*$'\n'}"; fi
  789. done
  790. echo "$file: $desc"
  791. done < <( grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg )
  792. fi
  793. [ $found_errors != 0 ] && abort "Due to previous errors."
  794. fi
  795. } 2>&1 | {
  796. trap '' INT
  797. echo_status "Writing build output to" \
  798. "\$root/var/adm/logs/$stagelevel-$xpkg.out"
  799. if [ "$SDECFG_VERBOSE" = 1 -o "$verbose" = 1 ] ; then
  800. tee $root/var/adm/logs/$stagelevel-$xpkg.out
  801. else
  802. cat > $root/var/adm/logs/$stagelevel-$xpkg.out
  803. fi
  804. }
  805. hook_eval finish
  806. if [ $update = 1 ] ; then
  807. echo_status "Restoring backup of old package data."
  808. while read fn ; do
  809. [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
  810. done < $builddir/backup_files.txt
  811. tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
  812. while read fn ; do
  813. cmp -s $fn $fn.new && rm -f $fn.new
  814. done < $builddir/backup_files.txt
  815. fi
  816. cd $base
  817. umount -r -d -f $builddir/* 2> /dev/null
  818. umount -r -d -f -l $builddir/* 2> /dev/null
  819. if [ "$SDECFG_SRC_TMPFS_LOG" = 1 -a -n "$( type -p df )" ]; then
  820. mkdir -p $root/var/adm/sde-debug
  821. if [ ! -f $root/var/adm/sde-debug/tmpfslog.txt ] ; then
  822. echo -e "# Config\tPackage\tInodes\tKB" | \
  823. expand -t20 > $root/var/adm/sde-debug/tmpfslog.txt
  824. fi
  825. echo -e "$config\t$stagelevel-$xpkg\t$(
  826. df 2> /dev/null -Pi $builddir | tail -n 1 | tr -s ' ' | cut -f3 -d' '
  827. )\t$(
  828. df 2> /dev/null -Pk $builddir | tail -n 1 | tr -s ' ' | cut -f3 -d' ')" | \
  829. expand -t20 >> $root/var/adm/sde-debug/tmpfslog.txt
  830. fi
  831. umount -r -d -f $builddir 2> /dev/null
  832. umount -r -d -f -l $builddir 2> /dev/null
  833. if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  834. if [ $clear_src = 1 ] ; then
  835. rm -rf $builddir/* $builddir
  836. else
  837. cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
  838. fi
  839. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  840. "-> $stagelevel-$xpkg.log"
  841. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  842. $root/var/adm/logs/$stagelevel-$xpkg.log
  843. echo_pkg_finish $stagelevel $repository $xpkg
  844. exit 0
  845. else
  846. if [ $clear_src = 1 -a "$SDECFG_ALWAYS_CLEAN" = 1 ] ; then
  847. rm -rf $builddir/* $builddir
  848. else
  849. cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
  850. fi
  851. if [ "$SDECFG_VERBOSE" != 1 -a "$verbose" != 1 ] ; then
  852. echo_errorquote "$( grep -v 'make[^ ]*:' \
  853. $root/var/adm/logs/$stagelevel-$xpkg.out |
  854. grep -B8 -- '--- BUILD ERROR ---' |
  855. sed '/--- BUILD ERROR ---/d' )"
  856. fi
  857. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  858. "-> $stagelevel-$xpkg.err"
  859. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  860. $root/var/adm/logs/$stagelevel-$xpkg.err
  861. echo_pkg_abort $stagelevel $repository $xpkg
  862. exit 1
  863. fi
  864. # ---- EOF