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.

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