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.

882 lines
24 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. parser="$( which descparser )"
  320. [ -z "${parser}" ] && parser="$base/src/descparser"
  321. if [ ! -x "${parser}" ] ; then
  322. mkdir -p $base/src
  323. cc -o $base/src/descparser $base/misc/tools-source/descparser.c
  324. fi
  325. [ ! -x "${parser}" ] && abort "Couldn't find \`descparser'! Please run ./scripts/Build-Tools!"
  326. tag="`grep '^\[' $base/Documentation/Developers/PKG-DESC-FORMAT | \
  327. sed 's, (\*),,; s,\] \[,|,g; s,\[,,; s,\],,;'`"
  328. descfile="$( pkg="$pkg" xpkg="$xpkg" $parser < $1 )"
  329. for tag in $tag ; do
  330. tagdata="`echo "$descfile" | egrep "^\[($tag)\]" | \
  331. cut -f2- -d']' | sed 's,^ ,,'`"
  332. tag="`echo $tag | cut -f1 -d'|' | tr - _`"
  333. if eval "[ -z \"\$desc_$tag\" ]"; then
  334. eval "desc_$tag=\"\$tagdata\""
  335. fi
  336. done
  337. }
  338. # This function is used for forcing a file to be in the flist
  339. #
  340. add_flist() {
  341. for addfile ; do
  342. echo "$addfile" | fl_wrparse -D -r "$xroot/" \
  343. >> $builddir/flist.txt
  344. done
  345. }
  346. # This function is used for forcing a package to be in the dependency list
  347. #
  348. add_dependency() {
  349. for addpackage ; do
  350. echo "$addpackage: add_dependency()" \
  351. >> $builddir/dependencies.debug
  352. done
  353. }
  354. # This function adds a wrapprer for the currently running build
  355. #
  356. # Usage:
  357. #
  358. # add_wrapper bin_name <<- 'EOT'
  359. # demo-demo-demo-demo
  360. # $orig "$@"; rc=$?
  361. # demo-demo-demo-demo
  362. # exit $rc
  363. # EOT
  364. #
  365. declare -a wrapper_data='()'
  366. add_wrapper() {
  367. local l data="$1"
  368. while read l; do
  369. data="$data
  370. $l"
  371. done
  372. wrapper_data[${#wrapper_data[@]}]="$data"
  373. }
  374. # This function is used to subsitute some important variables
  375. # using a D_ prefix thru m4 ...
  376. rock_substitute() {
  377. sed -e s,D_prefix,$prefix,g -e s,D_sysconfdir,$sysconfdir,g \
  378. -e s,D_docdir,$docdir,g -e s,D_localstatedir,$localstatedir,g \
  379. -e s,D_datadir,$datadir,g -e s,D_infodir,$infodir,g \
  380. -e s,D_bindir,$bindir,g -e s,D_sbindir,$sbindir,g \
  381. -e s,D_libdir,$libdir,g -e s,D_mandir,$mandir,g \
  382. -e s,D_version,$ver,g $1
  383. }
  384. # This outputs a predefined config.cache file as it needed by some
  385. # packages to cross-build correctly in stages 0 and 1.
  386. #
  387. create_config_cache() {
  388. cat $base/scripts/config.cache
  389. echo -e "\n# Architecture specific stuff\n"
  390. echo "arch_sizeof_char=1"
  391. echo "ac_cv_sizeof_short=$arch_sizeof_short"
  392. echo "ac_cv_sizeof_int=$arch_sizeof_int"
  393. echo "ac_cv_sizeof_long=$arch_sizeof_long"
  394. echo "ac_cv_sizeof_long_long=$arch_sizeof_long_long"
  395. echo "ac_cv_sizeof_char_p=$arch_sizeof_char_p"
  396. echo "ac_cv_sizeof_void_p=$arch_sizeof_char_p"
  397. echo "ac_cv_c_bigendian=$arch_bigendian"
  398. local pt=""
  399. [ $arch_sizeof_char_p -eq $arch_sizeof_int ] && pt="int"
  400. [ $arch_sizeof_char_p -eq $arch_sizeof_long ] && pt="long"
  401. [ $arch_sizeof_char_p -eq $arch_sizeof_long_long ] && pt="long long"
  402. [ -n "$pt" ] && echo "db_cv_alignp_t=\"unsigned $pt\""
  403. echo "ac_cv_prog_CC=$CC"
  404. }
  405. # Abort build before actual build starts
  406. # (is overwritten in Build-Pkg)
  407. #
  408. abort() {
  409. echo -e "The package build aborted with the following config" \
  410. "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err
  411. echo_errorquote "`cat $root/var/adm/logs/$stagelevel-$xpkg.err`"
  412. echo_pkg_abort $stagelevel $repository $xpkg
  413. exit 1
  414. }
  415. # Simple helper for checking the package version in *.conf files.
  416. # This is useful to force a check if the fix is still needed after
  417. # a package update.
  418. #
  419. versionhotfix() {
  420. [ "$1" = "$ver" ] && return
  421. abort "This package has hotfixes for version $1.
  422. Please check if they are still needed for $ver."
  423. }
  424. # Dump Environment
  425. #
  426. dump_env() {
  427. # Dump $base - only set if there is not already an older value.
  428. #
  429. echo "base=\"\${base:-$base}\""
  430. # Dump all variables including their flags, but skip read-only
  431. # variables and $base.
  432. #
  433. # Substitute base directory with ${base}.
  434. #
  435. for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
  436. ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
  437. ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
  438. ${!y*} ${!z*} \
  439. ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
  440. ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
  441. ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
  442. ${!Y*} ${!Z*} ${!_*}
  443. do
  444. [ $name = IFS ] && continue
  445. [ $name = base ] && continue
  446. if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
  447. then
  448. declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
  449. fi
  450. done
  451. # Dump functions
  452. #
  453. declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
  454. # Dump aliases
  455. #
  456. alias
  457. }
  458. # Check if a package is already installed
  459. #
  460. # Always checks the really installed package data. Checking the package list
  461. # doesn't work in Crystal+addon targets, where some packages are only built
  462. # in stage 9. The package data however is always there if the package has been
  463. # installed.
  464. #
  465. pkginstalled() {
  466. local pattern="$1" ; pattern="${pattern//+/\\+}"
  467. if [ $stagelevel = 0 ] ; then
  468. ls "$base/build/$ROCKCFG_ID/ROCK/$toolsdir/var/adm/flists"
  469. else
  470. ls $root/var/adm/flists
  471. fi | egrep -q "^($pattern)$"
  472. }
  473. # Register a window-manager
  474. #
  475. register_wm() {
  476. [ -e /usr/share/rock-registry/wm ] || mkdir -p $root/usr/share/rock-registry/wm
  477. echo -e "name=\"$2\"\nexec=\"$3\"\n" > $root/usr/share/rock-registry/wm/$1
  478. }
  479. # Register a xdm - display manager
  480. #
  481. register_xdm() {
  482. [ -e /usr/share/rock-registry/xdm ] \
  483. || mkdir -p /usr/share/rock-registry/xdm
  484. echo -e "name=\"$2\"\nexec=\"$3\"\n" > /usr/share/rock-registry/xdm/$1
  485. }
  486. # Create Package Database for gasgui install tool
  487. #
  488. create_package_db() {
  489. local admdir="$1"
  490. local outdir="$2"
  491. rm -f $outdir/packages.db $outdir/packages_stripped.db
  492. rm -f $outdir/packages.db.md5 $outdir/packages_stripped.db.md5
  493. rm -f $outdir/packages.db.tmp
  494. for file in $( ls $admdir/descs/ ) ; do
  495. pkg="${file##*/}"
  496. # only include the package if a binary file is available
  497. if [ "$ROCKCFG_PKGFILE_VER" = 1 ] ; then
  498. v=-$(grep '^Package Name and Version' \
  499. $admdir/packages/$pkg | cut -f6,7 -d' ' | tr ' ' -)
  500. else
  501. v=""
  502. fi
  503. if [ "$ROCKCFG_CREATE_GEM" = 1 ] ; then
  504. bfile=${pkg}${v}.gem
  505. else
  506. bfile=${pkg}${v}.tar.bz2
  507. fi
  508. if [ -e $outdir/$bfile ] ; then
  509. [ "$pkg" = TRANS.TBL ] && continue
  510. ( echo -e "$pkg"
  511. echo -e "\027"
  512. cat $admdir/descs/$pkg
  513. echo -e "\027"
  514. cat $admdir/dependencies/$pkg
  515. echo -e "\027"
  516. cat $admdir/cksums/$pkg
  517. echo -e "\027"
  518. echo -e "\004"
  519. ) >> $outdir/packages.db.tmp
  520. fi
  521. done
  522. gawk '
  523. BEGIN { chunk=0; }
  524. $0 == "\004" { chunk=0; print; next; }
  525. $0 == "\027" { chunk++; print; next; }
  526. chunk != 3 { print; }
  527. ' < $outdir/packages.db.tmp | gzip -9 > $outdir/packages_stripped.db
  528. gzip -9 < $outdir/packages.db.tmp > $outdir/packages.db
  529. rm -f $outdir/packages.db.tmp
  530. ( cd $outdir; md5sum packages.db > packages.db.md5; )
  531. ( cd $outdir; md5sum packages_stripped.db > packages_stripped.db.md5; )
  532. }
  533. # Add files to the 'badfiles' list
  534. #
  535. register_badfiles() {
  536. local x desc="$1"
  537. shift
  538. for x in "$@"; do
  539. var_append badfiles $'\n' " $x\$"
  540. badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
  541. (( badfiles_nr++ ))
  542. done
  543. }
  544. # Apply the given $patchfiles
  545. #
  546. apply_patchfiles() {
  547. for x in $patchfiles; do
  548. echo "Apply patch $x ..."
  549. if [[ $x = *.bz2 ]] ; then
  550. bzcat $x | patch $patchopt
  551. else
  552. patch $patchopt < $x
  553. fi
  554. eval "$@"
  555. done
  556. }
  557. # Main program for building a package
  558. #
  559. build_this_package() {
  560. if [ ".$desc_SRC" == "." ] ; then
  561. # Autodetect source tar and extract it
  562. #
  563. if [ $srctar = auto ] ; then
  564. xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' | \
  565. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  566. if [ -z "$xsourceballs" ] ; then
  567. echo "Can't auto-detect srctar for package '$xpkg'!"
  568. false
  569. fi
  570. else
  571. xsourceballs="$srctar"
  572. fi
  573. else
  574. sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' | \
  575. cut -f2 | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )
  576. xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' )
  577. xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
  578. fi
  579. for xsrctar in $xsourceballs; do
  580. saved_patchfiles="$patchfiles"
  581. var_append patchfiles " " \
  582. "`ls $confdir/*.patch.${xsrctar/-[0-9]*/} 2> /dev/null`"
  583. if [ $autoextract = 1 ]; then
  584. echo "Extracting $xsrctar ($taropt) ... "
  585. cd $builddir
  586. tar -v $taropt $archdir/$xsrctar | tee untar.txt |
  587. cut -f1 -d/ | sort -u > xsrcdir.txt
  588. #
  589. if [ $srcdir = auto ]; then
  590. xsrcdir=${xsrctar%.tar.bz2}
  591. xsrcdir=${xsrcdir%.tbz2}
  592. if [ ! -d $xsrcdir ] ; then
  593. for x in $pkg-$ver ${pkg}_$ver $pkg \
  594. $xpkg-$ver ${xpkg}_$ver $xpkg \
  595. "$( cat xsrcdir.txt )"
  596. do
  597. [ -d "$x" ] && xsrcdir="$x"
  598. done
  599. fi
  600. else
  601. xsrcdir="$srcdir"
  602. fi
  603. #
  604. if [ "$chownsrcdir" = 1 ]; then
  605. echo "Fixing ownership and permissions ..."
  606. chown -R 0:0 $builddir/$xsrcdir
  607. fi
  608. #
  609. if [ "$nocvsinsrcdir" = 1 ]; then
  610. echo "Removing CVS and .svn directories ..."
  611. egrep '(^|/)(CVS|\.svn)(/|$)' untar.txt |
  612. while read x; do
  613. echo "Removing $x ..."
  614. rm -rf "$x"
  615. done
  616. fi
  617. #
  618. echo "Changeing into $builddir/$xsrcdir ..."
  619. cd $builddir/$xsrcdir
  620. # Apply patches
  621. #
  622. if [ $autopatch = 1 ]; then
  623. hook_eval prepatch
  624. apply_patchfiles
  625. hook_eval postpatch
  626. fi
  627. else
  628. cd $builddir
  629. fi
  630. if [ "$createprefix" = 1 ]; then
  631. echo "Creating $root/$prefix/<..> if required ..."
  632. for x in $root/$prefix $bindir $sbindir $libdir $datadir $includedir \
  633. $docdir $infodir $mandir $sysconfdir $localstatedir
  634. do
  635. if [ ! -e $x ]; then
  636. mkdir -p $x
  637. rmemptydir="$x $rmemptydir"
  638. fi
  639. done
  640. if [ ! -e $root/$prefix/man ]; then
  641. ln -s ${mandir#$root} $root/$prefix/man
  642. rmemptydir="$rmemptydir $root/$prefix/man"
  643. fi
  644. if [ ! -e $root/$prefix/info ]; then
  645. ln -s ${infodir#$root} $root/$prefix/info
  646. rmemptydir="$rmemptydir $root/$prefix/info"
  647. fi
  648. fi
  649. if [ ".$custmain" = "." ]
  650. then
  651. # Run configure scripts etc.
  652. #
  653. hook_eval preconf
  654. #
  655. if [ $runconf = 1 ]; then
  656. if [ -n "$( type -p $configscript )" -o $autogen = 1 ]
  657. then
  658. eval_config_command $( eval echo $confopt )
  659. fi
  660. fi
  661. # automated package build
  662. # styles without make run first:
  663. if [ -f setup.py -a $runpysetup = 1 ] ; then
  664. pyconfopt="${pyconfopt:=--prefix $root/$prefix}"
  665. eval python setup.py build install $pyconfopt
  666. else # styles that include a make run
  667. if [ ! -f Makefile -a ! -f makefile -a \
  668. -f Makefile.PL -a $runmkpl = 1 ]; then
  669. sed -i 's/auto_install/# &/' Makefile.PL
  670. perl Makefile.PL INSTALLDIRS=perl
  671. fi
  672. #
  673. if [ ! -f Makefile -a ! -f makefile -a \
  674. -f Imakefile -a $runxmkmf = 1 ]; then
  675. xmkmf -a
  676. fi
  677. #
  678. # Build it
  679. #
  680. hook_eval premake
  681. if [ "$makeopt" ]
  682. then eval "$MAKE $makeopt"; fi
  683. hook_eval inmake
  684. if [ "$makeinstopt" ]
  685. then eval "$MAKE $makeinstopt"; fi
  686. hook_eval postmake
  687. fi
  688. else
  689. eval "$custmain"
  690. for x in preconf premake inmake postmake; do
  691. if eval "[ -n \"\$hookdirty_$x\" ]"; then
  692. echo "Hook $x is still marked as dirty ..."
  693. hook_eval $x
  694. fi
  695. done
  696. fi
  697. if [ "$createdocs" != 0 ]; then
  698. if [ ! -e $docdir ]; then
  699. mkdir -p $docdir
  700. rmemptydir="$rmemptydir $docdir"
  701. fi
  702. [ -z "$createdocs" ] && createdocs="$ROCKCFG_CREATE_DOCS"
  703. fi
  704. [ -n "${desktopfiles}" ] && for file in ${desktopfiles} ; do
  705. [ -f $file ] || continue
  706. echo -n "Install desktop file '$file': "
  707. mkdir -p $root/usr/share/applications
  708. rock_substitute $file > \
  709. $root/usr/share/applications/`basename $file`
  710. done
  711. if [ -f $confdir/postinstall.sh.$xpkg ] ; then
  712. echo "Installing postinstall file $confdir/postinstall.sh.$xpkg"
  713. mkdir -p $root/etc/postinstall
  714. rock_substitute $confdir/postinstall.sh.$xpkg > \
  715. $root/etc/postinstall/$xpkg-postinstall.sh
  716. elif [ -f $confdir/postinstall.sh -a "$pkg" != "$xpkg" ] ; then
  717. echo_error "forked package $xpkg from $pkg"
  718. echo_error "but only found a 'postinstall.sh'"
  719. echo_error "please create a 'postinstall.sh.$xpkg'"
  720. elif [ -f $confdir/postinstall.sh ] ; then
  721. echo "Installing postinstall file $confdir/postinstall.sh"
  722. mkdir -p $root/etc/postinstall
  723. rock_substitute $confdir/postinstall.sh > \
  724. $root/etc/postinstall/$pkg-postinstall.sh
  725. fi
  726. if [ "$createdocs" = 1 ]; then
  727. echo "Trying to copy the default documentation ..."
  728. [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
  729. for x in `find -type d \( -name 'doc' -o -name 'docs' -o \
  730. -name '[Dd]ocumentation' \) ! -empty`
  731. do
  732. if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
  733. then cp -rLv $x/* $docdir || true ; fi
  734. done
  735. for x in [A-Z][A-Z]* *.lsm ChangeLog*; do
  736. [ "${x#*.[cho0-9]}" ] || continue
  737. [ "${x#*.info*}" ] || continue
  738. if [ -f $x ] ; then cp -v $x $docdir/$x ; fi
  739. done
  740. for x in $confdir/*.doc; do
  741. if [ -f $x ]; then cp -v $x $docdir/${x%.doc}; fi
  742. done
  743. find $docdir/ -name '*.[0-9]' -o -name '*.info*' \
  744. -o -name '[Mm]akefile*' | \
  745. xargs -r rm -f 2> /dev/null || true
  746. find $docdir/* -type d -empty 2> /dev/null | \
  747. xargs -r rmdir 2> /dev/null || true
  748. fi
  749. hook_eval postdoc
  750. patchfiles="$saved_patchfiles"
  751. done
  752. for x in $rmemptydir; do
  753. rmdir $x 2> /dev/null || true
  754. [ -e $x ] || rm $x 2> /dev/null || true
  755. done
  756. return 0
  757. }
  758. # [D] line regex:
  759. Dre='\([^:]*\):\([^ ]*\)[ ]\([^ ]*\)[ ]\(\([^ ]\)[^ ]*\)[ ]\([^ ]*\)'
  760. # \1: package-desc-path \2: '[D]'
  761. # \3: cksum \4: archive-file
  762. # \5: first-letter-of-archive-file \6: download-url
  763. D2re='\([^ ]*\)[ ]\([^ ]*\)[ ]\(\([^ ]\)[^ ]*\)[ ]\([^ ]*\)'
  764. # \1: '[D]' \2: cksum
  765. # \3: archive-file \4: first-letter-of-archive-file
  766. # \5: download-url
  767. # NODIST flag regex:
  768. NODISTre='[nN][oO][dD][iI][sS][tT]'
  769. # source_file cksum file url flags...
  770. #
  771. # Create the file path from 'file' and 'flags'.
  772. # cksum and url are ignored
  773. # ([D] tag compatible format)
  774. source_file() {
  775. local pre="" file="$2"
  776. shift; shift; shift
  777. # inside Build-Pkg $archdir is set
  778. if [ -n "$archdir" ]; then
  779. pre=$base/; file="$( echo $file | sed 's,.\(t\?\)\(gz\|Z\)$,.\1bz2,' )"
  780. fi
  781. if echo $* | egrep -q "($NODISTre)"; then
  782. echo ${pre}download/nodist/${file:0:1}/$file
  783. else
  784. echo ${pre}download/mirror/${file:0:1}/$file
  785. fi
  786. }