bootstrap.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #!/bin/sh
  2. # Copyright 2019-2020 Rene Rivera
  3. # Copyright (C) 2005, 2006 Douglas Gregor.
  4. # Copyright (C) 2006 The Trustees of Indiana University
  5. #
  6. # Distributed under the Boost Software License, Version 1.0.
  7. # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  8. # boostinspect:notab - Tabs are required for the Makefile.
  9. BJAM=""
  10. TOOLSET=""
  11. BJAM_CONFIG=""
  12. BUILD=""
  13. PREFIX=/usr/local
  14. EPREFIX=
  15. LIBDIR=
  16. INCLUDEDIR=
  17. LIBS=""
  18. PYTHON=python
  19. PYTHON_VERSION=
  20. PYTHON_ROOT=
  21. ICU_ROOT=
  22. # Handle case where builtin shell version of echo command doesn't
  23. # support -n. Use the installed echo executable if there is one
  24. # rather than builtin version to ensure -n is supported.
  25. ECHO=`which echo`
  26. if test "x$ECHO" = x; then
  27. ECHO=echo
  28. fi
  29. # Internal flags
  30. flag_no_python=
  31. flag_icu=
  32. flag_show_libraries=
  33. for option
  34. do
  35. case $option in
  36. -help | --help | -h)
  37. want_help=yes ;;
  38. -prefix=* | --prefix=*)
  39. PREFIX=`expr "x$option" : "x-*prefix=\(.*\)"`
  40. ;;
  41. -exec-prefix=* | --exec-prefix=*)
  42. EPREFIX=`expr "x$option" : "x-*exec-prefix=\(.*\)"`
  43. ;;
  44. -libdir=* | --libdir=*)
  45. LIBDIR=`expr "x$option" : "x-*libdir=\(.*\)"`
  46. ;;
  47. -includedir=* | --includedir=*)
  48. INCLUDEDIR=`expr "x$option" : "x-*includedir=\(.*\)"`
  49. ;;
  50. -show-libraries | --show-libraries )
  51. flag_show_libraries=yes
  52. ;;
  53. -with-bjam=* | --with-bjam=* )
  54. BJAM=`expr "x$option" : "x-*with-bjam=\(.*\)"`
  55. ;;
  56. -with-icu | --with-icu )
  57. flag_icu=yes
  58. ;;
  59. -with-icu=* | --with-icu=* )
  60. flag_icu=yes
  61. ICU_ROOT=`expr "x$option" : "x-*with-icu=\(.*\)"`
  62. ;;
  63. -without-icu | --without-icu )
  64. flag_icu=no
  65. ;;
  66. -with-libraries=* | --with-libraries=* )
  67. library_list=`expr "x$option" : "x-*with-libraries=\(.*\)"`
  68. if test "$library_list" != "all"; then
  69. old_IFS=$IFS
  70. IFS=,
  71. for library in $library_list
  72. do
  73. LIBS="$LIBS --with-$library"
  74. if test $library = python; then
  75. requested_python=yes
  76. fi
  77. done
  78. IFS=$old_IFS
  79. if test "x$requested_python" != xyes; then
  80. flag_no_python=yes
  81. fi
  82. fi
  83. ;;
  84. -without-libraries=* | --without-libraries=* )
  85. library_list=`expr "x$option" : "x-*without-libraries=\(.*\)"`
  86. old_IFS=$IFS
  87. IFS=,
  88. for library in $library_list
  89. do
  90. LIBS="$LIBS --without-$library"
  91. if test $library = python; then
  92. flag_no_python=yes
  93. fi
  94. done
  95. IFS=$old_IFS
  96. ;;
  97. -with-python=* | --with-python=* )
  98. PYTHON=`expr "x$option" : "x-*with-python=\(.*\)"`
  99. ;;
  100. -with-python-root=* | --with-python-root=* )
  101. PYTHON_ROOT=`expr "x$option" : "x-*with-python-root=\(.*\)"`
  102. ;;
  103. -with-python-version=* | --with-python-version=* )
  104. PYTHON_VERSION=`expr "x$option" : "x-*with-python-version=\(.*\)"`
  105. ;;
  106. -with-toolset=* | --with-toolset=* )
  107. TOOLSET=`expr "x$option" : "x-*with-toolset=\(.*\)"`
  108. ;;
  109. -*)
  110. { echo "error: unrecognized option: $option
  111. Try \`$0 --help' for more information." >&2
  112. { (exit 1); exit 1; }; }
  113. ;;
  114. esac
  115. done
  116. if test "x$want_help" = xyes; then
  117. cat <<EOF
  118. \`./bootstrap.sh' prepares Boost for building on a few kinds of systems.
  119. Usage: $0 [OPTION]...
  120. Defaults for the options are specified in brackets.
  121. Configuration:
  122. -h, --help display this help and exit
  123. --with-bjam=BJAM use existing Boost.Jam executable (bjam)
  124. [automatically built]
  125. --with-toolset=TOOLSET use specific B2 toolset
  126. [automatically detected]
  127. --show-libraries show the set of libraries that require build
  128. and installation steps (i.e., those libraries
  129. that can be used with --with-libraries or
  130. --without-libraries), then exit
  131. --with-libraries=list build only a particular set of libraries,
  132. describing using either a comma-separated list of
  133. library names or "all"
  134. [all]
  135. --without-libraries=list build all libraries except the ones listed []
  136. --with-icu enable Unicode/ICU support in Regex
  137. [automatically detected]
  138. --without-icu disable Unicode/ICU support in Regex
  139. --with-icu=DIR specify the root of the ICU library installation
  140. and enable Unicode/ICU support in Regex
  141. [automatically detected]
  142. --with-python=PYTHON specify the Python executable [python]
  143. --with-python-root=DIR specify the root of the Python installation
  144. [automatically detected]
  145. --with-python-version=X.Y specify the Python version as X.Y
  146. [automatically detected]
  147. Installation directories:
  148. --prefix=PREFIX install Boost into the given PREFIX
  149. [/usr/local]
  150. --exec-prefix=EPREFIX install Boost binaries into the given EPREFIX
  151. [PREFIX]
  152. More precise control over installation directories:
  153. --libdir=DIR install libraries here [EPREFIX/lib]
  154. --includedir=DIR install headers here [PREFIX/include]
  155. EOF
  156. fi
  157. test -n "$want_help" && exit 0
  158. my_dir=$(dirname "$0")
  159. # Determine the toolset, if not already decided
  160. if test "x$TOOLSET" = x; then
  161. guessed_toolset=`$my_dir/tools/build/src/engine/build.sh --guess-toolset`
  162. case $guessed_toolset in
  163. acc | clang | gcc | como | mipspro | pathscale | pgi | qcc | vacpp )
  164. TOOLSET=$guessed_toolset
  165. ;;
  166. intel-* )
  167. TOOLSET=intel
  168. ;;
  169. mingw )
  170. TOOLSET=gcc
  171. ;;
  172. sun* )
  173. TOOLSET=sun
  174. ;;
  175. * )
  176. # Not supported by B2
  177. ;;
  178. esac
  179. fi
  180. rm -f config.log
  181. # Build bjam
  182. if test "x$BJAM" = x; then
  183. $ECHO "Building B2 engine.."
  184. pwd=`pwd`
  185. (cd "$my_dir/tools/build/src/engine" && ./build.sh)
  186. if [ $? -ne 0 ]; then
  187. echo
  188. echo "Failed to build B2 build engine"
  189. exit 1
  190. fi
  191. cd "$pwd"
  192. BJAM="$my_dir/tools/build/src/engine/b2"
  193. echo "tools/build/src/engine/b2"
  194. cp "$BJAM" .
  195. fi
  196. # TBD: Turn BJAM into an absolute path
  197. # If there is a list of libraries
  198. if test "x$flag_show_libraries" = xyes; then
  199. cat <<EOF
  200. The following Boost libraries have portions that require a separate build
  201. and installation step. Any library not listed here can be used by including
  202. the headers only.
  203. The Boost libraries requiring separate building and installation are:
  204. EOF
  205. $BJAM -d0 --show-libraries | grep '^[[:space:]]*-'
  206. exit 0
  207. fi
  208. # Setup paths
  209. if test "x$EPREFIX" = x; then
  210. EPREFIX="$PREFIX"
  211. fi
  212. if test "x$LIBDIR" = x; then
  213. LIBDIR="$EPREFIX/lib"
  214. fi
  215. if test "x$INCLUDEDIR" = x; then
  216. INCLUDEDIR="$PREFIX/include"
  217. fi
  218. # Find Python
  219. if test "x$flag_no_python" = x; then
  220. result=`$PYTHON -c "exit" > /dev/null 2>&1`
  221. if [ "$?" -ne "0" ]; then
  222. flag_no_python=yes
  223. fi
  224. fi
  225. if test "x$flag_no_python" = x; then
  226. if test "x$PYTHON_VERSION" = x; then
  227. $ECHO -n "Detecting Python version... "
  228. PYTHON_VERSION=`$PYTHON -c "import sys; print (\"%d.%d\" % (sys.version_info[0], sys.version_info[1]))"`
  229. echo $PYTHON_VERSION
  230. fi
  231. if test "x$PYTHON_ROOT" = x; then
  232. $ECHO -n "Detecting Python root... "
  233. PYTHON_ROOT=`$PYTHON -c "import sys; print(sys.prefix)"`
  234. echo $PYTHON_ROOT
  235. fi
  236. fi
  237. # Configure ICU
  238. $ECHO -n "Unicode/ICU support for Boost.Regex?... "
  239. if test "x$flag_icu" != xno; then
  240. if test "x$ICU_ROOT" = x; then
  241. if command -v pkg-config > /dev/null && pkg-config icu-uc ; then
  242. ICU_ROOT=`pkg-config --variable=prefix icu-uc`
  243. fi
  244. fi
  245. if test "x$ICU_ROOT" = x; then
  246. COMMON_ICU_PATHS="/usr /usr/local /sw"
  247. for p in $COMMON_ICU_PATHS; do
  248. if test -r $p/include/unicode/utypes.h; then
  249. ICU_ROOT=$p
  250. fi
  251. done
  252. if test "x$ICU_ROOT" = x; then
  253. echo "not found."
  254. else
  255. BJAM_CONFIG="$BJAM_CONFIG -sICU_PATH=$ICU_ROOT"
  256. echo "$ICU_ROOT"
  257. fi
  258. else
  259. BJAM_CONFIG="$BJAM_CONFIG -sICU_PATH=$ICU_ROOT"
  260. echo "$ICU_ROOT"
  261. fi
  262. else
  263. echo "disabled."
  264. fi
  265. # Backup the user's existing project-config.jam
  266. JAM_CONFIG_OUT="project-config.jam"
  267. if test -r "project-config.jam"; then
  268. counter=1
  269. while test -r "project-config.jam.$counter"; do
  270. counter=`expr $counter + 1`
  271. done
  272. echo "Backing up existing B2 configuration in project-config.jam.$counter"
  273. mv "project-config.jam" "project-config.jam.$counter"
  274. fi
  275. # Generate user-config.jam
  276. echo "Generating B2 configuration in project-config.jam for $TOOLSET..."
  277. cat > project-config.jam <<EOF
  278. # B2 Configuration
  279. # Automatically generated by bootstrap.sh
  280. import option ;
  281. import feature ;
  282. # Compiler configuration. This definition will be used unless
  283. # you already have defined some toolsets in your user-config.jam
  284. # file.
  285. if ! $TOOLSET in [ feature.values <toolset> ]
  286. {
  287. using $TOOLSET ;
  288. }
  289. project : default-build <toolset>$TOOLSET ;
  290. EOF
  291. # - Python configuration
  292. if test "x$flag_no_python" = x; then
  293. cat >> project-config.jam <<EOF
  294. # Python configuration
  295. import python ;
  296. if ! [ python.configured ]
  297. {
  298. using python : $PYTHON_VERSION : "$PYTHON_ROOT" ;
  299. }
  300. EOF
  301. fi
  302. if test "x$ICU_ROOT" != x; then
  303. cat >> project-config.jam << EOF
  304. path-constant ICU_PATH : $ICU_ROOT ;
  305. EOF
  306. fi
  307. cat >> project-config.jam << EOF
  308. # List of --with-<library> and --without-<library>
  309. # options. If left empty, all libraries will be built.
  310. # Options specified on the command line completely
  311. # override this variable.
  312. libraries = $LIBS ;
  313. # These settings are equivalent to corresponding command-line
  314. # options.
  315. option.set prefix : $PREFIX ;
  316. option.set exec-prefix : $EPREFIX ;
  317. option.set libdir : $LIBDIR ;
  318. option.set includedir : $INCLUDEDIR ;
  319. # Stop on first error
  320. option.set keep-going : false ;
  321. EOF
  322. cat << EOF
  323. Bootstrapping is done. To build, run:
  324. ./b2
  325. To generate header files, run:
  326. ./b2 headers
  327. To adjust configuration, edit 'project-config.jam'.
  328. Further information:
  329. - Command line help:
  330. ./b2 --help
  331. - Getting started guide:
  332. http://www.boost.org/more/getting_started/unix-variants.html
  333. - B2 documentation:
  334. http://www.boost.org/build/
  335. EOF
粤ICP备19079148号