]> git.saurik.com Git - bison.git/blob - m4/flex.m4
build: flex.m4.
[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 for the Lex output root, the Lex library, and whether Lex
24 # declares yytext as a char * by default.
25 m4_define([_AC_PROG_LEX_YYTEXT_DECL],
26 [cat >conftest.l <<_ACEOF[
27 %%
28 a { ECHO; }
29 b { REJECT; }
30 c { yymore (); }
31 d { yyless (1); }
32 e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument. */
33 yyless ((input () != 0)); }
34 f { unput (yytext[0]); }
35 . { BEGIN INITIAL; }
36 %%
37 #ifdef YYTEXT_POINTER
38 extern char *yytext;
39 #endif
40 int
41 main (void)
42 {
43 return ! yylex () + ! yywrap ();
44 }
45 ]_ACEOF
46 _AC_DO_VAR(LEX conftest.l)
47 AC_CACHE_CHECK([lex output file root], [ac_cv_prog_lex_root], [
48 if test -f lex.yy.c; then
49 ac_cv_prog_lex_root=lex.yy
50 elif test -f lexyy.c; then
51 ac_cv_prog_lex_root=lexyy
52 else
53 AC_MSG_ERROR([cannot find output from $LEX; giving up])
54 fi])
55 AC_SUBST([LEX_OUTPUT_ROOT], [$ac_cv_prog_lex_root])dnl
56
57 if test -z "${LEXLIB+set}"; then
58 AC_CACHE_CHECK([lex library], [ac_cv_lib_lex], [
59 ac_save_LIBS=$LIBS
60 ac_cv_lib_lex='none needed'
61 for ac_lib in '' -lfl -ll; do
62 LIBS="$ac_lib $ac_save_LIBS"
63 AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED[`cat $LEX_OUTPUT_ROOT.c`]],
64 [ac_cv_lib_lex=$ac_lib])
65 test "$ac_cv_lib_lex" != 'none needed' && break
66 done
67 LIBS=$ac_save_LIBS
68 ])
69 test "$ac_cv_lib_lex" != 'none needed' && LEXLIB=$ac_cv_lib_lex
70 fi
71 AC_SUBST(LEXLIB)
72
73 AC_CACHE_CHECK(whether yytext is a pointer, ac_cv_prog_lex_yytext_pointer,
74 [# POSIX says lex can declare yytext either as a pointer or an array; the
75 # default is implementation-dependent. Figure out which it is, since
76 # not all implementations provide the %pointer and %array declarations.
77 ac_cv_prog_lex_yytext_pointer=no
78 ac_save_LIBS=$LIBS
79 LIBS="$LEXLIB $ac_save_LIBS"
80 AC_LINK_IFELSE([AC_LANG_DEFINES_PROVIDED
81 [#define YYTEXT_POINTER 1
82 `cat $LEX_OUTPUT_ROOT.c`]],
83 [ac_cv_prog_lex_yytext_pointer=yes])
84 LIBS=$ac_save_LIBS
85 ])
86 dnl
87 if test $ac_cv_prog_lex_yytext_pointer = yes; then
88 AC_DEFINE(YYTEXT_POINTER, 1,
89 [Define to 1 if `lex' declares `yytext' as a `char *' by default,
90 not a `char[]'.])
91 fi
92 rm -f conftest.l $LEX_OUTPUT_ROOT.c
93 ])# _AC_PROG_LEX_YYTEXT_DECL