am-ft: make the environment available earlier
[platform/upstream/automake.git] / t / yflags-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 automake complains about *_YFLAGS variables which have
18 # conditional content.
19
20 . test-init.sh
21
22 cat >> configure.ac <<'END'
23 AC_PROG_CC
24
25 # 'YFLAGS' is AC_SUBST'd by AC_PROG_YACC by default, but we
26 # don't want this, since it might confuse our error messages.
27 # Also, AM_SUBST_NOTMAKE seems not to help about this.
28 # So we simply define $(YACC) by hand.
29 AC_SUBST([YACC], [yacc])
30
31 AM_CONDITIONAL([COND], [:])
32 END
33
34 $ACLOCAL
35
36 cat > Makefile.am <<'END'
37 bin_PROGRAMS = foo zardoz
38 foo_SOURCES = foo.y
39 zardoz_SOURCES = zardoz.y
40 if COND
41 AM_YFLAGS = -v
42 zardoz_YFLAGS = -v
43 endif COND
44 END
45
46 cat > Makefile1.am <<'END'
47 bin_PROGRAMS = foo
48 foo_SOURCES = foo.y
49 ## This is a dummy comment to keep line count right.
50 if COND
51 YFLAGS = foo
52 endif COND
53 END
54
55 cat > Makefile2.am <<'END'
56 bin_PROGRAMS = foo
57 foo_SOURCES = foo.y
58 AM_YFLAGS = am_yflags
59 if COND
60 YFLAGS = yflags
61 endif COND
62 END
63
64 cat > Makefile3.am <<'END'
65 bin_PROGRAMS = foo
66 foo_SOURCES = foo.y
67 foo_YFLAGS = foo_yflags
68 if COND
69 YFLAGS = yflags
70 endif COND
71 END
72
73 cat > Makefile4.am <<'END'
74 bin_PROGRAMS = foo zardoz
75
76 foo_SOURCES = foo.y
77 zardoz_SOURCES = $(foo_SOURCES)
78
79 YFLAGS =
80 AM_YFLAGS = $(COND_VAR1)
81 zardoz_YFLAGS = $(COND_VAR2:z=r)
82
83 COND_VAR2 = foo
84 if COND
85 YFLAGS += -v
86 COND_VAR2 += bar
87 else !COND
88 COND_VAR1 = -d
89 endif !COND
90 END
91
92 cat > Makefile5.am <<'END'
93 bin_PROGRAMS = foo zardoz
94 foo_SOURCES = foo.y
95 zardoz_SOURCES = zardoz.y
96 YFLAGS = -v
97 AM_YFLAGS = -v
98 if COND
99 zardoz_YFLAGS = -v
100 endif
101 END
102
103 cat > Makefile6.am <<'END'
104 bin_PROGRAMS = foo
105 foo_SOURCES = foo.y
106 foo_YFLAGS = -v
107 if COND
108 quux_YFLAGS = -v
109 AM_YFLAGS = -v
110 endif
111 END
112
113 : > ylwrap
114
115 LC_ALL=C; export LC_ALL; # For grep regexes below.
116
117 AUTOMAKE_fails -Wnone -Wunsupported Makefile
118 grep '^Makefile\.am:5:.*AM_YFLAGS.* conditional contents' stderr
119 grep '^Makefile\.am:6:.*zardoz_YFLAGS.* conditional contents' stderr
120
121 for i in 1 2 3; do
122   AUTOMAKE_fails -Wnone -Wunsupported Makefile$i
123   grep "^Makefile$i\\.am:5:.*[^a-zA-Z0-9_]YFLAGS.* conditional contents" \
124        stderr
125 done
126
127 AUTOMAKE_fails -Wnone -Wunsupported Makefile4
128 grep '^Makefile4\.am:6:.*[^a-zA-Z0-9_]YFLAGS.* conditional contents' stderr
129 grep '^Makefile4\.am:7:.*AM_YFLAGS.* conditional contents' stderr
130 grep '^Makefile4\.am:8:.*zardoz_YFLAGS.* conditional contents' stderr
131
132 # Now let's check we avoid false positives.
133
134 # Disable 'gnu' warnings because we override the user variable 'YFLAGS'.
135 AUTOMAKE_fails -Wno-gnu Makefile5
136 grep -v '^Makefile5\.am:.*zardoz_YFLAGS' stderr \
137  | grep -v ': warnings are treated as errors' \
138  | grep . && exit 1
139
140 # Disable 'gnu' warnings because we override the user variable 'YFLAGS'.
141 $AUTOMAKE -Wno-gnu Makefile6
142
143 :