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.

339 lines
12 KiB

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