Changing ANTLR3 detection in configure (Fixes #147)
[cvc5.git] / config / antlr.m4
1 ##
2 # Check for ANTLR's antlr3 script.
3 # Will set ANTLR to the location of the script.
4 ##
5 AC_DEFUN([AC_PROG_ANTLR], [
6 AC_ARG_VAR([ANTLR],[location of the antlr3 script])
7
8 # Check the existence of the runantlr script
9 if test "x$ANTLR" = "x"; then
10 AC_PATH_PROG(ANTLR, [antlr3])
11 else
12 AC_MSG_CHECKING([antlr3 script ($ANTLR)])
13 if test ! -e "$ANTLR"; then
14 AC_MSG_RESULT([not found])
15 unset ANTLR
16 elif test ! -x "$ANTLR"; then
17 AC_MSG_RESULT([not executable])
18 unset ANTLR
19 else
20 AC_MSG_RESULT([OK])
21 fi
22 fi
23 if test "x$ANTLR" = "x"; then
24 AC_MSG_WARN(
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/>.]
27 )
28 fi
29 ])
30
31 ##
32 # Check the existence of the ANTLR3 C runtime library and headers
33 # Will set ANTLR_INCLUDES and ANTLR_LIBS to the location of the ANTLR
34 # headers and library respectively
35 ##
36 AC_DEFUN([AC_LIB_ANTLR],[
37 AC_ARG_VAR(ANTLR_HOME, [path to libantlr3c installation])
38
39 # Get the location of the ANTLR3 C includes and libraries
40 AC_ARG_WITH(
41 [antlr-dir],
42 AS_HELP_STRING(
43 [--with-antlr-dir=PATH],
44 [path to ANTLR C headers and libraries]
45 ),
46 ANTLR_PREFIXES="$withval",
47 ANTLR_PREFIXES="$ANTLR_HOME /usr/local /usr /opt/local /opt"
48 )
49
50 AC_MSG_CHECKING(for ANTLR3 C runtime library)
51
52 # Use C and remember the variables we are changing
53 AC_LANG_PUSH(C)
54 OLD_CPPFLAGS="$CPPFLAGS"
55 OLD_LIBS="$LIBS"
56
57 # Try all the includes/libs set in ANTLR_PREFIXES
58 for antlr_prefix in $ANTLR_PREFIXES
59 do
60 CPPFLAGS="$OLD_CPPFLAGS -I$antlr_prefix/include"
61 LIBS="$OLD_LIBS -L$antlr_prefix/lib -lantlr3c"
62 AC_LINK_IFELSE(
63 [
64 #include <antlr3.h>
65
66 int main() {
67 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
68 pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
69 return 0;
70 }
71 ],
72 [
73 AC_MSG_RESULT(found in $antlr_prefix)
74 ANTLR_INCLUDES="-I$antlr_prefix/include"
75 ANTLR_LDFLAGS="-L$antlr_prefix/lib -lantlr3c"
76 break
77 ],
78 [
79 AC_MSG_RESULT(no)
80 AC_MSG_ERROR([ANTLR3 C runtime not found, see <http://www.antlr.org/>])
81 ]
82 )
83 done
84
85 # Return the old compile variables and pop the language.
86 LIBS="$OLD_LIBS"
87 CPPFLAGS="$OLD_CPPFLAGS"
88 AC_LANG_POP()
89
90 # Define the ANTLR include/libs variables
91 AC_SUBST(ANTLR_INCLUDES)
92 AC_SUBST(ANTLR_LDFLAGS)
93 ])