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.

1556 lines
39 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 - 2020 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.*|5.*)
  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|o|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) # move libtool archives to usr/lib and fixup the
  392. # dependency_libs and libdir entries accordingly
  393. local dependency_libs
  394. local deplibsnew
  395. eval `grep ^dependency_libs= $ffn`
  396. for deplib in $dependency_libs; do
  397. case "$deplib" in
  398. $libdir/*.la)
  399. deplib="`echo $deplib | sed "s,$libdir,/usr$libdir,g"`"
  400. ;;
  401. esac
  402. var_append deplibsnew ' ' "$deplib"
  403. done
  404. sed -e "s,^dependency_libs=.*,dependency_libs=' $deplibsnew'," \
  405. -e "s,^libdir=.*,libdir='/usr$libdir'," \
  406. "$ffn" > "$ffn2"
  407. rm "$ffn"
  408. unset dependency_libs
  409. unset deplibsnew
  410. ;;
  411. *.a|*.o|*.pc)
  412. mv -fv "$ffn" "$ffn2"
  413. ;;
  414. *.so)
  415. if [ -L "$ffn" ]; then
  416. local dfn="${ffn%/*}/$(readlink "$ffn")"
  417. dfn=$(relative_path "$dfn" "$ffn2")
  418. ln -svnf "$dfn" "$ffn2"
  419. rm -f "$ffn"
  420. fi
  421. ;;
  422. esac
  423. add_flist "$ffn2"
  424. if [ -L "$ffn2" -a ! -e "$ffn2" ]; then
  425. echo_error "broken symlink: usr/$fn (after static lib correction)"
  426. fi
  427. done
  428. # this check might be removed in the future when we decide this is not
  429. # an issue anymore ...
  430. echo "Verifing the .la files ..."
  431. # defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt |
  432. # xargs egrep 'dependency_libs=.*-pthread.*' |
  433. # cut -d : -f1 | sort -u | tr '\n' ' '`"
  434. # if [ "$defect_la" ] ; then
  435. # abort "-pthread in: $defect_la!"
  436. # fi
  437. defect_la="`egrep '(lib|lib64)/.*\.la$' $builddir/flist.txt |
  438. xargs egrep "dependency_libs=.*(TOOLCHAIN|BACKUP|$SDECFG_ID).*" |
  439. cut -d : -f1 | sort -u | tr '\n' ' '`"
  440. if [ "$defect_la" ]; then
  441. local la
  442. echo_warning "Detected problems in following libtool files:"
  443. for la in $defect_la; do
  444. echo_warning " $la"
  445. done
  446. echo_warning "In absence of a proper fix (or replacement) for libtool and friends,"
  447. echo_warning "for now the .la files are automatically corrected."
  448. # Cleanup dependency_libs, remove build system path
  449. local dependency_libs
  450. local dlibsnew=
  451. local dlibtmp deplib
  452. local libsub=${libdir##*/}
  453. for la in $defect_la; do
  454. eval `grep ^dependency_libs= $root/$la`
  455. for deplib in $dependency_libs; do
  456. if [ $libsub != lib ]; then
  457. case "$deplib" in
  458. */lib|*/lib/*)
  459. deplib="`echo $deplib | sed "s,/lib$,/$libsub,g; s,/lib/,/$libsub/,g"`"
  460. ;;
  461. esac
  462. fi
  463. case "$deplib" in
  464. *TOOLCHAIN*|*BACKUP*|*$SDECFG_ID*) ;;
  465. *)
  466. dlibtmp=$dlibsnew ; var_remove dlibtmp ' ' "$deplib"
  467. [ "$dlibtmp" = "$dlibsnew" ] && var_append dlibsnew ' ' "$deplib"
  468. ;;
  469. esac
  470. done
  471. sed -i "s,^dependency_libs=.*,dependency_libs='$dlibsnew'," $root/$la
  472. dlibsnew=
  473. done
  474. fi
  475. }
  476. # Parse the *.desc file. Use the description from etc/desc_format and
  477. # save the tag data in $desc_*.
  478. #
  479. parse_desc() {
  480. tag="`grep '^\[' $base/etc/desc_format |
  481. sed 's, (\*),,; s,\] \[,|,g; s,\[,,; s,\],,;'`"
  482. for tag in $tag ; do
  483. tagdata="`egrep "^\[($tag)\]" $confdir/$1.desc |
  484. cut -f2- -d']' | sed 's,^ ,,'`"
  485. tag="`echo $tag | cut -f1 -d'|' | tr - _`"
  486. eval "desc_$tag=\"\$tagdata\""
  487. done
  488. ver="`echo "$desc_V" | tail -n 1 | cut -f1 -d' '`"
  489. extraver="`echo "$desc_V" | tail -n 1 | cut -s -f2- -d' '`"
  490. [ -z "$extraver" ] && extraver="${sdever//DEV-*/DEV}"
  491. }
  492. # This function is used for forcing a file to be in the flist
  493. #
  494. add_flist() {
  495. for addfile ; do
  496. echo "$addfile" | fl_wrparse -D -r "$xroot/" \
  497. >> $builddir/flist.txt
  498. done
  499. }
  500. # This function is used for forcing a package to be in the dependency list
  501. #
  502. add_dependency() {
  503. for addpackage ; do
  504. echo "$addpackage: add_dependency()" \
  505. >> $builddir/dependencies.debug
  506. done
  507. }
  508. # This function is used to subsitute some important variables
  509. # using a D_ prefix thru m4 ...
  510. rock_substitute() {
  511. sed -e s,D_prefix,$prefix,g -e s,D_sysconfdir,$sysconfdir,g \
  512. -e s,D_docdir,$docdir,g -e s,D_localstatedir,$localstatedir,g \
  513. -e s,D_datadir,$datadir,g -e s,D_infodir,$infodir,g \
  514. -e s,D_bindir,$bindir,g -e s,D_sbindir,$sbindir,g \
  515. -e s,D_libdir,$libdir,g -e s,D_mandir,$mandir,g \
  516. -e s,D_ver,$ver,g $1
  517. }
  518. # This outputs a predefined config.cache file as it needed by some
  519. # packages to cross-build correctly in stages 0 and 1.
  520. #
  521. create_config_cache() {
  522. if [ -e $base/architecture/share/config.cache ]; then
  523. cat $base/architecture/share/config.cache
  524. fi
  525. if [ $createarchcache -eq 1 ]; then
  526. cat <<-EOT
  527. # Architecture specific stuff
  528. #
  529. arch_sizeof_char=1
  530. ac_cv_sizeof_short=$arch_sizeof_short
  531. ac_cv_sizeof_int=$arch_sizeof_int
  532. ac_cv_sizeof_long=$arch_sizeof_long
  533. ac_cv_sizeof_long_long=$arch_sizeof_long_long
  534. ac_cv_sizeof_char_p=$arch_sizeof_char_p
  535. ac_cv_sizeof_void_p=$arch_sizeof_char_p
  536. ac_cv_c_bigendian=$arch_bigendian
  537. EOT
  538. fi
  539. if [ -n "$configcachefile" ]; then
  540. for x in $configcachefile; do
  541. if [ -e $x ]; then
  542. cat <<-EOT
  543. # cache file: $x
  544. EOT
  545. cat "$x"
  546. fi
  547. done
  548. fi
  549. }
  550. # Abort build before actual build starts
  551. # (is overwritten in Build-Pkg)
  552. #
  553. abort() {
  554. ${ECHO_E:-echo -e} "The package build aborted with the following config" \
  555. "error:\n$*" > $root/var/adm/logs/$stagelevel-$xpkg.err
  556. echo_errorquote "`cat $root/var/adm/logs/$stagelevel-$xpkg.err`"
  557. echo_pkg_abort $stagelevel $repository $xpkg
  558. exit 1
  559. }
  560. # Dump Environment
  561. #
  562. dump_env() {
  563. # Dump $base - only set if there is not already an older value.
  564. #
  565. echo "base=\"\${base:-$base}\""
  566. # Dump all variables including their flags, but skip read-only
  567. # variables and $base.
  568. #
  569. # Substitute base directory with ${base}.
  570. #
  571. for name in ${!a*} ${!b*} ${!c*} ${!d*} ${!e*} ${!f*} ${!g*} ${!h*} \
  572. ${!i*} ${!j*} ${!k*} ${!l*} ${!m*} ${!n*} ${!o*} ${!p*} \
  573. ${!q*} ${!r*} ${!s*} ${!t*} ${!u*} ${!v*} ${!w*} ${!x*} \
  574. ${!y*} ${!z*} \
  575. ${!A*} ${!B*} ${!C*} ${!D*} ${!E*} ${!F*} ${!G*} ${!H*} \
  576. ${!I*} ${!J*} ${!K*} ${!L*} ${!M*} ${!N*} ${!O*} ${!P*} \
  577. ${!Q*} ${!R*} ${!S*} ${!T*} ${!U*} ${!V*} ${!W*} ${!X*} \
  578. ${!Y*} ${!Z*} ${!_*}
  579. do
  580. [ $name = base -o $name = PWD ] && continue
  581. if declare -p $name | head -n 1 | grep -qv '^declare -[a-z]*r'
  582. then
  583. declare -p $name | sed "s,\\(^\\|[\"=:]\\)$base\\([\"=:/]\\|\$\\),\\1\${base}\\2,g"
  584. fi
  585. done
  586. # Dump functions
  587. #
  588. declare -f | sed 's/^declare -f //; s/<<(/< <(/;'
  589. # Dump aliases
  590. #
  591. alias
  592. }
  593. # Returns the value of a field of the .desc file of a package
  594. #
  595. pkgdesc() {
  596. local pattern=
  597. local descfile=$( ls -1d $base/package/*/$2/$2.desc 2> /dev/null )
  598. case "$1" in
  599. ver) pattern="V" ;;
  600. *) pattern="$1" ;;
  601. esac
  602. if [ -s "$descfile" ]; then
  603. case "$1" in
  604. confdir)
  605. echo "${descfile%/*}"
  606. ;;
  607. *)
  608. sed -n "s,^\[$pattern\][ \t]\+\(.\+\)[ \t]*$,\1,p" "$descfile"
  609. ;;
  610. esac
  611. else
  612. echo_error "pkgdesc: Package $2 not found."
  613. fi
  614. }
  615. # Check if a package is already installed
  616. #
  617. # It does check the build-list if not in the rebuild stage - and
  618. # the really installed package data for rebuilds (and so manual builds).
  619. #
  620. # space delimited list, -f as first arguent for effective check
  621. #
  622. pkginstalled() {
  623. local effective=0
  624. if [ $# -eq 0 ]; then
  625. return 1 # nothing
  626. elif [ "$1" = "-f" ]; then
  627. effective=1; shift
  628. elif atstage rebuild; then
  629. effective=1
  630. fi
  631. if [ $effective -eq 0 ]; then
  632. local pattern=
  633. [ $# -gt 0 ] || return 1 # we expect at least one package
  634. if [ $# -eq 1 ]; then
  635. pattern="$1"
  636. else
  637. pattern="($*)"
  638. fi
  639. pattern="${pattern//+/\\+}"
  640. egrep -q "^X.* ${pattern// /|} " $base/config/$config/packages
  641. # we return what egrep returns
  642. else
  643. local pkg=
  644. # be happy if any package from the list is installed
  645. for pkg; do
  646. [ ! -f "$root/var/adm/packages/$pkg" ] || return 0
  647. done
  648. return 1
  649. fi
  650. }
  651. # pkgprefix [-rt] [<type>] <package>
  652. # returns the prefix or the location of a 'type' of an already build package
  653. #
  654. pkgprefix() {
  655. local type= pkg=
  656. local dotest= addroot= wantsroot= abortmsg=
  657. local prefix= value=
  658. while [ $# -gt 1 ]; do
  659. case "$1" in
  660. -t) dotest=1 ;;
  661. -r) addroot="$root" wantsroot="yes" ;;
  662. -*) abortmsg="invalid option $1" ;;
  663. *) break ;;
  664. esac
  665. shift
  666. done
  667. if [ $# -eq 2 ]; then
  668. type="$1"; shift
  669. fi
  670. pkg="$1"
  671. # test usual error causes
  672. if [ -n "$abortmsg" ]; then
  673. :
  674. elif [ -z "$pkg" ]; then
  675. abortmsg="you must specify a package"
  676. elif [ ! -f "$root/var/adm/packages/$pkg" ]; then
  677. abortmsg="package $pkg is not present"
  678. elif grep -q "^Prefix:" "$root/var/adm/packages/$pkg"; then
  679. prefix=$( grep "^Prefix: " "$root/var/adm/packages/$pkg" | cut -d' ' -f2- )
  680. else
  681. 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'`
  682. fi
  683. if [ "$dotest" ]; then
  684. # test mode: abort or continue
  685. if [ "$abortmsg" ]; then
  686. abort "pkgprefix: $abortmsg"
  687. else
  688. return 0
  689. fi
  690. elif [ "$abortmsg" ]; then
  691. echo "pkgprefix: $abortmsg" 1>&2
  692. elif [ -z "$type" -o "$type" = "prefix" ]; then
  693. type="prefix"
  694. if [ "$wantsroot" = "yes" ]; then
  695. value="${prefix:+/$prefix}"
  696. else
  697. value="$prefix"
  698. fi
  699. elif [ "$type" = "ver" ]; then
  700. value=$( grep "^Package Name and Version:" "$root/var/adm/packages/$pkg" | cut -d' ' -f6 )
  701. else
  702. value=$( grep "^Location $type: " "$root/var/adm/packages/$pkg" | cut -d' ' -f3- )
  703. if [ -z "$value" ]; then
  704. # try default location for that $prefix
  705. value=$( xpkg="$pkg"; pkggetdir "$type" )
  706. fi
  707. fi
  708. if [ -n "$value" -o "$type" = "prefix" ]; then
  709. echo "$addroot$value"
  710. else
  711. echo "PKGPREFIX_ERROR"
  712. fi
  713. }
  714. # pkggetdir <type> (needs $prefix and $xpkg)
  715. # returns the location for the file of a 'type' considering it's prefix
  716. #
  717. pkggetdir() {
  718. local xprefix=${prefix:+/$prefix}
  719. case "$1" in
  720. bindir) echo "$xprefix/bin" ;;
  721. sbindir) echo "$xprefix/sbin" ;;
  722. libdir)
  723. case $arch_machine in
  724. powerpc64|sparc64|x86_64|mips64)
  725. echo "$xprefix/lib64" ;;
  726. *)
  727. echo "$xprefix/lib" ;;
  728. esac
  729. ;;
  730. datadir) echo "${xprefix:-/usr}/share" ;;
  731. infodir) echo "${xprefix:-/usr}/info" ;;
  732. mandir) echo "${xprefix:-/usr}/man" ;;
  733. docdir) echo "${xprefix:-/usr}/doc/$xpkg" ;;
  734. includedir) echo "${xprefix:-/usr}/include" ;;
  735. sysconfdir) echo "/etc${xprefix##/usr*}" ;;
  736. localstatedir) echo "/var${xprefix##/usr*}" ;;
  737. esac
  738. }
  739. #
  740. # pkgchksum package-name
  741. #
  742. pkgchksum() {
  743. (
  744. # expand to full patch if only a package name was specified
  745. [[ $1 == */* ]] || set $base/package/*/$1/
  746. sh "$base/lib/sde-package/pkgchksum.sh" "$1"
  747. )
  748. }
  749. # Add files to the 'badfiles' list
  750. #
  751. register_badfiles() {
  752. local x desc="$1"
  753. shift
  754. for x in "$@"; do
  755. var_append badfiles $'\n' " $x\$"
  756. badfiles_desc[$badfiles_nr]=" $x\$"$'\n'"$desc"
  757. (( badfiles_nr++ ))
  758. done
  759. }
  760. # Detect the available patchfiles
  761. #
  762. detect_patchfiles()
  763. {
  764. local x= y=
  765. patchfiles="`ls $confdir/*.patch{,.$arch} \
  766. $confdir/*.patch_$xpkg{.$arch} \
  767. 2> /dev/null | tr '\n' ' '`"
  768. for x in $( get_reverted $targetchain ); do
  769. for y in pkg_$pkg.patch{,.$arch} xpkg_$xpkg.patch{,.$arch}; do
  770. if [ -f $base/target/$x/$y ]; then
  771. patchfiles="$patchfiles $base/target/$x/$y"
  772. fi
  773. done
  774. done
  775. }
  776. # Apply the given $patchfiles
  777. # [ hook called for each patch ] [ filter script ]
  778. #
  779. apply_patchfiles() {
  780. local hook="$1"
  781. local filter="$2"
  782. [ "$filter" ] || filter=cat
  783. for x in $patchfiles; do
  784. # correct the abolute path - e.g for patchfiles supplied
  785. # in the .desc file
  786. # we assume relative path patches are mirrorables //mnemoc
  787. if [ ! -e "$x" -a -n "${x##*/*}" ] ; then
  788. x="$base/download/mirror/${x:0:1}/$x"
  789. fi
  790. # Apply the patch if the file does exist or issue a warning
  791. if [ -f "$x" ] ; then
  792. echo "Apply patch $x ..."
  793. if [[ $x = *.bz2 ]] ; then
  794. patch_file=`mktemp` ; patch_del=1
  795. bzcat $x > $patch_file
  796. else
  797. patch_file=$x ; patch_del=0
  798. fi
  799. $filter $patch_file | patch $patchopt
  800. [ $patch_del = 1 ] && rm $patch_file
  801. eval "$hook"
  802. else
  803. echo_warning "Unable to apply patch: $x (File not found!)"
  804. fi
  805. done
  806. }
  807. # -------------------------------------------------------------------
  808. # The automatic extraction of archive (prior to building) supports
  809. # multiple archive types. For every archive type we have a separate
  810. # func that knows how to extract the archive. However, every func
  811. # should deliver two file: untar.txt and xsrcdir.txt.
  812. #
  813. # untar.txt needs to contain all extracted files.
  814. # xsrcdir.txt need to contain the top level extraction directories.
  815. # -------------------------------------------------------------------
  816. autoextract_tar_bz2() {
  817. echo "Extracting $xsrctar ($taropt) ... "
  818. tar -v $taropt $1 > untar.txt
  819. }
  820. autoextract_subdir_tar_bz2() {
  821. local taropt_orig="$taropt"
  822. mkdir -p "$pkg-$ver"
  823. taropt="-C $pkg-$ver $taropt"
  824. autoextract_tar_bz2 "$@"
  825. taropt="$taropt_orig"
  826. }
  827. autoextract_zip() {
  828. echo "Extracting $xsrctar ($zipopt) ... "
  829. unzip $zipopt $1 | sed 's,^.*/$,,' |
  830. cut -f4 -d" " | grep -v "^$" > untar.txt
  831. }
  832. autoextract_subdir_zip() {
  833. local zipopt_orig="$zipopt"
  834. mkdir -p "$pkg-$ver"
  835. zipopt="-d $pkg-$ver $zipopt"
  836. autoextract_zip "$@"
  837. zipopt="$zipopt_orig"
  838. }
  839. createprefix_function() {
  840. echo "Creating $root/$prefix/<..> if required ..."
  841. local dir=
  842. local foodir=
  843. for foodir in $foodirlist; do
  844. eval "dir=\"$root\$$foodir\""
  845. if [ ! -e $dir ]; then
  846. mkdir -p $dir
  847. rmemptydir="$rmemptydir $dir"
  848. fi
  849. case $foodir in
  850. libdir)
  851. # create lib -> lib64 compat symlinks
  852. # TODO: MULTILIB
  853. if [[ "$dir" = *lib64 ]] && [ ! -e "$root/$prefix/lib" ]; then
  854. echo "Creating 'lib -> lib64' compatibility symlink"
  855. ln -sf lib64 "$root/$prefix/lib"
  856. fi
  857. ;;
  858. esac
  859. done
  860. }
  861. # splitting debug symbols of ELF binaries into separate files
  862. #
  863. split_debug_files() {
  864. echo "split debug symbols into separate files"
  865. if ! atstage native; then
  866. # we need to use the objdump and objcopy from our toolchain
  867. # when cross-compiling
  868. objdumpcmd=${arch_target}-objdump
  869. objcopycmd=${arch_target}-objcopy
  870. else
  871. # use the installed objdump and a temporary copy of objcopy
  872. # when building natively in a chroot sandbox
  873. local objdumpcmd=objdump
  874. local objcopy=$( type -ap objcopy )
  875. local objcopytmp=${objcopy}.tmp
  876. local objcopycmd=$( basename $objcopytmp )
  877. cp -a $objcopy $objcopytmp
  878. fi
  879. # iterate through a list files generated from the fl_wrapper.wlog
  880. for x in $( fl_wrparse -D -s -r "$xroot/" < $builddir/fl_wrapper.wlog | sort -u ); do
  881. local is_dynelf=false
  882. # files we do not process
  883. case $( basename $root/$x ) in
  884. $objcopycmd|*.a) continue ;;
  885. esac
  886. # process regular files only
  887. [ "$( stat --printf="%F" $root/$x )" = "regular file" ] || continue;
  888. # only process dynamically linked ELF binaries
  889. $objdumpcmd -s -j .dynsym $root/$x &>/dev/null && is_dynelf=true
  890. if $is_dynelf; then
  891. # skip if the file has a '.gnu_debuglink' section yet such as a
  892. # hardlink which had been processed before
  893. local has_gnu_debuglink=false
  894. $objdumpcmd -s -j .gnu_debuglink $root/$x &>/dev/null && has_gnu_debuglink=true
  895. if $has_gnu_debuglink; then continue; fi
  896. # create destination directory for the debug info file if needed
  897. local debugdir=$( dirname $root/$libdir/debug/$x )
  898. [ -d $debugdir ] || mkdir -p $debugdir
  899. # split debug symbols into a separate file
  900. $objcopycmd --only-keep-debug $root/$x $root/$libdir/debug/$x
  901. chmod 644 $root/$libdir/debug/$x
  902. # preserve hardlinks
  903. if [ $( stat --printf="%h" $root/$x ) -gt 1 ]; then
  904. cp -fla $root/$x $root/$x.stripped
  905. else
  906. cp -a $root/$x $root/$x.stripped
  907. fi
  908. # create a stripped binary with gnu_debuglink section
  909. $objcopycmd --strip-debug $root/$x.stripped
  910. $objcopycmd --add-gnu-debuglink=$root/$libdir/debug/$x $root/$x.stripped
  911. # 'objcopy --strip-debug' will only remove debug symbols, whereas
  912. # 'strip -s' will remove debug symbols and the symbol table (.symtab)
  913. # 'objcopy --strip-unneeded' removes .symtab resulting in similarly
  914. # stripped binaries compared to 'strip -s'
  915. $objcopycmd --strip-unneeded $root/$x.stripped
  916. # preserve hardlinks
  917. cp -fla $root/$x.stripped $root/$x
  918. rm -f $root/$x.stripped
  919. fi
  920. done
  921. if atstage native; then
  922. # remove the temporary objcopy we used
  923. rm -f $objcopytmp
  924. fi
  925. }
  926. # Main program for building a package
  927. #
  928. build_this_package() {
  929. if [ ".$desc_SRC" = "." ] ; then
  930. # Autodetect source tar and extract it
  931. #
  932. if [ "$srctar" = auto ] ; then
  933. xsourceballs=$( echo "$desc_D" | head -n 1 | tr ' ' '\t' | tr -s '\t' |
  934. cut -f2 | bz2filename )
  935. if [ -z "$xsourceballs" ] ; then
  936. echo "Can't auto-detect srctar for package '$xpkg'!"
  937. false
  938. fi
  939. else
  940. xsourceballs="$srctar"
  941. fi
  942. elif [ "$srctar" = auto ] ; then
  943. sourceballs=$( echo "$desc_D" | tr ' ' '\t' | tr -s '\t' |
  944. cut -f2 | bz2filename )
  945. xsrcpattern=$( echo "$desc_SRC" | tr ' ' '\t' | tr -s '\t' | tr '\t' '\n' )
  946. xsourceballs=$( echo "$sourceballs" | grep -F "$xsrcpattern" )
  947. else
  948. xsourceballs="$srctar"
  949. fi
  950. for xsrctar in $xsourceballs; do
  951. saved_patchfiles="$patchfiles"
  952. buildloop=1
  953. var_append patchfiles " " \
  954. "`ls $confdir/*.patch.${xsrctar/-[v0-9]*/} 2> /dev/null`"
  955. if [ -d "$confdir/$xsrctar" ]; then
  956. xsrcdir="$pkg-$ver-$xsrctar"
  957. cp -a "$confdir/$xsrctar" "$builddir/$xsrcdir"
  958. cd "$builddir/$xsrcdir"
  959. elif [ "$xsrctar" != none -a "$autoextract" = 1 ]; then
  960. cd $builddir
  961. if [ -z "$custextract" ]; then
  962. # No custom extraction, so determine what
  963. # autoextraction to use.
  964. case "$xsrctar" in
  965. *.zip) custextract="autoextract_zip" ;;
  966. *) custextract="autoextract_tar_bz2" ;; # *.tar.bz2|*.tbz2|*.tbz
  967. esac
  968. fi
  969. if [ -n "$custextract" ]; then
  970. # Do the actual extraction of the archive.
  971. eval "$custextract $archdir/$xsrctar"
  972. cat untar.txt |
  973. sed 's,^\./,,' | cut -f1 -d/ |
  974. sort -u > xsrcdir.txt
  975. fi
  976. #
  977. if [ "$srcdir" = auto ]; then
  978. xsrcdir=${xsrctar%.tar.bz2}
  979. xsrcdir=${xsrcdir%.tbz2}
  980. xsrcdir=${xsrcdir%.tbz}
  981. if [ ! -d $xsrcdir ] ; then
  982. for x in $pkg-$ver ${pkg}_$ver $pkg \
  983. $xpkg-$ver ${xpkg}_$ver $xpkg \
  984. "$( cat xsrcdir.txt )"
  985. do
  986. [ -d "$x" ] && xsrcdir="$x"
  987. done
  988. fi
  989. else
  990. xsrcdir="$srcdir"
  991. fi
  992. #
  993. if [ "$chownsrcdir" = 1 ]; then
  994. echo "Fixing ownership and permissions ..."
  995. chown -R 0:0 $builddir/$xsrcdir
  996. fi
  997. #
  998. if [ "$nocvsinsrcdir" = 1 ]; then
  999. echo "Removing CVS, .svn, .git, {arch} and .arch-ids directories ..."
  1000. egrep '(^|/)(CVS|\.svn|\.git|\{arch\}|\.arch-ids)(/|$)' untar.txt |
  1001. while read x; do
  1002. echo "Removing $x ..."
  1003. rm -rf "$x"
  1004. done
  1005. fi
  1006. #
  1007. echo "Changeing into $builddir/$xsrcdir ..."
  1008. cd $builddir/$xsrcdir
  1009. # Apply patches
  1010. #
  1011. if [ $autopatch = 1 ]; then
  1012. hook_eval prepatch
  1013. apply_patchfiles
  1014. hook_eval postpatch
  1015. fi
  1016. else
  1017. cd $builddir
  1018. fi
  1019. if [ "$createprefix" = 1 ]; then
  1020. createprefix_function
  1021. fi
  1022. if [ -z "$custmain" ]; then
  1023. while [ ${buildloop:-1} -le ${buildloops:-1} ]; do
  1024. [ "${buildloops:-1}" = "1" ] || echo "loop ${buildloop:-1} of ${buildloops:-1} for $xsrctar."
  1025. hook_eval preconf
  1026. # Maybe generate a configure first
  1027. #
  1028. if [ $autogen -eq 1 -o \
  1029. \( -f autogen.sh -a ! -f configure \) ] ; then
  1030. if [ -f autogen.sh ] ; then
  1031. echo "Running package autogen script."
  1032. sed -i '/^\.\/configure /d' autogen.sh
  1033. sh autogen.sh
  1034. else
  1035. echo "Running builtin autogen script."
  1036. libtoolize --force --automake
  1037. aclocal $ACLOCAL_FLAGS
  1038. if grep AM_INIT_AUTOMAKE configure.[ia][nc]; then
  1039. automake --add-missing
  1040. fi
  1041. autoconf
  1042. fi
  1043. fi
  1044. # Run configure scripts etc.
  1045. #
  1046. if [ $runconf = 1 ]; then
  1047. if [ -n "$( type -p $configscript )" -o $autogen = 1 ]
  1048. then
  1049. eval_config_command $( eval echo $confopt )
  1050. fi
  1051. fi
  1052. # CMake based Makefile generation
  1053. #
  1054. if [ -f CMakeLists.txt -a $runcmake = 1 -a ! -f Makefile ]; then
  1055. local cmakesrcdir='..'
  1056. # check if we use a dedicated build directory
  1057. if [ $cmakebuilddir = 1 ]; then
  1058. mkdir -p build
  1059. cd build
  1060. else
  1061. cmakesrcdir='.'
  1062. fi
  1063. eval echo "Running cmake $cmakeopt"
  1064. cmake $( eval echo $cmakeopt $cmakesrcdir )
  1065. fi
  1066. # automated package build
  1067. # styles without make run first:
  1068. if [ -f setup.py -a $runpysetup = 1 ] ; then
  1069. hook_eval premake
  1070. eval ${pyscript:-python} setup.py $pyconfopt \
  1071. build $pybuildopt \
  1072. install $pyinstopt
  1073. hook_eval postmake
  1074. elif [ -f waf -a $runwaf = 1 ] ; then
  1075. wafconfopt="${wafconfopt:=configure --prefix=/$prefix}"
  1076. wafbuildopt="${wafbuildopt:=build}"
  1077. wafinstopt="${wafinstopt:=install --destdir=$root --force}"
  1078. hook_eval premake
  1079. eval ${wafscript:-./waf} $wafconfopt
  1080. eval ${wafscript:-./waf} $wafbuildopt
  1081. hook_eval inmake
  1082. eval ${wafscript:-./waf} $wafinstopt
  1083. hook_eval postmake
  1084. elif [ -f Sconstruct -o -f SConstruct -a $runscons = 1 -a ! -f configure ] ; then
  1085. hook_eval premake
  1086. eval ${sconsscript:-scons} $sconsopt
  1087. hook_eval inmake
  1088. hook_eval postmake
  1089. else # styles that include a make run
  1090. if [ ! -f Makefile -a ! -f makefile -a \
  1091. -f Makefile.PL -a $runmkpl = 1 ]; then
  1092. # always install into 'vendor' directory
  1093. var_append plconfopt ' ' "INSTALLDIRS=vendor"
  1094. perl Makefile.PL $plconfopt
  1095. fi
  1096. #
  1097. if [ ! -f Makefile -a ! -f makefile -a \
  1098. -f Imakefile -a $runxmkmf = 1 ]; then
  1099. xmkmf -a
  1100. fi
  1101. #
  1102. # Build it
  1103. #
  1104. hook_eval premake
  1105. if [ "$makeopt" ]; then
  1106. eval echo "Running $MAKE $makeopt"
  1107. eval "$MAKE $makeopt"
  1108. fi
  1109. hook_eval inmake
  1110. if [ "$makeinstopt" ]; then
  1111. eval echo "Running $MAKE $makeinstopt"
  1112. eval "$MAKE $makeinstopt"
  1113. fi
  1114. hook_eval postmake
  1115. fi
  1116. buildloop=$( expr ${buildloop:-1} + 1 )
  1117. done
  1118. else
  1119. eval "$custmain"
  1120. for x in preconf premake inmake postmake; do
  1121. if eval "[ -n \"\$hookdirty_$x\" ]"; then
  1122. echo "Hook $x is still marked as dirty ..."
  1123. hook_eval $x
  1124. fi
  1125. done
  1126. fi
  1127. if [ "$createdocs" != 0 ]; then
  1128. if [ ! -e $root$docdir ]; then
  1129. mkdir -p $docdir
  1130. rmemptydir="$rmemptydir $root$docdir"
  1131. fi
  1132. [ -z "$createdocs" ] && createdocs="$SDECFG_CREATE_DOCS"
  1133. fi
  1134. if [ "$createdocs" = 1 ]; then
  1135. echo "Trying to copy the default documentation ..."
  1136. for x in [A-Z][A-Z]* *.lsm ChangeLog* README LICENSE COPYING; do
  1137. [ "${x#*.[cho0-9]}" ] || continue
  1138. [ "${x#*.info*}" ] || continue
  1139. [ "${x#*.TAR*}" ] || continue
  1140. [ "${x#*akefile*}" ] || continue
  1141. [ -f $x ] && cp -v $x $root$docdir/$x
  1142. done
  1143. echo "Trying to copy even more documentation ..."
  1144. [ -d $builddir/$xsrcdir ] && cd $builddir/$xsrcdir
  1145. for x in `find -type d \( -name 'doc' -o -name 'docs' \
  1146. -o -name '[Dd]ocumentation' \) ! -empty`
  1147. do
  1148. if [ -d "$x" -a "`echo $x/*`" != "$x/*" ]
  1149. then cp -rLv $x/* $root$docdir || true ; fi
  1150. done
  1151. for x in $confdir/*.doc; do
  1152. if [ -f $x ]
  1153. then cp -v $x $root$docdir/${x%.doc}; fi
  1154. done
  1155. find $root$docdir/ -name '*.[0-9]' -o -name '*.info*' \
  1156. -o -name '[Mm]akefile*' |
  1157. xargs -r rm -f 2> /dev/null || true
  1158. find $root$docdir/* -type d -empty 2> /dev/null |
  1159. xargs -r rmdir 2> /dev/null || true
  1160. fi
  1161. hook_eval postdoc
  1162. if atstage native && [ -f /sbin/ldconfig ] ; then
  1163. echo "Running ldconfig ..."
  1164. ldconfig
  1165. fi
  1166. patchfiles="$saved_patchfiles"
  1167. done
  1168. if [ "$rmemptydir" ]; then
  1169. rmdir $rmemptydir 2> /dev/null || true
  1170. fi
  1171. return 0
  1172. }
  1173. # source_file cksum file url
  1174. #
  1175. # Create the file path from 'file' and 'url'.
  1176. # cksum and url are ignored
  1177. # ([D] tag compatible format)
  1178. #
  1179. source_file() {
  1180. local pre= file="$2" url="$3" mirror="mirror"
  1181. # '-' as $url prefix means, nomirrorable
  1182. [ "${url:0:1}" = "-" ] && mirror="local"
  1183. # inside Build-Pkg $archdir is set
  1184. if [ -n "$archdir" ]; then
  1185. pre=$base/; file="$( bz2filename $file )"
  1186. fi
  1187. echo ${pre}download/${mirror}/${file:0:1}/$file
  1188. }
  1189. # match_source_file [-p] pattern [[package] ...]
  1190. #
  1191. # returns path and name of a downloaded file from a list of packages, matching a grep pattern
  1192. # without -p it only returns it's name, not the path.
  1193. #
  1194. match_source_file() {
  1195. local pattern= package= showpath=0
  1196. local x= file= url= mirror=
  1197. local found=1
  1198. if [ "$1" = "-p" ]; then
  1199. showpath=1; shift
  1200. fi
  1201. pattern="$1"; shift
  1202. for package in ${*:-$pkg}; do
  1203. while read x x file url x; do
  1204. file="$( bz2filename $file )"
  1205. found=0
  1206. if [ $showpath -eq 0 ]; then
  1207. echo $file
  1208. else
  1209. [ "${url:0:1}" = "-" ] && mirror="local" || mirror="mirror"
  1210. echo $base/download/${mirror}/${file:0:1}/$file
  1211. fi
  1212. done < <( grep -e "^\[D\].*$pattern" $base/package/*/$package/$package.desc )
  1213. done
  1214. return $found
  1215. }
  1216. # create the virtual $archdir symlinks
  1217. #
  1218. populate_archdir()
  1219. {
  1220. local x= missing=0
  1221. for x in `match_source_file -p .`; do
  1222. if [ ! -f $x ]; then
  1223. echo_warning "File not found: ${x#$base/}"
  1224. missing=1
  1225. elif [ ! -e "$builddir/archdir/${x##*/}" ]; then
  1226. ln -vs $x $builddir/archdir/
  1227. fi
  1228. done
  1229. if [ $missing -eq 1 ]; then
  1230. echo_warning "Did you run download for this package?"
  1231. false
  1232. fi
  1233. }
  1234. # search for the package confdir
  1235. #
  1236. detect_confdir()
  1237. {
  1238. confdir=
  1239. if [ -z "$pkgdir" ] ; then
  1240. for x in package/*/$pkg/$pkg.desc ; do
  1241. if [ -f "$x" ] ; then
  1242. if [ "$confdir" ] ; then
  1243. echo_pkg_deny $stagelevel $pkg "in multiple trees"
  1244. echo "Package in multiple trees: $pkg !" \
  1245. > $root/var/adm/logs/$stagelevel-$xpkg.err
  1246. exit 1
  1247. fi
  1248. x=${x#package/}; x=${x%%/*}
  1249. confdir="$base/package/$x/$pkg"
  1250. repository=$x
  1251. fi
  1252. done
  1253. else
  1254. if [ -f "$pkgdir/$pkg.desc" ] ; then
  1255. confdir="$pkgdir"
  1256. repository=extern
  1257. fi
  1258. fi
  1259. }
  1260. # initialize standard vars and hooks
  1261. #
  1262. init_vars_and_hooks()
  1263. {
  1264. makeopt='CC="$CC" CPP="$CPP" CXX="$CXX"'
  1265. cmakeopt='-DCMAKE_INSTALL_PREFIX="/$prefix"'
  1266. cmakeopt="$cmakeopt"' -DCMAKE_LIBRARY_PATH="$libdir"'
  1267. cmakebuilddir=1
  1268. # some scons based builds are using 'prefix' others 'PREFIX'
  1269. sconsopt='PREFIX=/$prefix prefix=/$prefix install'
  1270. # python builds
  1271. pybuildopt=
  1272. pyinstopt='--prefix=/$prefix'
  1273. if atstage toolchain; then
  1274. makeopt="$makeopt"' prefix="$root${prefix:+/$prefix}"'
  1275. else
  1276. makeopt="$makeopt"' prefix="${prefix:+/$prefix}"'
  1277. fi
  1278. if ! atstage native; then
  1279. makeopt="$makeopt"' CC_FOR_BUILD="$BUILDCC"'
  1280. makeopt="$makeopt"' BUILDCC="$BUILDCC" BUILD_CC="$BUILD_CC"'
  1281. makeopt="$makeopt"' HOSTCC="$HOSTCC" HOST_CC="$HOST_CC"'
  1282. makeopt="$makeopt"' STRIP="$STRIP" AR="$AR" LD="$LD"'
  1283. makeopt="$makeopt"' RANLIB="$RANLIB" NM="$NM"'
  1284. fi
  1285. if atstage native; then
  1286. flistdel="$flistdel|`echo $base | sed s,^/,,`/.*"
  1287. fi
  1288. if atstage cross; then
  1289. makeopt="$makeopt"' INSTALL_PREFIX="$root"'
  1290. makeopt="$makeopt"' DESTDIR="$root" DEST_DIR="$root"'
  1291. makeopt="$makeopt"' INSTROOT="$root" INSTALLROOT="$root"'
  1292. # scons based build
  1293. sconsopt='DESTDIR="$root" '"$sconsopt"
  1294. fi
  1295. makeinstopt="$makeopt"' install'
  1296. custmain=
  1297. buildloop=1 buildloops=1
  1298. [ "$SDECFG_DO_CHECK" = 1 ] && hook_add inmake 6 'run_check'
  1299. hook_add postflist 3 'postflist_dirty_symlinks'
  1300. # no static lib corrections at toolchain stage
  1301. atstage toolchain || hook_add postflist 3 'postflist_static_lib'
  1302. createarchcache=0
  1303. configprefix=; configcache= ; autogen=0
  1304. configscript="./configure" ; extraconfopt=
  1305. srcdir=auto ; srctar=auto
  1306. taropt="--use-compress-program=bzip2 -xf"
  1307. mainfunction="build_this_package"
  1308. runconf=1 ; runcmake=1 ; runxmkmf=1 ; runmkpl=1 ; runpysetup=1 ; runwaf=1 ;
  1309. runscons=1 ;
  1310. autopatch=1 ; autoextract=1 ; chownsrcdir=1 ; nocvsinsrcdir=1 ; cleanconfopt=1
  1311. patchopt="-bfp1 -z .orig"
  1312. createprefix=1 ; createdocs= ; rmemptydir=
  1313. check_shared=1
  1314. check_usrlocal=1
  1315. check_badfiles=1
  1316. badfiles= badfiles_nr=0
  1317. declare -a badfiles_desc
  1318. }
  1319. # this is a 2nd lightweight and modular "build this package" implementation
  1320. # currently only used for the postlinux stuff - later maybe for more -ReneR
  1321. #
  1322. build_package()
  1323. {
  1324. logstamp=$PWD/log
  1325. (
  1326. set -e
  1327. pushd $base
  1328. super=$pkg
  1329. pkg="$1" ; xpkg="$pkg"
  1330. conffile="$2" ; [ "$conffile" ] || conffile="$pkg.conf"
  1331. unset ${!hook*}
  1332. declare -a hook_functions='()'
  1333. hook_fcounter=0
  1334. init_vars_and_hooks
  1335. detect_confdir
  1336. detect_patchfiles
  1337. parse_desc $pkg
  1338. # Erase positional parameters to prevent unintended parameter
  1339. # passing. We do not want to pass the current positional parameters
  1340. # to the loaded script.
  1341. set --
  1342. eval "$desc_O"
  1343. echo_status "Building $xpkg ($ver) within $super (using $conffile)."
  1344. for x in $( get_expanded $base/target/%/pkg_$pkg.conf $targetchain ) \
  1345. $confdir/$conffile; do
  1346. if [ -f $x ]; then
  1347. if [[ $x == */$conffile ]]; then
  1348. echo "Reading package configuration ($conffile) from package directory."
  1349. else
  1350. echo "Reading package configuration from target directory."
  1351. fi
  1352. . $x
  1353. break
  1354. fi
  1355. done
  1356. # short path - to not abort on missing downloads of postlinux.conf
  1357. # packages that are not built anyway -ReneR
  1358. if [ "$custmain" = "true" ] ; then
  1359. echo "Nothing is going to be done ayway - returning quickly."
  1360. return
  1361. fi
  1362. populate_archdir
  1363. popd
  1364. # dump for debugging
  1365. hook_dump > $builddir/debug.hooks.$pkg
  1366. dump_env > $builddir/debug.buildenv.$pkg
  1367. echo "Running main build function '$mainfunction' ..."
  1368. cd $builddir
  1369. eval "$mainfunction"
  1370. touch $logstamp
  1371. )
  1372. [ -f $logstamp ] || return 1
  1373. rm $logstamp
  1374. return 0
  1375. }