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.

896 lines
24 KiB

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