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