summaryrefslogtreecommitdiff
path: root/config/antlr.m4
blob: 955e1bb2a7f940e14cefdef8821697ba93cb3c90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
##
# Check for ANTLR's antlr3 script.
# Will set ANTLR to the location of the script.
##
AC_DEFUN([AC_PROG_ANTLR], [
  AC_ARG_VAR([ANTLR],[location of the antlr3 script])

  # Check the existence of the runantlr script
  if test "x$ANTLR" = "x"; then
    AC_PATH_PROG(ANTLR, [antlr3])
  else
    AC_MSG_CHECKING([antlr3 script ($ANTLR)])
    if test ! -e "$ANTLR"; then
      AC_MSG_RESULT([not found])
      unset ANTLR
    elif test ! -x "$ANTLR"; then
      AC_MSG_RESULT([not executable])
      unset ANTLR
    else
      AC_MSG_RESULT([OK])
    fi
  fi
  if test "x$ANTLR" = "x"; then
    AC_MSG_WARN(
[No usable antlr3 script found. Make sure that the parser code has
been generated already. To obtain ANTLR see <http://www.antlr3.org/>.]
    )
    ANTLR_VERSION=
  else
    ANTLR_VERSION="`$ANTLR -version 2>&1 | sed 's,.*Version  *\([[0-9.]]*\).*,\1,'`"
    case "$ANTLR_VERSION" in
      3.2|3.2.*) ANTLR_VERSION=3.2 ;;
      3.4|3.4.*) ANTLR_VERSION=3.4 ;;
      *) AC_MSG_WARN([unknown version of antlr: $ANTLR_VERSION]);;
    esac
  fi
])

##
# Check the existence of the ANTLR3 C runtime library and headers
# Will set ANTLR_INCLUDES and ANTLR_LIBS to the location of the ANTLR
# headers and library respectively
##
AC_DEFUN([AC_LIB_ANTLR],[
  AC_ARG_VAR(ANTLR_HOME, [path to libantlr3c installation])

  # Get the location of the ANTLR3 C includes and libraries
  AC_ARG_WITH(
    [antlr-dir],
    AS_HELP_STRING(
      [--with-antlr-dir=PATH],
      [path to ANTLR C headers and libraries]
    ),
    ANTLR_PREFIXES="$withval",
    ANTLR_PREFIXES="$ANTLR_HOME /usr/local /usr /opt/local /opt"
  )

  AC_MSG_CHECKING(for ANTLR3 C runtime library)

  # Use C and remember the variables we are changing
  AC_LANG_PUSH(C)
  OLD_CPPFLAGS="$CPPFLAGS"
  OLD_LIBS="$LIBS"

  # Try all the includes/libs set in ANTLR_PREFIXES
  for antlr_prefix in $ANTLR_PREFIXES
  do
    CPPFLAGS="$OLD_CPPFLAGS -I$antlr_prefix/include"
    LIBS="$OLD_LIBS -L$antlr_prefix/lib -lantlr3c"
    AC_LINK_IFELSE([AC_LANG_SOURCE(
      [
        #include <antlr3.h>

        int main() {
          pANTLR3_TOKEN_FACTORY factory = antlr3TokenFactoryNew((pANTLR3_INPUT_STREAM) NULL);
          return 0;
        }
      ])],
      [
        AC_MSG_RESULT(found in $antlr_prefix)
        ANTLR_INCLUDES="-I$antlr_prefix/include"
        ANTLR_LDFLAGS="-L$antlr_prefix/lib -lantlr3c"
        break
      ],
          [
            AC_MSG_RESULT(no)
            AC_MSG_ERROR([ANTLR3 C runtime not found, see <http://www.antlr3.org/>])
          ]
    )
  done

  AC_MSG_CHECKING([for presence of older antlr3AsciiFileStreamNew()])
  AC_LINK_IFELSE([AC_LANG_SOURCE(
    [
      #include <antlr3.h>

      int main() {
        pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
        pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew(fName);
        return 0;
      }
    ])],
    [
      AC_MSG_RESULT([found it (must be antlr3 3.2 or similar)])
      if test -n "$ANTLR_VERSION" -a "$ANTLR_VERSION" != 3.2; then
        AC_MSG_WARN([your antlr parser generator is version $ANTLR_VERSION, which doesn't match the library!])
      fi
      CVC4CPPFLAGS="${CVC4CPPFLAGS:+$CVC4CPPFLAGS }-DCVC4_ANTLR3_OLD_INPUT_STREAM"
    ],
        [
          AC_MSG_RESULT(failed)
          AC_MSG_CHECKING([for presence of newer antlr3FileStreamNew()])
          AC_LINK_IFELSE([AC_LANG_SOURCE(
            [
              #include <antlr3.h>

              int main() {
                pANTLR3_UINT8 fName = (pANTLR3_UINT8)"foo";
                pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fName, ANTLR3_ENC_8BIT);
                return 0;
              }
            ])],
            [
              AC_MSG_RESULT([found it (must be antlr3 3.4 or similar)])
              if test -n "$ANTLR_VERSION" -a "$ANTLR_VERSION" != 3.4; then
                AC_MSG_WARN([your antlr parser generator is version $ANTLR_VERSION, which doesn't match the library!])
              fi
            ],
                [
                  AC_MSG_ERROR([cannot figure out how to create an antlr3 input stream, bailing..])
                ]
          )
        ]
  )

  # Return the old compile variables and pop the language.
  LIBS="$OLD_LIBS"
  CPPFLAGS="$OLD_CPPFLAGS"
  AC_LANG_POP()

  # Define the ANTLR include/libs variables
  AC_SUBST(ANTLR_INCLUDES)
  AC_SUBST(ANTLR_LDFLAGS)
])
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback