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