maint: post-release: bump version to 1.16.93
[automake.git] / t / lex-multiple.sh
blob73bb18d23204a29406c2b55582aef0c0efdfc738
1 #! /bin/sh
2 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 # Check that we can build a program using several lexers at once
18 # (assuming Flex is used). That is a little tricky, but possible.
19 # See:
20 # <https://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
21 # <https://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>
23 required='cc flex'
24 . test-init.sh
26 cat >> configure.ac << 'END'
27 AC_PROG_CC
28 AC_PROG_LEX
29 AM_PROG_AR
30 AC_PROG_RANLIB
31 AC_OUTPUT
32 END
34 cat > Makefile.am << 'END'
35 AM_LFLAGS = --never-interactive
37 bin_PROGRAMS = zardoz
39 zardoz_SOURCES = main.c
40 # Convenience libraries.
41 noinst_LIBRARIES = liblex.a liblex-foo.a liblex-bar.a
42 zardoz_LDADD = $(noinst_LIBRARIES)
44 liblex_a_SOURCES = 0.l
46 # We need the output to always be named 'lex.yy.c', in order for
47 # ylwrap to pick it up.
48 liblex_foo_a_LFLAGS = -Pfoo -olex.yy.c
49 liblex_foo_a_SOURCES = a.l
51 # Ditto.
52 liblex_bar_a_LFLAGS = -Pbar_ -olex.yy.c
53 liblex_bar_a_SOURCES = b.l
54 END
56 cat > main.c << 'END'
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
61 extern int yylex (void);
62 extern int foolex (void);
63 extern int bar_lex (void);
65 int main (int argc, char *argv[])
67 if (argc != 2)
68 abort ();
69 else if (!strcmp(argv[1], "--vanilla"))
70 return (yylex () != 121);
71 else if (!strcmp(argv[1], "--foo"))
72 return (foolex () != 121);
73 else if (!strcmp(argv[1], "--bar"))
74 return (bar_lex () != 121);
75 else
76 abort ();
78 END
80 cat > 0.l << 'END'
82 "VANILLA" { printf (":%s:\n", yytext); return 121; }
83 . { printf (":%s:\n", yytext); return 1; }
85 /* Avoid possible link errors. */
86 int yywrap (void) { return 1; }
87 END
89 sed 's/VANILLA/FOO/' 0.l > a.l
90 sed 's/VANILLA/BAR/' 0.l > b.l
92 $ACLOCAL
93 $AUTOCONF
94 $AUTOMAKE --add-missing
96 ./configure
97 $MAKE
99 if ! cross_compiling; then
100 echo VANILLA | ./zardoz --vanilla
101 echo FOO | ./zardoz --foo
102 echo BAR | ./zardoz --bar
103 ./zardoz --vanilla </dev/null && exit 1
104 echo BAR | ./zardoz --foo && exit 1
105 : For shells with busted 'set -e'.
108 yl_distcheck