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.
26CXXINCLUDE=". @abs_top_srcdir@/lib/cpp"
27
28test -z "${DEBUG}" && {
29  DEBUG="@DEBUG@"
30}
31
32##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
33##       Here we set flags for well know programs         ##
34##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
35##
36## Do not set variable CXXFLAGS here, just use it's sister
37## variable 'cxxflags'. This  allows  the call to override
38## this settings - see handling of CXXFLAGS below.
39
40case "${cxx}" in
41  gcc)
42    cxxflags="-MM"
43    ;;
44  *)
45    for x in ${ARGV} ; do
46      echo > $x.d
47    done
48    return 0
49    ;;
50esac
51
52case ${cxx} in
53  bcc32|CC|aCC|xlC)
54    CXX_OPT_INCLUDE="-I"
55    ;;
56  *)
57    CXX_OPT_INCLUDE="-I "
58    ;;
59esac
60
61##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
62## **NO CHANGE NECESSARY BELOW THIS LINE - EXPERTS ONLY** ##
63##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
64
65
66## If specific flags have been configured then they overrule
67## our precomputed flags. Still a user can override by using
68## environment variable $CXXFLAGS - see below.
69test -n "@CXXFLAGS@" && {
70  set x @CXXFLAGS@  ; shift
71  case $1 in
72    +)
73      shift
74      CXXFLAGS="${cxxflags} $*"
75      ;;
76    -)
77      shift
78      cxxflags="$* ${cxxflags}"
79      ;;
80    =)
81      shift
82      cxxflags="$*"
83      ;;
84    *)
85      if test -z "$1" ; then
86        cxxflags="${cxxflags}"
87      else
88        cxxflags="$*"
89      fi
90      ;;
91  esac
92}
93
94## Regardless what has been configured, a user should always
95## be able to  override  without  the need to reconfigure or
96## change this file. Therefore we check variable $CXXFLAGS.
97## In almost all cases the precomputed flags are just ok but
98## some  additional  flags are needed. To support this in an
99## easy way, we check for the very first value. If this val-
100## ue is
101## '+'  -> append content of CXXFLAGS to precomputed flags
102## '-'  -> prepend content    -*-
103## '='  -> do not use precomputed flags
104## If none of these characters are given, the behaviour will
105## be the same as if "=" would have been given.
106
107set x ${CXXFLAGS}  ; shift
108case $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    ;;
128esac
129
130##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
131##    No  c u s t o m i z a t i o n  below this line          ##
132##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
133
134## translate args - requires that we are on cygwin. Other-
135## wise  we have to assume that args are already in proper
136## format.
137
138case "@build_os@" in
139  cygwin)
140    case "@cxx@" in
141      cl|bcc32)
142        ARGV="`cygpath -m ${ARGV}`"
143        ;;
144    esac
145    ;;
146esac
147
148## we only add valid directories - note that CXXINCLUDE is
149## supposed to  contain  directories  and  not optionized'
150## arguments.
151
152set x ${CXXINCLUDE} ; shift
153Y=""
154
155## filter non valid directories
156while test $# -gt 0 ; do
157  y="$1" ; shift
158  test -d "${y}" && {
159    Y="${Y} ${y}"
160  }
161done
162
163set x ${Y} ; shift ; Y=""
164
165## translate directories on cygwin
166case "@build_os@" in
167  cygwin)
168    set x `cygpath -m ${*}` ; shift
169    ;;
170esac
171
172## prefix each arg with CXX_OPT_INCLUDE (for instance -I)
173while test $# -gt 0 ; do
174  y="$1" ; shift
175  Y="${Y} ${CXX_OPT_INCLUDE}${y}"
176done
177
178CXXINCLUDE="${Y}"
179
180###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
181###            LAST CHANCE COMPILER TUNIG HERE                     ###
182###================================================================###
183
184case "${cxx}" in
185  cl)
186    ;;
187  bcc32)
188    ;;
189  gcc)
190    ;;
191  xlC)
192    ;;
193  CC)
194    ;;
195  aCC)
196    ;;
197  *)
198    ;;
199esac
200
201case "@cxx@" in
202  *)
203    CXXFLAGS="${CXXFLAGS} -c"
204    ;;
205esac
206
207###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
208### all variables participating in calling must be set now..
209###---------------------------------------------------------
210
211CXX_CMD="${CXX} ${CXXFLAGS} ${CXXINCLUDE}"
212
213test -z "${ARGV}" && exit 0
214
215
216for x in ${ARGV} ; do
217  cmd="$CXX_CMD $x"
218
219  case "${verbose}" in
220    0|no|nein|non)
221      echo "*** update deps for `basename $x`"
222      ;;
223    *)
224      echo "*** making $x.d"
225      echo $cmd
226      ;;
227  esac
228
229  $cmd > $x.$$$$ || {
230    rc=$?
231    cat <<EOF
232
233xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
234                      >> E R R O R <<
235============================================================
236
237$cmd
238
239============================================================
240Got an error while trying to execute  command  above.  Error
241messages (if any) must have shown before. The exit code was:
242exit($rc)
243xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
244EOF
245    exit $rc
246 }
247  ## on compiling ${dir}/x.cpp we get dep  x.o : x.cpp ${dir}/y.h ..
248  ## but we need to have x.o ${dir}/x.o ${dir}/x.d : ...
249  dx=`echo $x|sed 's,\.[^.]*$,@OBJEXT@,g'`
250  sed "s,\(.*\)\@OBJEXT@[ ]*:,\1@OBJEXT@ ${dx} ${x}.d : ,g" < $x.$$$$ > $x.d
251  rm -f $x.$$$$
252
253done
254exit 0
255
256