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.

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