test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / yflags-force-conditional.sh
blob9ada694495b30611db8ade5478683213687e7aea
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 the user can force automake to use *_YFLAGS variables
18 # which have conditional content.
20 . test-init.sh
22 cat >> configure.ac <<'END'
23 AC_SUBST([CC], [false])
24 AC_PROG_YACC
25 AM_CONDITIONAL([COND], [test x"$cond" = x"yes"])
26 AC_OUTPUT
27 END
29 mkdir bin
30 cat > bin/fake-yacc <<'END'
31 #!/bin/sh
32 echo "/* $* */" > y.tab.c
33 echo 'extern int dummy;' >> y.tab.c
34 END
35 chmod a+x bin/fake-yacc
36 PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
37 YACC=fake-yacc; export YACC
39 cat > Makefile.am <<'END'
40 AUTOMAKE_OPTIONS = no-dependencies
41 AM_LFLAGS = --never-interactive
43 bin_PROGRAMS = foo bar
44 foo_SOURCES = foo.y main.c
45 bar_SOURCES = $(foo_SOURCES)
46 bar_YFLAGS = $(bar_yflags2)
47 if COND
48 AM_YFLAGS = __am_cond_yes__
49 bar_YFLAGS += __bar_cond_yes__
50 else !COND
51 AM_YFLAGS = __am_cond_no__
52 bar_yflags2 = __bar_cond_no__
53 endif !COND
54 END
56 : > foo.y
58 $ACLOCAL
59 $AUTOCONF
60 $AUTOMAKE -a -Wno-unsupported
62 $EGREP '(YFLAGS|yflags|am__append)' Makefile.in # For debugging.
64 ./configure cond=yes
65 $MAKE foo.c bar-foo.c
67 cat foo.c
68 cat bar-foo.c
70 $FGREP ' __am_cond_yes__ ' foo.c
71 $FGREP ' __bar_cond_yes__ ' bar-foo.c
72 $FGREP 'cond_no' foo.c bar-foo.c && exit 1
74 $MAKE maintainer-clean
75 ls -l
77 ./configure cond=no
78 $MAKE foo.c bar-foo.c
80 cat foo.c
81 cat bar-foo.c
83 $FGREP ' __am_cond_no__ ' foo.c
84 $FGREP ' __bar_cond_no__ ' bar-foo.c
85 $FGREP 'cond_yes' foo.c bar-foo.c && exit 1