Fixing documentation for glpk configuration.
[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.antlr3.org/>.]
27 )
28 ANTLR_VERSION=
29 else
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]);;
35 esac
36 fi
37 ])
38
39 ##
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
43 ##
44 AC_DEFUN([AC_LIB_ANTLR],[
45 AC_ARG_VAR(ANTLR_HOME, [path to libantlr3c installation])
46
47 # Get the location of the ANTLR3 C includes and libraries
48 AC_ARG_WITH(
49 [antlr-dir],
50 AS_HELP_STRING(
51 [--with-antlr-dir=PATH],
52 [path to ANTLR C headers and libraries]
53 ),
54 ANTLR_PREFIXES="$withval",
55 ANTLR_PREFIXES="$ANTLR_HOME /usr/local /usr /opt/local /opt"
56 )
57
58 AC_MSG_CHECKING(for ANTLR3 C runtime library)
59
60 # Use C and remember the variables we are changing
61 AC_LANG_PUSH(C)
62 OLD_CPPFLAGS="$CPPFLAGS"
63 OLD_LIBS="$LIBS"
64
65 # Try all the includes/libs set in ANTLR_PREFIXES
66 for antlr_prefix in $ANTLR_PREFIXES
67 do
68 CPPFLAGS="$OLD_CPPFLAGS -I$antlr_prefix/include"
69 LIBS="$OLD_LIBS -L$antlr_prefix/lib -lantlr3c"
70 AC_LINK_IFELSE([AC_LANG_SOURCE(
71 [
72 #include <antlr3.h>
73
74 int main() {
75 pANTLR3_TOKEN_FACTORY factory = antlr3TokenFactoryNew((pANTLR3_INPUT_STREAM) NULL);
76 return 0;
77 }
78 ])],
79 [
80 AC_MSG_RESULT(found in $antlr_prefix)
81 ANTLR_INCLUDES="-I$antlr_prefix/include"
82 ANTLR_LDFLAGS="-L$antlr_prefix/lib -lantlr3c"
83 break
84 ],
85 [
86 AC_MSG_RESULT(no)
87 AC_MSG_ERROR([ANTLR3 C runtime not found, see <http://www.antlr3.org/>])
88 ]
89 )
90 done
91
92 AC_MSG_CHECKING([for presence of older antlr3AsciiFileStreamNew()])
93 AC_LINK_IFELSE([AC_LANG_SOURCE(
94 [
95 #include <antlr3.h>
96
97 int main() {
98 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
99 pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
100 return 0;
101 }
102 ])],
103 [
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!])
107 fi
108 CVC4CPPFLAGS="${CVC4CPPFLAGS:+$CVC4CPPFLAGS }-DCVC4_ANTLR3_OLD_INPUT_STREAM"
109 ],
110 [
111 AC_MSG_RESULT(failed)
112 AC_MSG_CHECKING([for presence of newer antlr3FileStreamNew()])
113 AC_LINK_IFELSE([AC_LANG_SOURCE(
114 [
115 #include <antlr3.h>
116
117 int main() {
118 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
119 pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);
120 return 0;
121 }
122 ])],
123 [
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!])
127 fi
128 ],
129 [
130 AC_MSG_ERROR([cannot figure out how to create an antlr3 input stream, bailing..])
131 ]
132 )
133 ]
134 )
135
136 # Return the old compile variables and pop the language.
137 LIBS="$OLD_LIBS"
138 CPPFLAGS="$OLD_CPPFLAGS"
139 AC_LANG_POP()
140
141 # Define the ANTLR include/libs variables
142 AC_SUBST(ANTLR_INCLUDES)
143 AC_SUBST(ANTLR_LDFLAGS)
144 ])