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.

974 lines
28 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 - 2003 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. update=0
  31. make_tar=''
  32. prefix="usr"
  33. prefix_auto=1
  34. pkgdir=""
  35. verbose=0
  36. xtrace=0
  37. debug=0
  38. chroot=0
  39. root=""
  40. id=''
  41. stagelevel=9
  42. #
  43. # ---- Functions
  44. #
  45. . scripts/functions
  46. help_msg() {
  47. spacer=" "
  48. echo
  49. echo "Usage: ./scripts/Build-Pkg" \
  50. "[ -0 | -1 | -2 ... | -8 | -9 ] \\"
  51. echo "$spacer [ -v ] [ -xtrace ] [ -chroot ] \\"
  52. echo "$spacer [ -root { <rootdir> | auto } ] \\"
  53. echo "$spacer [ -cfg <config> ] [ -update ] \\"
  54. echo "$spacer [ -prefix <prefix-dir> ] [ -norebuild ] \\"
  55. echo "$spacer [ -noclearsrc ] [ -pkgdir <pkgdir> ] \\"
  56. echo "$spacer [ -id <id> ] [ -debug ] pkg-name(s)"
  57. echo
  58. echo "Type './scripts/Help Build-Pkg' for details."
  59. echo
  60. }
  61. #
  62. # ---- Parse options + config and make Build-Pkg sub-calls
  63. #
  64. this_is_the_2nd_run=0
  65. while [ "$1" ] ; do
  66. case "$1" in
  67. -this_is_the_2nd_run) this_is_the_2nd_run=1 ;;
  68. -[0-9]) options="$options $1" ; stagelevel=${1#-} ;;
  69. -v) options="$options $1" ; verbose=1 ;;
  70. -xtrace) options="$options $1" ; xtrace=1 ;;
  71. -debug) options="$options $1" ; debug=1 ; clear_src=0 ;;
  72. -update) options="$options $1" ; update=1 ;;
  73. -chroot) options="$options $1" ; chroot=1 ;;
  74. -chr-sub) options="$options $1" ; chroot=0 ;;
  75. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  76. -root) options="$options $1 $2" ; root="$2" ; shift ;;
  77. -prefix) options="$options $1 $2" ;
  78. prefix_auto=0 ; prefix="$2" ; shift ;;
  79. -id) options="$options $1 $2" ; id="$2" ; shift ;;
  80. -pkgdir) options="$options $1 $2" ; pkgdir="$2" ; shift ;;
  81. -noclearsrc) options="$options $1" ; clear_src=0 ;;
  82. -norebuild) options="$options $1" ; norebuild=1 ;;
  83. -*) help_msg ; exit 1 ;;
  84. *) break ;;
  85. esac
  86. shift
  87. done
  88. . ./scripts/parse-config
  89. if [ -z "$root" -a $stagelevel -le 1 ] || \
  90. [ -z "$root" -a $chroot -eq 1 ] || \
  91. [ "$root" = auto ]; then
  92. if [ $stagelevel -gt 0 ]; then root="build/$ROCKCFG_ID/root"
  93. else root="build/$ROCKCFG_ID/$toolsdir"; fi
  94. fi
  95. [ "$pkgdir" -a "${pkgdir#/}" = "$pkgdir" ] && pkgdir="$base/$pkgdir"
  96. [ "$root" -a "${root#/}" = "$root" ] && root="$base/$root"
  97. prefix=${prefix%/} ; prefix=${prefix#/} ; root=${root%/}
  98. xroot="$root" ; [ $stagelevel -gt 1 ] && root=""
  99. if [ -z "$id" ] ; then
  100. id=`get_unique`
  101. options="$options -id $id"
  102. fi
  103. ./scripts/Build-Tools -$stagelevel -cfg $config || exit 1
  104. if [ -z "$1" ] ; then
  105. help_msg ; exit 1
  106. elif [ "$2" ] ; then
  107. for x ; do
  108. if ! ./scripts/Build-Pkg $options $x && \
  109. [ "$ROCKCFG_ABORT_ON_ERROR" = 1 ] ; then
  110. exit 1
  111. fi
  112. done
  113. exit 0
  114. fi
  115. pkg="${1%=*}" ; xpkg="${1#*=}"
  116. builddir="$base/src.$pkg.$id"
  117. if [ "$chroot" = 1 ] ; then
  118. mkdir -p $builddir
  119. cd $builddir || exit 1
  120. mkdir -p R.orig R.build R.work R.src
  121. ln -s ../R.src R.work/src.$pkg.$id
  122. ln -s ../R.build R.work/build
  123. mkdir -p dev proc tmp mnt
  124. [ -d dev/shm ] || mount -t devfs none $builddir/dev
  125. [ -f proc/mounts ] || mount -t proc none $builddir/proc
  126. realbase=$(dirname $(cd $base/scripts ; pwd -P))
  127. mount --bind $realbase $builddir/R.orig
  128. # handle mounted download dirs
  129. if [ -L $realbase/download ]; then
  130. abort "download dir can't be a symlink, use mount instead."
  131. fi
  132. mount --bind $realbase/download $builddir/R.orig/download
  133. realbuild=$(cd $base/build ; pwd -P)
  134. mount --bind $realbuild $builddir/R.build
  135. ln -sf R.build/$ROCKCFG_ID/root/* . 2> /dev/null
  136. cat > R_chroot.sh <<- EOT
  137. cd /R.orig ; ./scripts/Create-Links /R.work > /dev/null
  138. cd /R.work ; ./scripts/Build-Pkg $options -chr-sub -root "/R.build/$ROCKCFG_ID/root" "$1"
  139. EOT
  140. cat <<- EOT > $builddir/R_mount.sh
  141. mount -t devfs none $builddir/dev
  142. mount -t proc none $builddir/proc
  143. mount --bind $realbase $builddir/R.orig
  144. mount --bind $realbase/download $builddir/R.orig/download
  145. mount --bind $realbuild $builddir/R.build
  146. EOT
  147. cat <<- EOT > $builddir/R_umount.sh
  148. umount dev proc R.orig/download R.orig R.build
  149. EOT
  150. cat <<- 'EOT' > $builddir/debug.sh
  151. sh R_mount.sh
  152. chroot . bin/bash -c 'cd R.src ; exec ./debug.sh'
  153. [ -z "`fuser R.src/build.pid`" ] && sh R_umount.sh
  154. EOT
  155. chmod +x $builddir/debug.sh
  156. mkdir -p R.work/config/
  157. cp -rp $base/config/$config R.work/config/
  158. if [ "$TZ" ] ; then
  159. if [ "${TZ#/}" != "$TZ" ] ; then
  160. cp $TZ R.localtime
  161. else
  162. cp /usr/share/zoneinfo/$TZ R.localtime
  163. fi
  164. else
  165. if [ -f /etc/localtime ] ; then
  166. cp /etc/localtime R.localtime
  167. else
  168. ln -s /usr/share/zoneinfo/Factory R.localtime
  169. fi
  170. fi
  171. TZ="/R.localtime" chroot . bin/bash R_chroot.sh ; returncode=$?
  172. {
  173. umount -d -f $builddir/R.orig/download
  174. umount -d -f $builddir/R.orig $builddir/R.build
  175. umount -d -f $builddir/dev $builddir/proc
  176. umount -l -d -f $builddir/R.orig/download
  177. umount -l -d -f $builddir/R.orig $builddir/R.build
  178. umount -l -d -f $builddir/dev $builddir/proc
  179. } > /dev/null 2>&1
  180. delbuilddir=1
  181. for x in R.src R.orig R.build dev proc ; do
  182. if [ $delbuilddir = 1 ] ; then
  183. rmdir $x 2>/dev/null
  184. [ -e "$x" ] && delbuilddir=0
  185. fi
  186. done
  187. cd $base
  188. if [ $delbuilddir = 1 ] ; then
  189. rm -rf $builddir/
  190. fi
  191. exit $returncode
  192. fi
  193. if [ "$ROCKCFG_FLIST" = "flwrapper" -a -z "$FLWRAPPER" ] ; then
  194. export FLWRAPPER_WLOG="$builddir/fl_wrapper.wlog"
  195. export FLWRAPPER_RLOG="$builddir/fl_wrapper.rlog"
  196. [ "$LD_PRELOAD" ] && LD_PRELOAD="${LD_PRELOAD}:"
  197. export FLWRAPPER="$base/build/$ROCKCFG_ID/$toolsdir/lib/fl_wrapper.so"
  198. export LD_PRELOAD="${LD_PRELOAD}$FLWRAPPER"
  199. fi
  200. export INSTALL_WRAPPER_LOGFILE="$builddir/install_wrapper.log"
  201. export CMD_WRAPPER_LOGFILE="$builddir/cmd_wrapper.log"
  202. if [ $norebuild = 1 -a -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  203. echo_pkg_deny $stagelevel $pkg "already built"
  204. exit 0
  205. fi
  206. if [ "$ROCKCFG_RETRY_BROKEN" = 0 -a $norebuild = 1 -a \
  207. -f $root/var/adm/logs/$stagelevel-$xpkg.err ] ; then
  208. echo_pkg_deny $stagelevel $pkg "already failed"
  209. exit 1
  210. fi
  211. confdir="" ; archdir=""
  212. if [ -z "$pkgdir" ] ; then
  213. for x in package/* ; do
  214. x=${x#package/}
  215. if [ -f "package/$x/$pkg/$pkg.desc" ] ; then
  216. if [ "$confdir" ] ; then
  217. echo_pkg_deny $stagelevel $pkg "in multiple trees"
  218. echo "Package in multiple trees: $pkg !" \
  219. > $root/var/adm/logs/$stagelevel-$xpkg.err
  220. exit 1
  221. fi
  222. confdir="$base/package/$x/$pkg"
  223. archdir="$base/download/$x/$pkg"
  224. repository=$x
  225. fi
  226. done
  227. else
  228. if [ -f "$pkgdir/$pkg.desc" ] ; then
  229. confdir="$pkgdir"
  230. archdir="$pkgdir"
  231. repository=extern
  232. fi
  233. fi
  234. if [ -z "$confdir" ] ; then
  235. echo_pkg_deny $stagelevel $pkg "does not exist" ; exit 1
  236. fi
  237. mkdir -p $root/var/adm/logs
  238. mkdir -p $root/var/adm/flists
  239. mkdir -p $root/var/adm/cksums
  240. mkdir -p $root/var/adm/md5sums
  241. mkdir -p $root/var/adm/packages
  242. mkdir -p $root/var/adm/dependencies
  243. mkdir -p $root/var/adm/dep-debug
  244. mkdir -p $root/var/adm/parse-config
  245. mkdir -p $root/var/adm/cache
  246. mkdir -p $root/var/adm/descs
  247. [ "$root" ] && chmod 700 $root
  248. rm -f $root/var/adm/logs/$stagelevel-$xpkg.out
  249. rm -f $root/var/adm/logs/$stagelevel-$xpkg.log
  250. rm -f $root/var/adm/logs/$stagelevel-$xpkg.err
  251. if [ $this_is_the_2nd_run = 0 ] ; then
  252. [ $stagelevel -gt 1 ] && . /etc/profile
  253. options="-this_is_the_2nd_run $options $pkg=$xpkg"
  254. if [ "$ROCKCFG_CREATE_CACHE" = 1 -a $stagelevel -gt 1 ] ; then
  255. mkdir -p $root/var/adm/cache
  256. rm -f $root/var/adm/cache/$xpkg
  257. rm -f $root/var/adm/cache/$xpkg.tm
  258. /usr/bin/time -o "$root/var/adm/cache/$xpkg.tm" \
  259. -f 'buildtime=$(qcalc %U + %S)' $0 $options
  260. returncode=$?
  261. qcalc() { gawk "BEGIN { printf(\"%d\n\", ($*)*100); }"; }
  262. eval "`grep -v '^Command ' < $root/var/adm/cache/$xpkg.tm`"
  263. rm -f $root/var/adm/cache/$xpkg.tm
  264. {
  265. if [ -f $confdir/$pkg.desc ] ; then
  266. grep '^\[COPY\] ' $confdir/$pkg.desc | \
  267. sed "s,/$pkg.desc\$,/$pkg.cache,"
  268. fi
  269. date '+%n[TIMESTAMP] %s %c'
  270. echo "[CONFIG-ID] ${ROCKCFG_ID#*-}"
  271. echo -e "[ROCKVER] $rockver\n"
  272. echo "[LOGS]" $( cd $root/var/adm/logs ; \
  273. ls ?-$xpkg.* 2> /dev/null )
  274. echo
  275. unset stagelevel
  276. for x in 0 1 2 3 4 5 6 7 8 9 ; do
  277. [ -f "$root/var/adm/logs/$x-$xpkg.log" ] && \
  278. stagelevel=$x
  279. done
  280. if [ "$stagelevel" ] ; then
  281. echo "[BUILDTIME] $buildtime ($stagelevel)"
  282. x="$root/var/adm/packages/$xpkg"
  283. if [ -f $x ]; then
  284. echo "[SIZE] `grep "^Package Size: " \
  285. $x | cut -f3- -d' '`"
  286. fi
  287. echo
  288. x="$root/var/adm/dependencies/$xpkg"
  289. if [ "$pkg" != "rock-debug" -a -f $x ]; then
  290. cut -f2- -d' ' "$x" | \
  291. fmt -70 | sed 's,^,[DEP] ,'
  292. echo
  293. fi
  294. fi
  295. for stagelevel in 0 1 2 3 4 5 6 7 8 9 ; do
  296. x="$root/var/adm/logs/$stagelevel-$xpkg.err"
  297. if [ -f "$x" ] ; then
  298. tail -50 "$x" | \
  299. sed "s,^,[$stagelevel-ERROR] ,"
  300. echo
  301. fi
  302. done
  303. } > $root/var/adm/cache/$xpkg
  304. exit $returncode
  305. else
  306. exec $0 $options
  307. fi
  308. fi
  309. #
  310. # ---- Setting Build Variables
  311. #
  312. flistroot="bin boot etc lib sbin usr var opt"
  313. flistrfilter="ldconfig\..*: .*|.*: /var/adm/.*"
  314. flistdel="etc/ld.so.cache|var/tmp/.*|usr/tmp/.*|var/adm/logs/.*|.*\\.old"
  315. if [ $stagelevel -le 1 ]
  316. then
  317. makeopt='CC="$CC" CXX="$CXX" CC_FOR_BUILD="$BUILDCC"'
  318. makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
  319. makeopt="$makeopt"' HOSTCC="$HOSTCC" HOST_CC="$HOST_CC"'
  320. makeinstopt="$makeopt"' prefix=$root/$prefix install'
  321. for x in prefix bindir sbindir libdir datadir \
  322. infodir mandir sysconfdir localstatedir
  323. do
  324. makeopt="$makeopt $x=\${$x/${root//\//\\/}/}"
  325. done
  326. makeopt="$makeopt"' includedir=$root/usr/include'
  327. else
  328. makeopt='prefix=/$prefix CC="$CC" CXX="$CXX"'
  329. makeinstopt='prefix=/$prefix CC="$CC" CXX="$CXX" install'
  330. flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
  331. fi
  332. prepare="" ; hook_add prepare 5 'eval "$prepare"'
  333. prepatch="" ; hook_add prepatch 5 'eval "$prepatch"'
  334. postpatch="" ; hook_add postpatch 5 'eval "$postpatch"'
  335. postdoc="" ; hook_add postdoc 5 'eval "$postdoc"'
  336. preconf="" ; hook_add preconf 5 'eval "$preconf"'
  337. premake="" ; hook_add premake 5 'eval "$premake"'
  338. inmake="" ; hook_add inmake 5 'eval "$inmake"'
  339. postmake="" ; hook_add postmake 5 'eval "$postmake"'
  340. postinstall="" ; hook_add postinstall 5 'eval "$postinstall"'
  341. postflist="" ; hook_add postflist 5 'eval "$postflist"'
  342. finish="" ; hook_add finish 5 'eval "$finish"'
  343. configprefix="" ; autogen=0
  344. configscript="./configure" ; extraconfopt=""
  345. srcdir=auto ; srctar=auto
  346. taropt="--use-compress-program=bzip2 -xf"
  347. mainfunction="build_this_package"
  348. runconf=1 ; runxmkmf=1 ; runmkpl=1 ; autopatch=1
  349. autoextract=1 ; chownsrcdir=1 ; patchopt="-bfp1 -z .orig"
  350. createprefix=1 ; createdocs="" ; rmemptydir=""
  351. check_shared=1
  352. check_usrlocal=1
  353. check_badfiles=1
  354. badfiles="" badfiles_nr=0
  355. declare -a badfiles_desc
  356. #
  357. # ---- Read various config files
  358. #
  359. parse_desc $pkg
  360. ver="`echo $desc_V | cut -f1 -d' '`"
  361. extraver="`echo $desc_V | cut -s -f2- -d' '`"
  362. [ -z "$extraver" ] && extraver="${rockver//DEV-*/DEV}"
  363. echo_pkg_start $stagelevel $repository $xpkg $ver $extraver
  364. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 -a -z "$pkgdir" ] ; then
  365. x="`./scripts/Check-PkgFormat $pkg`"
  366. [ "$x" ] && abort "$x\nDisable the 'Paranoia Check' config `
  367. `option to ignore such errors."
  368. fi
  369. targetdir="$base/target/$target"
  370. patchfiles="`ls $confdir/*.patch $confdir/*.patch.$arch \
  371. $targetdir/pkg_$pkg.patch $targetdir/pkg_$pkg.patch.$arch \
  372. 2>/dev/null | tr '\n' ' '`"
  373. if [ $stagelevel -eq 0 ]; then
  374. patchfiles="`ls $patchfiles $confdir/*.patch.cross \
  375. $confdir/*.patch.cross.$arch 2>/dev/null | tr '\n' ' '`"
  376. flistroot="$flistroot include share"
  377. fi
  378. if [ $stagelevel -gt 1 ]; then
  379. for pc_file in $xroot/var/adm/parse-config/* ; do
  380. if [ -s "$pc_file" -a "${pc_file##*/}" != "$xpkg" ]
  381. then . "$pc_file" ; fi
  382. done
  383. unset pc_file
  384. fi
  385. . $base/build/$ROCKCFG_ID/$toolsdir/lib/parse-config
  386. set_confopt
  387. eval "$desc_O"
  388. # include package pre config - if any
  389. if [ -f $base/build/$ROCKCFG_ID/$toolsdir/lib/pkg_${pkg}_pre.conf ] ; then
  390. echo_status "Reading tools/pkg_${pkg}_pre.conf"
  391. . $base/build/$ROCKCFG_ID/$toolsdir/lib/pkg_${pkg}_pre.conf
  392. fi
  393. if [ -f $targetdir/pkg_$pkg.conf ] ; then
  394. echo_status "Reading package configuration from target directory."
  395. . $targetdir/pkg_$pkg.conf
  396. elif [ -f $confdir/$pkg.conf ] ; then
  397. echo_status "Reading package configuration from package directory."
  398. . $confdir/$pkg.conf
  399. fi
  400. # include package post config - if any
  401. if [ -f $base/build/$ROCKCFG_ID/$toolsdir/lib/pkg_${pkg}_post.conf ] ; then
  402. echo_status "Reading tools/pkg_${pkg}_post.conf"
  403. . $base/build/$ROCKCFG_ID/$toolsdir/lib/pkg_${pkg}_post.conf
  404. fi
  405. if [ -f $base/architecture/$arch/pkg-header ] ; then
  406. echo_status "Reading overwrites from architecture/$arch/pkg-header."
  407. . $base/architecture/$arch/pkg-header
  408. fi
  409. if [ -f $base/target/$target/pkg-header ] ; then
  410. echo_status "Reading overwrites from target/$target/pkg-header."
  411. . $base/target/$target/pkg-header
  412. fi
  413. #
  414. # ---- Variable updates based on the configuration files read
  415. #
  416. if [ "${prefix#usr}" != "$prefix" ] ; then
  417. flistdel="$flistdel|usr/share/info/(dir|standards.info)"
  418. if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  419. flistdel="$flistdel|usr/share/locale/..[/_].*"
  420. flistdel="$flistdel|usr/share/man/..[/_].*"
  421. fi
  422. else
  423. flistdel="$flistdel|$prefix/info/(dir|standards.info)"
  424. if [ "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  425. flistdel="$flistdel|$prefix/share/locale/..[/_].*"
  426. flistdel="$flistdel|$prefix/man/..[/_].*"
  427. fi
  428. fi
  429. #
  430. # ---- Build Package
  431. #
  432. echo_status "Preparing build in src.$pkg.$id"
  433. umount -r -d -f $builddir/* 2> /dev/null
  434. umount -r -d -f -l $builddir/* 2> /dev/null
  435. umount -r -d -f $builddir 2> /dev/null
  436. umount -r -d -f -l $builddir 2> /dev/null
  437. if [ $clear_src = 1 ] ; then
  438. rm -rf $builddir/* ; mkdir -p $builddir ; chmod 700 $builddir
  439. if [ "$ROCKCFG_SRC_TMPFS" = 1 ] ; then
  440. mount -t tmpfs -o $ROCKCFG_SRC_TMPFS_OPT none $builddir
  441. fi
  442. else
  443. mkdir -p $builddir ; chmod 700 $builddir
  444. fi
  445. if [ "$xroot" != "$root" ] ; then
  446. for x in $flistroot ; do
  447. [ -d $xroot/$x ] || mkdir -p $xroot/$x
  448. [ -d $root/$x ] || ln -sf $xroot/$x $root/
  449. done
  450. fi
  451. if [ $update = 1 -a ! -f $xroot/var/adm/md5sums/$xpkg ] ; then
  452. echo_status "Ignoring update mode sice package isn't installed already."
  453. update=0
  454. fi
  455. if [ $update = 1 ] ; then
  456. echo_status "Creating backup of old package data."
  457. (
  458. cd $xroot/
  459. md5sum --check var/adm/md5sums/$xpkg 2>&1 < /dev/null |
  460. grep ': FAILED$' | cut -f1 -d:
  461. ) > $builddir/backup_files.txt
  462. if [ -s $builddir/backup_files.txt ] ; then
  463. mkdir -p "$xroot/var/adm/backup"
  464. chmod 700 "$xroot/var/adm/backup"
  465. backup_tar="$xroot/var/adm/backup/$(
  466. date '+%Y%m%d%H%M%S')_$xpkg.tar.bz2"
  467. ( cd $xroot/; tar --no-recursion -cf - -T $builddir/`
  468. `backup_files.txt || true; ) | bzip2 > $backup_tar
  469. else
  470. update=0
  471. fi
  472. fi
  473. if [ "$ROCKCFG_FLIST" = "flwrapper" ] ; then
  474. rm -f $builddir/fl_wrapper.wlog $builddir/fl_wrapper.rlog
  475. touch $builddir/fl_wrapper.wlog $builddir/fl_wrapper.rlog
  476. elif [ "$ROCKCFG_FLIST" = "find" ] ; then
  477. touch $builddir/temp.time_stamp
  478. sleep 2
  479. fi
  480. hook_eval prepare
  481. # define new abort function for errors while building
  482. #
  483. abort() {
  484. [ "$*" ] && echo "$*"; echo "--- BUILD ERROR ---"
  485. rm -vf $root/var/adm/logs/$stagelevel-$xpkg.log
  486. false
  487. }
  488. {
  489. trap 'echo "Got SIGIN (Crtl-C). Aborting build." ; exit 1' INT
  490. exec < /dev/null
  491. # Makes debugging build problems easier
  492. #
  493. hook_dump > $builddir/debug.hooks
  494. #
  495. { dump_env
  496. echo "PS1='\\[\\e[00m\\e[01;31m\\]debug-`
  497. `$xpkg\\[\\e[00m\\]:[\\W]\\\$ '"
  498. echo 'alias cp="cp -i" ; alias mv="mv -i"'
  499. echo 'alias rm="rm -i" ; alias ls="ls --color=auto -a"'
  500. echo 'alias ..="cd .." ; alias ...="cd ../.."'
  501. echo "alias xdiff='sh $base/misc/archive/xdiff.sh'"
  502. echo "alias bked='sh $base/misc/archive/bked.sh'"
  503. } > $builddir/debug.buildenv
  504. #
  505. { echo "#!/bin/bash"
  506. echo "export PROMPT_COMMAND='. debug.buildenv ; cd . ;" \
  507. "unset PROMPT_COMMAND'" ; echo "exec bash 3> build.pid"
  508. } > $builddir/debug.sh
  509. chmod +x $builddir/debug.sh
  510. # Create PID file
  511. #
  512. # The builtin-variable '$$' is not this pid because this proc
  513. # is just a sub-proc of $$. That's why the $builddir/strace.tmp
  514. # hack is required to get the right pid to trace.
  515. #
  516. # We also conntect filedescriptor 3 with the pid file. So the command
  517. # 'fuser' can be used to create a list of all processes which are part
  518. # of this build process.
  519. #
  520. sh -c 'echo $PPID' > $builddir/build.pid
  521. exec 3>> $builddir/build.pid
  522. echo "Command Wrapper Debug: running '${CC} --version' .."
  523. type ${CC}; CMD_WRAPPER_DEBUG=1 ${CC} --version
  524. echo "[ writing debug log to $builddir/cmd_wrapper.log ]"
  525. if [ "$debug" = 1 ] ; then
  526. echo "Everything is set up." \
  527. "We are in debug mode - so exit now."
  528. exit
  529. fi
  530. if [ "$ROCKCFG_FLIST" = "strace" ] ; then
  531. strace -o $builddir/strace.out -F -f -q -e open,creat,`
  532. `mkdir,mknod,link,symlink,rename,utime,chdir,`
  533. `execve,fork,vfork,_exit -p `cat $builddir/build.pid` &
  534. strace_pid=$! ; sleep 1 ; cd $base
  535. fi
  536. (
  537. set -e
  538. for xsrctar in $( echo "$desc_D" | tr ' ' '\t' | \
  539. tr -s '\t' | cut -f2 | sed 's,.\(t\?\)gz$,.\1bz2,' )
  540. do
  541. if [ ! -f $archdir/$xsrctar ]; then
  542. echo "File not found: ${archdir#$base/}/$xsrctar"
  543. echo "Did you run ./scripts/Download for this package?"
  544. false
  545. fi
  546. done
  547. echo "Running main build function '$mainfunction' ..."
  548. if [ $xtrace -eq 1 -o $ROCKCFG_XTRACE -eq 1 ] ; then
  549. PS4=$'=[$FUNCNAME:$LINENO> ' ; set -o xtrace
  550. cd $builddir ; eval "$mainfunction"
  551. set +o xtrace
  552. else
  553. cd $builddir ; eval "$mainfunction"
  554. fi
  555. touch $root/var/adm/logs/$stagelevel-$xpkg.log
  556. )
  557. [ ! -f $root/var/adm/logs/$stagelevel-$xpkg.log ] && abort
  558. hook_eval postinstall
  559. echo "Creating file list and doing final adaptions ... "
  560. #
  561. cd $xroot/
  562. [ -s "var/adm/parse-config/$xpkg" ] && \
  563. echo "var/adm/parse-config/$xpkg" >> $builddir/flist.txt
  564. for x in var/adm/flists/$xpkg var/adm/md5sums/$xpkg \
  565. var/adm/cksums/$xpkg var/adm/packages/$xpkg \
  566. var/adm/descs/$xpkg var/adm/dependencies/$xpkg ; do
  567. touch $x ; echo "$x" >> $builddir/flist.txt
  568. done
  569. #
  570. if [ "$ROCKCFG_FLIST" = "strace" ] ; then
  571. sleep 1 ; kill -INT $strace_pid ; sleep 1
  572. fl_stparse -w $builddir/fl_wrapper.wlog \
  573. -r $builddir/fl_wrapper.rlog < $builddir/strace.out
  574. fi
  575. if [ "$ROCKCFG_FLIST" = "flwrapper" -o \
  576. "$ROCKCFG_FLIST" = "strace" ] ; then
  577. if [ "$stagelevel" -le 1 ]
  578. then
  579. xbase="$( cd $xroot/ 2> /dev/null ; pwd -P )"
  580. if egrep -qv "($base|$xbase|/tmp|/proc|/dev)/" \
  581. $builddir/fl_wrapper.wlog
  582. then
  583. x="Created file outside basedir: "
  584. egrep -v "($base|$xbase|/tmp|/proc|/dev)/" \
  585. $builddir/fl_wrapper.wlog | \
  586. cut -f2- | sort -u | sed "s,^,$x,"
  587. echo "base #1: $base"
  588. echo "base #2: $xbase"
  589. false
  590. fi
  591. fi
  592. if fl_wrparse -s -r "$xroot/" < $builddir/fl_wrapper.wlog | \
  593. egrep "^(${flistroot// /|})(/|$)" >> \
  594. $builddir/flist.txt
  595. then : ; fi
  596. elif [ "$ROCKCFG_FLIST" = "find" ] ; then
  597. if find $flistroot \
  598. \( -not -type d -or -type d -empty \) \
  599. -and \( -newer $builddir/temp.time_stamp -or \
  600. -cnewer $builddir/temp.time_stamp \) -printf "%p\n" >> \
  601. $builddir/flist.txt
  602. then : ; fi
  603. fi
  604. # merge flist of previous build
  605. [ -f var/adm/flists/$xpkg ] &&
  606. cut -f2- -d' ' var/adm/flists/$xpkg >> $builddir/flist.txt
  607. # evaluate flistdel
  608. egrep -v "^($flistdel)\$" $builddir/flist.txt > $builddir/flist.txt.new
  609. mv $builddir/flist.txt.new $builddir/flist.txt
  610. hook_eval postflist
  611. fl_wrparse -D -p "$xpkg" -r "$xroot/" < $builddir/flist.txt | \
  612. sort -u > var/adm/flists/$xpkg
  613. echo Found `wc -l < var/adm/flists/$xpkg` "files for this package."
  614. echo "Clear (old) md5sums and cksums ..."
  615. cat /dev/null > var/adm/md5sums/$xpkg
  616. cat /dev/null > var/adm/cksums/$xpkg
  617. if [ "$ROCKCFG_FLIST" = "flwrapper" -o \
  618. "$ROCKCFG_FLIST" = "strace" ] && [ $stagelevel -gt 1 ] ; then
  619. echo "Calculating package dependencies ..."
  620. ! egrep -v "^($flistrfilter)\$" $builddir/fl_wrapper.rlog |
  621. sort -u | fl_wrparse -s -r "$xroot/" -p '' | \
  622. sort -k2 var/adm/flists/* - | grep -v ' var/adm/' | awk '
  623. BEGIN { FS=": "; current="."; }
  624. $2 == current && $1 != "" && $2 != "'$xpkg'" { print; }
  625. $1 == "" { current=$2; }' \
  626. >> $builddir/dependencies.debug
  627. awk 'BEGIN { FS=": "; } { print "'$xpkg': " $1; }' \
  628. < $builddir/dependencies.debug \
  629. >> $builddir/dependencies.txt
  630. if [ -f var/adm/dep-debug/$xpkg ] ; then
  631. cat var/adm/dep-debug/$xpkg \
  632. >> $builddir/dependencies.debug
  633. fi
  634. sort -u $builddir/dependencies.debug > var/adm/dep-debug/$xpkg
  635. # merge the dependencies defined by the package
  636. for x in `echo "$desc_E" | egrep '^add ' | sed 's/^add //' ` ; do
  637. echo "Adding dependency: $x ..."
  638. echo "$xpkg: $x" >> $builddir/dependencies.txt
  639. done
  640. # remove dependencies as requested by the package
  641. # TODO: goups are not used yet (and it is not easy here)
  642. del_pattern=""
  643. for x in `echo "$desc_E" | egrep '^del ' | sed 's/^del //' ` ; do
  644. del_pattern="$del_pattern -e \".*: $x\$\""
  645. done
  646. if [ -n "$del_pattern" ] ; then
  647. echo "Deleting dependencies, pattern: $del_pattern ..."
  648. eval egrep -v $del_pattern \
  649. $builddir/dependencies.txt > \
  650. $builddir/dependencies.txt.new
  651. mv $builddir/dependencies.txt{.new,}
  652. fi
  653. if [ -f var/adm/dependencies/$xpkg ] ; then
  654. cat var/adm/dependencies/$xpkg \
  655. >> $builddir/dependencies.txt
  656. fi
  657. sort -u $builddir/dependencies.txt > var/adm/dependencies/$xpkg
  658. fi
  659. echo -n "Creating md5sum and cksum files ..."
  660. getfiles < var/adm/flists/$xpkg > $builddir/files.lst
  661. if [ -s $builddir/files.lst ] ; then
  662. cat $builddir/files.lst | \
  663. grep -v '^var/adm/' | sed -e 's/ /\\ /g' | \
  664. xargs -r md5sum > var/adm/md5sums/$xpkg
  665. cat $builddir/files.lst | \
  666. grep -v '^var/adm/' | sed -e 's/ /\\ /g' | \
  667. xargs -r cksum > var/adm/cksums/$xpkg
  668. fi
  669. echo ' done.'
  670. echo "Creating package description ..."
  671. #
  672. rocksrcck=$(cd $base; md5sum package/*/$pkg/* 2> /dev/null | \
  673. grep -v '\.cache$' | md5sum | cut -f1 -d' ')
  674. buildlist="$( grep "^Build \[.\] at " var/adm/packages/$xpkg || true
  675. echo "Build [$stagelevel] at $buildstart to `date "+%T %Z"`")"
  676. #
  677. cat > var/adm/packages/$xpkg << EOT
  678. Package Name and Version: $xpkg $ver $extraver
  679. Package Size: `getdu $root/ < var/adm/flists/$xpkg`, `
  680. wc -l < var/adm/flists/$xpkg | tr -d ' '` files
  681. ROCK Linux Package Source Checksum: $rocksrcck
  682. ROCK Linux Version and Architecture: $rockver $arch
  683. Build on `uname -m -n -r -s -p`
  684. $buildlist
  685. Status: ${desc_S:-ALPHA}, License: ${desc_L:-Unknown}
  686. ${desc_I:-$xpkg}
  687. $( echo "${desc_T:-No description available.}" | sed 's,^, ,' )
  688. URL(s):
  689. $( echo "${desc_U:-http://www.rocklinux.org/packages/$pkg.html}" | sed 's,^, ,' )
  690. Original Author(s):
  691. $( echo "${desc_A:-Unknown}" | sed 's,^, ,' )
  692. ROCK Package Maintainer(s):
  693. $( echo "${desc_M:-Unknown}" | sed 's,^, ,' )
  694. Download URL(s):
  695. $( echo "${desc_D:-None}" | awk '{ print " " $3 $2; }' )
  696. EOT
  697. {
  698. echo "[CONFIG] ${ROCKCFG_ID#*-}"
  699. descfile=$base/package/*/$pkg/$pkg.desc
  700. while read x ; do
  701. if [ "${x#\[}" != "$x" ] ; then
  702. x="`echo ${x// /|} | tr -d '[]'`"
  703. y="${x%%|*}" ; x="(${x%|(*)})"
  704. egrep "^\[$x\]" $descfile | expand | sed "s,^[^ ]*,[$y],"
  705. fi
  706. done < $base/Documentation/Developers/PKG-DESC-FORMAT
  707. } > var/adm/descs/$xpkg
  708. echo "Making post-install adaptions."
  709. if [ $stagelevel -ge 2 -a -f /sbin/ldconfig ] ; then ldconfig ; fi
  710. if [ "$ROCKCFG_PARANOIA_CHECK" = 1 ] ; then
  711. found_errors=0
  712. found_dups=0
  713. # check for files which are 'shared' with other packages
  714. if [ "$check_shared" != "0" ]; then
  715. while read dummy file; do
  716. if [ $found_dups = 0 ] ; then
  717. echo "Found shared files with other packages:"
  718. found_errors=1; found_dups=1
  719. fi
  720. echo "$file:" $( cd $root/var/adm/flists
  721. grep -l " $file\$" * )
  722. done < <( cat $root/var/adm/flists/* | sed "s,^$xpkg:,.," | \
  723. sort +1 | uniq -d -f1 | grep '^\. ' )
  724. fi
  725. found_local=0
  726. # check for files in /usr/local
  727. if [ "$check_usrlocal" != "0" ]; then
  728. while read file ; do
  729. if [ $found_local = 0 ] ; then
  730. echo "Found files in /usr/local:"
  731. found_errors=1; found_local=1
  732. fi
  733. echo $file
  734. done < <( sed "s,^$xpkg: ,/," $root/var/adm/flists/$xpkg | \
  735. egrep "^/usr/local" )
  736. fi
  737. found_bad=0
  738. # check for registered 'bad files'
  739. if [ "$check_badfiles" != "0" -a -n "$badfiles" ]; then
  740. echo "$badfiles" > $builddir/badfiles.txt
  741. while read x file; do
  742. if [ $found_bad = 0 ]; then
  743. echo "Found registered 'bad files' in package:"
  744. found_errors=1; found_bad=1
  745. fi
  746. desc="No description found!"
  747. for ((x=0; x<badfiles_nr; x++)); do
  748. if echo " $file" | grep -q "${badfiles_desc[x]%%$'\n'*}"
  749. then desc="${badfiles_desc[x]#*$'\n'}"; fi
  750. done
  751. echo "$file: $desc"
  752. done < <( grep -f $builddir/badfiles.txt $root/var/adm/flists/$xpkg )
  753. fi
  754. [ $found_errors != 0 ] && abort
  755. fi
  756. } 2>&1 | {
  757. trap '' INT
  758. echo_status "Building. Writing output to" \
  759. "\$root/var/adm/logs/$stagelevel-$xpkg.out"
  760. if [ "$ROCKCFG_VERBOSE" = 1 -o "$verbose" = 1 ] ; then
  761. tee $root/var/adm/logs/$stagelevel-$xpkg.out
  762. else
  763. cat > $root/var/adm/logs/$stagelevel-$xpkg.out
  764. fi
  765. }
  766. hook_eval finish
  767. if [ $update = 1 ] ; then
  768. echo_status "Restoring backup of old package data."
  769. while read fn ; do
  770. [ -f $xroot/$fn ] && mv $xroot/$fn $xroot/$fn.new
  771. done < $builddir/backup_files.txt
  772. tar --use-compress-program=bzip2 -C $xroot/ -xpf $backup_tar
  773. while read fn ; do
  774. cmp -s $fn $fn.new && rm -f $fn.new
  775. done < $builddir/backup_files.txt
  776. fi
  777. cd $base
  778. umount -r -d -f $builddir/* 2> /dev/null
  779. umount -r -d -f -l $builddir/* 2> /dev/null
  780. if [ "$ROCKCFG_SRC_TMPFS_LOG" = 1 -a -n "$( type -p df )" ]; then
  781. mkdir -p $root/var/adm/rock-debug
  782. if [ ! -f $root/var/adm/rock-debug/tmpfslog.txt ] ; then
  783. echo -e "# Config\tPackage\tInodes\tKB" | \
  784. expand -20 > $root/var/adm/rock-debug/tmpfslog.txt
  785. fi
  786. echo -e "$config\t$stagelevel-$xpkg\t$(
  787. df 2> /dev/null -Pi $builddir | tail -1 | tr -s ' ' | cut -f3 -d' '
  788. )\t$(
  789. df 2> /dev/null -Pk $builddir | tail -1 | tr -s ' ' | cut -f3 -d' ')" | \
  790. expand -20 >> $root/var/adm/rock-debug/tmpfslog.txt
  791. fi
  792. umount -r -d -f $builddir 2> /dev/null
  793. umount -r -d -f -l $builddir 2> /dev/null
  794. if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
  795. if [ $clear_src = 1 ] ; then
  796. rm -rf $builddir/* $builddir
  797. else
  798. cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
  799. fi
  800. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  801. "-> $stagelevel-$xpkg.log"
  802. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  803. $root/var/adm/logs/$stagelevel-$xpkg.log
  804. echo_pkg_finish $stagelevel $repository $xpkg
  805. exit 0
  806. else
  807. if [ $clear_src = 1 -a "$ROCKCFG_ALWAYS_CLEAN" = 1 ] ; then
  808. rm -rf $builddir/* $builddir
  809. else
  810. cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG
  811. fi
  812. if [ "$ROCKCFG_VERBOSE" != 1 -a "$verbose" != 1 ] ; then
  813. echo_errorquote "$( grep -B7 -- '--- BUILD ERROR ---' \
  814. $root/var/adm/logs/$stagelevel-$xpkg.out | \
  815. sed '$ s,--- BUILD ERROR ---,,' | \
  816. grep . | grep -vx -- -- )"
  817. fi
  818. echo_status "\$root/var/adm/logs/$stagelevel-$xpkg.out" \
  819. "-> $stagelevel-$xpkg.err"
  820. mv $root/var/adm/logs/$stagelevel-$xpkg.out \
  821. $root/var/adm/logs/$stagelevel-$xpkg.err
  822. echo_pkg_abort $stagelevel $repository $xpkg
  823. exit 1
  824. fi
  825. # ---- EOF