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.

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