test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / lex-lib-external.sh
blob30fc25b15db91100947011dd93cbcc4931dce626
1 #! /bin/sh
2 # Copyright (C) 2011-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 get use the 'yywrap' function from a system-wide
18 # library, if that's available.
20 required='cc lex'
21 . test-init.sh
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_PROG_RANLIB
26 AC_PROG_LEX
27 AC_OUTPUT
28 END
30 cat > Makefile.am << 'END'
31 AM_LFLAGS = --never-interactive
33 bin_PROGRAMS = lexer
34 lexer_SOURCES = foo.l
35 lexer_LDADD = $(LEXLIB)
37 .PHONY: have-lexlib
38 have-lexlib:
39 test x'$(LEXLIB)' != x
40 echo 'int main (void) { return yywrap (); }' > x.c
41 $(CC) -c x.c
42 $(CC) x.$(OBJEXT) $(LEXLIB)
43 rm -f x.c *.$(OBJEXT) *.o *.out *.exe
44 END
46 cat > foo.l <<'END'
48 "GOOD" return EOF;
51 int main (void)
53 /* We don't use a 'while' loop here (like a real lexer would do)
54 to avoid possible hangs. */
55 if (yylex () == EOF)
56 return 0;
57 else
58 return 1;
60 END
62 $ACLOCAL
63 $AUTOCONF
64 $AUTOMAKE -a
66 ./configure
67 $MAKE have-lexlib || skip_ "no system-wide lex library found"
69 # Program should build and run and distribute.
70 $MAKE all
71 if ! cross_compiling; then
72 echo GOOD | ./lexer
73 echo BAD | ./lexer && exit 1
74 : For shells with busted 'set -e'.
76 yl_distcheck