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.

374 lines
9.6 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. # flist tools plugin
  120. #
  121. flist_tools_clean() {
  122. :
  123. }
  124. flist_tools_build() {
  125. :
  126. }
  127. if [ -s "lib/sde-build/flist_${SDECFG_FLIST}_tools.in" ]; then
  128. . "lib/sde-build/flist_${SDECFG_FLIST}_tools.in"
  129. fi
  130. if [ $cleanup = 1 ] ; then
  131. echo_header "Removing old stuff in $toolsdir/ directory ..."
  132. rm -f $TOOLSDIR/wrapper/*
  133. rm -f $TOOLSDIR/bin/getdu
  134. rm -f $TOOLSDIR/bin/getfiles
  135. rm -f $TOOLSDIR/bin/fl_wrparse
  136. rm -f $TOOLSDIR/bin/fl_stparse
  137. rm -f $TOOLSDIR/lib/fl_wrapper.so
  138. rm -f $TOOLSDIR/lib/parse-config
  139. rm -f $TOOLSDIR/lib/parse-config-fixarch
  140. rm -f $TOOLSDIR/.lastupdate
  141. flist_tools_clean
  142. fi
  143. if [ ! -f $TOOLSDIR/.lastupdate ] ; then
  144. echo_header "Building tools in build/.../TOOLCHAIN/$toolsdir:"
  145. # CC, CXX, F77 and KCC Wrapper
  146. #
  147. wrappers="cmd_wrapper" ; wrappervars=
  148. echo_status "Building $toolsdir/wrapper/cmd_wrapper."
  149. $BUILDCC -Wall -O2 src/tools-source/cmd_wrapper.c \
  150. -DENVPREFIX='"CMD"' -DMYNAME='"cmd_wrapper"' \
  151. -o $TOOLSDIR/wrapper/tmp.$$ || exit 1
  152. mv $TOOLSDIR/wrapper/tmp.$$ \
  153. $TOOLSDIR/wrapper/cmd_wrapper
  154. #
  155. build_wrapper() {
  156. local x="$( echo ${1//,/ } )" y z
  157. wrappervars="$wrappervars $x"
  158. while shift ; [ $# != 0 ]
  159. do
  160. wrappers="$wrappers $1"
  161. tmp=`mktemp -p $TOOLSDIR/wrapper`
  162. {
  163. echo '#!/bin/bash'
  164. for y in $x ; do
  165. echo -n "[ \"\$${y}_WRAPPER_DEBUG\" = 1 ] && "
  166. echo "export CMD_WRAPPER_DEBUG=1"
  167. done
  168. for y in $x ; do
  169. echo -n "[ \"\$${y}_WRAPPER_BYPASS\" = 1 ] && "
  170. echo "export CMD_WRAPPER_BYPASS=1"
  171. done
  172. z=; echo -n 'export CMD_WRAPPER_APPEND_PO="'
  173. for y in $x; do
  174. echo -n "${z}\$${y}_WRAPPER_APPEND_PO"; z=" "
  175. done ; echo '"'
  176. z=; echo -n 'export CMD_WRAPPER_OTHERS="'
  177. for y in $x; do
  178. echo -n "${z}\$${y}_WRAPPER_OTHERS"; z=":"
  179. done ; echo '"'
  180. z=; echo -n 'export CMD_WRAPPER_INSERT="'
  181. for y in $x; do
  182. echo -n "${z}\$${y}_WRAPPER_INSERT"; z=" "
  183. done ; echo '"'
  184. z=; echo -n 'export CMD_WRAPPER_REMOVE="'
  185. for y in $x; do
  186. echo -n "${z}\$${y}_WRAPPER_REMOVE"; z=" "
  187. done ; echo '"'
  188. z=; echo -n 'export CMD_WRAPPER_APPEND="'
  189. for y in $x; do
  190. echo -n "${z}\$${y}_WRAPPER_APPEND"; z=" "
  191. done ; echo '"'
  192. z=; echo -n 'export CMD_WRAPPER_FILTER="'
  193. for y in $x; do
  194. echo -n "${z}\$${y}_WRAPPER_FILTER"; z="|"
  195. done ; echo '"'
  196. echo 'exec cmd_wrapper $( basename $0 ) "$@"'
  197. } > $tmp
  198. chmod +rx $tmp
  199. mv $tmp "$TOOLSDIR/wrapper/$1"
  200. done
  201. }
  202. #
  203. while read script ; do . $script
  204. done < <( bin/find package/. lib/*/. \
  205. $( get_reverted `get_expanded target/%/. $targetchain` ) -name 'wrappers.in' )
  206. #
  207. echo_status "Building $toolsdir/wrapper/strip_wrapper."
  208. cp src/tools-source/strip_wrapper.sh $TOOLSDIR/wrapper/strip_wrapper
  209. chmod +x $TOOLSDIR/wrapper/strip_wrapper
  210. wrappers="$wrappers strip_wrapper"
  211. #
  212. for x in strip $arch_target-strip ; do
  213. [ $crossnative = cross -a $x = strip ] && continue
  214. if [ -x "`type -p $x`" ] ; then
  215. ln -sf strip_wrapper \
  216. $TOOLSDIR/wrapper/$x
  217. wrappers="$wrappers $x"
  218. fi
  219. done
  220. #
  221. if [ "$toolsdir" = "tools.chroot" ]; then
  222. echo_status "Building $toolsdir/wrapper/{uname,arch}."
  223. sed -e "s,@@ARCH_MACHINE@@,$arch_machine,g" \
  224. src/tools-source/uname_wrapper.in.sh > $TOOLSDIR/wrapper/uname
  225. sed -e "s,@@ARCH@@,$( echo $arch | arch2uname ),g" \
  226. src/tools-source/arch_wrapper.in.sh > $TOOLSDIR/wrapper/arch
  227. chmod +x $TOOLSDIR/wrapper/{uname,arch}
  228. wrappers="$wrappers uname arch"
  229. fi
  230. #
  231. echo_status "Building $toolsdir/wrapper/install_wrapper."
  232. cp src/tools-source/install_wrapper.sh $TOOLSDIR/wrapper/install_wrapper
  233. chmod +x $TOOLSDIR/wrapper/install_wrapper
  234. ln -sf install_wrapper $TOOLSDIR/wrapper/install
  235. ln -sf install_wrapper $TOOLSDIR/wrapper/cp
  236. ln -sf install_wrapper $TOOLSDIR/wrapper/ln
  237. ln -sf install_wrapper $TOOLSDIR/wrapper/mv
  238. wrappers="$wrappers install_wrapper install cp ln mv"
  239. #
  240. for x in $( ls $TOOLSDIR/wrapper/ )
  241. do
  242. z=0
  243. for y in $wrappers ; do
  244. [ "$x" = "$y" ] && z=1
  245. done
  246. if [ "$z" = 0 ] ; then
  247. rm -f $TOOLSDIR/wrapper/$x
  248. fi
  249. done
  250. # Various small tools
  251. #
  252. for x in getdu getfiles fl_wrparse fl_stparse ; do
  253. echo_status "Building $toolsdir/bin/$x."
  254. $BUILDCC -Wall -O2 src/tools-source/$x.c \
  255. -o $TOOLSDIR/bin/$x.$$ || exit 1
  256. mv $TOOLSDIR/bin/$x.$$ \
  257. $TOOLSDIR/bin/$x
  258. done
  259. # Flist Wrapper Library
  260. #
  261. flist_tools_build
  262. # Create Parse-Config Collection
  263. #
  264. prio_find() {
  265. local name="$1"; shift
  266. local mode="$1"; shift
  267. wrapper() {
  268. if [ "$mode" = "preserve" ]; then
  269. grep -n ^
  270. else
  271. sed -e "s|^|$mode:|"
  272. fi
  273. }
  274. bin/find "$@" -type f '(' -name "$name" -o -name "$name-[0-9]" ')' | wrapper |
  275. sed -e "s|^.*/$name\$|5:\0|" -e "s|^.*/$name-\(.\)\$|\1\:\0|" -e 's|/\./|/|'
  276. }
  277. echo_status "Creating $toolsdir/lib/parse-config."
  278. (
  279. prio_find parse-config 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output
  280. prio_find parse-config preserve $( get_reverted `get_expanded target/%/. $targetchain` )
  281. ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config.$$
  282. mv $TOOLSDIR/lib/parse-config.$$ \
  283. $TOOLSDIR/lib/parse-config
  284. (
  285. prio_find parse-config-fixarch 0 architecture/$arch/. lib/*/. package/. | grep -v lib/output
  286. prio_find parse-config-fixarch preserve $( get_reverted `get_expanded target/%/. $targetchain` )
  287. ) | sort -n -t: | sed -e 's|^....|\. |' > $TOOLSDIR/lib/parse-config-fixarch.$$
  288. mv $TOOLSDIR/lib/parse-config-fixarch.$$ \
  289. $TOOLSDIR/lib/parse-config-fixarch
  290. # Create pkg_*_{pre,post}.conf files
  291. #
  292. echo_status "Creating $toolsdir/lib/pkg_*_{pre,post}.conf"
  293. rm -f $TOOLSDIR/lib/pkg_*_{pre,post}.conf
  294. for y in `echo architecture/$arch/pkg_*_{pre,post}.conf`; do
  295. if [ -f $y ]; then
  296. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  297. fi
  298. done
  299. if atstage rebuild; then
  300. for x in /var/adm/packages/*; do
  301. ls -1d package/*/${x##*/}/pkg_*_{pre,post}.conf 2> /dev/null
  302. done
  303. else
  304. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 4,5 | tr ' ' '/'`; do
  305. ls -1d package/$x/pkg_*_{pre,post}.conf 2> /dev/null
  306. done
  307. fi | while read y; do
  308. echo " . $y" >> $TOOLSDIR/lib/${y##*/}
  309. done
  310. $ECHO_E "${wrappervars// /\\n}" | grep . | sort -u |
  311. while read x ; do
  312. echo "export ${x}_WRAPPER_DEBUG=0 ${x}_WRAPPER_BYPASS=0"
  313. echo "export ${x}_WRAPPER_OTHERS= ${x}_WRAPPER_REMOVE="
  314. echo "export ${x}_WRAPPER_INSERT= ${x}_WRAPPER_APPEND="
  315. echo "export ${x}_WRAPPER_FILTER= ${x}_WRAPPER_APPEND_PO="
  316. done > $TOOLSDIR/lib/wrapper-config.$$
  317. mv $TOOLSDIR/lib/wrapper-config.$$ \
  318. $TOOLSDIR/lib/wrapper-config
  319. touch $TOOLSDIR/.lastupdate
  320. fi
  321. exit 0