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