tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / yflags-force-conditional.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Check that the user can force automake to use *_YFLAGS variables
18 # which have conditional content.
19
20 . test-init.sh
21
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
28
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
38
39 cat > Makefile.am <<'END'
40 AUTOMAKE_OPTIONS = no-dependencies
41 bin_PROGRAMS = foo bar
42 foo_SOURCES = foo.y main.c
43 bar_SOURCES = $(foo_SOURCES)
44 bar_YFLAGS = $(bar_yflags2)
45 if COND
46 AM_YFLAGS = __am_cond_yes__
47 bar_YFLAGS += __bar_cond_yes__
48 else !COND
49 AM_YFLAGS = __am_cond_no__
50 bar_yflags2 = __bar_cond_no__
51 endif !COND
52 END
53
54 : > foo.y
55
56 $ACLOCAL
57 $AUTOCONF
58 $AUTOMAKE -a -Wno-unsupported
59
60 $EGREP '(YFLAGS|yflags|am__append)' Makefile.in # For debugging.
61
62 ./configure cond=yes
63 $MAKE foo.c bar-foo.c
64
65 cat foo.c
66 cat bar-foo.c
67
68 $FGREP ' __am_cond_yes__ ' foo.c
69 $FGREP ' __bar_cond_yes__ ' bar-foo.c
70 $FGREP 'cond_no' foo.c bar-foo.c && exit 1
71
72 $MAKE maintainer-clean
73 ls -l
74
75 ./configure cond=no
76 $MAKE foo.c bar-foo.c
77
78 cat foo.c
79 cat bar-foo.c
80
81 $FGREP ' __am_cond_no__ ' foo.c
82 $FGREP ' __bar_cond_no__ ' bar-foo.c
83 $FGREP 'cond_yes' foo.c bar-foo.c && exit 1
84
85 :