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.

833 lines
22 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 - 2005 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. rm -f $3 $3.tmp
  470. for file in $( ls $1/descs/ ) ; do
  471. pkg="${file##*/}"
  472. # only include the package if a binary file is available
  473. if [ "$ROCKCFG_PKGFILE_VER" = 1 ] ; then
  474. v=-$(grep '^Package Name and Version' \
  475. $1/packages/$pkg | cut -f6,7 -d' ' | tr ' ' -)
  476. else
  477. v=""
  478. fi
  479. if [ "$ROCKCFG_CREATE_GEM" = 1 ] ; then
  480. bfile=${pkg}${v}.gem
  481. else
  482. bfile=${pkg}${v}.tar.bz2
  483. fi
  484. if [ -e $2/$bfile ] ; then
  485. [ "$pkg" = TRANS.TBL ] && continue
  486. ( echo -e "$pkg"
  487. echo -e "\027"
  488. cat $1/descs/$pkg
  489. echo -e "\027"
  490. cat $1/dependencies/$pkg
  491. echo -e "\027"
  492. cat $1/cksums/$pkg
  493. echo -e "\027"
  494. echo -e "\004"
  495. ) >> $3.tmp
  496. fi
  497. done
  498. gzip -c $3.tmp > $3
  499. rm -f $3.tmp
  500. }
  501. # Add files to the 'badfiles' list
  502. #
  503. register_badfiles() {
  504. local x desc="$1"
  505. shift
  506. for x in "$@"; do
  507. var_append badfiles $'\n' " $x\$"
  508. badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
  509. (( badfiles_nr++ ))
  510. done
  511. }
  512. # Apply the given $patchfiles
  513. #
  514. apply_patchfiles() {
  515. for x in $patchfiles; do
  516. echo "Apply patch $x ..."
  517. if [[ $x = *.bz2 ]] ; then
  518. bzcat $x | patch $patchopt
  519. else
  520. patch $patchopt < $x
  521. fi
  522. eval "$@"
  523. done
  524. }
  525. # Main program for building a package
  526. #
  527. build_this_package() {
  528. if [ ".$desc_SRC" == "." ] ; then
  529. # Autodetect source tar and extract it
  530. #
  531. if [ $srctar = auto ] ; then
  532. xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' | \
  533. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  534. if [ -z "$xsourceballs" ] ; then
  535. echo "Can't auto-detect srctar for package '$xpkg'!"
  536. false
  537. fi
  538. else
  539. xsourceballs="$srctar"
  540. fi
  541. else
  542. sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' | \
  543. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  544. xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' )
  545. xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
  546. fi
  547. for xsrctar in $xsourceballs; do
  548. saved_patchfiles="$patchfiles"
  549. var_append patchfiles " " \
  550. "`ls $confdir/*.patch.${xsrctar/-[0-9]*/} 2> /dev/null`"
  551. if [ $autoextract = 1 ]; then
  552. echo "Extracting $xsrctar ($taropt) ... "
  553. cd $builddir
  554. tar -v $taropt $archdir/$xsrctar | tee untar.txt |
  555. cut -f1 -d/ | sort -u > xsrcdir.txt
  556. #
  557. if [ $srcdir = auto ]; then
  558. xsrcdir=${xsrctar%.tar.bz2}
  559. xsrcdir=${xsrcdir%.tbz2}
  560. if [ ! -d $xsrcdir ] ; then
  561. for x in $pkg-$ver ${pkg}_$ver $pkg \
  562. $xpkg-$ver ${xpkg}_$ver $xpkg \
  563. "$( cat xsrcdir.txt )"
  564. do
  565. [ -d "$x" ] && xsrcdir="$x"
  566. done
  567. fi
  568. else
  569. xsrcdir="$srcdir"
  570. fi
  571. #
  572. if [ "$chownsrcdir" = 1 ]; then
  573. echo "Fixing ownership and permissions ..."
  574. chown -R 0:0 $builddir/$xsrcdir
  575. fi
  576. #
  577. if [ "$nocvsinsrcdir" = 1 ]; then
  578. echo "Removing CVS and .svn directories ..."
  579. egrep '(^|/)(CVS|\.svn)(/|$)' untar.txt |
  580. while read x; do
  581. echo "Removing $x ..."
  582. rm -rf "$x"
  583. done
  584. fi
  585. #
  586. echo "Changeing into $builddir/$xsrcdir ..."
  587. cd $builddir/$xsrcdir
  588. # Apply patches
  589. #
  590. if [ $autopatch = 1 ]; then
  591. hook_eval prepatch
  592. apply_patchfiles
  593. hook_eval postpatch
  594. fi
  595. else
  596. cd $builddir
  597. fi
  598. if [ "$createprefix" = 1 ]; then
  599. echo "Creating $root/$prefix/<..> if required ..."
  600. for x in $root/$prefix $bindir $sbindir $libdir $datadir $includedir \
  601. $docdir $infodir $mandir $sysconfdir $localstatedir
  602. do
  603. if [ ! -e $x ]; then
  604. mkdir -p $x
  605. rmemptydir="$x $rmemptydir"
  606. fi
  607. done
  608. if [ ! -e $root/$prefix/man ]; then
  609. ln -s ${mandir#$root} $root/$prefix/man
  610. rmemptydir="$rmemptydir $root/$prefix/man"
  611. fi
  612. if [ ! -e $root/$prefix/info ]; then
  613. ln -s ${infodir#$root} $root/$prefix/info
  614. rmemptydir="$rmemptydir $root/$prefix/info"
  615. fi
  616. fi
  617. if [ ".$custmain" = "." ]
  618. then
  619. # Run configure scripts etc.
  620. #
  621. hook_eval preconf
  622. #
  623. if [ $runconf = 1 ]; then
  624. if [ -n "$( type -p $configscript )" -o $autogen = 1 ]
  625. then
  626. eval_config_command $( eval echo $confopt )
  627. fi
  628. fi
  629. # automated package build
  630. # styles without make run first:
  631. if [ -f setup.py -a $runpysetup = 1 ] ; then
  632. pyconfopt="${pyconfopt:=--prefix $root/$prefix}"
  633. eval python setup.py build install $pyconfopt
  634. else # styles that include a make run
  635. if [ ! -f Makefile -a ! -f makefile -a \
  636. -f Makefile.PL -a $runmkpl = 1 ]; then
  637. sed -i 's/auto_install/# &/' Makefile.PL
  638. perl Makefile.PL INSTALLDIRS=perl
  639. fi
  640. #
  641. if [ ! -f Makefile -a ! -f makefile -a \
  642. -f Imakefile -a $runxmkmf = 1 ]; then
  643. xmkmf -a
  644. fi
  645. #
  646. # Build it
  647. #
  648. hook_eval premake
  649. if [ "$makeopt" ]
  650. then eval "$MAKE $makeopt"; fi
  651. hook_eval inmake
  652. if [ "$makeinstopt" ]
  653. then eval "$MAKE $makeinstopt"; fi
  654. hook_eval postmake
  655. fi
  656. else
  657. eval "$custmain"
  658. for x in preconf premake inmake postmake; do
  659. if eval "[ -n \"\$hookdirty_$x\" ]"; then
  660. echo "Hook $x is still marked as dirty ..."
  661. hook_eval $x
  662. fi
  663. done
  664. fi
  665. if [ "$createdocs" != 0 ]; then
  666. if [ ! -e $docdir ]; then
  667. mkdir -p $docdir
  668. rmemptydir="$rmemptydir $docdir"
  669. fi
  670. [ -z "$createdocs" ] && createdocs="$ROCKCFG_CREATE_DOCS"
  671. fi
  672. for file in $confdir/*.desktop ; do
  673. [ -f $file ] || continue
  674. echo -n "Install desktop file '$file': "
  675. mkdir -p $root/usr/share/applications
  676. rock_substitute $file > \
  677. $root/usr/share/applications/`basename $file`
  678. done
  679. if [ -f $confdir/postinstall.sh ] ; then
  680. echo "Installing postinstall file $confdir/postinstall.sh"
  681. mkdir -p $root/etc/postinstall
  682. rock_substitute $confdir/postinstall.sh > \
  683. $root/etc/postinstall/$pkg-postinstall.sh
  684. fi
  685. if [ "$createdocs" = 1 ]; then
  686. echo "Trying to copy the default documentation ..."
  687. [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
  688. for x in `find -type d \( -name 'doc' -o -name 'docs' -o \
  689. -name '[Dd]ocumentation' \) ! -empty`
  690. do
  691. if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
  692. then cp -rLv $x/* $docdir || true ; fi
  693. done
  694. for x in [A-Z][A-Z]* *.lsm ChangeLog*; do
  695. [ "${x#*.[cho0-9]}" ] || continue
  696. [ "${x#*.info*}" ] || continue
  697. if [ -f $x ] ; then cp -v $x $docdir/$x ; fi
  698. done
  699. for x in $confdir/*.doc; do
  700. if [ -f $x ]; then cp -v $x $docdir/${x%.doc}; fi
  701. done
  702. find $docdir/ -name '*.[0-9]' -o -name '*.info*' \
  703. -o -name '[Mm]akefile*' | \
  704. xargs -r rm -f 2> /dev/null || true
  705. find $docdir/* -type d -empty 2> /dev/null | \
  706. xargs -r rmdir 2> /dev/null || true
  707. fi
  708. hook_eval postdoc
  709. patchfiles="$saved_patchfiles"
  710. done
  711. for x in $rmemptydir; do
  712. rmdir $x 2> /dev/null || true
  713. [ -e $x ] || rm $x 2> /dev/null || true
  714. done
  715. return 0
  716. }
  717. # [D] line regex:
  718. Dre='\([^:]*\):\([^ ]*\)[ ]\([^ ]*\)[ ]\(\([^ ]\)[^ ]*\)[ ]\([^ ]*\)'
  719. # \1: package-desc-path \2: '[D]'
  720. # \3: cksum \4: archive-file
  721. # \5: first-letter-of-archive-file \6: download-url
  722. D2re='\([^ ]*\)[ ]\([^ ]*\)[ ]\(\([^ ]\)[^ ]*\)[ ]\([^ ]*\)'
  723. # \1: '[D]' \2: cksum
  724. # \3: archive-file \4: first-letter-of-archive-file
  725. # \5: download-url
  726. # NODIST flag regex:
  727. NODISTre='[nN][oO][dD][iI][sS][tT]'
  728. # source_file cksum file url flags...
  729. #
  730. # Create the file path from 'file' and 'flags'.
  731. # cksum and url are ignored
  732. # ([D] tag compatible format)
  733. source_file() {
  734. local pre="" file="$2"
  735. shift; shift; shift
  736. # inside Build-Pkg $archdir is set
  737. if [ -n "$archdir" ]; then
  738. pre=$base/; file="$( echo $file | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )"
  739. fi
  740. if echo $* | egrep -q "($NODISTre)"; then
  741. echo ${pre}download/nodist/${file:0:1}/$file
  742. else
  743. echo ${pre}download/mirror/${file:0:1}/$file
  744. fi
  745. }