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.

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