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.

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