1 AC_DEFUN([AC_PROG_FLEX],
4 min_flex_version=ifelse([$1], ,2.5.30,$1)
5 AC_MSG_CHECKING(for flex - version >= $min_flex_version)
6 if test "$LEX" != flex; then
7 LEX="$am_aux_dir/oldtool flex ${min_flex_version}"
8 AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
9 AC_SUBST([LEXLIB], [''])
10 AC_SUBST(HAVE_FLEX, 0)
13 flex_version=`$LEX --version | sed -e 's/^flex //' -e 's/version //'`
20 char* my_strdup (const char *str);
22 char* my_strdup (const char *str)
28 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
29 strcpy (new_str, str);
39 int major = 0, minor = 0, micro = 0;
40 int min_major = 0, min_minor = 0, min_micro = 0;
44 /* HP/UX 9 (%@#!) writes to sscanf strings */
45 tmp_version = my_strdup("$min_flex_version");
46 n = sscanf(tmp_version, "%d.%d.%d", &min_major, &min_minor, &min_micro);
48 if (n != 2 && n != 3) {
49 printf("%s, bad minimum version string\n", "$min_flex_version");
53 tmp_version = my_strdup("$flex_version");
54 n = sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) ;
56 if (n != 2 && n != 3) {
57 printf("%d, %s, bad version string\n", n, "$flex_version");
61 if ((major > min_major) ||
62 ((major == min_major) && (minor > min_minor)) ||
63 ((major == min_major) && (minor == min_minor) && (micro >= min_micro)))
70 printf("WARNING: \`flex' on your system reports version %d.%d.%d, but version\n"
71 " %d.%d.%d is required. You should only need it if you\n"
72 " modified a .ll file. You may need the \`Flex' package\n"
73 " in order for those modifications to take effect. You can get\n"
74 " directions for how to obtain a recent \`Flex' from any GNU\n"
76 major, minor, micro, min_major, min_minor, min_micro);
82 AC_SUBST(HAVE_FLEX, 1)
85 LEX="$am_aux_dir/oldtool flex ${min_flex_version}"
86 AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
87 AC_SUBST([LEXLIB], [''])
88 AC_SUBST(HAVE_FLEX, 0)
92 cat <<EOF > lex_header.cc
93 #include "FlexLexer.h"
95 FLEXLEXER_HEADER=`$CXX $CPPFLAGS -M -MP lex_header.cc | sed -n -e 's/\(.*FlexLexer.h\):.*/\\1/p' \
96 | sed -e 's/\/\/\+/\//g'`
97 AC_SUBST(FLEXLEXER_HEADER, [$FLEXLEXER_HEADER])
100 # Note that it is basically required that $LEX equals "flex". Now, if someone has installed a nice and new flex
101 # in a directory early on the path, but has forgotten to place the directory with the new FlexLexer.h equally early
102 # in the include path, there is trouble. We now take some measures to detect this.
104 # The idea is that the flex program and FlexLexer.h should reside in sibling directories. The most robust way to
105 # cover various cases of binary locations is to find the prefix used for the include, and then make sure that this
106 # prefix is also a prefix of the binary.
107 FlexLexer_prefix=`echo ${FLEXLEXER_HEADER} | sed -n -e 's/\\(.*\\)\/[[^\\/]]\\{1,\\}\/FlexLexer\\.h/\\1/p'`
108 prefix_sed_mask=`echo ${FlexLexer_prefix} | tr [[:print:]] .`
109 flex_program_prefix=`which flex | sed -n -e "s/\\(${prefix_sed_mask}\\).*/\\1/p"`
110 if test "X${FlexLexer_prefix}" != "X${flex_program_prefix}"; then
111 echo "Suspicious mismatch between location of flex program and FlexLexer.h:"
112 echo " " `which flex` " vs " $FLEXLEXER_HEADER
113 echo "Treating as broken flex."
114 LEX="$am_aux_dir/oldtool FlexLexer.h ${min_flex_version}"
116 AC_SUBST(HAVE_FLEX, 0)
119 # In addition, any occurrence of <iostream.h> is a sign of a way too old FlexLexer.h.
120 if test `grep -c 'iostream.h' ${FLEXLEXER_HEADER}` != 0; then
121 echo "Found <iostream.h> in FlexLexer.h, which reminds of the much too old 2.5.4 version."
122 echo "Please update FlexLexer.h to something more recent."
123 echo "Treating as broken flex."
124 LEX="$am_aux_dir/oldtool FlexLexer.h ${min_flex_version}"
126 AC_SUBST(HAVE_FLEX, 0)