Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / src / engine / build.sh
1 #!/bin/sh
2
3 #~ Copyright 2002-2005 Rene Rivera.
4 #~ Distributed under the Boost Software License, Version 1.0.
5 #~ (See accompanying file LICENSE_1_0.txt or copy at
6 #~ http://www.boost.org/LICENSE_1_0.txt)
7
8 # Reset the toolset.
9 BOOST_JAM_TOOLSET=
10
11 # Run a command, and echo before doing so. Also checks the exit status and quits
12 # if there was an error.
13 echo_run ()
14 {
15     echo "$@"
16     $@
17     r=$?
18     if test $r -ne 0 ; then
19         exit $r
20     fi
21 }
22
23 # Print an error message, and exit with a status of 1.
24 error_exit ()
25 {
26     echo "###"
27     echo "###" "$@"
28     echo "###"
29     echo "### You can specify the toolset as the argument, i.e.:"
30     echo "###     ./build.sh gcc"
31     echo "###"
32     echo "### Toolsets supported by this script are:"
33     echo "###     acc, como, darwin, gcc, intel-darwin, intel-linux, kcc, kylix,"
34     echo "###     mipspro, mingw(msys), pathscale, pgi, qcc, sun, sunpro, tru64cxx, vacpp"
35     echo "###"
36     echo "### A special toolset; cc, is available which is used as a fallback"
37     echo "### when a more specific toolset is not found and the cc command is"
38     echo "### detected. The 'cc' toolset will use the CC, CFLAGS, and LIBS"
39     echo "### environment variables, if present."
40     echo "###"
41     exit 1
42 }
43
44 # Check that a command is in the PATH.
45 test_path ()
46 {
47     if `command -v command 1>/dev/null 2>/dev/null`; then
48         command -v $1 1>/dev/null 2>/dev/null
49     else
50         hash $1 1>/dev/null 2>/dev/null
51     fi
52 }
53
54 # Check that the OS name, as returned by "uname", is as given.
55 test_uname ()
56 {
57     if test_path uname; then
58         test `uname` = $*
59     fi
60 }
61
62 # Try and guess the toolset to bootstrap the build with...
63 Guess_Toolset ()
64 {
65     if test -r /mingw/bin/gcc ; then
66         BOOST_JAM_TOOLSET=mingw
67         BOOST_JAM_TOOLSET_ROOT=/mingw/
68     elif test_uname Darwin ; then BOOST_JAM_TOOLSET=darwin
69     elif test_uname IRIX ; then BOOST_JAM_TOOLSET=mipspro
70     elif test_uname IRIX64 ; then BOOST_JAM_TOOLSET=mipspro
71     elif test_uname OSF1 ; then BOOST_JAM_TOOLSET=tru64cxx
72     elif test_uname QNX && test_path qcc ; then BOOST_JAM_TOOLSET=qcc
73     elif test_path gcc ; then BOOST_JAM_TOOLSET=gcc
74     elif test_path icc ; then BOOST_JAM_TOOLSET=intel-linux
75     elif test -r /opt/intel/cc/9.0/bin/iccvars.sh ; then
76         BOOST_JAM_TOOLSET=intel-linux
77         BOOST_JAM_TOOLSET_ROOT=/opt/intel/cc/9.0
78     elif test -r /opt/intel_cc_80/bin/iccvars.sh ; then
79         BOOST_JAM_TOOLSET=intel-linux
80         BOOST_JAM_TOOLSET_ROOT=/opt/intel_cc_80
81     elif test -r /opt/intel/compiler70/ia32/bin/iccvars.sh ; then
82         BOOST_JAM_TOOLSET=intel-linux
83         BOOST_JAM_TOOLSET_ROOT=/opt/intel/compiler70/ia32/
84     elif test -r /opt/intel/compiler60/ia32/bin/iccvars.sh ; then
85         BOOST_JAM_TOOLSET=intel-linux
86         BOOST_JAM_TOOLSET_ROOT=/opt/intel/compiler60/ia32/
87     elif test -r /opt/intel/compiler50/ia32/bin/iccvars.sh ; then
88         BOOST_JAM_TOOLSET=intel-linux
89         BOOST_JAM_TOOLSET_ROOT=/opt/intel/compiler50/ia32/
90     elif test_path pgcc ; then BOOST_JAM_TOOLSET=pgi
91     elif test_path pathcc ; then BOOST_JAM_TOOLSET=pathscale
92     elif test_path xlc ; then BOOST_JAM_TOOLSET=vacpp
93     elif test_path como ; then BOOST_JAM_TOOLSET=como
94     elif test_path KCC ; then BOOST_JAM_TOOLSET=kcc
95     elif test_path bc++ ; then BOOST_JAM_TOOLSET=kylix
96     elif test_path aCC ; then BOOST_JAM_TOOLSET=acc
97     elif test_uname HP-UX ; then BOOST_JAM_TOOLSET=acc
98     elif test -r /opt/SUNWspro/bin/cc ; then
99         BOOST_JAM_TOOLSET=sunpro
100         BOOST_JAM_TOOLSET_ROOT=/opt/SUNWspro/
101     # Test for "cc" as the default fallback.
102     elif test_path $CC ; then BOOST_JAM_TOOLSET=cc
103     elif test_path cc ; then
104         BOOST_JAM_TOOLSET=cc
105         CC=cc
106     fi
107     if test "$BOOST_JAM_TOOLSET" = "" ; then
108         error_exit "Could not find a suitable toolset."
109     fi
110 }
111
112 # The one option we support in the invocation
113 # is the name of the toolset to force building
114 # with.
115 case "$1" in
116     --guess-toolset) Guess_Toolset ; echo "$BOOST_JAM_TOOLSET" ; exit 1 ;;
117     -*) Guess_Toolset ;;
118     ?*) BOOST_JAM_TOOLSET=$1 ; shift ;;
119     *) Guess_Toolset ;;
120 esac
121 BOOST_JAM_OPT_JAM="-o bootstrap/jam0"
122 BOOST_JAM_OPT_MKJAMBASE="-o bootstrap/mkjambase0"
123 BOOST_JAM_OPT_YYACC="-o bootstrap/yyacc0"
124 case $BOOST_JAM_TOOLSET in
125     mingw)
126     if test -r ${BOOST_JAM_TOOLSET_ROOT}bin/gcc ; then
127         export PATH=${BOOST_JAM_TOOLSET_ROOT}bin:$PATH
128     fi
129     BOOST_JAM_CC="gcc -DNT"
130     ;;
131
132     gcc)
133     BOOST_JAM_CC=gcc
134     ;;
135
136     darwin)
137     BOOST_JAM_CC=cc
138     ;;
139
140     intel-darwin)
141     BOOST_JAM_CC=icc
142     ;;
143
144     intel-linux)
145     if test -r /opt/intel/cc/9.0/bin/iccvars.sh ; then
146         BOOST_JAM_TOOLSET_ROOT=/opt/intel/cc/9.0/
147     elif test -r /opt/intel_cc_80/bin/iccvars.sh ; then
148         BOOST_JAM_TOOLSET_ROOT=/opt/intel_cc_80/
149     elif test -r /opt/intel/compiler70/ia32/bin/iccvars.sh ; then
150         BOOST_JAM_TOOLSET_ROOT=/opt/intel/compiler70/ia32/
151     elif test -r /opt/intel/compiler60/ia32/bin/iccvars.sh ; then
152         BOOST_JAM_TOOLSET_ROOT=/opt/intel/compiler60/ia32/
153     elif test -r /opt/intel/compiler50/ia32/bin/iccvars.sh ; then
154         BOOST_JAM_TOOLSET_ROOT=/opt/intel/compiler50/ia32/
155     fi
156     if test -r ${BOOST_JAM_TOOLSET_ROOT}bin/iccvars.sh ; then
157         # iccvars does not change LD_RUN_PATH. We adjust LD_RUN_PATH here in
158         # order not to have to rely on ld.so.conf knowing the icc library
159         # directory. We do this before running iccvars.sh in order to allow a
160         # user to add modifications to LD_RUN_PATH in iccvars.sh.
161         if test -z "${LD_RUN_PATH}"; then
162             LD_RUN_PATH="${BOOST_JAM_TOOLSET_ROOT}lib"
163         else
164             LD_RUN_PATH="${BOOST_JAM_TOOLSET_ROOT}lib:${LD_RUN_PATH}"
165         fi
166         export LD_RUN_PATH
167         . ${BOOST_JAM_TOOLSET_ROOT}bin/iccvars.sh
168     fi
169     BOOST_JAM_CC=icc
170     ;;
171
172     vacpp)
173     BOOST_JAM_CC=xlc
174     ;;
175
176     como)
177     BOOST_JAM_CC="como --c"
178     ;;
179
180     kcc)
181     BOOST_JAM_CC=KCC
182     ;;
183
184     kylix)
185     BOOST_JAM_CC=bc++
186     ;;
187
188     mipspro)
189     BOOST_JAM_CC=cc
190     ;;
191
192     pathscale)
193     BOOST_JAM_CC=pathcc
194     ;;
195
196     pgi)
197     BOOST_JAM_CC=pgcc
198     ;;
199
200     sun*)
201     if test -z "${BOOST_JAM_TOOLSET_ROOT}" -a -r /opt/SUNWspro/bin/cc ; then
202         BOOST_JAM_TOOLSET_ROOT=/opt/SUNWspro/
203     fi
204     if test -r "${BOOST_JAM_TOOLSET_ROOT}bin/cc" ; then
205         PATH=${BOOST_JAM_TOOLSET_ROOT}bin:${PATH}
206         export PATH
207     fi
208     BOOST_JAM_CC=cc
209     ;;
210
211     clang*)
212     BOOST_JAM_CC="clang -Wno-unused -Wno-format"
213     BOOST_JAM_TOOLSET=clang
214     ;;
215
216     tru64cxx)
217     BOOST_JAM_CC=cc
218     ;;
219
220     acc)
221     BOOST_JAM_CC="cc -Ae"
222     ;;
223
224     cc)
225     if test -z "$CC" ; then CC=cc ; fi
226     BOOST_JAM_CC=$CC
227     BOOST_JAM_OPT_JAM="$BOOST_JAM_OPT_JAM $CFLAGS $LIBS"
228     BOOST_JAM_OPT_MKJAMBASE="$BOOST_JAM_OPT_MKJAMBASE $CFLAGS $LIBS"
229     BOOST_JAM_OPT_YYACC="$BOOST_JAM_OPT_YYACC $CFLAGS $LIBS"
230     ;;
231
232     qcc)
233     BOOST_JAM_CC=qcc
234     ;;
235
236     *)
237     error_exit "Unknown toolset: $BOOST_JAM_TOOLSET"
238     ;;
239 esac
240
241 echo "###"
242 echo "### Using '$BOOST_JAM_TOOLSET' toolset."
243 echo "###"
244
245 YYACC_SOURCES="yyacc.c"
246 MKJAMBASE_SOURCES="mkjambase.c"
247 BJAM_SOURCES="\
248  command.c compile.c constants.c debug.c execcmd.c frames.c function.c glob.c\
249  hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c\
250  object.c option.c output.c parse.c pathsys.c regexp.c rules.c\
251  scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c\
252  builtins.c class.c cwd.c native.c md5.c w32_getreg.c modules/set.c\
253  modules/path.c modules/regex.c modules/property-set.c modules/sequence.c\
254  modules/order.c"
255 case $BOOST_JAM_TOOLSET in
256     mingw)
257     BJAM_SOURCES="${BJAM_SOURCES} execnt.c filent.c pathnt.c"
258     ;;
259
260     *)
261     BJAM_SOURCES="${BJAM_SOURCES} execunix.c fileunix.c pathunix.c"
262     ;;
263 esac
264
265 BJAM_UPDATE=
266 if test "$1" = "--update" -o "$2" = "--update" -o "$3" = "--update" -o "$4" = "--update" ; then
267     BJAM_UPDATE="update"
268 fi
269 if test "${BJAM_UPDATE}" = "update" -a ! -x "./bootstrap/jam0" ; then
270     BJAM_UPDATE=
271 fi
272
273 if test "${BJAM_UPDATE}" != "update" ; then
274     echo_run rm -rf bootstrap
275     echo_run mkdir bootstrap
276     if test ! -r jamgram.y -o ! -r jamgramtab.h ; then
277         echo_run ${BOOST_JAM_CC} ${BOOST_JAM_OPT_YYACC} ${YYACC_SOURCES}
278         if test -x "./bootstrap/yyacc0" ; then
279             echo_run ./bootstrap/yyacc0 jamgram.y jamgramtab.h jamgram.yy
280         fi
281     fi
282     if test ! -r jamgram.c -o ! -r jamgram.h ; then
283         if test_path yacc ; then YACC="yacc -d"
284         elif test_path bison ; then YACC="bison -y -d --yacc"
285         fi
286         echo_run $YACC jamgram.y
287         mv -f y.tab.c jamgram.c
288         mv -f y.tab.h jamgram.h
289     fi
290     if test ! -r jambase.c ; then
291         echo_run ${BOOST_JAM_CC} ${BOOST_JAM_OPT_MKJAMBASE} ${MKJAMBASE_SOURCES}
292         if test -x "./bootstrap/mkjambase0" ; then
293             echo_run ./bootstrap/mkjambase0 jambase.c Jambase
294         fi
295     fi
296     echo_run ${BOOST_JAM_CC} ${BOOST_JAM_OPT_JAM} ${BJAM_SOURCES}
297 fi
298 if test -x "./bootstrap/jam0" ; then
299     if test "${BJAM_UPDATE}" != "update" ; then
300         echo_run ./bootstrap/jam0 -f build.jam --toolset=$BOOST_JAM_TOOLSET "--toolset-root=$BOOST_JAM_TOOLSET_ROOT" "$@" clean
301     fi
302     echo_run ./bootstrap/jam0 -f build.jam --toolset=$BOOST_JAM_TOOLSET "--toolset-root=$BOOST_JAM_TOOLSET_ROOT" "$@"
303 fi