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.

1362 lines
41 KiB

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