bootstrap.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. #!/bin/sh
  2. # Copyright 2019-2021 René Ferdinand Rivera Morell
  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\' builds the Boost build system B2 and prepares Boost for
  119. building. This includes setting defaults in the project-config.jam which you
  120. can adjust prior to invoking B2.
  121. Usage: $0 [OPTION]...
  122. Defaults for the options are specified in brackets.
  123. Configuration:
  124. -h, --help display this help and exit
  125. --with-bjam=BJAM use existing Boost.Jam executable (bjam)
  126. [automatically built]
  127. --with-toolset=TOOLSET use specific TOOLSET to build B2 and as default
  128. for building Boost
  129. [automatically detected]
  130. --show-libraries show the set of libraries that require build
  131. and installation steps (i.e., those libraries
  132. that can be used with --with-libraries or
  133. --without-libraries), then exit
  134. --with-libraries=list build only a particular set of libraries,
  135. describing using either a comma-separated list of
  136. library names or "all"
  137. [all]
  138. --without-libraries=list build all libraries except the ones listed []
  139. --with-icu enable Unicode/ICU support in Regex
  140. [automatically detected]
  141. --without-icu disable Unicode/ICU support in Regex
  142. --with-icu=DIR specify the root of the ICU library installation
  143. and enable Unicode/ICU support in Regex
  144. [automatically detected]
  145. --with-python=PYTHON specify the Python executable [python]
  146. --with-python-root=DIR specify the root of the Python installation
  147. [automatically detected]
  148. --with-python-version=X.Y specify the Python version as X.Y
  149. [automatically detected]
  150. Installation directories:
  151. --prefix=PREFIX install Boost into the given PREFIX
  152. [/usr/local]
  153. --exec-prefix=EPREFIX install Boost binaries into the given EPREFIX
  154. [PREFIX]
  155. More precise control over installation directories:
  156. --libdir=DIR install libraries here [EPREFIX/lib]
  157. --includedir=DIR install headers here [PREFIX/include]
  158. EOF
  159. fi
  160. test -n "$want_help" && exit 0
  161. my_dir=$(dirname "$0")
  162. # Determine the toolset, if not already decided
  163. if test "x$TOOLSET" = x; then
  164. guessed_toolset=`CXX= CXXFLAGS= $my_dir/tools/build/src/engine/build.sh --guess-toolset`
  165. case $guessed_toolset in
  166. acc | clang | gcc | como | mipspro | pathscale | pgi | qcc | vacpp )
  167. TOOLSET=$guessed_toolset
  168. ;;
  169. intel-* )
  170. TOOLSET=intel
  171. ;;
  172. mingw )
  173. TOOLSET=gcc
  174. ;;
  175. sun* )
  176. TOOLSET=sun
  177. ;;
  178. * )
  179. # Not supported by B2
  180. ;;
  181. esac
  182. fi
  183. rm -f config.log
  184. # Build bjam
  185. if test "x$BJAM" = x; then
  186. $ECHO "Building B2 engine.."
  187. pwd=`pwd`
  188. CXX= CXXFLAGS= "$my_dir/tools/build/src/engine/build.sh" ${TOOLSET}
  189. if [ $? -ne 0 ]; then
  190. echo
  191. echo "Failed to build B2 build engine"
  192. exit 1
  193. fi
  194. cd "$pwd"
  195. BJAM="$my_dir/tools/build/src/engine/b2"
  196. echo "tools/build/src/engine/b2"
  197. cp "$BJAM" .
  198. fi
  199. # TBD: Turn BJAM into an absolute path
  200. # If there is a list of libraries
  201. if test "x$flag_show_libraries" = xyes; then
  202. cat <<EOF
  203. The following Boost libraries have portions that require a separate build
  204. and installation step. Any library not listed here can be used by including
  205. the headers only.
  206. The Boost libraries requiring separate building and installation are:
  207. EOF
  208. $BJAM -d0 --show-libraries | grep '^[[:space:]]*-'
  209. exit 0
  210. fi
  211. # Setup paths
  212. if test "x$EPREFIX" = x; then
  213. EPREFIX="$PREFIX"
  214. fi
  215. if test "x$LIBDIR" = x; then
  216. LIBDIR="$EPREFIX/lib"
  217. fi
  218. if test "x$INCLUDEDIR" = x; then
  219. INCLUDEDIR="$PREFIX/include"
  220. fi
  221. # Find Python
  222. if test "x$flag_no_python" = x; then
  223. result=`$PYTHON -c "exit" > /dev/null 2>&1`
  224. if [ "$?" -ne "0" ]; then
  225. flag_no_python=yes
  226. fi
  227. fi
  228. if test "x$flag_no_python" = x; then
  229. if test "x$PYTHON_VERSION" = x; then
  230. $ECHO -n "Detecting Python version... "
  231. PYTHON_VERSION=`$PYTHON -c "import sys; print (\"%d.%d\" % (sys.version_info[0], sys.version_info[1]))"`
  232. echo $PYTHON_VERSION
  233. fi
  234. if test "x$PYTHON_ROOT" = x; then
  235. $ECHO -n "Detecting Python root... "
  236. PYTHON_ROOT=`$PYTHON -c "import sys; print(sys.prefix)"`
  237. echo $PYTHON_ROOT
  238. fi
  239. fi
  240. # Configure ICU
  241. $ECHO -n "Unicode/ICU support for Boost.Regex?... "
  242. if test "x$flag_icu" != xno; then
  243. if test "x$ICU_ROOT" = x; then
  244. if command -v pkg-config > /dev/null && pkg-config icu-uc ; then
  245. ICU_ROOT=`pkg-config --variable=prefix icu-uc`
  246. fi
  247. fi
  248. if test "x$ICU_ROOT" = x; then
  249. COMMON_ICU_PATHS="/usr /usr/local /sw"
  250. for p in $COMMON_ICU_PATHS; do
  251. if test -r $p/include/unicode/utypes.h; then
  252. ICU_ROOT=$p
  253. fi
  254. done
  255. if test "x$ICU_ROOT" = x; then
  256. echo "not found."
  257. else
  258. BJAM_CONFIG="$BJAM_CONFIG -sICU_PATH=$ICU_ROOT"
  259. echo "$ICU_ROOT"
  260. fi
  261. else
  262. BJAM_CONFIG="$BJAM_CONFIG -sICU_PATH=$ICU_ROOT"
  263. echo "$ICU_ROOT"
  264. fi
  265. else
  266. echo "disabled."
  267. fi
  268. # Backup the user's existing project-config.jam
  269. JAM_CONFIG_OUT="project-config.jam"
  270. if test -r "project-config.jam"; then
  271. counter=1
  272. while test -r "project-config.jam.$counter"; do
  273. counter=`expr $counter + 1`
  274. done
  275. echo "Backing up existing B2 configuration in project-config.jam.$counter"
  276. mv "project-config.jam" "project-config.jam.$counter"
  277. fi
  278. # Generate user-config.jam
  279. echo "Generating B2 configuration in project-config.jam for $TOOLSET..."
  280. cat > project-config.jam <<EOF
  281. # B2 Configuration
  282. # Automatically generated by bootstrap.sh
  283. import option ;
  284. import feature ;
  285. # Compiler configuration. This definition will be used unless
  286. # you already have defined some toolsets in your user-config.jam
  287. # file.
  288. if ! $TOOLSET in [ feature.values <toolset> ]
  289. {
  290. using $TOOLSET ;
  291. }
  292. project : default-build <toolset>$TOOLSET ;
  293. EOF
  294. # - Python configuration
  295. if test "x$flag_no_python" = x; then
  296. cat >> project-config.jam <<EOF
  297. # Python configuration
  298. import python ;
  299. if ! [ python.configured ]
  300. {
  301. using python : $PYTHON_VERSION : "$PYTHON_ROOT" ;
  302. }
  303. EOF
  304. fi
  305. if test "x$ICU_ROOT" != x; then
  306. cat >> project-config.jam << EOF
  307. path-constant ICU_PATH : $ICU_ROOT ;
  308. EOF
  309. fi
  310. cat >> project-config.jam << EOF
  311. # List of --with-<library> and --without-<library>
  312. # options. If left empty, all libraries will be built.
  313. # Options specified on the command line completely
  314. # override this variable.
  315. libraries = $LIBS ;
  316. # These settings are equivalent to corresponding command-line
  317. # options.
  318. option.set prefix : $PREFIX ;
  319. option.set exec-prefix : $EPREFIX ;
  320. option.set libdir : $LIBDIR ;
  321. option.set includedir : $INCLUDEDIR ;
  322. # Stop on first error
  323. option.set keep-going : false ;
  324. EOF
  325. cat << EOF
  326. Bootstrapping is done. To build, run:
  327. ./b2
  328. To generate header files, run:
  329. ./b2 headers
  330. The configuration generated uses ${TOOLSET} to build by default. If that is
  331. unintended either use the --with-toolset option or adjust configuration, by
  332. editing 'project-config.jam'.
  333. Further information:
  334. - Command line help:
  335. ./b2 --help
  336. - Getting started guide:
  337. http://www.boost.org/more/getting_started/unix-variants.html
  338. - B2 documentation:
  339. http://www.boost.org/build/
  340. EOF
粤ICP备19079148号