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.

860 lines
23 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/scripts/functions
  9. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. # This function returns a "uniqe id" as output
  23. #
  24. get_unique() {
  25. date "+%s.$$.`{ /sbin/ifconfig -a; /sbin/ip a; } 2>&1 | cksum | cut -f1 -d' '`"
  26. }
  27. # Hook variables
  28. #
  29. unset hook_functions hook_fcounter
  30. declare -a hook_functions='()'
  31. hook_fcounter=0
  32. # This function adds a code fragment to a named hook with the named priority
  33. #
  34. # hook_add hook_name priority code
  35. #
  36. hook_add() {
  37. hook_functions[hook_fcounter]="$3" # declare -a hookidx_$1
  38. eval "hookidx_$1[\${#hookidx_$1[@]}]=\"$2 $hook_fcounter\""
  39. eval "(( hookdirty_$1++ ))"; (( hook_fcounter++ ))
  40. }
  41. # This function executes all code fragments from the named hook
  42. #
  43. # hook_eval hook_name
  44. #
  45. hook_eval() {
  46. while read pri fnr ; do
  47. eval "${hook_functions[fnr]}"
  48. done < <( IFS=$'\n' ; eval "echo \"\${hookidx_$1[*]}\"" | sort )
  49. eval "unset hookdirty_$1"
  50. }
  51. # This function prints all hooks and their current contents
  52. #
  53. # hook_dump
  54. #
  55. hook_dump() {
  56. for hook in ${!hookidx_*} ; do
  57. hook=${hook#hookidx_}
  58. echo ; echo "Contents of hook $hook:"
  59. while read pri fnr ; do
  60. echo ; echo " $pri ($fnr)"
  61. echo "${hook_functions[fnr]}" | sed 's,^, ,'
  62. done < <( IFS=$'\n'
  63. eval "echo \"\${hookidx_$hook[*]}\"" | sort )
  64. if eval "[ -n \"\$hookdirty_\$hook\" ]"; then
  65. echo ; echo -n " Hook is marked as dirty: "
  66. eval "echo \"\${hookdirty_$hook}\""
  67. fi
  68. done
  69. echo
  70. }
  71. # This function register a split package
  72. #
  73. # splitreg prio name regex
  74. #
  75. splitreg() {
  76. var_append pkgsplits "," "$1 $2 $3"
  77. }
  78. # This function modifies an flist file according to the registered splits
  79. #
  80. # splitapply pkg-name flist-file
  81. #
  82. splitapply() {
  83. local p n r
  84. sed -i "s/^[^ ]+/$1:/" $2
  85. while read -r p n r; do
  86. if [ "$n" = "." ]; then
  87. echo "Applying package split: $p $1 $r"
  88. sed -ri "\,$r, s/^[^ ]+/$1:/" $2
  89. else
  90. if type "splitdesc_${n}" > /dev/null 2>&1; then
  91. echo "Applying package split: $p $1:$n $r"
  92. sed -ri "\,$r, s/^[^ ]+/$1:$n:/" $2
  93. else
  94. echo "Skipping package split: $p $1:$n $r (splitdesc_$n() undefined)"
  95. fi
  96. fi
  97. done < <( echo "$pkgsplits" | tr ',' '\n' | sort; )
  98. }
  99. # This functions append, insert or remove values in variables:
  100. #
  101. # var_append PATH ":" "$HOME/bin"
  102. # var_insert CC_WRAPPER_INSERT " " "-O3"
  103. # var_remove CC_WRAPPER_INSERT " " "-O3"
  104. #
  105. # var_remove_regex CC_WRAPPER_INSERT " " "-O.*"
  106. #
  107. # var_insert_before_regex patchfiles " " "mypatch.diff" ".*\/foo.diff"
  108. #
  109. # 1st Parameter: Variable Name
  110. # 2nd Parameter: Delimiter Text
  111. # 3rd Parameter: Value (or regex)
  112. # 4th Parameter: regex for insert_before
  113. #
  114. var_append() {
  115. eval "[ \"\$$1\" ] && $1=\"\${$1}$2\"" || true
  116. eval "$1=\"\${$1}\$3\""
  117. }
  118. var_insert() {
  119. eval "[ \"\$$1\" ] && $1=\"$2\$$1\"" || true
  120. eval "$1=\"\$3\$$1\""
  121. }
  122. var_remove() {
  123. local a=${2//\/\\/}
  124. local b=${3//\/\\/}
  125. eval '[ "$'$1'" = "$3" ] && '$1'="" || true'
  126. eval $1'="${'$1'//$a$b$a/$2}"'
  127. eval $1'="${'$1'%$a$b}"'
  128. eval $1'="${'$1'#$b$a}"'
  129. }
  130. var_remove_regex() {
  131. eval "$1=\"\`echo \"\$$1\" | awk -- ' { split(\$0, a, \"$2\"); for (c1=c2=1; c1 in a; c1++) if ( a[c1] !~ /^$3\\\$/ ) b[c2++]=a[c1]; for (c1=1; c1 in b; c1++) printf \"%s%s\", (c1 > 0 ? \"$2\" : \"\"), b[c1]; }'\`\""
  132. }
  133. var_insert_before_regex() {
  134. eval "$1=\"\`echo \"\$$1\" | awk -- '{ split(\$0, a, \"$2\"); for (d=c1=c2=1; c1 in a; c1++) { if ( d && a[c1] ~ /^$4\\\$/ ) { b[c2++]=\"$3\"; d=0; } b[c2++]=a[c1]; } if (d) b[c2++]=\"$3\"; for (c1=1; c1 in b; c1++) printf \"%s%s\", (c1 > 0 ? \"$2\" : \"\"), b[c1]; }'\`\""
  135. }
  136. # This function can be used to duplicate a shell-function. E.g. when
  137. # overwriting a shell-function but the old one should stay available under
  138. # a new name:
  139. #
  140. # copy_function set_confopt set_confopt_foobar_old
  141. #
  142. # set_confopt() {
  143. # ....
  144. # set_confopt_foobar_old "$@"
  145. # ....
  146. # }
  147. #
  148. copy_function() {
  149. eval "$( declare -f $1 | sed "1 s,$1,$2," )"
  150. }
  151. # | column_clean |
  152. #
  153. # convert tabs to spaces, transform multiple consecutive spaces to one,
  154. # remove leading and trailing spaces
  155. column_clean() {
  156. tr '\t' ' ' | tr -s ' ' | sed -e 's,^[ ]*,,; s,[ ]*$,,;'
  157. }
  158. # | column_clean_tab |
  159. #
  160. # see column_clean, but with tabs
  161. column_clean_tab() {
  162. tr ' ' '\t' | tr -s '\t' | sed -e 's,^[\t]*,,; s,[\t]*$,,;'
  163. }
  164. # This function sets the 'confopt' and some other variables.
  165. # Re-run it in the package .conf file if you modify $prefix
  166. #
  167. set_confopt() {
  168. confopt="--prefix=$root/$prefix"
  169. bindir="$root/$prefix/bin"
  170. confopt="$confopt --bindir=\$bindir"
  171. sbindir="$root/$prefix/sbin"
  172. confopt="$confopt --sbindir=\$sbindir"
  173. libdir="$root/$prefix/lib"
  174. confopt="$confopt --libdir=\$libdir"
  175. if [ -z "$prefix" ]; then
  176. datadir="$root/usr/share"
  177. includedir="$root/usr/include"
  178. docdir="$root/usr/share/doc/$xpkg"
  179. infodir="$root/usr/share/info"
  180. mandir="$root/usr/share/man"
  181. else
  182. datadir="$root/$prefix/share"
  183. includedir="$root/$prefix/include"
  184. docdir="$root/$prefix/share/doc/$xpkg"
  185. infodir="$root/$prefix/share/info"
  186. mandir="$root/$prefix/share/man"
  187. fi
  188. confopt="$confopt --datadir=\$datadir"
  189. confopt="$confopt --includedir=\$includedir"
  190. confopt="$confopt --infodir=\$infodir"
  191. confopt="$confopt --mandir=\$mandir"
  192. if [ "${prefix#opt/}" != "$prefix" ] ; then
  193. sysconfdir="$root/etc/$prefix"
  194. localstatedir="$root/var/$prefix"
  195. elif [ "${prefix#usr}" != "$prefix" ] ; then
  196. sysconfdir="$root/etc"
  197. localstatedir="$root/var"
  198. else
  199. sysconfdir="$root/$prefix/etc"
  200. localstatedir="$root/$prefix/var"
  201. fi
  202. confopt="$confopt --sysconfdir=\$sysconfdir"
  203. confopt="$confopt --localstatedir=\$localstatedir"
  204. if [ "$ROCKCFG_CONFIGURE_OPTS" ] ; then
  205. confopt="$confopt $ROCKCFG_CONFIGURE_OPTS"
  206. fi
  207. if [ "$ROCKCFG_DEBUG" = 0 ] ; then
  208. confopt="$confopt --disable-debug"
  209. fi
  210. if [ "$stagelevel" -le 1 -o "$ROCKCFG_DISABLE_NLS" = 1 ] ; then
  211. confopt="${confopt//--enable-nls/} --disable-nls"
  212. fi
  213. confopt="$confopt \$extraconfopt"
  214. if [ "$stagelevel" -eq 0 ]; then
  215. confopt="$confopt --target=\$arch_target --host=\$arch_build"
  216. else
  217. confopt="$confopt --build=\$arch_build --host=\$arch_target"
  218. fi
  219. }
  220. #
  221. # eval_config_command $( eval echo $confopt )
  222. #
  223. function eval_config_command() {
  224. local config_command
  225. for x in /usr/share/automake/*
  226. do
  227. [ -x "$x" -a -f "$x" ] || continue
  228. x="$( basename "$x" )"
  229. if [ -L $x -a ! -e $x ] ; then
  230. echo "Fixing dead symlink $x."
  231. ln -sf /usr/share/automake/$x .
  232. fi
  233. done
  234. if [ $autogen -eq 1 -a \( -f configure.in -o -f configure.ac \) ] ; then
  235. if [ -f configure.orig ] ; then
  236. echo "Found configure.orig. Not" \
  237. "running autogen script."
  238. elif [ -f autogen.sh ] ; then
  239. echo "Running package autogen script."
  240. sh autogen.sh
  241. else
  242. echo "Running builtin autogen script."
  243. libtoolize --force --automake
  244. aclocal$automakever
  245. if grep AM_INIT_AUTOMAKE configure.[ia][nc]
  246. then automake$automakever ; fi
  247. autoconf
  248. fi
  249. fi
  250. if [ $stagelevel -le 1 ] ; then
  251. create_config_cache >> config.cache
  252. grep -q '.--cache-file=' $configscript &&
  253. set -- "$@" "--cache-file=config.cache"
  254. export cache_file=config.cache
  255. fi
  256. config_command="$configprefix $configexec $configscript"
  257. sub_scripts="$( find $( dirname $configscript ) -name configure )"
  258. # remove unsupported config script options
  259. for x ; do
  260. if grep -q "[[ ]${x%%=*}[]= ):]" $configscript $sub_scripts ; then
  261. config_command="$config_command $x"
  262. elif [[ $x = --*able-* ]] && egrep -q "\-\-(en|dis)able-\*" $configscript ; then
  263. echo "Autodetection for option impossible: " \
  264. "$x passed thru."
  265. config_command="$config_command $x"
  266. else
  267. echo "Removing unsupported '$x' from" \
  268. "configure option string."
  269. fi
  270. done
  271. echo Running "$config_command"
  272. eval "$config_command"
  273. }
  274. # run 'make check' if Makefile supports it.
  275. #
  276. function run_check() {
  277. if grep -q -e "^check:" ./Makefile; then
  278. echo "Running make check ..."
  279. $MAKE check
  280. fi
  281. if grep -q -e "^test:" ./Makefile; then
  282. echo "Running make test ..."
  283. $MAKE test
  284. fi
  285. }
  286. # move the static libs from lib to usr/lib and correct the libdir used
  287. # inside the .la file
  288. #
  289. postflist_static_lib() {
  290. echo "Processing static lib corrections ..."
  291. egrep '^lib/.*\.(a|la)$' $builddir/flist.txt |
  292. while read fn ; do
  293. [ -e $root/$fn -o -L $root/$fn ] || continue
  294. if [[ $fn = *.a ]] ; then
  295. mv -fv $root/$fn $root/usr/$fn
  296. else
  297. sed "s,\([ =']\)/lib\(.*\),\1/usr/lib\2,g" \
  298. $root/$fn > $root/usr/$fn
  299. rm $root/$fn
  300. fi
  301. add_flist $root/usr/$fn
  302. done
  303. # this check might be removed in the future when we decide this is not
  304. # an issue anymore ...
  305. echo "Verifing the .la files ..."
  306. defect_la="`egrep 'lib/.*\.la$' $builddir/flist.txt |
  307. xargs egrep 'dependency_libs=.*-pthread.*' |
  308. cut -d : -f1 | sort -u | tr '\n' ' '`"
  309. if [ "$defect_la" ] ; then
  310. abort "-pthread in: $defect_la!"
  311. fi
  312. }
  313. # Parse the *.desc file. Use the description from PKG-DESC-FORMAT and
  314. # save the tag data in $desc_*.
  315. #
  316. parse_desc() {
  317. tag="`grep '^\[' $base/Documentation/Developers/PKG-DESC-FORMAT | \
  318. sed 's, (\*),,; s,\] \[,|,g; s,\[,,; s,\],,;'`"
  319. descfile="$( pkg="$pkg" xpkg="$xpkg" descparser < $1 )"
  320. for tag in $tag ; do
  321. tagdata="`echo "$descfile" | egrep "^\[($tag)\]" | \
  322. cut -f2- -d']' | sed 's,^ ,,'`"
  323. tag="`echo $tag | cut -f1 -d'|' | tr - _`"
  324. if eval "[ -z \"\$desc_$tag\" ]"; then
  325. eval "desc_$tag=\"\$tagdata\""
  326. fi
  327. done
  328. }
  329. # This function is used for forcing a file to be in the flist
  330. #
  331. add_flist() {
  332. for addfile ; do
  333. echo "$addfile" | fl_wrparse -D -r "$xroot/" \
  334. >> $builddir/flist.txt
  335. done
  336. }
  337. # This function is used for forcing a package to be in the dependency list
  338. #
  339. add_dependency() {
  340. for addpackage ; do
  341. echo "$addpackage: add_dependency()" \
  342. >> $builddir/dependencies.debug
  343. done
  344. }
  345. # This function adds a wrapprer for the currently running build
  346. #
  347. # Usage:
  348. #
  349. # add_wrapper bin_name <<- 'EOT'
  350. # demo-demo-demo-demo
  351. # $orig "$@"; rc=$?
  352. # demo-demo-demo-demo
  353. # exit $rc
  354. # EOT
  355. #
  356. declare -a wrapper_data='()'
  357. add_wrapper() {
  358. local l data="$1"
  359. while read l; do
  360. data="$data
  361. $l"
  362. done
  363. wrapper_data[${#wrapper_data[@]}]="$data"
  364. }
  365. # This function is used to subsitute some important variables
  366. # using a D_ prefix thru m4 ...
  367. rock_substitute() {
  368. sed -e s,D_prefix,$prefix,g -e s,D_sysconfdir,$sysconfdir,g \
  369. -e s,D_docdir,$docdir,g -e s,D_localstatedir,$localstatedir,g \
  370. -e s,D_datadir,$datadir,g -e s,D_infodir,$infodir,g \
  371. -e s,D_bindir,$bindir,g -e s,D_sbindir,$sbindir,g \
  372. -e s,D_libdir,$libdir,g -e s,D_mandir,$mandir,g \
  373. -e s,D_version,$ver,g $1
  374. }
  375. # This outputs a predefined config.cache file as it needed by some
  376. # packages to cross-build correctly in stages 0 and 1.
  377. #
  378. create_config_cache() {
  379. cat $base/scripts/config.cache
  380. echo -e "\n# Architecture specific stuff\n"
  381. echo "arch_sizeof_char=1"
  382. echo "ac_cv_sizeof_short=$arch_sizeof_short"
  383. echo "ac_cv_sizeof_int=$arch_sizeof_int"
  384. echo "ac_cv_sizeof_long=$arch_sizeof_long"
  385. echo "ac_cv_sizeof_long_long=$arch_sizeof_long_long"
  386. echo "ac_cv_sizeof_char_p=$arch_sizeof_char_p"
  387. echo "ac_cv_sizeof_void_p=$arch_sizeof_char_p"
  388. echo "ac_cv_c_bigendian=$arch_bigendian"
  389. local pt=""
  390. [ $arch_sizeof_char_p -eq $arch_sizeof_int ] && pt="int"
  391. [ $arch_sizeof_char_p -eq $arch_sizeof_long ] && pt="long"
  392. [ $arch_sizeof_char_p -eq $arch_sizeof_long_long ] && pt="long long"
  393. [ -n "$pt" ] && echo "db_cv_alignp_t=\"unsigned $pt\""
  394. echo "ac_cv_prog_CC=$CC"
  395. }
  396. # Abort build before actual build starts
  397. # (is overwritten in Build-Pkg)
  398. #
  399. abort() {
  400. echo -e "The package build aborted with the following config" \
  401. "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err
  402. echo_errorquote "`cat $root/var/adm/logs/$stagelevel-$xpkg.err`"
  403. echo_pkg_abort $stagelevel $repository $xpkg
  404. exit 1
  405. }
  406. # Dump Environment
  407. #
  408. dump_env() {
  409. # Dump $base - only set if there is not already an older value.
  410. #
  411. echo "base=\"\${base:-$base}\""
  412. # Dump all variables including their flags, but skip read-only
  413. # variables and $base.
  414. #
  415. # Substitute base directory with ${base}.
  416. #
  417. for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
  418. ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
  419. ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
  420. ${!y*} ${!z*} \
  421. ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
  422. ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
  423. ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
  424. ${!Y*} ${!Z*} ${!_*}
  425. do
  426. [ $name = IFS ] && continue
  427. [ $name = base ] && continue
  428. if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
  429. then
  430. declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
  431. fi
  432. done
  433. # Dump functions
  434. #
  435. declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
  436. # Dump aliases
  437. #
  438. alias
  439. }
  440. # Check if a package is already installed
  441. #
  442. # It does check the build-list if not in the rebuild stage - and
  443. # the really installed package data for rebuilds (and so manual builds).
  444. #
  445. pkginstalled() {
  446. local pattern="$1"; pattern="${pattern//+/\\+}"
  447. if [ "$stagelevel" -le 8 ] ; then
  448. egrep -q "^X.* ($pattern) " $base/config/$config/packages
  449. else
  450. ls $root/var/adm/flists | egrep -q "^($pattern)$"
  451. fi
  452. }
  453. # Register a window-manager
  454. #
  455. register_wm() {
  456. [ -e /usr/share/rock-registry/wm ] || mkdir -p $root/usr/share/rock-registry/wm
  457. echo -e "name=\"$2\"\nexec=\"$3\"\n" > $root/usr/share/rock-registry/wm/$1
  458. }
  459. # Register a xdm - display manager
  460. #
  461. register_xdm() {
  462. [ -e /usr/share/rock-registry/xdm ] \
  463. || mkdir -p /usr/share/rock-registry/xdm
  464. echo -e "name=\"$2\"\nexec=\"$3\"\n" > /usr/share/rock-registry/xdm/$1
  465. }
  466. # Create Package Database for gasgui install tool
  467. #
  468. create_package_db() {
  469. local admdir="$1"
  470. local outdir="$2"
  471. rm -f $outdir/packages.db $outdir/packages_stripped.db
  472. rm -f $outdir/packages.db.md5 $outdir/packages_stripped.db.md5
  473. rm -f $outdir/packages.db.tmp
  474. for file in $( ls $admdir/descs/ ) ; do
  475. pkg="${file##*/}"
  476. # only include the package if a binary file is available
  477. if [ "$ROCKCFG_PKGFILE_VER" = 1 ] ; then
  478. v=-$(grep '^Package Name and Version' \
  479. $admdir/packages/$pkg | cut -f6,7 -d' ' | tr ' ' -)
  480. else
  481. v=""
  482. fi
  483. if [ "$ROCKCFG_CREATE_GEM" = 1 ] ; then
  484. bfile=${pkg}${v}.gem
  485. else
  486. bfile=${pkg}${v}.tar.bz2
  487. fi
  488. if [ -e $outdir/$bfile ] ; then
  489. [ "$pkg" = TRANS.TBL ] && continue
  490. ( echo -e "$pkg"
  491. echo -e "\027"
  492. cat $admdir/descs/$pkg
  493. echo -e "\027"
  494. cat $admdir/dependencies/$pkg
  495. echo -e "\027"
  496. cat $admdir/cksums/$pkg
  497. echo -e "\027"
  498. echo -e "\004"
  499. ) >> $outdir/packages.db.tmp
  500. fi
  501. done
  502. gawk '
  503. BEGIN { chunk=0; }
  504. $0 == "\004" { chunk=0; print; next; }
  505. $0 == "\027" { chunk++; print; next; }
  506. chunk != 3 { print; }
  507. ' < $outdir/packages.db.tmp | gzip -9 > $outdir/packages_stripped.db
  508. gzip -9 < $outdir/packages.db.tmp > $outdir/packages.db
  509. rm -f $outdir/packages.db.tmp
  510. ( cd $outdir; md5sum packages.db > packages.db.md5; )
  511. ( cd $outdir; md5sum packages_stripped.db > packages_stripped.db.md5; )
  512. }
  513. # Add files to the 'badfiles' list
  514. #
  515. register_badfiles() {
  516. local x desc="$1"
  517. shift
  518. for x in "$@"; do
  519. var_append badfiles $'\n' " $x\$"
  520. badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
  521. (( badfiles_nr++ ))
  522. done
  523. }
  524. # Apply the given $patchfiles
  525. #
  526. apply_patchfiles() {
  527. for x in $patchfiles; do
  528. echo "Apply patch $x ..."
  529. if [[ $x = *.bz2 ]] ; then
  530. bzcat $x | patch $patchopt
  531. else
  532. patch $patchopt < $x
  533. fi
  534. eval "$@"
  535. done
  536. }
  537. # Main program for building a package
  538. #
  539. build_this_package() {
  540. if [ ".$desc_SRC" == "." ] ; then
  541. # Autodetect source tar and extract it
  542. #
  543. if [ $srctar = auto ] ; then
  544. xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' | \
  545. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  546. if [ -z "$xsourceballs" ] ; then
  547. echo "Can't auto-detect srctar for package '$xpkg'!"
  548. false
  549. fi
  550. else
  551. xsourceballs="$srctar"
  552. fi
  553. else
  554. sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' | \
  555. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  556. xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' )
  557. xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
  558. fi
  559. for xsrctar in $xsourceballs; do
  560. saved_patchfiles="$patchfiles"
  561. var_append patchfiles " " \
  562. "`ls $confdir/*.patch.${xsrctar/-[0-9]*/} 2> /dev/null`"
  563. if [ $autoextract = 1 ]; then
  564. echo "Extracting $xsrctar ($taropt) ... "
  565. cd $builddir
  566. tar -v $taropt $archdir/$xsrctar | tee untar.txt |
  567. cut -f1 -d/ | sort -u > xsrcdir.txt
  568. #
  569. if [ $srcdir = auto ]; then
  570. xsrcdir=${xsrctar%.tar.bz2}
  571. xsrcdir=${xsrcdir%.tbz2}
  572. if [ ! -d $xsrcdir ] ; then
  573. for x in $pkg-$ver ${pkg}_$ver $pkg \
  574. $xpkg-$ver ${xpkg}_$ver $xpkg \
  575. "$( cat xsrcdir.txt )"
  576. do
  577. [ -d "$x" ] && xsrcdir="$x"
  578. done
  579. fi
  580. else
  581. xsrcdir="$srcdir"
  582. fi
  583. #
  584. if [ "$chownsrcdir" = 1 ]; then
  585. echo "Fixing ownership and permissions ..."
  586. chown -R 0:0 $builddir/$xsrcdir
  587. fi
  588. #
  589. if [ "$nocvsinsrcdir" = 1 ]; then
  590. echo "Removing CVS and .svn directories ..."
  591. egrep '(^|/)(CVS|\.svn)(/|$)' untar.txt |
  592. while read x; do
  593. echo "Removing $x ..."
  594. rm -rf "$x"
  595. done
  596. fi
  597. #
  598. echo "Changeing into $builddir/$xsrcdir ..."
  599. cd $builddir/$xsrcdir
  600. # Apply patches
  601. #
  602. if [ $autopatch = 1 ]; then
  603. hook_eval prepatch
  604. apply_patchfiles
  605. hook_eval postpatch
  606. fi
  607. else
  608. cd $builddir
  609. fi
  610. if [ "$createprefix" = 1 ]; then
  611. echo "Creating $root/$prefix/<..> if required ..."
  612. for x in $root/$prefix $bindir $sbindir $libdir $datadir $includedir \
  613. $docdir $infodir $mandir $sysconfdir $localstatedir
  614. do
  615. if [ ! -e $x ]; then
  616. mkdir -p $x
  617. rmemptydir="$x $rmemptydir"
  618. fi
  619. done
  620. if [ ! -e $root/$prefix/man ]; then
  621. ln -s ${mandir#$root} $root/$prefix/man
  622. rmemptydir="$rmemptydir $root/$prefix/man"
  623. fi
  624. if [ ! -e $root/$prefix/info ]; then
  625. ln -s ${infodir#$root} $root/$prefix/info
  626. rmemptydir="$rmemptydir $root/$prefix/info"
  627. fi
  628. fi
  629. if [ ".$custmain" = "." ]
  630. then
  631. # Run configure scripts etc.
  632. #
  633. hook_eval preconf
  634. #
  635. if [ $runconf = 1 ]; then
  636. if [ -n "$( type -p $configscript )" -o $autogen = 1 ]
  637. then
  638. eval_config_command $( eval echo $confopt )
  639. fi
  640. fi
  641. # automated package build
  642. # styles without make run first:
  643. if [ -f setup.py -a $runpysetup = 1 ] ; then
  644. pyconfopt="${pyconfopt:=--prefix $root/$prefix}"
  645. eval python setup.py build install $pyconfopt
  646. else # styles that include a make run
  647. if [ ! -f Makefile -a ! -f makefile -a \
  648. -f Makefile.PL -a $runmkpl = 1 ]; then
  649. sed -i 's/auto_install/# &/' Makefile.PL
  650. perl Makefile.PL INSTALLDIRS=perl
  651. fi
  652. #
  653. if [ ! -f Makefile -a ! -f makefile -a \
  654. -f Imakefile -a $runxmkmf = 1 ]; then
  655. xmkmf -a
  656. fi
  657. #
  658. # Build it
  659. #
  660. hook_eval premake
  661. if [ "$makeopt" ]
  662. then eval "$MAKE $makeopt"; fi
  663. hook_eval inmake
  664. if [ "$makeinstopt" ]
  665. then eval "$MAKE $makeinstopt"; fi
  666. hook_eval postmake
  667. fi
  668. else
  669. eval "$custmain"
  670. for x in preconf premake inmake postmake; do
  671. if eval "[ -n \"\$hookdirty_$x\" ]"; then
  672. echo "Hook $x is still marked as dirty ..."
  673. hook_eval $x
  674. fi
  675. done
  676. fi
  677. if [ "$createdocs" != 0 ]; then
  678. if [ ! -e $docdir ]; then
  679. mkdir -p $docdir
  680. rmemptydir="$rmemptydir $docdir"
  681. fi
  682. [ -z "$createdocs" ] && createdocs="$ROCKCFG_CREATE_DOCS"
  683. fi
  684. [ -n "${desktopfiles}" ] && for file in ${desktopfiles} ; do
  685. [ -f $file ] || continue
  686. echo -n "Install desktop file '$file': "
  687. mkdir -p $root/usr/share/applications
  688. rock_substitute $file > \
  689. $root/usr/share/applications/`basename $file`
  690. done
  691. if [ -f $confdir/postinstall.sh.$xpkg ] ; then
  692. echo "Installing postinstall file $confdir/postinstall.sh.$xpkg"
  693. mkdir -p $root/etc/postinstall
  694. rock_substitute $confdir/postinstall.sh.$xpkg > \
  695. $root/etc/postinstall/$xpkg-postinstall.sh
  696. elif [ -f $confdir/postinstall.sh -a "$pkg" != "$xpkg" ] ; then
  697. echo_error "forked package $xpkg from $pkg"
  698. echo_error "but only found a 'postinstall.sh'"
  699. echo_error "please create a 'postinstall.sh.$xpkg'"
  700. elif [ -f $confdir/postinstall.sh ] ; then
  701. echo "Installing postinstall file $confdir/postinstall.sh"
  702. mkdir -p $root/etc/postinstall
  703. rock_substitute $confdir/postinstall.sh > \
  704. $root/etc/postinstall/$pkg-postinstall.sh
  705. fi
  706. if [ "$createdocs" = 1 ]; then
  707. echo "Trying to copy the default documentation ..."
  708. [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
  709. for x in `find -type d \( -name 'doc' -o -name 'docs' -o \
  710. -name '[Dd]ocumentation' \) ! -empty`
  711. do
  712. if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
  713. then cp -rLv $x/* $docdir || true ; fi
  714. done
  715. for x in [A-Z][A-Z]* *.lsm ChangeLog*; do
  716. [ "${x#*.[cho0-9]}" ] || continue
  717. [ "${x#*.info*}" ] || continue
  718. if [ -f $x ] ; then cp -v $x $docdir/$x ; fi
  719. done
  720. for x in $confdir/*.doc; do
  721. if [ -f $x ]; then cp -v $x $docdir/${x%.doc}; fi
  722. done
  723. find $docdir/ -name '*.[0-9]' -o -name '*.info*' \
  724. -o -name '[Mm]akefile*' | \
  725. xargs -r rm -f 2> /dev/null || true
  726. find $docdir/* -type d -empty 2> /dev/null | \
  727. xargs -r rmdir 2> /dev/null || true
  728. fi
  729. hook_eval postdoc
  730. patchfiles="$saved_patchfiles"
  731. done
  732. for x in $rmemptydir; do
  733. rmdir $x 2> /dev/null || true
  734. [ -e $x ] || rm $x 2> /dev/null || true
  735. done
  736. return 0
  737. }
  738. # [D] line regex:
  739. Dre='\([^:]*\):\([^ ]*\)[ ]\([^ ]*\)[ ]\(\([^ ]\)[^ ]*\)[ ]\([^ ]*\)'
  740. # \1: package-desc-path \2: '[D]'
  741. # \3: cksum \4: archive-file
  742. # \5: first-letter-of-archive-file \6: download-url
  743. D2re='\([^ ]*\)[ ]\([^ ]*\)[ ]\(\([^ ]\)[^ ]*\)[ ]\([^ ]*\)'
  744. # \1: '[D]' \2: cksum
  745. # \3: archive-file \4: first-letter-of-archive-file
  746. # \5: download-url
  747. # NODIST flag regex:
  748. NODISTre='[nN][oO][dD][iI][sS][tT]'
  749. # source_file cksum file url flags...
  750. #
  751. # Create the file path from 'file' and 'flags'.
  752. # cksum and url are ignored
  753. # ([D] tag compatible format)
  754. source_file() {
  755. local pre="" file="$2"
  756. shift; shift; shift
  757. # inside Build-Pkg $archdir is set
  758. if [ -n "$archdir" ]; then
  759. pre=$base/; file="$( echo $file | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )"
  760. fi
  761. if echo $* | egrep -q "($NODISTre)"; then
  762. echo ${pre}download/nodist/${file:0:1}/$file
  763. else
  764. echo ${pre}download/mirror/${file:0:1}/$file
  765. fi
  766. }