]> git.draconx.ca Git - dxcommon.git/blob - m4/flex.m4
Update some copyright years.
[dxcommon.git] / m4 / flex.m4
1 dnl Copyright © 2020-2021 Nick Bowler
2 dnl
3 dnl License WTFPL2: Do What the Fuck You Want To Public License, version 2.
4 dnl This is free software: you are free to do what the fuck you want to.
5 dnl There is NO WARRANTY, to the extent permitted by law.
6
7 dnl DX_PROG_FLEX([min-version], [action-if-found], [action-if-not-found])
8 dnl
9 dnl Search PATH for a working flex utility with the given minimum version,
10 dnl which may be empty to accept any version.  If found, the FLEX
11 dnl variable (which is substituted by AC_SUBST) is set with the result,
12 dnl and action-if-found is executed.  Otherwise, action-if-not-found
13 dnl is executed if nonempty, else configure will exit with a fatal error.
14 AC_DEFUN([DX_PROG_FLEX], [AC_PREREQ([2.62])dnl
15 AC_ARG_VAR([FLEX], [Fast Lexical Analyzer command])dnl
16 AC_ARG_VAR([FLEXFLAGS], [Additional options to pass to flex])dnl
17 cat >conftest.l <<'EOF'
18 m4_apply([_DX_FLEX_TEST_PROGRAM], m4_split([$1], [\.]))
19 EOF
20 AC_CACHE_CHECK([for flex], [ac_cv_path_FLEX],
21 [dx_cv_flex_found=:
22 AC_PATH_PROGS_FEATURE_CHECK([FLEX], [flex lex],
23 [_DX_FLEX_DO_TEST([$ac_path_FLEX],
24 [DX_BASENAME([flex_relcmd], ["$ac_path_FLEX"])
25 flex_bypath=`{ command -v "$flex_relcmd"; } 2>/dev/null` #''
26 ac_cv_path_FLEX=$ac_path_FLEX
27 test x"$flex_bypath" = x"$ac_path_FLEX" && ac_cv_path_FLEX=$flex_relcmd
28 ac_path_FLEX_found=:
29 dx_cv_flex_works=yes])], [ac_cv_path_FLEX=no dx_cv_flex_found=false])])
30 AS_IF([$dx_cv_flex_found],
31 [FLEX=$ac_cv_path_FLEX
32 AC_CACHE_CHECK([whether $FLEX works], [dx_cv_flex_works],
33 [_DX_FLEX_DO_TEST([$FLEX], [dx_cv_flex_works=yes], [dx_cv_flex_works=no])])])
34 AS_IF([test x"$dx_cv_flex_works" = x"yes"],
35   [$2], [m4_default([$3], [AC_MSG_FAILURE(
36 [flex m4_ifnblank([$1], [version at least $1 ])is required.
37
38 The latest version may be found at <https://github.com/westes/flex/>.
39 ])])])
40 rm -f conftest.c conftest.inc conftest.l
41 ])
42
43 m4_define([_DX_FLEX_TEST_PROGRAM],
44 [%option noyywrap
45 %{
46 #ifndef FLEX_SCANNER
47 DX_LIB_COMPILE_ERROR([FLEX_SCANNER not defined])
48 #endif
49 m4_ifnblank([$1], [dnl
50 #if YY_FLEX_MAJOR_VERSION < $1
51 DX_LIB_COMPILE_ERROR([major version insufficient])
52 m4_ifnblank([$2], [dnl
53 #elif YY_FLEX_MAJOR_VERSION == $1
54 #  if YY_FLEX_MINOR_VERSION < $2
55 DX_LIB_COMPILE_ERROR([minor version insufficient])
56 m4_ifnblank([$3], [dnl
57 #  elif YY_FLEX_MINOR_VERSION == $2
58 #    if YY_FLEX_SUBMINOR_VERSION < $3
59 DX_LIB_COMPILE_ERROR([subminor version insufficient])
60 #    endif
61 ])dnl
62 #  endif
63 ])dnl
64 #endif
65 ])dnl
66 %}
67 %%
68 %%
69 int main(void)
70 {
71   return yylex();
72 }])
73
74 AC_DEFUN([_DX_FLEX_DO_TEST], [rm -f conftest.c
75 AS_IF([$1 -o conftest.inc conftest.l 2>&AS_MESSAGE_LOG_FD],
76 [AC_LINK_IFELSE([AC_LANG_SOURCE([[#include "conftest.inc"]])], [$2], [$3])],
77 [$3])])