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