]> git.saurik.com Git - bison.git/blob - m4/flex.m4
NEWS: Update.
[bison.git] / m4 / flex.m4
1 # flex.m4 serial 1
2 # Copyright (C) 2012 Free Software Foundation, Inc.
3 # This file is free software; the Free Software Foundation
4 # gives unlimited permission to copy and/or distribute it,
5 # with or without modifications, as long as this notice is preserved.
6
7 # AC_PROG_LEX
8 # -----------
9 # Look for flex or lex. Set its associated library to LEXLIB.
10 # Check if lex declares yytext as a char * by default, not a char[].
11 AN_MAKEVAR([LEX], [AC_PROG_LEX])
12 AN_PROGRAM([lex], [AC_PROG_LEX])
13 AN_PROGRAM([flex], [AC_PROG_LEX])
14 AC_DEFUN_ONCE([AC_PROG_LEX],
15 [AC_CHECK_PROGS([LEX], [flex lex], [:])
16 if test "x$LEX" != "x:"; then
17 _AC_PROG_LEX_YYTEXT_DECL
18 fi])
19
20
21 # _AC_PROG_LEX_YYTEXT_DECL
22 # ------------------------
23 # Check whether this is Flex, for the Lex output root, the Lex library,
24 # and whether Lex declares yytext as a char * by default.
25 m4_define([_AC_PROG_LEX_YYTEXT_DECL],
26 [AC_CACHE_CHECK([whether lex is flex],
27 [ac_cv_prog_flex],
28 [cat >conftest.l <<_ACEOF[
29 %option debug nodefault noinput nounput noyywrap never-interactive
30 %x SC_CONF_TEST
31 %%
32 a { BEGIN SC_CONF_TEST; }
33 ]_ACEOF
34 if _AC_DO_VAR([LEX conftest.l]); then
35 ac_cv_prog_flex=yes
36 else
37 ac_cv_prog_flex=no
38 fi
39 ])
40 FLEX=
41 if test $ac_cv_prog_flex = yes; then
42 AC_SUBST([FLEX], [yes])dnl
43 fi
44
45 cat >conftest.l <<_ACEOF[
46 %%
47 a { ECHO; }
48 b { REJECT; }
49 c { yymore (); }
50 d { yyless (1); }
51 e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument. */
52 yyless ((input () != 0)); }
53 f { unput (yytext[0]); }
54 . { BEGIN INITIAL; }
55 %%
56 #ifdef YYTEXT_POINTER
57 extern char *yytext;
58 #endif
59 int
60 main (void)
61 {
62 return ! yylex () + ! yywrap ();
63 }
64 ]_ACEOF
65 _AC_DO_VAR([LEX conftest.l])
66 AC_CACHE_CHECK([lex output file root], [ac_cv_prog_lex_root], [
67 if test -f lex.yy.c; then
68 ac_cv_prog_lex_root=lex.yy
69 elif test -f lexyy.c; then
70 ac_cv_prog_lex_root=lexyy
71 else
72 AC_MSG_ERROR([cannot find output from $LEX; giving up])
73 fi])
74 AC_SUBST([LEX_OUTPUT_ROOT], [$ac_cv_prog_lex_root])dnl
75
76 if test -z "${LEXLIB+set}"; then
77 AC_CACHE_CHECK([lex library], [ac_cv_lib_lex], [
78 ac_save_LIBS=$LIBS
79 ac_cv_lib_lex='none needed'
80 for ac_lib in '' -lfl -ll; do
81 LIBS="$ac_lib $ac_save_LIBS"
82 AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED[`cat $LEX_OUTPUT_ROOT.c`]],
83 [ac_cv_lib_lex=$ac_lib])
84 test "$ac_cv_lib_lex" != 'none needed' && break
85 done
86 LIBS=$ac_save_LIBS
87 ])
88 test "$ac_cv_lib_lex" != 'none needed' && LEXLIB=$ac_cv_lib_lex
89 fi
90 AC_SUBST([LEXLIB])
91
92 AC_CACHE_CHECK([whether yytext is a pointer],
93 [ac_cv_prog_lex_yytext_pointer],
94 [# POSIX says lex can declare yytext either as a pointer or an array; the
95 # default is implementation-dependent. Figure out which it is, since
96 # not all implementations provide the %pointer and %array declarations.
97 ac_cv_prog_lex_yytext_pointer=no
98 ac_save_LIBS=$LIBS
99 LIBS="$LEXLIB $ac_save_LIBS"
100 AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED
101 [#define YYTEXT_POINTER 1
102 `cat $LEX_OUTPUT_ROOT.c`]],
103 [ac_cv_prog_lex_yytext_pointer=yes])
104 LIBS=$ac_save_LIBS
105 ])
106 dnl
107 if test $ac_cv_prog_lex_yytext_pointer = yes; then
108 AC_DEFINE([YYTEXT_POINTER], [1],
109 [Define to 1 if `lex' declares `yytext' as a `char *' by default,
110 not a `char[]'.])
111 fi
112 rm -f conftest.l $LEX_OUTPUT_ROOT.c
113 ])# _AC_PROG_LEX_YYTEXT_DECL