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.

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