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.

391 lines
10 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 - 2015 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. case $arch_machine in
  76. powerpc64|sparc64|x86_64|mips64)
  77. mkdir -p $TOOLSDIR/lib64
  78. if [ ! -L $TOOLSDIR/lib ]; then
  79. ln -sf lib64 $TOOLSDIR/lib
  80. fi
  81. ;;
  82. *)
  83. mkdir -p $TOOLSDIR/lib
  84. ;;
  85. esac
  86. if [ $toolsdir = tools.cross ]; then
  87. mkdir -p $TOOLSDIR/{var/adm,etc,share,include}
  88. [ -L $TOOLSDIR/usr ] || ln -s . $TOOLSDIR/usr
  89. [ -L $TOOLSDIR/sbin ] || ln -s bin $TOOLSDIR/sbin
  90. [ -L $TOOLSDIR/var/adm/logs ] || ln -s ../../../../var/adm/logs \
  91. $TOOLSDIR/var/adm/logs
  92. mkdir -p build/$SDECFG_ID/var/adm/logs
  93. fi
  94. x="$( bin/find config/$config/. package/. scripts/. \
  95. lib/. architecture/. target/. \( ! -name '*.cache' ! \
  96. -name '*.patch*' ! -name '.*' ! -name 'svn-commit.tmp' \
  97. \( \! -name '*.conf' -o -name 'pkg*.conf' \) \) -a -type f \
  98. -newer $TOOLSDIR/.lastupdate \
  99. -printf 'Found new/updated file: %p\n' 2> /dev/null )"
  100. if [ "$x" ] ; then
  101. echo_header Found $( echo "$x" | wc -l ) new/updated \
  102. files in source tree:
  103. echo "$x" | head -n 3 | sed 's,/\./,/,g' |
  104. while read y ; do echo_status $y ; done
  105. [ "$( echo "$x" | tail -n +4 )" ] &&
  106. echo_status "** list truncated to save space on the terminal **"
  107. if [ "$SDEDEBUG_TOOLS_SKIP" = 1 ]; then
  108. echo_error "Found \$SDEDEBUG_TOOLS_SKIP ..."
  109. else
  110. rm -f $TOOLSDIR/.lastupdate
  111. if echo "$x" | grep -qv " config/$config/package" ; then
  112. echo_header Re-running configuration:
  113. while read -r line ; do
  114. echo_status "$line"
  115. done < <( ./scripts/Config -cfg $config -oldconfig )
  116. fi
  117. fi
  118. fi
  119. if [ $cleanup = 1 ] ; then
  120. echo_header "Removing old stuff in $toolsdir/ directory ..."
  121. rm -f $TOOLSDIR/wrapper/*
  122. rm -f $TOOLSDIR/bin/getdu
  123. rm -f $TOOLSDIR/bin/getfiles
  124. rm -f $TOOLSDIR/bin/fl_wrparse
  125. rm -f $TOOLSDIR/bin/fl_stparse
  126. rm -f $TOOLSDIR/lib/fl_wrapper.so
  127. rm -f $TOOLSDIR/lib/parse-config
  128. rm -f $TOOLSDIR/lib/parse-config-fixarch
  129. rm -f $TOOLSDIR/.lastupdate
  130. fi
  131. if [ ! -f $TOOLSDIR/.lastupdate ] ; then
  132. echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
  133. # CC, CXX, F77 and KCC Wrapper
  134. #
  135. wrappers="cmd_wrapper" ; wrappervars=
  136. echo_status "Building $toolsdir/wrapper/cmd_wrapper."
  137. $BUILDCC -Wall -O2 src/tools-source/cmd_wrapper.c \
  138. -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
  139. -o $TOOLSDIR/wrapper/tmp.$$ || exit 1
  140. mv $TOOLSDIR/wrapper/tmp.$$ \
  141. $TOOLSDIR/wrapper/cmd_wrapper
  142. #
  143. build_wrapper() {
  144. local x="$( echo ${1//,/ } )" y z
  145. wrappervars="$wrappervars $x"
  146. while shift ; [ $# != 0 ]
  147. do
  148. wrappers="$wrappers $1"
  149. tmp=`mktemp -p $TOOLSDIR/wrapper`
  150. {
  151. echo '#!/bin/bash'
  152. for y in $x ; do
  153. echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
  154. echo "export CMD_WRAPPER_DEBUG=1"
  155. done
  156. for y in $x ; do
  157. echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
  158. echo "export CMD_WRAPPER_BYPASS=1"
  159. done
  160. z=; echo -n 'export CMD_WRAPPER_APPEND_PO="'
  161. for y in $x; do
  162. echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
  163. done ; echo '"'
  164. z=; echo -n 'export CMD_WRAPPER_OTHERS="'
  165. for y in $x; do
  166. echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
  167. done ; echo '"'
  168. z=; echo -n 'export CMD_WRAPPER_INSERT="'
  169. for y in $x; do
  170. echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
  171. done ; echo '"'
  172. z=; echo -n 'export CMD_WRAPPER_REMOVE="'
  173. for y in $x; do
  174. echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
  175. done ; echo '"'
  176. z=; echo -n 'export CMD_WRAPPER_APPEND="'
  177. for y in $x; do
  178. echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
  179. done ; echo '"'
  180. z=; echo -n 'export CMD_WRAPPER_FILTER="'
  181. for y in $x; do
  182. echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
  183. done ; echo '"'
  184. echo 'exec cmd_wrapper $( basename $0 ) "$@"'
  185. } > $tmp
  186. chmod +rx $tmp
  187. mv $tmp "$TOOLSDIR/wrapper/$1"
  188. done
  189. }
  190. #
  191. while read script ; do . $script
  192. done < <( bin/find package/. lib/*/. \
  193. $( get_reverted `get_expanded target/%/. $targetchain` ) -name 'wrappers.in' )
  194. #
  195. echo_status "Building $toolsdir/wrapper/strip_wrapper."
  196. cp src/tools-source/strip_wrapper.sh $TOOLSDIR/wrapper/strip_wrapper
  197. chmod +x $TOOLSDIR/wrapper/strip_wrapper
  198. wrappers="$wrappers strip_wrapper"
  199. #
  200. for x in strip $arch_target-strip ; do
  201. [ $crossnative = cross -a $x = strip ] && continue
  202. if [ -x "`type -p $x`" ] ; then
  203. ln -sf strip_wrapper \
  204. $TOOLSDIR/wrapper/$x
  205. wrappers="$wrappers $x"
  206. fi
  207. done
  208. #
  209. if [ "$toolsdir" = "tools.chroot" ]; then
  210. echo_status "Building $toolsdir/wrapper/{uname,arch}."
  211. sed -e "s,@@ARCH_MACHINE@@,$arch_machine,g" \
  212. src/tools-source/uname_wrapper.in.sh > $TOOLSDIR/wrapper/uname
  213. sed -e "s,@@ARCH@@,$( echo $arch | arch2uname ),g" \
  214. src/tools-source/arch_wrapper.in.sh > $TOOLSDIR/wrapper/arch
  215. chmod +x $TOOLSDIR/wrapper/{uname,arch}
  216. wrappers="$wrappers uname arch"
  217. fi
  218. #
  219. echo_status "Building $toolsdir/wrapper/install_wrapper."
  220. cp src/tools-source/install_wrapper.sh $TOOLSDIR/wrapper/install_wrapper
  221. chmod +x $TOOLSDIR/wrapper/install_wrapper
  222. ln -sf install_wrapper $TOOLSDIR/wrapper/install
  223. ln -sf install_wrapper $TOOLSDIR/wrapper/cp
  224. ln -sf install_wrapper $TOOLSDIR/wrapper/ln
  225. ln -sf install_wrapper $TOOLSDIR/wrapper/mv
  226. wrappers="$wrappers install_wrapper install cp ln mv"
  227. #
  228. for x in $( ls $TOOLSDIR/wrapper/ )
  229. do
  230. z=0
  231. for y in $wrappers ; do
  232. [ "$x" = "$y" ] && z=1
  233. done
  234. if [ "$z" = 0 ] ; then
  235. rm -f $TOOLSDIR/wrapper/$x
  236. fi
  237. done
  238. # Various small tools
  239. #
  240. for x in getdu getfiles fl_wrparse fl_stparse ; do
  241. echo_status "Building $toolsdir/bin/$x."
  242. $BUILDCC -Wall -O2 src/tools-source/$x.c \
  243. -o $TOOLSDIR/bin/$x.$$ || exit 1
  244. mv $TOOLSDIR/bin/$x.$$ \
  245. $TOOLSDIR/bin/$x
  246. done
  247. # Flist Wrapper Library
  248. #
  249. if [ "$SDECFG_FLIST" = "flwrapper" ] ; then
  250. FLWRAPPER_LIBC=$(ls -1 \
  251. "$xroot"/lib*/{*/,}libc[.-]* 2> /dev/null |
  252. grep -v '\.a$' | grep '\.so' |
  253. sort -V | head -n1 )
  254. if [ ! -f "$FLWRAPPER_LIBC" ]; then
  255. abort 'Unable to detect /lib/libc.* for flwrapper'
  256. fi
  257. echo_status "Building $toolsdir/lib/fl_wrapper.so ($FLWRAPPER_LIBC)."
  258. if ! atstage native; then
  259. FLWRAPPER_BASEDIR="$base"
  260. else
  261. FLWRAPPER_BASEDIR=
  262. fi
  263. make -s -C src/tools-source/fl_wrapper LIB="$PWD/$TOOLSDIR/lib/fl_wrapper.so" \
  264. CC="$BUILDCC" LIBC="${FLWRAPPER_LIBC##*/}" BASE="$FLWRAPPER_BASEDIR" \
  265. || exit 1
  266. echo_status "Testing $toolsdir/lib/fl_wrapper.so."
  267. if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
  268. `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date ; `
  269. `exit \$?" >/dev/null 2>&1
  270. then
  271. echo_error "Detected a problem with the flist" \
  272. "wrapper lib on your system."
  273. echo_error "Please specify another flist-creation" \
  274. "system in your build configuration."
  275. rm -f $TOOLSDIR/lib/fl_wrapper.so
  276. echo ; exit 1
  277. fi
  278. fi
  279. # Create Parse-Config Collection
  280. #
  281. prio_find() {
  282. local name="$1"; shift
  283. local mode="$1"; shift
  284. wrapper() {
  285. if [ "$mode" = "preserve" ]; then
  286. grep -n ^
  287. else
  288. sed -e "s|^|$mode:|"
  289. fi
  290. }
  291. bin/find "$@" -type f '(' -name "$name" -o -name "$name-[0-9]" ')' | wrapper |
  292. sed -e "s|^.*/$name\$|5:\0|" -e "s|^.*/$name-\(.\)\$|\1\:\0|" -e 's|/\./|/|'
  293. }
  294. echo_status "Creating $toolsdir/lib/parse-config."
  295. (
  296. prio_find parse-config 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output
  297. prio_find parse-config preserve $( get_reverted `get_expanded target/%/. $targetchain` )
  298. ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config.$$
  299. mv $TOOLSDIR/lib/parse-config.$$ \
  300. $TOOLSDIR/lib/parse-config
  301. (
  302. prio_find parse-config-fixarch 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output
  303. prio_find parse-config-fixarch preserve $( get_reverted `get_expanded target/%/. $targetchain` )
  304. ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config-fixarch.$$
  305. mv $TOOLSDIR/lib/parse-config-fixarch.$$ \
  306. $TOOLSDIR/lib/parse-config-fixarch
  307. # Create pkg_*_{pre,post}.conf files
  308. #
  309. echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
  310. rm -f $TOOLSDIR/lib/pkg_*_{pre,post}.conf
  311. for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
  312. if [ -f $y ]; then
  313. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  314. fi
  315. done
  316. if atstage rebuild; then
  317. for x in /var/adm/packages/*; do
  318. ls -1d package/*/${x##*/}/pkg_*_{pre,post}.conf 2> /dev/null
  319. done
  320. else
  321. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
  322. ls -1d package/$x/pkg_*_{pre,post}.conf 2> /dev/null
  323. done
  324. fi | while read y; do
  325. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  326. done
  327. $ECHO_E "${wrappervars// /\\n}" | grep . | sort -u |
  328. while read x ; do
  329. echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
  330. echo "export ${x}_WRAPPER_OTHERS= ${x}_WRAPPER_REMOVE="
  331. echo "export ${x}_WRAPPER_INSERT= ${x}_WRAPPER_APPEND="
  332. echo "export ${x}_WRAPPER_FILTER= ${x}_WRAPPER_APPEND_PO="
  333. done > $TOOLSDIR/lib/wrapper-config.$$
  334. mv $TOOLSDIR/lib/wrapper-config.$$ \
  335. $TOOLSDIR/lib/wrapper-config
  336. touch $TOOLSDIR/.lastupdate
  337. fi
  338. exit 0