fixing some build systme warnings
[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([AC_LANG_SOURCE(
63 [
64 #include <antlr3.h>
65
66 int main() {
67 pANTLR3_TOKEN_FACTORY factory = antlr3TokenFactoryNew((pANTLR3_INPUT_STREAM) NULL);
68 return 0;
69 }
70 ])],
71 [
72 AC_MSG_RESULT(found in $antlr_prefix)
73 ANTLR_INCLUDES="-I$antlr_prefix/include"
74 ANTLR_LDFLAGS="-L$antlr_prefix/lib -lantlr3c"
75 break
76 ],
77 [
78 AC_MSG_RESULT(no)
79 AC_MSG_ERROR([ANTLR3 C runtime not found, see <http://www.antlr.org/>])
80 ]
81 )
82 done
83
84 AC_MSG_CHECKING([for presence of older antlr3AsciiFileStreamNew()])
85 AC_LINK_IFELSE([AC_LANG_SOURCE(
86 [
87 #include <antlr3.h>
88
89 int main() {
90 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
91 pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
92 return 0;
93 }
94 ])],
95 [
96 AC_MSG_RESULT([found it (must be antlr3 3.2 or similar)])
97 CVC4CPPFLAGS="${CVC4CPPFLAGS:+$CVC4CPPFLAGS }-DCVC4_ANTLR3_OLD_INPUT_STREAM"
98 ],
99 [
100 AC_MSG_RESULT(failed)
101 AC_MSG_CHECKING([for presence of newer antlr3FileStreamNew()])
102 AC_LINK_IFELSE([AC_LANG_SOURCE(
103 [
104 #include <antlr3.h>
105
106 int main() {
107 pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
108 pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);
109 return 0;
110 }
111 ])],
112 [
113 AC_MSG_RESULT([found it (must be antlr3 3.4 or similar)])
114 ],
115 [
116 AC_MSG_ERROR([cannot figure out how to create an antlr3 input stream, bailing..])
117 ]
118 )
119 ]
120 )
121
122 # Return the old compile variables and pop the language.
123 LIBS="$OLD_LIBS"
124 CPPFLAGS="$OLD_CPPFLAGS"
125 AC_LANG_POP()
126
127 # Define the ANTLR include/libs variables
128 AC_SUBST(ANTLR_INCLUDES)
129 AC_SUBST(ANTLR_LDFLAGS)
130 ])