OpenSDE Framework (without history before r20070)

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