2 # Check for ANTLR's antlr3 script.
3 # Will set ANTLR to the location of the script.
5 AC_DEFUN([AC_PROG_ANTLR], [
6 AC_ARG_VAR([ANTLR],[location of the antlr3 script])
8 # Check the existence of the runantlr script
9 if test "x$ANTLR" = "x"; then
10 AC_PATH_PROG(ANTLR, [antlr3])
12 AC_MSG_CHECKING([antlr3 script ($ANTLR)])
13 if test ! -e "$ANTLR"; then
14 AC_MSG_RESULT([not found])
16 elif test ! -x "$ANTLR"; then
17 AC_MSG_RESULT([not executable])
23 if test "x$ANTLR" = "x"; then
25 [No usable antlr3 script found. Make sure that the parser code has
26 been generated already. To obtain ANTLR see <http://www.antlr.org/>.]
30 ANTLR_VERSION="`$ANTLR -version 2>&1 | sed 's,.*\<Version *\([[0-9.]]*\).*,\1,'`"
31 case "$ANTLR_VERSION" in
32 3.2|3.2.*) ANTLR_VERSION=3.2 ;;
33 3.4|3.4.*) ANTLR_VERSION=3.4 ;;
34 *) AC_MSG_WARN([unknown version of antlr: $ANTLR_VERSION]);;
40 # Check the existence of the ANTLR3 C runtime library and headers
41 # Will set ANTLR_INCLUDES and ANTLR_LIBS to the location of the ANTLR
42 # headers and library respectively
44 AC_DEFUN([AC_LIB_ANTLR],[
45 AC_ARG_VAR(ANTLR_HOME, [path to libantlr3c installation])
47 # Get the location of the ANTLR3 C includes and libraries
51 [--with-antlr-dir=PATH],
52 [path to ANTLR C headers and libraries]
54 ANTLR_PREFIXES="$withval",
55 ANTLR_PREFIXES="$ANTLR_HOME /usr/local /usr /opt/local /opt"
58 AC_MSG_CHECKING(for ANTLR3 C runtime library)
60 # Use C and remember the variables we are changing
62 OLD_CPPFLAGS="$CPPFLAGS"
65 # Try all the includes/libs set in ANTLR_PREFIXES
66 for antlr_prefix in $ANTLR_PREFIXES
68 CPPFLAGS="$OLD_CPPFLAGS -I$antlr_prefix/include"
69 LIBS="$OLD_LIBS -L$antlr_prefix/lib -lantlr3c"
70 AC_LINK_IFELSE([AC_LANG_SOURCE(
75 pANTLR3_TOKEN_FACTORY factory = antlr3TokenFactoryNew((pANTLR3_INPUT_STREAM) NULL);
80 AC_MSG_RESULT(found in $antlr_prefix)
81 ANTLR_INCLUDES="-I$antlr_prefix/include"
82 ANTLR_LDFLAGS="-L$antlr_prefix/lib -lantlr3c"
87 AC_MSG_ERROR([ANTLR3 C runtime not found, see <http://www.antlr.org/>])
92 AC_MSG_CHECKING([for presence of older antlr3AsciiFileStreamNew()])
93 AC_LINK_IFELSE([AC_LANG_SOURCE(
98 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
99 pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
104 AC_MSG_RESULT([found it (must be antlr3 3.2 or similar)])
105 if test -n "$ANTLR_VERSION" -a "$ANTLR_VERSION" != 3.2; then
106 AC_MSG_WARN([your antlr parser generator is version $ANTLR_VERSION, which doesn't match the library!])
108 CVC4CPPFLAGS="${CVC4CPPFLAGS:+$CVC4CPPFLAGS }-DCVC4_ANTLR3_OLD_INPUT_STREAM"
111 AC_MSG_RESULT(failed)
112 AC_MSG_CHECKING([for presence of newer antlr3FileStreamNew()])
113 AC_LINK_IFELSE([AC_LANG_SOURCE(
118 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
119 pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);
124 AC_MSG_RESULT([found it (must be antlr3 3.4 or similar)])
125 if test -n "$ANTLR_VERSION" -a "$ANTLR_VERSION" != 3.4; then
126 AC_MSG_WARN([your antlr parser generator is version $ANTLR_VERSION, which doesn't match the library!])
130 AC_MSG_ERROR([cannot figure out how to create an antlr3 input stream, bailing..])
136 # Return the old compile variables and pop the language.
138 CPPFLAGS="$OLD_CPPFLAGS"
141 # Define the ANTLR include/libs variables
142 AC_SUBST(ANTLR_INCLUDES)
143 AC_SUBST(ANTLR_LDFLAGS)