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##
9test -z "${verbose}" && {
10  verbose=@VERBOSE@
11}
12
13## If there's nothing to be done we exit gracefully.
14test -z "$1" && exit 0
15
16## This is the top build directory.
17abs_top_build_dir="@abs_this_builddir@"
18
19## If $ANTLR_JAR is given as environment variable we are going
20## to use it, otherwise we are using configured value. The value
21## given by $ANTLR_JAR must be a valid file or directory - this
22## will be checked. If not, an error gets reported.
23antlr_jar=
24test -n "${ANTLR_JAR}" && {
25  antlr_jar="${ANTLR_JAR}"
26  test -f "${antlr_jar}" -o -d "${antlr_jar}" || {
27    cat <<EOF
28error: \$ANTLR_JAR is neither file nor directory: "${ANTLR_JAR}"
29EOF
30    exit 1
31  }
32}
33
34
35test -z "${antlr_jar}" && {
36  for x in "@ANTLR_JAR@" ${abs_top_build_dir}/antlr.jar ${abs_top_build_dir}/lib/antlr.jar
37   do
38   test -f "${x}" -o -d "${x}" && {
39     antlr_jar="$x"
40     break
41   }
42   done
43}
44
45test -z "${antlr_jar}" && {
46  antlr_jar="@ANTLR_WITH_ANTLR_JAR@"
47}
48
49case @build_os@ in
50  cygwin)
51    ARGV="`cygpath -w ${*}`"
52    set x ${ARGV} ; shift
53    test -f "${antlr_jar}" && {
54      classpath=`cygpath -m ${antlr_jar}`
55    }
56    ;;
57  *)
58    ARGV="${*}"
59    classpath="${antlr_jar}"
60    ;;
61esac
62
63cmd=""
64if test -f "${antlr_jar}" ; then
65  cmd="@JAVA@ @JAVAFLAGS@ -classpath ${classpath} antlr.Tool ${ANTLRFLAGS}"
66else
67  ### Ok, so there's no $cmd yet
68  if test -n "@ANTLR_WITH_ANTLR_CMD@" ; then
69    cmd="@ANTLR_WITH_ANTLR_CMD@ ${ANTLRFLAGS}"
70  fi
71fi
72
73test -z "$cmd" && {
74  ### We give up.
75  exec 1>&2
76  cat <<EOF
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78Unable to compile ANTLR grammar file(s)
79 $*
80Reason(s): 
81 (a) there's no @ANTLR_JAR@
82 (b) there's no ${abs_top_build_dir}/antlr.jar
83 (c) there's no ${abs_top_build_dir}/lib/antlr.jar
84 (d) options --with-antlr-jar --with-antlr-cmd not applied
85     or value given is not correct.
86You may resolve this problem by setting environment variable
87\$ANTLR_JAR.
88%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89EOF
90  exit 1
91}
92
93
94##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
95##        standard template to execute a command          ##
96##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx##
97for arg in ${ARGV} ; do
98  echo $cmd $arg
99  $cmd $arg || {
100    rc=$?
101    cat <<EOF
102
103xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
104                      >> E R R O R <<
105============================================================
106
107CLASSPATH=$CLASSPATH
108
109$cmd $arg
110
111============================================================
112Got an error while trying to execute  command  above.  Error
113messages (if any) must have shown before. The exit code was:
114exit($rc)
115xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
116EOF
117    exit $rc
118  }
119done
120exit 0
121
122
123