1#!/bin/sh
2## This script shall wrap/hide how we are going to compile C++
3## source files within the ANTLR (www.antlr.org) project.
4test -z "${verbose}" && {
5  verbose=@VERBOSE@
6}
7
8## check whether we have something to do ..
9test -z "$1" &&  exit 0
10
11## get arguments
12ARGV="$*"
13
14## Command CXX is precomputed but user may override.
15if test -z "${CXX}" ; then
16  CXX="@CXX@"
17  cxx="@cxx@"
18else
19  cxx="`basename $CXX`"
20  cxx="`echo $cxx|sed 's,\..*$,,'`"
21fi
22
23## use whitespace  to separate dirs, don't use compiler specific
24## options like '-I' etc.  That will be added at runtime when we
25## know what compiler is in use.
26## 2.7.6: take CXXINCLUDE from environment into account.
27CXXINCLUDE=". ${CXXINCLUDE} @abs_top_srcdir@/lib/cpp"
28
29## according to Kurt we need to set some additional included
30## paths when using 'cxx' on Tru64. Here we go ..
31case $cxx in
32  cxx)
33    CXXINCLUDE="$CXXINCLUDE @abs_top_srcdir@/include"
34    CXXINCLUDE="$CXXINCLUDE /usr/include/cxx"
35    CXXINCLUDE="$CXXINCLUDE /usr/include"
36    ;;
37esac
38
39
40test -z "${DEBUG}" && {
41  DEBUG="@DEBUG@"
42}
43
44##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
45##       Here we set flags for well know programs         ##
46##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
47##
48## Do not set variable CXXFLAGS here, just  use it's sister
49## variable 'cxxflags'. This  allows the caller to override
50## this settings - see handling of CXXFLAGS below.
51
52case "${cxx}" in
53  cxx)
54    cxxflags="-D__DECCXX -ieee -DDEC -O0 -arch host -trapuv -check_bounds -warnprotos -std1 -noansi_args -portable"
55    #-I/spare/mccalke/antlr-2.7.5-new/include -I/usr/include/cxx -I/usr/include -L/usr/lib/cmplrs/cxx -L/usr/lib/cmplrs/cxx/V6.5-042"
56    ;;
57
58  gcc)
59    cxxflags="-felide-constructors -pipe"
60    case "${DEBUG}" in
61      0)
62        cxxflags="-O2 -DNDEBUG ${cxxflags}"
63        ;;
64      1)
65        cxxflags="-g ${cxxflags} -W -Wall"
66        ;;
67    esac
68    ;;
69  cl)
70    cxxflags="-nologo -GX -GR"
71    ;;
72  bcc32)
73    cxxflags="-q -v -w-inl -w-aus -w-par -w-ccc"
74    ;;
75  CC)
76    cxxflags="-g"
77    ;;
78  xlC)
79    cxxflags=""
80    ;;
81  aCC)
82    cxxflags=""
83    ;;
84  *)
85    cxxflag=""
86    ;;
87esac
88
89case ${cxx} in
90  bcc32|CC|aCC|xlC|cxx)
91    CXX_OPT_INCLUDE="-I"
92    ;;
93  *)
94    CXX_OPT_INCLUDE="-I "
95    ;;
96esac
97
98##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
99## **NO CHANGE NECESSARY BELOW THIS LINE - EXPERTS ONLY** ##
100##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
101
102
103## If specific flags have been configured then they overrule
104## our precomputed flags. Still a user can override by using
105## environment variable $CXXFLAGS - see below.
106test -n "@CXXFLAGS@" && {
107  set x @CXXFLAGS@  ; shift
108  case $1 in
109    +)
110      shift
111      CXXFLAGS="${cxxflags} $*"
112      ;;
113    -)
114      shift
115      cxxflags="$* ${cxxflags}"
116      ;;
117    =)
118      shift
119      cxxflags="$*"
120      ;;
121    *)
122      if test -z "$1" ; then
123        cxxflags="${cxxflags}"
124      else
125        cxxflags="$*"
126      fi
127      ;;
128  esac
129}
130
131## Regardless what has been configured, a user should always
132## be able to  override  without  the need to reconfigure or
133## change this file. Therefore we check variable $CXXFLAGS.
134## In almost all cases the precomputed flags are just ok but
135## some  additional  flags are needed. To support this in an
136## easy way, we check for the very first value. If this val-
137## ue is
138## '+'  -> append content of CXXFLAGS to precomputed flags
139## '-'  -> prepend content    -*-
140## '='  -> do not use precomputed flags
141## If none of these characters are given, the behaviour will
142## be the same as if "=" would have been given.
143
144set x ${CXXFLAGS}  ; shift
145case $1 in
146  +)
147    shift
148    CXXFLAGS="${cxxflags} $*"
149    ;;
150  -)
151    shift
152    CXXFLAGS="$* ${cxxflags}"
153    ;;
154  =)
155    shift
156    CXXFLAGS="$*"
157    ;;
158  *)
159    if test -z "$1" ; then
160      CXXFLAGS="${cxxflags}"
161    else
162      CXXFLAGS="$*"
163    fi
164    ;;
165esac
166
167##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
168##    No  c u s t o m i z a t i o n  below this line          ##
169##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
170
171## translate args - requires that we are on cygwin. Other-
172## wise  we have to assume that args are already in proper
173## format.
174
175case "@build_os@" in
176  cygwin)
177    case "@cxx@" in
178      cl|bcc32)
179        ARGV="`cygpath -m ${ARGV}`"
180        ;;
181    esac
182    ;;
183esac
184
185## we only add valid directories - note that CXXINCLUDE is
186## supposed to  contain  directories  and  not optionized'
187## arguments.
188
189set x ${CXXINCLUDE} ; shift
190Y=""
191
192## filter non valid directories
193while test $# -gt 0 ; do
194  y="$1" ; shift
195  test -d "${y}" && {
196    Y="${Y} ${y}"
197  }
198done
199
200set x ${Y} ; shift ; Y=""
201
202## translate directories on cygwin
203case "@build_os@" in
204  cygwin)
205    set x `cygpath -m ${*}` ; shift
206    ;;
207esac
208
209## prefix each arg with CXX_OPT_INCLUDE (for instance -I)
210while test $# -gt 0 ; do
211  y="$1" ; shift
212  Y="${Y} ${CXX_OPT_INCLUDE}${y}"
213done
214
215CXXINCLUDE="${Y}"
216
217###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
218###            LAST CHANCE COMPILER TUNIG HERE                     ###
219###================================================================###
220
221case "${cxx}" in
222  cl)
223    ;;
224  bcc32)
225    ;;
226  gcc)
227    ;;
228  xlC)
229    ;;
230  CC)
231    ;;
232  aCC)
233    ;;
234  cxx)
235    ;;
236  *)
237    ;;
238esac
239
240case "@cxx@" in
241  *)
242    CXXFLAGS="${CXXFLAGS} -c"
243    ;;
244esac
245
246###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
247### all variables participating in calling must be set now..
248###---------------------------------------------------------
249
250CXX_CMD="${CXX} ${CXXFLAGS} ${CXXINCLUDE}"
251
252test -z "${ARGV}" && exit 0
253
254for x in ${ARGV} ; do
255  cmd="$CXX_CMD $x"
256
257  case "${verbose}" in
258    0|no|nein|non)
259      echo "*** compiling $x"
260      ;;
261    *)
262      echo $cmd
263      ;;
264  esac
265
266  $cmd || {
267    rc=$?
268    cat <<EOF
269
270xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
271                      >> E R R O R <<
272============================================================
273
274$cmd
275
276============================================================
277Got an error while trying to execute  command  above.  Error
278messages (if any) must have shown before. The exit code was:
279exit($rc)
280xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
281EOF
282    exit $rc
283 }
284
285done
286exit 0
287
288