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.

403 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 - 2012 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. cat << EOT > $TOOLSDIR/wrapper/strip_wrapper.$$
  197. #!/bin/sh
  198. if [ "\$STRIP_WRAPPER_NOLOOP" = 1 ] ; then
  199. echo "Aaaaaeik! Strip wrapper is looping!" >&2
  200. exit 1
  201. fi
  202. if [ "\$SDECFG_DEBUG" = 0 ] ; then
  203. PATH=\${PATH//\$STRIP_WRAPPER_MYPATH:/}
  204. export STRIP_WRAPPER_NOLOOP=1
  205. exec "\$( basename \$0 )" "\$@"
  206. fi
  207. exit 0
  208. EOT
  209. chmod +x $TOOLSDIR/wrapper/strip_wrapper.$$
  210. mv $TOOLSDIR/wrapper/strip_wrapper.$$ \
  211. $TOOLSDIR/wrapper/strip_wrapper
  212. wrappers="$wrappers strip_wrapper"
  213. #
  214. for x in strip $arch_target-strip ; do
  215. [ $crossnative = cross -a $x = strip ] && continue
  216. if [ -x "`type -p $x`" ] ; then
  217. ln -sf strip_wrapper \
  218. $TOOLSDIR/wrapper/$x
  219. wrappers="$wrappers $x"
  220. fi
  221. done
  222. #
  223. if [ "$toolsdir" = "tools.chroot" ]; then
  224. echo_status "Building $toolsdir/wrapper/{uname,arch}."
  225. sed -e "s,@@ARCH_MACHINE@@,$arch_machine,g" \
  226. src/tools-source/uname_wrapper.in.sh > $TOOLSDIR/wrapper/uname
  227. sed -e "s,@@ARCH@@,$( echo $arch | arch2uname ),g" \
  228. src/tools-source/arch_wrapper.in.sh > $TOOLSDIR/wrapper/arch
  229. chmod +x $TOOLSDIR/wrapper/{uname,arch}
  230. wrappers="$wrappers uname arch"
  231. fi
  232. #
  233. echo_status "Building $toolsdir/wrapper/install_wrapper."
  234. cp src/tools-source/install_wrapper.sh $TOOLSDIR/wrapper/install_wrapper
  235. chmod +x $TOOLSDIR/wrapper/install_wrapper
  236. ln -sf install_wrapper $TOOLSDIR/wrapper/install
  237. ln -sf install_wrapper $TOOLSDIR/wrapper/cp
  238. ln -sf install_wrapper $TOOLSDIR/wrapper/ln
  239. ln -sf install_wrapper $TOOLSDIR/wrapper/mv
  240. wrappers="$wrappers install_wrapper install cp ln mv"
  241. #
  242. for x in $( ls $TOOLSDIR/wrapper/ )
  243. do
  244. z=0
  245. for y in $wrappers ; do
  246. [ "$x" = "$y" ] && z=1
  247. done
  248. if [ "$z" = 0 ] ; then
  249. rm -f $TOOLSDIR/wrapper/$x
  250. fi
  251. done
  252. # Various small tools
  253. #
  254. for x in getdu getfiles fl_wrparse fl_stparse ; do
  255. echo_status "Building $toolsdir/bin/$x."
  256. $BUILDCC -Wall -O2 src/tools-source/$x.c \
  257. -o $TOOLSDIR/bin/$x.$$ || exit 1
  258. mv $TOOLSDIR/bin/$x.$$ \
  259. $TOOLSDIR/bin/$x
  260. done
  261. # Flist Wrapper Library
  262. #
  263. if [ "$SDECFG_FLIST" = "flwrapper" ] ; then
  264. echo_status "Building $toolsdir/lib/fl_wrapper.so."
  265. FLWRAPPER_LIBC=$( ls $xroot/{lib64,lib}/libc.* 2>/dev/null |
  266. head -n1 )
  267. if [ ! -f "$FLWRAPPER_LIBC" ]; then
  268. abort 'Unable to detect /lib/libc.* for flwrapper'
  269. fi
  270. if ! atstage native; then
  271. FLWRAPPER_BASEDIR="$base"
  272. else
  273. FLWRAPPER_BASEDIR=
  274. fi
  275. make -s -C src/tools-source/fl_wrapper LIB="$PWD/$TOOLSDIR/lib/fl_wrapper.so" \
  276. CC="$BUILDCC" LIBC="${FLWRAPPER_LIBC##*/}" BASE="$FLWRAPPER_BASEDIR" \
  277. || exit 1
  278. echo_status "Testing $toolsdir/lib/fl_wrapper.so."
  279. if ! sh -c "LD_PRELOAD=\"\$LD_PRELOAD:build/\$SDECFG_ID/`
  280. `TOOLCHAIN/$toolsdir/lib/fl_wrapper.so\" date ; `
  281. `exit \$?" >/dev/null 2>&1
  282. then
  283. echo_error "Detected a problem with the flist" \
  284. "wrapper lib on your system."
  285. echo_error "Please specify another flist-creation" \
  286. "system in your build configuration."
  287. rm -f $TOOLSDIR/lib/fl_wrapper.so
  288. echo ; exit 1
  289. fi
  290. fi
  291. # Create Parse-Config Collection
  292. #
  293. prio_find() {
  294. local name="$1"; shift
  295. local mode="$1"; shift
  296. wrapper() {
  297. if [ "$mode" = "preserve" ]; then
  298. grep -n ^
  299. else
  300. sed -e "s|^|$mode:|"
  301. fi
  302. }
  303. bin/find "$@" -type f '(' -name "$name" -o -name "$name-[0-9]" ')' | wrapper |
  304. sed -e "s|^.*/$name\$|5:\0|" -e "s|^.*/$name-\(.\)\$|\1\:\0|" -e 's|/\./|/|'
  305. }
  306. echo_status "Creating $toolsdir/lib/parse-config."
  307. (
  308. prio_find parse-config 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output
  309. prio_find parse-config preserve $( get_reverted `get_expanded target/%/. $targetchain` )
  310. ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config.$$
  311. mv $TOOLSDIR/lib/parse-config.$$ \
  312. $TOOLSDIR/lib/parse-config
  313. (
  314. prio_find parse-config-fixarch 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output
  315. prio_find parse-config-fixarch preserve $( get_reverted `get_expanded target/%/. $targetchain` )
  316. ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config-fixarch.$$
  317. mv $TOOLSDIR/lib/parse-config-fixarch.$$ \
  318. $TOOLSDIR/lib/parse-config-fixarch
  319. # Create pkg_*_{pre,post}.conf files
  320. #
  321. echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
  322. rm -f $TOOLSDIR/lib/pkg_*_{pre,post}.conf
  323. for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
  324. if [ -f $y ]; then
  325. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  326. fi
  327. done
  328. if atstage rebuild; then
  329. for x in /var/adm/packages/*; do
  330. ls -1d package/*/${x##*/}/pkg_*_{pre,post}.conf 2> /dev/null
  331. done
  332. else
  333. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
  334. ls -1d package/$x/pkg_*_{pre,post}.conf 2> /dev/null
  335. done
  336. fi | while read y; do
  337. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  338. done
  339. $ECHO_E "${wrappervars// /\n}" | grep . | sort -u |
  340. while read x ; do
  341. echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
  342. echo "export ${x}_WRAPPER_OTHERS= ${x}_WRAPPER_REMOVE="
  343. echo "export ${x}_WRAPPER_INSERT= ${x}_WRAPPER_APPEND="
  344. echo "export ${x}_WRAPPER_FILTER= ${x}_WRAPPER_APPEND_PO="
  345. done > $TOOLSDIR/lib/wrapper-config.$$
  346. mv $TOOLSDIR/lib/wrapper-config.$$ \
  347. $TOOLSDIR/lib/wrapper-config
  348. touch $TOOLSDIR/.lastupdate
  349. fi
  350. exit 0