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.

756 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/$pkg"
  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/$pkg"
  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. # do not log read for the config script ...
  244. touch $FLWRAPPER_RLOG-config
  245. FLWRAPPER_RLOG="$FLWRAPPER_RLOG-config" eval "$config_command"
  246. }
  247. # run 'make check' if Makefile supports it.
  248. #
  249. function run_check() {
  250. if grep -q -e "^check:" ./Makefile; then
  251. echo "Running make check ..."
  252. $MAKE check
  253. fi
  254. if grep -q -e "^test:" ./Makefile; then
  255. echo "Running make test ..."
  256. $MAKE test
  257. fi
  258. }
  259. # move the static libs from lib to usr/lib and correct the libdir used
  260. # inside the .la file
  261. #
  262. postflist_static_lib() {
  263. echo "Processing static lib corrections ..."
  264. egrep '^lib/.*\.(a|la)$' $builddir/flist.txt |
  265. while read fn ; do
  266. [ -e $root/$fn -o -L $root/$fn ] || continue
  267. if [[ $fn = *.a ]] ; then
  268. mv -fv $root/$fn $root/usr/$fn
  269. else
  270. sed "s,\([ =']\)/lib\(.*\),\1/usr/lib\2,g" \
  271. $root/$fn > $root/usr/$fn
  272. rm $root/$fn
  273. fi
  274. add_flist $root/usr/$fn
  275. done
  276. # this check might be removed in the future when we decide this is not
  277. # an issue anymore ...
  278. echo "Verifing the .la files ..."
  279. defect_la="`egrep 'lib/.*\.la$' $builddir/flist.txt |
  280. xargs egrep 'dependency_libs=.*-pthread.*' |
  281. cut -d : -f1 | sort -u | tr '\n' ' '`"
  282. if [ "$defect_la" ] ; then
  283. abort "-pthread in: $defect_la!"
  284. fi
  285. }
  286. # Parse the *.desc file. Use the description from PKG-DESC-FORMAT and
  287. # save the tag data in $desc_*.
  288. #
  289. parse_desc() {
  290. tag="`grep '^\[' $base/Documentation/Developers/PKG-DESC-FORMAT | \
  291. sed 's, (\*),,; s,\] \[,|,g; s,\[,,; s,\],,;'`"
  292. descfile="$( pkg="$pkg" xpkg="$xpkg" descparser < $confdir/$1.desc )"
  293. for tag in $tag ; do
  294. tagdata="`echo "$descfile" | egrep "^\[($tag)\]" | \
  295. cut -f2- -d']' | sed 's,^ ,,'`"
  296. tag="`echo $tag | cut -f1 -d'|' | tr - _`"
  297. eval "desc_$tag=\"\$tagdata\""
  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 "ac_cv_sizeof_short=$arch_sizeof_short"
  332. echo "ac_cv_sizeof_int=$arch_sizeof_int"
  333. echo "ac_cv_sizeof_long=$arch_sizeof_long"
  334. echo "ac_cv_sizeof_long_long=$arch_sizeof_long_long"
  335. echo "ac_cv_sizeof_char_p=$arch_sizeof_char_p"
  336. echo "ac_cv_c_bigendian=$arch_bigendian"
  337. echo "ac_cv_prog_CC=$CC"
  338. }
  339. # Abort build before actual build starts
  340. # (is overwritten in Build-Pkg)
  341. #
  342. abort() {
  343. echo -e "The package build aborted with the following config" \
  344. "error:\n$*" > $root/var/adm/logs/$stagelevel-$pkg.err
  345. echo_errorquote "`cat $root/var/adm/logs/$stagelevel-$pkg.err`"
  346. echo_pkg_abort $stagelevel $repository $pkg
  347. exit 1
  348. }
  349. # Dump Environment
  350. #
  351. dump_env() {
  352. # Dump $base - only set if there is not already an older value.
  353. #
  354. echo "base=\"\${base:-$base}\""
  355. # Dump all variables including their flags, but skip read-only
  356. # variables and $base.
  357. #
  358. # Substitute base directory with ${base}.
  359. #
  360. for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
  361. ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
  362. ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
  363. ${!y*} ${!z*} \
  364. ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
  365. ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
  366. ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
  367. ${!Y*} ${!Z*} ${!_*}
  368. do
  369. [ $name = base ] && continue
  370. if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
  371. then
  372. declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
  373. fi
  374. done
  375. # Dump functions
  376. #
  377. declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
  378. # Dump aliases
  379. #
  380. alias
  381. }
  382. # Check if a package is already installed
  383. #
  384. # It does check the build-list if not in the rebuild stage - and
  385. # the really installed package data for rebuilds (and so manual builds).
  386. #
  387. pkginstalled() {
  388. if [ "$stagelevel" -le 8 ] ; then
  389. local pattern="$1"; pattern="${pattern//+/\\+}"
  390. egrep -q "^X.* ($pattern) " $base/config/$config/packages
  391. else
  392. [ -f $root/var/adm/packages/$1 ]
  393. fi
  394. }
  395. # Register a window-manager
  396. #
  397. register_wm() {
  398. [ -e /usr/share/rock-registry/wm ] || mkdir -p $root/usr/share/rock-registry/wm
  399. echo -e "name=\"$2\"\nexec=\"$3\"\n" > $root/usr/share/rock-registry/wm/$1
  400. }
  401. # Register an application
  402. #
  403. register_application() {
  404. [ -e /usr/share/rock-registry/app ] \
  405. || mkdir -p /usr/share/rock-registry/app
  406. echo -e "name=\"$2\"\nexec=\"$3\"\n" > /usr/share/rock-registry/app/$1
  407. }
  408. # Register a xdm - display manager
  409. #
  410. register_xdm() {
  411. [ -e /usr/share/rock-registry/xdm ] \
  412. || mkdir -p /usr/share/rock-registry/xdm
  413. echo -e "name=\"$2\"\nexec=\"$3\"\n" > /usr/share/rock-registry/xdm/$1
  414. }
  415. # Create Package Database for gasgui install tool
  416. #
  417. create_package_db() {
  418. rm -f $3.tmp
  419. for file in $( ls -dr $1/descs/?* ) ; do
  420. pkg="${file##*/}"
  421. # only include the package if a binary file is available
  422. if [ "$ROCKCFG_PKGFILE_VER" = 1 ] ; then
  423. v=-$(grep '^Package Name and Version' \
  424. $1/packages/$pkg | cut -f6 -d' ')
  425. else
  426. v=""
  427. fi
  428. if [ "$ROCKCFG_CREATE_GEM" = 1 ] ; then
  429. bfile=${pkg}${v}.gem
  430. else
  431. bfile=${pkg}${v}.tar.bz2
  432. fi
  433. if [ -e $2/$bfile ] ; then
  434. [ "$pkg" = TRANS.TBL ] && continue
  435. ( echo -e "$pkg"
  436. echo -e "\027"
  437. cat $1/descs/$pkg
  438. echo -e "\027"
  439. cat $1/dependencies/$pkg
  440. echo -e "\027"
  441. cat $1/cksums/$pkg
  442. echo -e "\027"
  443. echo -e "\004"
  444. ) >> $3.tmp
  445. else
  446. echo_error "Binary file for $bfile not present." \
  447. "Skipped in package database."
  448. fi
  449. done
  450. gzip -c $3.tmp > $3 ; rm -f $3.tmp
  451. }
  452. # Add files to the 'badfiles' list
  453. #
  454. register_badfiles() {
  455. local x desc="$1"
  456. shift
  457. for x in "$@"; do
  458. var_append badfiles $'\n' " $x\$"
  459. badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
  460. (( badfiles_nr++ ))
  461. done
  462. }
  463. # Apply the given $patchfiles
  464. #
  465. apply_patchfiles() {
  466. for x in $patchfiles; do
  467. echo "Apply patch $x ..."
  468. if [[ $x = *.bz2 ]] ; then
  469. bzcat $x | patch $patchopt
  470. else
  471. patch $patchopt < $x
  472. fi
  473. eval "$@"
  474. done
  475. }
  476. # Main program for building a package
  477. #
  478. build_this_package() {
  479. if [ ".$desc_SRC" == "." ] ; then
  480. # Autodetect source tar and extract it
  481. #
  482. if [ $srctar = auto ] ; then
  483. xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' | \
  484. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  485. if [ -z "$xsourceballs" ] ; then
  486. echo "Can't auto-detect srctar for package '$pkg'!"
  487. false
  488. fi
  489. else
  490. xsourceballs="$srctar"
  491. fi
  492. else
  493. sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' | \
  494. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  495. xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' )
  496. xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
  497. fi
  498. for xsrctar in $xsourceballs; do
  499. saved_patchfiles="$patchfiles"
  500. var_append patchfiles " " \
  501. "`ls $confdir/*.patch.${xsrctar/-[0-9]*/} 2> /dev/null`"
  502. if [ $autoextract = 1 ]; then
  503. echo "Extracting $xsrctar ($taropt) ... "
  504. cd $builddir
  505. tar -v $taropt $archdir/$xsrctar | tee untar.txt |
  506. cut -f1 -d/ | sort -u > xsrcdir.txt
  507. #
  508. if [ $srcdir = auto ]; then
  509. xsrcdir=${xsrctar%.tar.bz2}
  510. xsrcdir=${xsrcdir%.tbz2}
  511. if [ ! -d $xsrcdir ] ; then
  512. for x in $pkg-$ver $pkg_$ver $pkg \
  513. "`cat xsrcdir.txt`" ; 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. }