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.

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