OpenSDE Framework (without history before r20070)
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.

1448 lines
36 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/functions.in
  5. # Copyright (C) 2006 - 2012 The OpenSDE Project
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. # Copyright (C) 1998 - 2003 Clifford Wolf
  8. #
  9. # More information can be found in the files COPYING and README.
  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; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. . ${SDEROOT:-.}/lib/core-functions.in
  17. # This function returns a "uniqe id" as output
  18. #
  19. get_unique() {
  20. local hostsum=`hostname 2>/dev/null | tr '()' _`
  21. if [ -z "$hostsum" -a -x /sbin/ip ]; then
  22. hostsum=`/sbin/ip link show eth0 |
  23. sed -e '/link\//!d' -e 's,.*link[^ ]* \([^ ]*\) .*,\1,'`
  24. fi
  25. if [ -z "$hostsum" -a -f /sbin/ifconfig ]; then
  26. hostsum=`/sbin/ifconfig eth0 |
  27. sed -e '/HWaddr/!d' -e 's/.* HWaddr \([^ ]*\)/\1/'`
  28. fi
  29. if [ -z "$hostsum" -a -x /usr/bin/hostid ]; then
  30. hostsum=`/usr/bin/hostid`
  31. fi
  32. date "+%Y%m%d.%H%M%S.$$.$hostsum"
  33. }
  34. # this functions expands an string replacing % with all possible values
  35. # listed after
  36. case "$BASH_VERSION" in # damn workaround for different syntax in both versions
  37. 2*)
  38. get_expanded() {
  39. local string="$1"; shift
  40. while [ $# -gt 0 ]; do
  41. echo "${string//\\%/$1}"
  42. shift
  43. done
  44. }
  45. ;;
  46. 3*|4*)
  47. get_expanded() {
  48. local string="$1"; shift
  49. while [ $# -gt 0 ]; do
  50. echo "${string//\%/$1}"
  51. shift
  52. done
  53. }
  54. ;;
  55. esac
  56. # atstage <stagename> ...
  57. # returns true if the build is on a stage related to the given name
  58. #
  59. atstage() {
  60. local x=
  61. for x; do
  62. case "$x" in
  63. toolchain)
  64. [ $stagelevel -gt 0 ] || return 0 ;;
  65. cross|crossbuild|crosscompile)
  66. [ $stagelevel -ne 1 ] || return 0 ;;
  67. rebuild)
  68. [ $stagelevel -ne 9 ] || return 0 ;;
  69. native)
  70. [ $stagelevel -lt 2 ] || return 0 ;;
  71. *)
  72. echo "atstage: '$x' stagename is not supported." >&2
  73. break ;;
  74. esac
  75. done
  76. return 1
  77. }
  78. # hasflag FLAG
  79. #
  80. hasflag() {
  81. local flag=
  82. for flag; do
  83. if ! echo "$desc_F" | grep -q -e "^\(.* \)\?$flag\( .*\)\?\$"; then
  84. return 1
  85. fi
  86. done
  87. return 0
  88. }
  89. # bz2filename [<filename>]
  90. # outputs filename converted to .bz2. stdin and $1 inputs are accepted
  91. #
  92. bz2filename() {
  93. local pattern='-e s,\.\(t\?\)\(gz\|xz\|Z\)$,.\1bz2,'
  94. pattern="-e s,\.gpg$,, $pattern"
  95. pattern="-e s,\.tar$,\.tar.bz2, $pattern"
  96. if [ -n "$1" ]; then
  97. echo "$1" | sed $pattern
  98. else
  99. sed $pattern
  100. fi
  101. }
  102. # pseudo_realpath <path>
  103. # returns a clean absolute path without caring about symlinks or actual existance
  104. #
  105. pseudo_realpath() {
  106. local origpath="$1"
  107. local newpath= x=
  108. local path="$(echo "$1" | sed -e "s,^\([^/]\),$PWD/\1," )"
  109. while [ -n "$path" ]; do
  110. x="${path%%/*}"
  111. if [ "$x" = "$path" ]; then
  112. path=
  113. else
  114. path="${path#*/}"
  115. fi
  116. case "$x" in
  117. ""|.)
  118. ;; # skip
  119. ..)
  120. if [ -n "$newpath" ]; then
  121. newpath="${newpath%/*}"
  122. else
  123. echo "$origpath: invalid" >&2
  124. return
  125. fi
  126. ;;
  127. *)
  128. newpath="$newpath/$x"
  129. esac
  130. done
  131. echo "$newpath"
  132. }
  133. # relative_path <target> <source>
  134. # returns a relative patch from source to target (for symlinking)
  135. #
  136. relative_path() {
  137. local orig_to="$1" orig_from="$2"
  138. local to=$(pseudo_realpath "$orig_to")
  139. local from=$(pseudo_realpath "$orig_from")
  140. local rel= x= y=
  141. [ -n "$to" -a -n "$from" ] || return
  142. # remove common part
  143. while [ -n "$from" ]; do
  144. x="${to%%/*}"
  145. y="${from%%/*}"
  146. [ "$x" = "$y" ] || break
  147. if [ "$x" = "$to" ]; then
  148. to=
  149. else
  150. to="${to#*/}"
  151. fi
  152. if [ "$y" = "$from" ]; then
  153. from=
  154. else
  155. from="${from#*/}"
  156. fi
  157. done
  158. if [ -z "$from" ]; then
  159. echo "$orig_to: invalid target for $orig_from" >&2
  160. return
  161. fi
  162. case "$from" in
  163. */*)
  164. rel=$(echo "${from%/*}/" | sed -e 's,[^/]*/,../,g' -e 's,/$,,')
  165. ;;
  166. *)
  167. rel=.
  168. ;;
  169. esac
  170. echo "$rel${to:+/$to}" | sed -e 's,^\./,,'
  171. }
  172. # Hook variables
  173. #
  174. unset hook_functions hook_fcounter
  175. declare -a hook_functions='()'
  176. hook_fcounter=0
  177. # This function adds a code fragment to a named hook with the named priority
  178. #
  179. # hook_add hook_name priority code
  180. #
  181. hook_add() {
  182. hook_functions[hook_fcounter]="$3" # declare -a hookidx_$1
  183. eval "hookidx_$1[\${#hookidx_$1[@]}]=\"$2 $hook_fcounter\""
  184. eval "(( hookdirty_$1++ ))" || true ; (( hook_fcounter++ )) || true
  185. }
  186. # This function executes all code fragments from the named hook
  187. #
  188. # hook_eval hook_name
  189. #
  190. hook_eval() {
  191. while read pri fnr ; do
  192. [ "$pri" ] && eval "${hook_functions[fnr]}"
  193. done < <( IFS=$'\n' ; eval "echo \"\${hookidx_$1[*]}\"" | sort )
  194. eval "unset hookdirty_$1"
  195. }
  196. # This function prints all hooks and their current contents
  197. #
  198. # hook_dump
  199. #
  200. hook_dump() {
  201. for hook in ${!hookidx_*} ; do
  202. hook=${hook#hookidx_}
  203. echo ; echo "Contents of hook $hook:"
  204. while read pri fnr ; do
  205. echo ; echo " $pri ($fnr)"
  206. echo "${hook_functions[fnr]}" | sed 's,^, ,'
  207. done < <( IFS=$'\n'
  208. eval "echo \"\${hookidx_$hook[*]}\"" | sort )
  209. if eval "[ -n \"\$hookdirty_\$hook\" ]"; then
  210. echo ; echo -n " Hook is marked as dirty: "
  211. eval "echo \"\${hookdirty_$hook}\""
  212. fi
  213. done
  214. echo
  215. }
  216. # This function can be used to duplicate a shell-function. E.g. when
  217. # overwriting a shell-function but the old one should stay available under
  218. # a new name:
  219. #
  220. # copy_function set_confopt set_confopt_foobar_old
  221. #
  222. # set_confopt() {
  223. # ....
  224. # set_confopt_foobar_old "$@"
  225. # ....
  226. # }
  227. #
  228. copy_function() {
  229. eval "$( declare -f $1 | sed "1 s,$1,$2," )"
  230. }
  231. # | column_clean |
  232. #
  233. # convert tabs to spaces, transform multiple consecutive spaces to one,
  234. # remove leading and trailing spaces
  235. column_clean() {
  236. tr '\t' ' ' | tr -s ' ' | sed -e 's,^[ ]*,,; s,[ ]*$,,;'
  237. }
  238. # | column_clean_tab |
  239. #
  240. # see column_clean, but with tabs
  241. column_clean_tab() {
  242. tr ' ' '\t' | tr -s '\t' | sed -e 's,^[\t]*,,; s,[\t]*$,,;'
  243. }
  244. # This function sets the 'confopt' and some other variables.
  245. # Re-run it in the package .conf file if you modify $prefix
  246. #
  247. set_confopt() {
  248. local x= z=
  249. prefix=${prefix#/}
  250. if atstage toolchain; then
  251. z="$root"
  252. fi
  253. confopt="--prefix=$z${prefix:+/$prefix}"
  254. for x in bindir sbindir libdir datadir includedir \
  255. docdir infodir mandir sysconfdir localstatedir
  256. do
  257. # bindir=/usr/bin
  258. eval "$x=`pkggetdir $x`"
  259. # --bindir=$root\$bindir
  260. confopt="$confopt --$x=$z\$$x"
  261. done
  262. export LIBSUFF=${libdir##*/lib}
  263. if [ "$SDECFG_CONFIGURE_OPTS" ] ; then
  264. confopt="$confopt $SDECFG_CONFIGURE_OPTS"
  265. fi
  266. if [ "$SDECFG_DEBUG" = 0 ] ; then
  267. confopt="$confopt --disable-debug"
  268. fi
  269. if ! atstage native || [ "$SDECFG_DISABLE_NLS" = 1 ] ; then
  270. confopt="${confopt//--enable-nls/} --disable-nls"
  271. fi
  272. confopt="$confopt \$extraconfopt"
  273. if atstage toolchain; then
  274. confopt="$confopt --target=\$arch_target --build=\$arch_build --host=\$arch_build"
  275. else
  276. confopt="$confopt --build=\$arch_build --host=\$arch_target"
  277. fi
  278. }
  279. #
  280. # eval_config_command $( eval echo $confopt )
  281. #
  282. function eval_config_command() {
  283. local config_command=
  284. local config_cache=$builddir/config.cache.$buildloop
  285. for x in /usr/share/automake/*
  286. do
  287. [ -x "$x" -a -f "$x" ] || continue
  288. x="$( basename "$x" )"
  289. if [ -L $x -a ! -e $x ] ; then
  290. echo "Fixing dead symlink $x."
  291. ln -sf /usr/share/automake/$x .
  292. fi
  293. done
  294. if [ -n "$configcache" ] || atstage cross; then
  295. if atstage cross; then
  296. create_config_cache >> $config_cache
  297. fi
  298. if [ -n "$configcache" ]; then
  299. cat <<-EOT
  300. # Some custom values
  301. EOT
  302. for x in $configcache; do
  303. echo "$x"
  304. done
  305. fi >> $config_cache
  306. grep -q '.--cache-file=' $configscript &&
  307. set -- "$@" "--cache-file=$config_cache"
  308. export cache_file=$config_cache
  309. fi
  310. config_command="$configprefix $configscript"
  311. sub_scripts="$( find $( dirname $configscript ) -name configure )"
  312. if [ "$cleanconfopt" = "0" ]; then
  313. config_command="$config_command $@"
  314. else
  315. # remove unsupported config script options
  316. for x ; do
  317. if grep -q "[[ ]${x%%=*}[]= ):]" $configscript $sub_scripts ; then
  318. config_command="$config_command $x"
  319. elif [[ $x = --*able-* ]] && egrep -q "\-\-(en|dis)able-\*" $configscript ||
  320. [[ $x = --with* ]] && egrep -q "\-\-with(|out)-\*" $configscript; then
  321. echo "Autodetection for option impossible: " \
  322. "$x passed thru."
  323. config_command="$config_command $x"
  324. else
  325. echo "Removing unsupported '$x' from" \
  326. "configure option string."
  327. fi
  328. done
  329. fi
  330. echo Running "$config_command"
  331. eval "$config_command"
  332. }
  333. # run 'make check' if Makefile supports it.
  334. #
  335. function run_check() {
  336. if grep -q -e "^check:" ./Makefile; then
  337. echo "Running make check ..."
  338. $MAKE check
  339. fi
  340. if grep -q -e "^test:" ./Makefile; then
  341. echo "Running make test ..."
  342. $MAKE test
  343. fi
  344. }
  345. # make symlinks relative
  346. #
  347. postflist_dirty_symlinks() {
  348. echo "Processing symlink corrections ..."
  349. while read fn; do
  350. local ffn="$root/$fn"
  351. if [ -L "$ffn" ]; then
  352. local dfn=$(readlink "$ffn")
  353. if [ "${dfn:0:1}" = '/' ]; then
  354. local dfn2="${dfn#$root}"
  355. if [ "$dfn2" != "$dfn" ]; then
  356. echo_warning "dirty symlink: $fn (fixing)"
  357. echo "$fn: dirty!"
  358. dfn="$dfn2"
  359. else
  360. echo_warning "absolute symlink: $fn (fixing)"
  361. echo "$fn: absolute, fixing."
  362. fi
  363. dfn2=$(relative_path "$dfn" "/$fn")
  364. if [ -z "$dfn2" ]; then
  365. echo_error "invalid symlink: $fn (can't fix)"
  366. echo "$fn: invalid!"
  367. continue
  368. fi
  369. ln -svnf "$dfn2" "$ffn"
  370. if [ ! -e "$ffn" ]; then
  371. echo_error "broken absolute symlink: $fn"
  372. echo "$fn: broken"
  373. fi
  374. elif [ ! -e "$ffn" ]; then
  375. echo_error "broken symlink: $fn"
  376. echo "$fn: broken"
  377. fi
  378. fi
  379. done < "$builddir/flist.txt"
  380. }
  381. # move the static libs from lib to usr/lib and correct the libdir used
  382. # inside the .la file
  383. #
  384. postflist_static_lib() {
  385. echo "Processing static lib corrections ..."
  386. egrep '^(lib|lib64)/.*\.(a\..*|a|la|so|pc)$' $builddir/flist.txt |
  387. while read fn ; do
  388. local ffn="$root/$fn" ffn2="$root/usr/$fn"
  389. [ -e "$ffn" -o -L "$ffn" ] || continue
  390. case "$fn" in
  391. *.la)
  392. sed "s,\([ =']\)/lib\(.*\),\1/usr/lib\2,g" \
  393. "$ffn" > "$ffn2"
  394. rm "$ffn"
  395. ;;
  396. *.a|*.pc)
  397. mv -fv "$ffn" "$ffn2"
  398. ;;
  399. *.so)
  400. if [ -L "$ffn" ]; then
  401. local dfn="${ffn%/*}/$(readlink "$ffn")"
  402. dfn=$(relative_path "$dfn" "$ffn2")
  403. ln -svnf "$dfn" "$ffn2"
  404. rm -f "$ffn"
  405. fi
  406. ;;
  407. esac
  408. add_flist "$ffn2"
  409. if [ -L "$ffn2" -a ! -e "$ffn2" ]; then
  410. echo_error "broken symlink: usr/$fn (after static lib correction)"
  411. fi
  412. done
  413. # this check might be removed in the future when we decide this is not
  414. # an issue anymore ...
  415. echo "Verifing the .la files ..."
  416. # defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt |
  417. # xargs egrep 'dependency_libs=.*-pthread.*' |
  418. # cut -d : -f1 | sort -u | tr '\n' ' '`"
  419. # if [ "$defect_la" ] ; then
  420. # abort "-pthread in: $defect_la!"
  421. # fi
  422. defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt |
  423. xargs egrep "dependency_libs=.*(TOOLCHAIN|BACKUP|$SDECFG_ID).*" |
  424. cut -d : -f1 | sort -u | tr '\n' ' '`"
  425. if [ "$defect_la" ]; then
  426. local la
  427. echo_warning "Detected problems in following libtool files:"
  428. for la in $defect_la; do
  429. echo_warning " $la"
  430. done
  431. echo_warning "In absence of a proper fix (or replacement) for libtool and friends,"
  432. echo_warning "for now the .la files are automatically corrected."
  433. # Cleanup dependency_libs, remove build system path
  434. local dependency_libs
  435. local dlibsnew=
  436. local dlibtmp deplib
  437. local libsub=${libdir##*/}
  438. for la in $defect_la; do
  439. eval `grep ^dependency_libs= $root/$la`
  440. for deplib in $dependency_libs; do
  441. if [ $libsub != lib ]; then
  442. case "$deplib" in
  443. */lib|*/lib/*)
  444. deplib="`echo $deplib | sed "s,/lib$,/$libsub,g; s,/lib/,/$libsub/,g"`"
  445. ;;
  446. esac
  447. fi
  448. case "$deplib" in
  449. *TOOLCHAIN*|*BACKUP*|*$SDECFG_ID*) ;;
  450. *)
  451. dlibtmp=$dlibsnew ; var_remove dlibtmp ' ' "$deplib"
  452. [ "$dlibtmp" = "$dlibsnew" ] && var_append dlibsnew ' ' "$deplib"
  453. ;;
  454. esac
  455. done
  456. sed -i "s,^dependency_libs=.*,dependency_libs='$dlibsnew'," $root/$la
  457. dlibsnew=
  458. done
  459. fi
  460. }
  461. # Parse the *.desc file. Use the description from etc/desc_format and
  462. # save the tag data in $desc_*.
  463. #
  464. parse_desc() {
  465. tag="`grep '^\[' $base/etc/desc_format |
  466. sed 's, (\*),,; s,\] \[,|,g; s,\[,,; s,\],,;'`"
  467. for tag in $tag ; do
  468. tagdata="`egrep "^\[($tag)\]" $confdir/$1.desc |
  469. cut -f2- -d']' | sed 's,^ ,,'`"
  470. tag="`echo $tag | cut -f1 -d'|' | tr - _`"
  471. eval "desc_$tag=\"\$tagdata\""
  472. done
  473. ver="`echo "$desc_V" | tail -n 1 | cut -f1 -d' '`"
  474. extraver="`echo "$desc_V" | tail -n 1 | cut -s -f2- -d' '`"
  475. [ -z "$extraver" ] && extraver="${sdever//DEV-*/DEV}"
  476. }
  477. # This function is used for forcing a file to be in the flist
  478. #
  479. add_flist() {
  480. for addfile ; do
  481. echo "$addfile" | fl_wrparse -D -r "$xroot/" \
  482. >> $builddir/flist.txt
  483. done
  484. }
  485. # This function is used for forcing a package to be in the dependency list
  486. #
  487. add_dependency() {
  488. for addpackage ; do
  489. echo "$addpackage: add_dependency()" \
  490. >> $builddir/dependencies.debug
  491. done
  492. }
  493. # This function is used to subsitute some important variables
  494. # using a D_ prefix thru m4 ...
  495. rock_substitute() {
  496. sed -e s,D_prefix,$prefix,g -e s,D_sysconfdir,$sysconfdir,g \
  497. -e s,D_docdir,$docdir,g -e s,D_localstatedir,$localstatedir,g \
  498. -e s,D_datadir,$datadir,g -e s,D_infodir,$infodir,g \
  499. -e s,D_bindir,$bindir,g -e s,D_sbindir,$sbindir,g \
  500. -e s,D_libdir,$libdir,g -e s,D_mandir,$mandir,g \
  501. -e s,D_ver,$ver,g $1
  502. }
  503. # This outputs a predefined config.cache file as it needed by some
  504. # packages to cross-build correctly in stages 0 and 1.
  505. #
  506. create_config_cache() {
  507. cat $base/architecture/share/config.cache
  508. if [ $createarchcache -eq 1 ]; then
  509. cat <<-EOT
  510. # Architecture specific stuff
  511. #
  512. arch_sizeof_char=1
  513. ac_cv_sizeof_short=$arch_sizeof_short
  514. ac_cv_sizeof_int=$arch_sizeof_int
  515. ac_cv_sizeof_long=$arch_sizeof_long
  516. ac_cv_sizeof_long_long=$arch_sizeof_long_long
  517. ac_cv_sizeof_char_p=$arch_sizeof_char_p
  518. ac_cv_sizeof_void_p=$arch_sizeof_char_p
  519. ac_cv_c_bigendian=$arch_bigendian
  520. EOT
  521. fi
  522. }
  523. # Abort build before actual build starts
  524. # (is overwritten in Build-Pkg)
  525. #
  526. abort() {
  527. ${ECHO_E:-echo -e} "The package build aborted with the following config" \
  528. "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err
  529. echo_errorquote "`cat $root/var/adm/logs/$stagelevel-$xpkg.err`"
  530. echo_pkg_abort $stagelevel $repository $xpkg
  531. exit 1
  532. }
  533. # Dump Environment
  534. #
  535. dump_env() {
  536. # Dump $base - only set if there is not already an older value.
  537. #
  538. echo "base=\"\${base:-$base}\""
  539. # Dump all variables including their flags, but skip read-only
  540. # variables and $base.
  541. #
  542. # Substitute base directory with ${base}.
  543. #
  544. for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
  545. ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
  546. ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
  547. ${!y*} ${!z*} \
  548. ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
  549. ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
  550. ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
  551. ${!Y*} ${!Z*} ${!_*}
  552. do
  553. [ $name = base -o $name = PWD ] && continue
  554. if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
  555. then
  556. declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
  557. fi
  558. done
  559. # Dump functions
  560. #
  561. declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
  562. # Dump aliases
  563. #
  564. alias
  565. }
  566. # Returns the value of a field of the .desc file of a package
  567. #
  568. pkgdesc() {
  569. local pattern=
  570. local descfile=$( ls -1d $base/package/*/$2/$2.desc 2> /dev/null )
  571. case "$1" in
  572. ver) pattern="V" ;;
  573. *) pattern="$1" ;;
  574. esac
  575. if [ -s "$descfile" ]; then
  576. case "$1" in
  577. confdir)
  578. echo "${descfile%/*}"
  579. ;;
  580. *)
  581. sed -n "s,^\[$pattern\][ \t]\+\(.\+\)[ \t]*$,\1,p" "$descfile"
  582. ;;
  583. esac
  584. else
  585. echo_error "pkgdesc: Package $2 not found."
  586. fi
  587. }
  588. # Check if a package is already installed
  589. #
  590. # It does check the build-list if not in the rebuild stage - and
  591. # the really installed package data for rebuilds (and so manual builds).
  592. #
  593. # space delimited list, -f as first arguent for effective check
  594. #
  595. pkginstalled() {
  596. local effective=0
  597. if [ $# -eq 0 ]; then
  598. return 1 # nothing
  599. elif [ "$1" = "-f" ]; then
  600. effective=1; shift
  601. elif atstage rebuild; then
  602. effective=1
  603. fi
  604. if [ $effective -eq 0 ]; then
  605. local pattern=
  606. [ $# -gt 0 ] || return 1 # we expect at least one package
  607. if [ $# -eq 1 ]; then
  608. pattern="$1"
  609. else
  610. pattern="($*)"
  611. fi
  612. pattern="${pattern//+/\\+}"
  613. egrep -q "^X.* ${pattern// /|} " $base/config/$config/packages
  614. # we return what egrep returns
  615. else
  616. local pkg=
  617. # be happy if any package from the list is installed
  618. for pkg; do
  619. [ ! -f "$root/var/adm/packages/$pkg" ] || return 0
  620. done
  621. return 1
  622. fi
  623. }
  624. # pkgprefix [-rt] [<type>] <package>
  625. # returns the prefix or the location of a 'type' of an already build package
  626. #
  627. pkgprefix() {
  628. local type= pkg=
  629. local dotest= addroot= wantsroot= abortmsg=
  630. local prefix= value=
  631. while [ $# -gt 1 ]; do
  632. case "$1" in
  633. -t) dotest=1 ;;
  634. -r) addroot="$root" wantsroot="yes" ;;
  635. -*) abortmsg="invalid option $1" ;;
  636. *) break ;;
  637. esac
  638. shift
  639. done
  640. if [ $# -eq 2 ]; then
  641. type="$1"; shift
  642. fi
  643. pkg="$1"
  644. # test usual error causes
  645. if [ -n "$abortmsg" ]; then
  646. :
  647. elif [ -z "$pkg" ]; then
  648. abortmsg="you must specify a package"
  649. elif [ ! -f "$root/var/adm/packages/$pkg" ]; then
  650. abortmsg="package $pkg is not present"
  651. elif grep -q "^Prefix:" "$root/var/adm/packages/$pkg"; then
  652. prefix=$( grep "^Prefix: " "$root/var/adm/packages/$pkg" | cut -d' ' -f2- )
  653. else
  654. abortmsg=`echo "$pkg record is old, please rebuild the package $pkg. As an alternative, you can insert a line into the file $root/var/adm/packages/$pkg containing the text below:\n\nPrefix: <prefix>" | fmt -w 55 | sed 's,$,\\n,g'`
  655. fi
  656. if [ "$dotest" ]; then
  657. # test mode: abort or continue
  658. if [ "$abortmsg" ]; then
  659. abort "pkgprefix: $abortmsg"
  660. else
  661. return 0
  662. fi
  663. elif [ "$abortmsg" ]; then
  664. echo "pkgprefix: $abortmsg" 1>&2
  665. elif [ -z "$type" -o "$type" = "prefix" ]; then
  666. type="prefix"
  667. if [ "$wantsroot" = "yes" ]; then
  668. value="${prefix:+/$prefix}"
  669. else
  670. value="$prefix"
  671. fi
  672. elif [ "$type" = "ver" ]; then
  673. value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 )
  674. else
  675. value=$( grep "^Location $type: " "$root/var/adm/packages/$pkg" | cut -d' ' -f3- )
  676. if [ -z "$value" ]; then
  677. # try default location for that $prefix
  678. value=$( xpkg="$pkg"; pkggetdir "$type" )
  679. fi
  680. fi
  681. if [ -n "$value" -o "$type" = "prefix" ]; then
  682. echo "$addroot$value"
  683. else
  684. echo "PKGPREFIX_ERROR"
  685. fi
  686. }
  687. # pkggetdir <type> (needs $prefix and $xpkg)
  688. # returns the location for the file of a 'type' considering it's prefix
  689. #
  690. pkggetdir() {
  691. local xprefix=${prefix:+/$prefix}
  692. case "$1" in
  693. bindir) echo "$xprefix/bin" ;;
  694. sbindir) echo "$xprefix/sbin" ;;
  695. libdir)
  696. case $arch_machine in
  697. powerpc64|sparc64|x86_64|mips64)
  698. echo "$xprefix/lib64" ;;
  699. *)
  700. echo "$xprefix/lib" ;;
  701. esac
  702. ;;
  703. datadir) echo "${xprefix:-/usr}/share" ;;
  704. infodir) echo "${xprefix:-/usr}/info" ;;
  705. mandir) echo "${xprefix:-/usr}/man" ;;
  706. docdir) echo "${xprefix:-/usr}/doc/$xpkg" ;;
  707. includedir) echo "${xprefix:-/usr}/include" ;;
  708. sysconfdir) echo "/etc${xprefix##/usr*}" ;;
  709. localstatedir) echo "/var${xprefix##/usr*}" ;;
  710. esac
  711. }
  712. #
  713. # pkgchksum package-name
  714. #
  715. pkgchksum() {
  716. (
  717. # expand to full patch if only a package name was specified
  718. [[ $1 == */* ]] || set $base/package/*/$1/
  719. sh "$base/lib/sde-package/pkgchksum.sh" "$1"
  720. )
  721. }
  722. # Add files to the 'badfiles' list
  723. #
  724. register_badfiles() {
  725. local x desc="$1"
  726. shift
  727. for x in "$@"; do
  728. var_append badfiles $'\n' " $x\$"
  729. badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
  730. (( badfiles_nr++ ))
  731. done
  732. }
  733. # Detect the available patchfiles
  734. #
  735. detect_patchfiles()
  736. {
  737. local x= y=
  738. patchfiles="`ls $confdir/*.patch{,.$arch} \
  739. $confdir/*.patch_$xpkg{.$arch} \
  740. 2> /dev/null | tr '\n' ' '`"
  741. for x in $( get_reverted $targetchain ); do
  742. for y in pkg_$pkg.patch{,.$arch} xpkg_$xpkg.patch{,.$arch}; do
  743. if [ -f $base/target/$x/$y ]; then
  744. patchfiles="$patchfiles $base/target/$x/$y"
  745. fi
  746. done
  747. done
  748. }
  749. # Apply the given $patchfiles
  750. # [ hook called for each patch ] [ filter script ]
  751. #
  752. apply_patchfiles() {
  753. local hook="$1"
  754. local filter="$2"
  755. [ "$filter" ] || filter=cat
  756. for x in $patchfiles; do
  757. # correct the abolute path - e.g for patchfiles supplied
  758. # in the .desc file
  759. # we assume relative path patches are mirrorables //mnemoc
  760. if [ ! -e "$x" -a -n "${x##*/*}" ] ; then
  761. x="$base/download/mirror/${x:0:1}/$x"
  762. fi
  763. # Apply the patch if the file does exist or issue a warning
  764. if [ -f "$x" ] ; then
  765. echo "Apply patch $x ..."
  766. if [[ $x = *.bz2 ]] ; then
  767. patch_file=`mktemp` ; patch_del=1
  768. bzcat $x > $patch_file
  769. else
  770. patch_file=$x ; patch_del=0
  771. fi
  772. $filter $patch_file | patch $patchopt
  773. [ $patch_del = 1 ] && rm $patch_file
  774. eval "$hook"
  775. else
  776. echo_warning "Unable to apply patch: $x (File not found!)"
  777. fi
  778. done
  779. }
  780. # -------------------------------------------------------------------
  781. # The automatic extraction of archive (prior to building) supports
  782. # multiple archive types. For every archive type we have a separate
  783. # func that knows how to extract the archive. However, every func
  784. # should deliver two file: untar.txt and xsrcdir.txt.
  785. #
  786. # untar.txt needs to contain all extracted files.
  787. # xsrcdir.txt need to contain the top level extraction directories.
  788. # -------------------------------------------------------------------
  789. autoextract_tar_bz2() {
  790. echo "Extracting $xsrctar ($taropt) ... "
  791. tar -v $taropt $1 > untar.txt
  792. }
  793. autoextract_subdir_tar_bz2() {
  794. local taropt_orig="$taropt"
  795. mkdir -p "$pkg-$ver"
  796. taropt="-C $pkg-$ver $taropt"
  797. autoextract_tar_bz2 "$@"
  798. taropt="$taropt_orig"
  799. }
  800. autoextract_zip() {
  801. echo "Extracting $xsrctar ($zipopt) ... "
  802. unzip $zipopt $1 | sed 's,^.*/$,,' |
  803. cut -f4 -d" " | grep -v "^$" > untar.txt
  804. }
  805. autoextract_subdir_zip() {
  806. local zipopt_orig="$zipopt"
  807. mkdir -p "$pkg-$ver"
  808. zipopt="-d $pkg-$ver $zipopt"
  809. autoextract_zip "$@"
  810. zipopt="$zipopt_orig"
  811. }
  812. createprefix_function() {
  813. echo "Creating $root/$prefix/<..> if required ..."
  814. local dir=
  815. local foodir=
  816. for foodir in $foodirlist; do
  817. eval "dir=\"$root\$$foodir\""
  818. if [ ! -e $dir ]; then
  819. mkdir -p $dir
  820. rmemptydir="$rmemptydir $dir"
  821. fi
  822. case $foodir in
  823. libdir)
  824. # create lib -> lib64 compat symlinks
  825. # TODO: MULTILIB
  826. if [[ "$dir" = *lib64 ]] && [ ! -e "$root/$prefix/lib" ]; then
  827. echo "Creating 'lib -> lib64' compatibility symlink"
  828. ln -sf lib64 "$root/$prefix/lib"
  829. fi
  830. ;;
  831. esac
  832. done
  833. }
  834. # Main program for building a package
  835. #
  836. build_this_package() {
  837. if [ ".$desc_SRC" = "." ] ; then
  838. # Autodetect source tar and extract it
  839. #
  840. if [ "$srctar" = auto ] ; then
  841. xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' |
  842. cut -f2 | bz2filename )
  843. if [ -z "$xsourceballs" ] ; then
  844. echo "Can't auto-detect srctar for package '$xpkg'!"
  845. false
  846. fi
  847. else
  848. xsourceballs="$srctar"
  849. fi
  850. elif [ "$srctar" = auto ] ; then
  851. sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' |
  852. cut -f2 | bz2filename )
  853. xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' )
  854. xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
  855. else
  856. xsourceballs="$srctar"
  857. fi
  858. for xsrctar in $xsourceballs; do
  859. saved_patchfiles="$patchfiles"
  860. buildloop=1
  861. var_append patchfiles " " \
  862. "`ls $confdir/*.patch.${xsrctar/-[v0-9]*/} 2> /dev/null`"
  863. if [ -d "$confdir/$xsrctar" ]; then
  864. xsrcdir="$pkg-$ver-$xsrctar"
  865. cp -a "$confdir/$xsrctar" "$builddir/$xsrcdir"
  866. cd "$builddir/$xsrcdir"
  867. elif [ "$xsrctar" != none -a "$autoextract" = 1 ]; then
  868. cd $builddir
  869. if [ -z "$custextract" ]; then
  870. # No custom extraction, so determine what
  871. # autoextraction to use.
  872. case "$xsrctar" in
  873. *.zip) custextract="autoextract_zip" ;;
  874. *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz
  875. esac
  876. fi
  877. if [ -n "$custextract" ]; then
  878. # Do the actual extraction of the archive.
  879. eval "$custextract $archdir/$xsrctar"
  880. cat untar.txt |
  881. sed 's,^\./,,' | cut -f1 -d/ |
  882. sort -u > xsrcdir.txt
  883. fi
  884. #
  885. if [ "$srcdir" = auto ]; then
  886. xsrcdir=${xsrctar%.tar.bz2}
  887. xsrcdir=${xsrcdir%.tbz2}
  888. xsrcdir=${xsrcdir%.tbz}
  889. if [ ! -d $xsrcdir ] ; then
  890. for x in $pkg-$ver ${pkg}_$ver $pkg \
  891. $xpkg-$ver ${xpkg}_$ver $xpkg \
  892. "$( cat xsrcdir.txt )"
  893. do
  894. [ -d "$x" ] && xsrcdir="$x"
  895. done
  896. fi
  897. else
  898. xsrcdir="$srcdir"
  899. fi
  900. #
  901. if [ "$chownsrcdir" = 1 ]; then
  902. echo "Fixing ownership and permissions ..."
  903. chown -R 0:0 $builddir/$xsrcdir
  904. fi
  905. #
  906. if [ "$nocvsinsrcdir" = 1 ]; then
  907. echo "Removing CVS, .svn, .git, {arch} and .arch-ids directories ..."
  908. egrep '(^|/)(CVS|\.svn|\.git|\{arch\}|\.arch-ids)(/|$)' untar.txt |
  909. while read x; do
  910. echo "Removing $x ..."
  911. rm -rf "$x"
  912. done
  913. fi
  914. #
  915. echo "Changeing into $builddir/$xsrcdir ..."
  916. cd $builddir/$xsrcdir
  917. # Apply patches
  918. #
  919. if [ $autopatch = 1 ]; then
  920. hook_eval prepatch
  921. apply_patchfiles
  922. hook_eval postpatch
  923. fi
  924. else
  925. cd $builddir
  926. fi
  927. if [ "$createprefix" = 1 ]; then
  928. createprefix_function
  929. fi
  930. if [ -z "$custmain" ]; then
  931. while [ ${buildloop:-1} -le ${buildloops:-1} ]; do
  932. [ "${buildloops:-1}" = "1" ] || echo "loop ${buildloop:-1} of ${buildloops:-1} for $xsrctar."
  933. hook_eval preconf
  934. # Maybe generate a configure first
  935. #
  936. if [ $autogen -eq 1 -o \
  937. \( -f autogen.sh -a ! -f configure \) ] ; then
  938. if [ -f autogen.sh ] ; then
  939. echo "Running package autogen script."
  940. sed -i '/^\.\/configure /d' autogen.sh
  941. sh autogen.sh
  942. else
  943. echo "Running builtin autogen script."
  944. libtoolize --force --automake
  945. aclocal $ACLOCAL_FLAGS
  946. if grep AM_INIT_AUTOMAKE configure.[ia][nc]; then
  947. automake --add-missing
  948. fi
  949. autoconf
  950. fi
  951. fi
  952. # Run configure scripts etc.
  953. #
  954. if [ $runconf = 1 ]; then
  955. if [ -n "$( type -p $configscript )" -o $autogen = 1 ]
  956. then
  957. eval_config_command $( eval echo $confopt )
  958. fi
  959. fi
  960. # CMake based Makefile generation
  961. #
  962. if [ -f CMakeLists.txt -a $runcmake = 1 -a ! -f Makefile ]; then
  963. local cmakesrcdir='..'
  964. # check if we use a dedicated build directory
  965. if [ $cmakebuilddir = 1 ]; then
  966. mkdir -p build
  967. cd build
  968. else
  969. cmakesrcdir='.'
  970. fi
  971. eval echo "Running cmake $cmakeopt"
  972. cmake $( eval echo $cmakeopt $cmakesrcdir )
  973. fi
  974. # automated package build
  975. # styles without make run first:
  976. if [ -f setup.py -a $runpysetup = 1 ] ; then
  977. hook_eval premake
  978. eval ${pyscript:-python} setup.py $pyconfopt \
  979. build $pybuildopt \
  980. install $pyinstopt
  981. hook_eval postmake
  982. elif [ -f waf -a $runwaf = 1 ] ; then
  983. wafconfopt="${wafconfopt:=configure --prefix=/$prefix}"
  984. wafbuildopt="${wafbuildopt:=build}"
  985. wafinstopt="${wafinstopt:=install --destdir=$root --force}"
  986. hook_eval premake
  987. eval ${wafscript:-./waf} $wafconfopt
  988. eval ${wafscript:-./waf} $wafbuildopt
  989. hook_eval inmake
  990. eval ${wafscript:-./waf} $wafinstopt
  991. hook_eval postmake
  992. elif [ -f Sconstruct -o -f SConstruct -a $runscons = 1 -a ! -f configure ] ; then
  993. hook_eval premake
  994. eval ${sconsscript:-scons} $sconsopt
  995. hook_eval inmake
  996. hook_eval postmake
  997. else # styles that include a make run
  998. if [ ! -f Makefile -a ! -f makefile -a \
  999. -f Makefile.PL -a $runmkpl = 1 ]; then
  1000. # always install into 'vendor' directory
  1001. var_append plconfopt ' ' "INSTALLDIRS=vendor"
  1002. perl Makefile.PL $plconfopt
  1003. fi
  1004. #
  1005. if [ ! -f Makefile -a ! -f makefile -a \
  1006. -f Imakefile -a $runxmkmf = 1 ]; then
  1007. xmkmf -a
  1008. fi
  1009. #
  1010. # Build it
  1011. #
  1012. hook_eval premake
  1013. if [ "$makeopt" ]; then
  1014. eval echo "Running $MAKE $makeopt"
  1015. eval "$MAKE $makeopt"
  1016. fi
  1017. hook_eval inmake
  1018. if [ "$makeinstopt" ]; then
  1019. eval echo "Running $MAKE $makeinstopt"
  1020. eval "$MAKE $makeinstopt"
  1021. fi
  1022. hook_eval postmake
  1023. fi
  1024. buildloop=$( expr ${buildloop:-1} + 1 )
  1025. done
  1026. else
  1027. eval "$custmain"
  1028. for x in preconf premake inmake postmake; do
  1029. if eval "[ -n \"\$hookdirty_$x\" ]"; then
  1030. echo "Hook $x is still marked as dirty ..."
  1031. hook_eval $x
  1032. fi
  1033. done
  1034. fi
  1035. if [ "$createdocs" != 0 ]; then
  1036. if [ ! -e $root$docdir ]; then
  1037. mkdir -p $docdir
  1038. rmemptydir="$rmemptydir $root$docdir"
  1039. fi
  1040. [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
  1041. fi
  1042. if [ "$createdocs" = 1 ]; then
  1043. echo "Trying to copy the default documentation ..."
  1044. for x in [A-Z][A-Z]* *.lsm ChangeLog* README LICENSE COPYING; do
  1045. [ "${x#*.[cho0-9]}" ] || continue
  1046. [ "${x#*.info*}" ] || continue
  1047. [ "${x#*.TAR*}" ] || continue
  1048. [ "${x#*akefile*}" ] || continue
  1049. [ -f $x ] && cp -v $x $root$docdir/$x
  1050. done
  1051. echo "Trying to copy even more documentation ..."
  1052. [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
  1053. for x in `find -type d \( -name 'doc' -o -name 'docs' \
  1054. -o -name '[Dd]ocumentation' \) ! -empty`
  1055. do
  1056. if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
  1057. then cp -rLv $x/* $root$docdir || true ; fi
  1058. done
  1059. for x in $confdir/*.doc; do
  1060. if [ -f $x ]
  1061. then cp -v $x $root$docdir/${x%.doc}; fi
  1062. done
  1063. find $root$docdir/ -name '*.[0-9]' -o -name '*.info*' \
  1064. -o -name '[Mm]akefile*' |
  1065. xargs -r rm -f 2> /dev/null || true
  1066. find $root$docdir/* -type d -empty 2> /dev/null |
  1067. xargs -r rmdir 2> /dev/null || true
  1068. fi
  1069. hook_eval postdoc
  1070. if atstage native && [ -f /sbin/ldconfig ] ; then
  1071. echo "Running ldconfig ..."
  1072. ldconfig
  1073. fi
  1074. patchfiles="$saved_patchfiles"
  1075. done
  1076. if [ "$rmemptydir" ]; then
  1077. rmdir $rmemptydir 2> /dev/null || true
  1078. fi
  1079. return 0
  1080. }
  1081. # source_file cksum file url
  1082. #
  1083. # Create the file path from 'file' and 'url'.
  1084. # cksum and url are ignored
  1085. # ([D] tag compatible format)
  1086. #
  1087. source_file() {
  1088. local pre= file="$2" url="$3" mirror="mirror"
  1089. # '-' as $url prefix means, nomirrorable
  1090. [ "${url:0:1}" = "-" ] && mirror="local"
  1091. # inside Build-Pkg $archdir is set
  1092. if [ -n "$archdir" ]; then
  1093. pre=$base/; file="$( bz2filename $file )"
  1094. fi
  1095. echo ${pre}download/${mirror}/${file:0:1}/$file
  1096. }
  1097. # match_source_file [-p] pattern [[package] ...]
  1098. #
  1099. # returns path and name of a downloaded file from a list of packages, matching a grep pattern
  1100. # without -p it only returns it's name, not the path.
  1101. #
  1102. match_source_file() {
  1103. local pattern= package= showpath=0
  1104. local x= file= url= mirror=
  1105. local found=1
  1106. if [ "$1" = "-p" ]; then
  1107. showpath=1; shift
  1108. fi
  1109. pattern="$1"; shift
  1110. for package in ${*:-$pkg}; do
  1111. while read x x file url x; do
  1112. file="$( bz2filename $file )"
  1113. found=0
  1114. if [ $showpath -eq 0 ]; then
  1115. echo $file
  1116. else
  1117. [ "${url:0:1}" = "-" ] && mirror="local" || mirror="mirror"
  1118. echo $base/download/${mirror}/${file:0:1}/$file
  1119. fi
  1120. done < <( grep -e "^\[D\].*$pattern" $base/package/*/$package/$package.desc )
  1121. done
  1122. return $found
  1123. }
  1124. # create the virtual $archdir symlinks
  1125. #
  1126. populate_archdir()
  1127. {
  1128. local x= missing=0
  1129. for x in `match_source_file -p .`; do
  1130. if [ ! -f $x ]; then
  1131. echo_warning "File not found: ${x#$base/}"
  1132. missing=1
  1133. elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
  1134. ln -vs $x $builddir/archdir/
  1135. fi
  1136. done
  1137. if [ $missing -eq 1 ]; then
  1138. echo_warning "Did you run download for this package?"
  1139. false
  1140. fi
  1141. }
  1142. # search for the package confdir
  1143. #
  1144. detect_confdir()
  1145. {
  1146. confdir=
  1147. if [ -z "$pkgdir" ] ; then
  1148. for x in package/*/$pkg/$pkg.desc ; do
  1149. if [ -f "$x" ] ; then
  1150. if [ "$confdir" ] ; then
  1151. echo_pkg_deny $stagelevel $pkg "in multiple trees"
  1152. echo "Package in multiple trees: $pkg !" \
  1153. > $root/var/adm/logs/$stagelevel-$xpkg.err
  1154. exit 1
  1155. fi
  1156. x=${x#package/}; x=${x%%/*}
  1157. confdir="$base/package/$x/$pkg"
  1158. repository=$x
  1159. fi
  1160. done
  1161. else
  1162. if [ -f "$pkgdir/$pkg.desc" ] ; then
  1163. confdir="$pkgdir"
  1164. repository=extern
  1165. fi
  1166. fi
  1167. }
  1168. # initialize standard vars and hooks
  1169. #
  1170. init_vars_and_hooks()
  1171. {
  1172. makeopt='CC="$CC" CPP="$CPP" CXX="$CXX"'
  1173. cmakeopt='-DCMAKE_INSTALL_PREFIX="$root/$prefix"'
  1174. cmakeopt="$cmakeopt"' -DCMAKE_LIBRARY_PATH="$libdir"'
  1175. cmakebuilddir=1
  1176. # some scons based builds are using 'prefix' others 'PREFIX'
  1177. sconsopt='PREFIX=/$prefix prefix=/$prefix install'
  1178. # python builds
  1179. pybuildopt=
  1180. pyinstopt='--prefix=/$prefix'
  1181. if atstage toolchain; then
  1182. makeopt="$makeopt"' prefix="$root${prefix:+/$prefix}"'
  1183. else
  1184. makeopt="$makeopt"' prefix="${prefix:+/$prefix}"'
  1185. fi
  1186. if ! atstage native; then
  1187. makeopt="$makeopt"' CC_FOR_BUILD="$BUILDCC"'
  1188. makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
  1189. makeopt="$makeopt"' HOSTCC="$HOSTCC" HOST_CC="$HOST_CC"'
  1190. makeopt="$makeopt"' STRIP="$STRIP" AR="$AR" LD="$LD"'
  1191. makeopt="$makeopt"' RANLIB="$RANLIB" NM="$NM"'
  1192. fi
  1193. if atstage native; then
  1194. flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
  1195. fi
  1196. if atstage cross; then
  1197. makeopt="$makeopt"' INSTALL_PREFIX="$root"'
  1198. makeopt="$makeopt"' DESTDIR="$root" DEST_DIR="$root"'
  1199. makeopt="$makeopt"' INSTROOT="$root" INSTALLROOT="$root"'
  1200. # scons based build
  1201. sconsopt='DESTDIR="$root" '"$sconsopt"
  1202. fi
  1203. makeinstopt="$makeopt"' install'
  1204. custmain=
  1205. buildloop=1 buildloops=1
  1206. [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
  1207. hook_add postflist 3 'postflist_dirty_symlinks'
  1208. # no static lib corrections at toolchain stage
  1209. atstage toolchain || hook_add postflist 3 'postflist_static_lib'
  1210. createarchcache=0
  1211. configprefix=; configcache= ; autogen=0
  1212. configscript="./configure" ; extraconfopt=
  1213. srcdir=auto ; srctar=auto
  1214. taropt="--use-compress-program=bzip2 -xf"
  1215. mainfunction="build_this_package"
  1216. runconf=1 ; runcmake=1 ; runxmkmf=1 ; runmkpl=1 ; runpysetup=1 ; runwaf=1 ;
  1217. runscons=1 ;
  1218. autopatch=1 ; autoextract=1 ; chownsrcdir=1 ; nocvsinsrcdir=1 ; cleanconfopt=1
  1219. patchopt="-bfp1 -z .orig"
  1220. createprefix=1 ; createdocs= ; rmemptydir=
  1221. check_shared=1
  1222. check_usrlocal=1
  1223. check_badfiles=1
  1224. badfiles= badfiles_nr=0
  1225. declare -a badfiles_desc
  1226. }
  1227. # this is a 2nd lightweight and modular "build this package" implementation
  1228. # currently only used for the postlinux stuff - later maybe for more -ReneR
  1229. #
  1230. build_package()
  1231. {
  1232. logstamp=$PWD/log
  1233. (
  1234. set -e
  1235. pushd $base
  1236. super=$pkg
  1237. pkg="$1" ; xpkg="$pkg"
  1238. conffile="$2" ; [ "$conffile" ] || conffile="$pkg.conf"
  1239. unset ${!hook*}
  1240. declare -a hook_functions='()'
  1241. hook_fcounter=0
  1242. init_vars_and_hooks
  1243. detect_confdir
  1244. detect_patchfiles
  1245. parse_desc $pkg
  1246. # Erase positional parameters to prevent unintended parameter
  1247. # passing. We do not want to pass the current positional parameters
  1248. # to the loaded script.
  1249. set --
  1250. eval "$desc_O"
  1251. echo_status "Building $xpkg ($ver) within $super (using $conffile)."
  1252. for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
  1253. $confdir/$conffile; do
  1254. if [ -f $x ]; then
  1255. if [[ $x == */$conffile ]]; then
  1256. echo "Reading package configuration ($conffile) from package directory."
  1257. else
  1258. echo "Reading package configuration from target directory."
  1259. fi
  1260. . $x
  1261. break
  1262. fi
  1263. done
  1264. # short path - to not abort on missing downloads of postlinux.conf
  1265. # packages that are not built anyway -ReneR
  1266. if [ "$custmain" = "true" ] ; then
  1267. echo "Nothing is going to be done ayway - returning quickly."
  1268. return
  1269. fi
  1270. populate_archdir
  1271. popd
  1272. # dump for debugging
  1273. hook_dump > $builddir/debug.hooks.$pkg
  1274. dump_env > $builddir/debug.buildenv.$pkg
  1275. echo "Running main build function '$mainfunction' ..."
  1276. cd $builddir
  1277. eval "$mainfunction"
  1278. touch $logstamp
  1279. )
  1280. [ -f $logstamp ] || return 1
  1281. rm $logstamp
  1282. return 0
  1283. }