1#!/bin/sh
2##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
3## This file is part of ANTLR. See LICENSE.txt for licence  ##
4## details. Written by W. Haefelinger.                      ##
5##                                                          ##
6##       Copyright (C) Wolfgang Haefelinger, 2004           ##
7##                                                          ##
8##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
9## This script shall wrap/hide how we are going to build a library
10## within the ANTLR (www.antlr.org) project.
11test -z "${1}" && exit 0
12
13if test -z "${AR}" ; then
14  AR="@AR@"
15  ar="@ar@"
16else
17  ar="`basename $AR`"
18  ar="`echo $ar|sed 's,\..*$,,'`"
19fi
20
21test -z "${DEBUG}" && {
22  DEBUG="@DEBUG@"
23}
24
25RANLIB="@RANLIB@"
26LIBNAME="@ANTLR_LIB@"
27
28##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
29##             Prepate input arguments                    ##
30##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
31case "@build_os@" in
32  cygwin)
33    LIBNAME="`cygpath -m ${LIBNAME}`"
34    ARGV="`cygpath -m ${*}`"
35    ;;
36  *)
37    ARGV="${*}"
38    ;;
39esac
40
41L="${ARGV}" ; ARGV=""
42for x in $L ; do
43  if test -f "${x}" ; then
44    ARGV="$ARGV ${x}"
45  fi
46done
47unset L
48
49if test -z "${ARGV}" ; then
50cat <<EOF
51%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52Uuups, something went wrong. Have not been able to collect
53a list of object files. Perhaps nothing has been compiled 
54so far?
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56EOF
57exit 0
58fi
59
60##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
61##       Here we set flags for well know programs         ##
62##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
63##
64## Do not set variable ARFLAGS here, just use it's sister
65## variable 'arflags'. This  allows  the call to override
66## this settings - see handling of ARFLAGS below.
67
68case "@cxx@" in
69  cl)
70    ## I'm shamelessly override what has been configured --
71    ## nothing more than a hack.
72    AR='lib'
73    ## MSYS: usually MSYS translates Unix paths - under the
74    ## hood - into a mixed path (/c => c:/). This does not
75    ## work when using arguments like "-out:/c". Such a path
76    ## remains untranslated causing underlying tool to choke.
77    case @build_os@ in
78      mingw*)
79        d=`dirname "${LIBNAME}"`
80        b=`basename "${LIBNAME}"`
81        d=`cd "$d" && pwd -W`
82        LIBNAME="$d/$b"
83        ;;
84    esac
85    arflags="-nologo -verbose -out:${LIBNAME}"
86    cmd_pfx="rm -f ${LIBNAME}"
87    ## no runlib required
88    unset RANLIB
89    ;;
90  bcc32)
91    ## I'm shamelessly override what has been configured --
92    ## nothing more than a hack.
93    AR='tlib'
94    ## to make the general command work
95    b=`basename "${LIBNAME}"`
96    cmd_pfx="rm -f ${b} ${LIBNAME}"
97    cmd_sfx="cp $b .${b} ; rm ${b}; cp .${b} ${LIBNAME}"
98    arflags="/P128 ${b}"
99      ## no runlib required
100    unset RANLIB
101
102    ## Borland's interface for tlib (making a static library)
103    ## is most stupid ever seen. For example,  it  does  not
104    ## accept "-" in file  names,  not  is it able to handle
105    ## forward  slashes  in pathnames. Even Microsoft can do
106    ## this..
107    L="${ARGV}" ; ARGV=""
108    for x in $L ; do
109      ARGV="$ARGV +`basename ${x}`"
110    done
111    unset L
112    ;;
113  CC)
114    AR="@CXX@"
115    arflags="-xar -o ${LIBNAME}"
116    cmd_pfx="rm -f ${LIBNAME}"
117    ;;
118  *)
119    arflags="rus"
120    ARGV="${LIBNAME} ${ARGV}"
121    cmd_pfx="rm -f ${LIBNAME}"
122    ;;
123esac
124
125##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
126## **NO CHANGE NECESSARY BELOW THIS LINE - EXPERTS ONLY** ##
127##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
128test -z "${verbose}" && {
129  verbose=@VERBOSE@
130}
131
132## If specific flags have been configured then they overrule
133## our precomputed flags. Still a user can override by using
134## environment variable $ARFLAGS - see below.
135test -n "@ARFLAGS@" && {
136  set x @ARFLAGS@  ; shift
137  case $1 in
138    +)
139      shift
140      ARFLAGS="${arflags} $*"
141      ;;
142    -)
143      shift
144      arflags="$* ${arflags}"
145      ;;
146    =)
147      shift
148      arflags="$*"
149      ;;
150    *)
151      if test -z "$1" ; then
152        arflags="${arflags}"
153      else
154        arflags="$*"
155      fi
156      ;;
157  esac
158}
159
160## Regardless what has been configured, a user should always
161## be able to  override  without  the need to reconfigure or
162## change this file. Therefore we check variable $ARFLAGS.
163## In almost all cases the precomputed flags are just ok but
164## some  additional  flags are needed. To support this in an
165## easy way, we check for the very first value. If this val-
166## ue is
167## '+'  -> append content of ARFLAGS to precomputed flags
168## '-'  -> prepend content    -*-
169## '='  -> do not use precomputed flags
170## If none of these characters are given, the behaviour will
171## be the same as if "=" would have been given.
172
173set x ${ARFLAGS}  ; shift
174case $1 in
175  +)
176    shift
177    ARFLAGS="${arflags} $*"
178    ;;
179  -)
180    shift
181    ARFLAGS="$* ${arflags}"
182    ;;
183  =)
184    shift
185    ARFLAGS="$*"
186    ;;
187  *)
188    if test -z "$1" ; then
189      ARFLAGS="${arflags}"
190    else
191      ARFLAGS="$*"
192    fi
193    ;;
194esac
195
196## Any special treatment goes here ..
197case "${ar}" in
198  ar)
199    ;;
200  *)
201    ;;
202esac
203
204##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
205##    No  c u s t o m i z a t i o n  below this line          ##
206##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%##
207
208
209## Reset positional args
210set x ${ARGV} ; shift
211
212## This is how we would run 'ranlib' ..
213test -n "${RANLIB}" && {
214  ranlib_cmd="${RANLIB} ${LIBNAME}"
215}
216
217
218
219## This extra copy is a hack for Borland's TLIB which does
220## not accept '-' in filenames.
221cmd="${AR} ${ARFLAGS} ${ARGV}"
222
223## If there's something to be done ..
224test -n "${cmd}" && {
225
226  test -n "${cmd_pfx}" && {
227    test $verbose -gt 0 && {
228      echo $cmd_pfx
229    }
230    eval ${cmd_pfx} || exit 1
231  }
232
233  ## be verbose of required
234  case "${verbose}" in
235    0|no|nein|non)
236      echo "*** creating ${LIBNAME}"
237      ;;
238    *)
239      echo $cmd
240      ;;
241  esac
242
243  ## remove library - just in case.
244  test -n "${LIBNAME}" -a -f "${LIBNAME}" && {
245    rm -f ${LIBNAME}
246  }
247
248
249  ## eventually ..
250  $cmd || {
251    rc=$?
252    cat <<EOF
253
254xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
255                      >> E R R O R <<
256============================================================
257
258$cmd
259
260============================================================
261Got an error while trying to execute  command  above.  Error
262messages (if any) must have shown before. The exit code was:
263exit($rc)
264xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
265EOF
266    exit $rc
267  }
268
269  test -n "${cmd_sfx}" && {
270    test $verbose -gt 0 && {
271      echo $cmd_sfx
272    }
273    eval ${cmd_sfx} || exit 1
274  }
275
276  ## and even later ..
277  test -n "${RANLIB}" && {
278    cmd="${RANLIB} ${LIBNAME}"
279    test $verbose -gt 0 && {
280      echo $cmd
281    }
282    $cmd || {
283      exit 1
284    }
285  }
286}
287
288exit 0