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.

386 lines
11 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-build-tools
  6. # Copyright (C) 2006 - 2008 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. #Description: Builds tools, wrappers and caches needed for a build
  18. [ -n "$SDEROOT" ] ||
  19. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  20. . "$SDEROOT/lib/libsde.in"
  21. create_usage() {
  22. local progname=${0##*/}
  23. cat <<EOT
  24. Usage: ${progname//-/ } [--config <config>] [-<stagelevel>] [--cleanup]
  25. EOT
  26. }
  27. shortopts='0123456789c:'
  28. longopts='help,config:,cfg:,cleanup'
  29. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  30. if [ $? -ne 0 ]; then
  31. create_usage
  32. exit -1
  33. fi
  34. # load new arguments list
  35. eval set -- "$options"
  36. config=default
  37. stagelevel=9
  38. cleanup=0
  39. while [ $# -gt 0 ]; do
  40. case "$1" in
  41. --help)
  42. create_usage
  43. exit 0
  44. ;;
  45. --cleanup)
  46. cleanup=1
  47. ;;
  48. -c|--cfg|--config)
  49. config="$2"
  50. shift
  51. ;;
  52. -[0-9])
  53. stagelevel=${1#-}
  54. ;;
  55. --)
  56. shift
  57. break
  58. ;;
  59. *)
  60. echo_abort 1 "Unknown argument '$1', aborting."
  61. esac
  62. shift
  63. done
  64. cd "$SDEROOT"
  65. . lib/functions.in
  66. . lib/parse-config
  67. # all our work here goes to the same location, $TOOLSDIR
  68. #
  69. TOOLSDIR="build/$SDECFG_ID/TOOLCHAIN/$toolsdir"
  70. var_remove PATH ":" $base/$TOOLSDIR/bin
  71. var_remove PATH ":" $base/$TOOLSDIR/wrapper
  72. mkdir -p tmp
  73. mkdir -p $TOOLSDIR/bin
  74. mkdir -p $TOOLSDIR/wrapper
  75. mkdir -p $TOOLSDIR/lib
  76. if [ $toolsdir = tools.cross ]; then
  77. mkdir -p $TOOLSDIR/{var/adm,etc,share,include}
  78. [ -L $TOOLSDIR/usr ] || ln -s . $TOOLSDIR/usr
  79. [ -L $TOOLSDIR/sbin ] || ln -s bin $TOOLSDIR/sbin
  80. [ -L $TOOLSDIR/var/adm/logs ] || ln -s ../../../../var/adm/logs \
  81. $TOOLSDIR/var/adm/logs
  82. mkdir -p build/$SDECFG_ID/var/adm/logs
  83. fi
  84. x="$( bin/find config/$config/. package/. scripts/. \
  85. lib/. architecture/. target/. \( ! -name '*.cache' ! \
  86. -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \
  87. \( \! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \
  88. -newer $TOOLSDIR/.lastupdate \
  89. -printf 'Found new/updated file: %p\n' 2> /dev/null )"
  90. if [ "$x" ] ; then
  91. echo_header Found $( echo "$x" | wc -l ) new/updated \
  92. files in source tree:
  93. echo "$x" | head -n 3 | sed 's,/\./,/,g' |
  94. while read y ; do echo_status $y ; done
  95. [ "$( echo "$x" | tail -n +4 )" ] &&
  96. echo_status "** list truncated to save space on the terminal **"
  97. if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then
  98. echo_error "Found \$SDEDEBUG_TOOLS_SKIP ..."
  99. else
  100. rm -f $TOOLSDIR/.lastupdate
  101. if echo "$x" | grep -qv " config/$config/package" ; then
  102. echo_header Re-running configuration:
  103. while read -r line ; do
  104. echo_status "$line"
  105. done < <( ./scripts/Config -cfg $config -oldconfig )
  106. fi
  107. fi
  108. fi
  109. if [ $cleanup = 1 ] ; then
  110. echo_header "Removing old stuff in $toolsdir/ directory ..."
  111. rm -f $TOOLSDIR/wrapper/*
  112. rm -f $TOOLSDIR/bin/getdu
  113. rm -f $TOOLSDIR/bin/getfiles
  114. rm -f $TOOLSDIR/bin/fl_wrparse
  115. rm -f $TOOLSDIR/bin/fl_stparse
  116. rm -f $TOOLSDIR/lib/fl_wrapper.so
  117. rm -f $TOOLSDIR/lib/parse-config
  118. rm -f $TOOLSDIR/lib/parse-config-fixarch
  119. rm -f $TOOLSDIR/.lastupdate
  120. fi
  121. if [ ! -f $TOOLSDIR/.lastupdate ] ; then
  122. echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
  123. # CC, CXX, F77 and KCC Wrapper
  124. #
  125. wrappers="cmd_wrapper" ; wrappervars=
  126. echo_status "Building $toolsdir/wrapper/cmd_wrapper."
  127. $BUILDCC -Wall -O2 src/tools-source/cmd_wrapper.c \
  128. -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
  129. -o $TOOLSDIR/wrapper/tmp.$$ || exit 1
  130. mv $TOOLSDIR/wrapper/tmp.$$ \
  131. $TOOLSDIR/wrapper/cmd_wrapper
  132. #
  133. build_wrapper() {
  134. local x="$( echo ${1//,/ } )" y z
  135. wrappervars="$wrappervars $x"
  136. while shift ; [ $# != 0 ]
  137. do
  138. wrappers="$wrappers $1"
  139. tmp=`mktemp -p $TOOLSDIR/wrapper`
  140. {
  141. echo '#!/bin/bash'
  142. for y in $x ; do
  143. echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
  144. echo "export CMD_WRAPPER_DEBUG=1"
  145. done
  146. for y in $x ; do
  147. echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
  148. echo "export CMD_WRAPPER_BYPASS=1"
  149. done
  150. z=; echo -n 'export CMD_WRAPPER_APPEND_PO="'
  151. for y in $x; do
  152. echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
  153. done ; echo '"'
  154. z=; echo -n 'export CMD_WRAPPER_OTHERS="'
  155. for y in $x; do
  156. echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
  157. done ; echo '"'
  158. z=; echo -n 'export CMD_WRAPPER_INSERT="'
  159. for y in $x; do
  160. echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
  161. done ; echo '"'
  162. z=; echo -n 'export CMD_WRAPPER_REMOVE="'
  163. for y in $x; do
  164. echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
  165. done ; echo '"'
  166. z=; echo -n 'export CMD_WRAPPER_APPEND="'
  167. for y in $x; do
  168. echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
  169. done ; echo '"'
  170. z=; echo -n 'export CMD_WRAPPER_FILTER="'
  171. for y in $x; do
  172. echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
  173. done ; echo '"'
  174. echo 'exec cmd_wrapper $( basename $0 ) "$@"'
  175. } > $tmp
  176. chmod +rx $tmp
  177. mv $tmp "$TOOLSDIR/wrapper/$1"
  178. done
  179. }
  180. #
  181. while read script ; do . $script
  182. done < <( bin/find package/. lib/*/. \
  183. $( get_reverted `get_expanded target/%/. $targetchain` ) -name 'wrappers.in' )
  184. #
  185. echo_status "Building $toolsdir/wrapper/strip_wrapper."
  186. cat << EOT > $TOOLSDIR/wrapper/strip_wrapper.$$
  187. #!/bin/sh
  188. if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ] ; then
  189. echo "Aaaaaeik! Strip wrapper is looping!" >&2
  190. exit 1
  191. fi
  192. if [ "\$SDECFG_DEBUG" = 0 ] ; then
  193. PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
  194. export STRIP_WRAPPER_NOLOOP=1
  195. exec "\$( basename \$0 )" "\$@"
  196. fi
  197. exit 0
  198. EOT
  199. chmod +x $TOOLSDIR/wrapper/strip_wrapper.$$
  200. mv $TOOLSDIR/wrapper/strip_wrapper.$$ \
  201. $TOOLSDIR/wrapper/strip_wrapper
  202. wrappers="$wrappers strip_wrapper"
  203. #
  204. for x in strip $arch_target-strip ; do
  205. [ $crossnative = cross -a $x = strip ] && continue
  206. if [ -x "`type -p $x`" ] ; then
  207. ln -sf strip_wrapper \
  208. $TOOLSDIR/wrapper/$x
  209. wrappers="$wrappers $x"
  210. fi
  211. done
  212. #
  213. if [ "$toolsdir" = "tools.chroot" ]; then
  214. echo_status "Building $toolsdir/wrapper/{uname,arch}."
  215. sed -e "s,@@ARCH_MACHINE@@,$arch_machine,g" \
  216. src/tools-source/uname_wrapper.in.sh > $TOOLSDIR/wrapper/uname
  217. sed -e "s,@@ARCH@@,$( echo $arch | arch2uname ),g" \
  218. src/tools-source/arch_wrapper.in.sh > $TOOLSDIR/wrapper/arch
  219. chmod +x $TOOLSDIR/wrapper/{uname,arch}
  220. wrappers="$wrappers uname arch"
  221. fi
  222. #
  223. echo_status "Building $toolsdir/wrapper/install_wrapper."
  224. cp src/tools-source/install_wrapper.sh $TOOLSDIR/wrapper/install_wrapper
  225. chmod +x $TOOLSDIR/wrapper/install_wrapper
  226. ln -sf install_wrapper $TOOLSDIR/wrapper/install
  227. ln -sf install_wrapper $TOOLSDIR/wrapper/cp
  228. ln -sf install_wrapper $TOOLSDIR/wrapper/ln
  229. ln -sf install_wrapper $TOOLSDIR/wrapper/mv
  230. wrappers="$wrappers install_wrapper install cp ln mv"
  231. #
  232. for x in $( ls $TOOLSDIR/wrapper/ )
  233. do
  234. z=0
  235. for y in $wrappers ; do
  236. [ "$x" = "$y" ] && z=1
  237. done
  238. if [ "$z" = 0 ] ; then
  239. rm -f $TOOLSDIR/wrapper/$x
  240. fi
  241. done
  242. # Various small tools
  243. #
  244. for x in getdu getfiles fl_wrparse fl_stparse ; do
  245. echo_status "Building $toolsdir/bin/$x."
  246. $BUILDCC -Wall -O2 src/tools-source/$x.c \
  247. -o $TOOLSDIR/bin/$x.$$ || exit 1
  248. mv $TOOLSDIR/bin/$x.$$ \
  249. $TOOLSDIR/bin/$x
  250. done
  251. # Flist Wrapper Library
  252. #
  253. if [ "$SDECFG_FLIST" = "flwrapper" ] ; then
  254. echo_status "Building $toolsdir/lib/fl_wrapper.so."
  255. FLWRAPPER_LIBC=$( ls $xroot/{lib64,lib}/libc.* 2>/dev/null |
  256. head -n1 )
  257. if [ ! -f "$FLWRAPPER_LIBC" ]; then
  258. abort 'Unable to detect /lib/libc.* for flwrapper'
  259. fi
  260. if ! atstage native; then
  261. FLWRAPPER_BASEDIR="-DFLWRAPPER_BASEDIR=\"$base\""
  262. else
  263. FLWRAPPER_BASEDIR=
  264. fi
  265. sh src/tools-source/fl_wrapper.c.sh > tmp/fl_wrapper_$$.c
  266. $BUILDCC -O2 -shared -fPIC -Wall -ldl tmp/fl_wrapper_$$.c \
  267. $FLWRAPPER_BASEDIR \
  268. -DFLWRAPPER_LIBC=\"${FLWRAPPER_LIBC##*/}\" \
  269. -o $TOOLSDIR/lib/fl_wrapper.so.$$ || exit 1
  270. rm tmp/fl_wrapper_$$.c
  271. mv $TOOLSDIR/lib/fl_wrapper.so.$$ \
  272. $TOOLSDIR/lib/fl_wrapper.so
  273. echo_status "Testing $toolsdir/lib/fl_wrapper.so."
  274. if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
  275. `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date ; `
  276. `exit \$?" >/dev/null 2>&1
  277. then
  278. echo_error "Detected a problem with the flist" \
  279. "wrapper lib on your system."
  280. echo_error "Please specify another flist-creation" \
  281. "system in your build configuration."
  282. rm -f $TOOLSDIR/lib/fl_wrapper.so
  283. echo ; exit 1
  284. fi
  285. fi
  286. # Create Parse-Config Collection
  287. #
  288. echo_status "Creating $toolsdir/lib/parse-config."
  289. bin/find \
  290. architecture/$arch/. lib/*/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) -type f \
  291. '(' -name 'parse-config' -o -name 'parse-config-[0-9]' ')' \
  292. -printf '%f\t%p\n' | sed \
  293. -e 's,^parse-config\t,5\t,g' -e 's,^parse-config-\(.\)\t,\1\t,g' | \
  294. sort -n | awk '{ $1="."; print; }' \
  295. | grep -v lib/output/ \
  296. > $TOOLSDIR/lib/parse-config.$$
  297. mv $TOOLSDIR/lib/parse-config.$$ \
  298. $TOOLSDIR/lib/parse-config
  299. bin/find \
  300. architecture/$arch/. lib/*/. package/. $( get_reverted `get_expanded target/%/. $targetchain` ) -type f \
  301. -name 'parse-config-fixarch' \
  302. -printf '%f\t%p\n' | sort | awk '{ $1="."; print; }' \
  303. > $TOOLSDIR/lib/parse-config-fixarch.$$
  304. mv $TOOLSDIR/lib/parse-config-fixarch.$$ \
  305. $TOOLSDIR/lib/parse-config-fixarch
  306. # Create pkg_*_{pre,post}.conf files
  307. #
  308. echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
  309. rm -f $TOOLSDIR/lib/pkg_*_{pre,post}.conf
  310. for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
  311. if [ -f $y ]; then
  312. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  313. fi
  314. done
  315. if atstage rebuild; then
  316. for x in /var/adm/packages/*; do
  317. ls -1d package/*/${x##*/}/pkg_*_{pre,post}.conf 2> /dev/null
  318. done
  319. else
  320. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
  321. ls -1d package/$x/pkg_*_{pre,post}.conf 2> /dev/null
  322. done
  323. fi | while read y; do
  324. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  325. done
  326. $ECHO_E "${wrappervars// /\n}" | grep . | sort -u |
  327. while read x ; do
  328. echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
  329. echo "export ${x}_WRAPPER_OTHERS= ${x}_WRAPPER_REMOVE="
  330. echo "export ${x}_WRAPPER_INSERT= ${x}_WRAPPER_APPEND="
  331. echo "export ${x}_WRAPPER_FILTER= ${x}_WRAPPER_APPEND_PO="
  332. done > $TOOLSDIR/lib/wrapper-config.$$
  333. mv $TOOLSDIR/lib/wrapper-config.$$ \
  334. $TOOLSDIR/lib/wrapper-config
  335. touch $TOOLSDIR/.lastupdate
  336. fi
  337. exit 0