tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / remake-gnulib-add-header.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 # Test remake rules when a new C header "guarded" by AC_SUBST'd
18 # variables is added.
19 # This test overlaps with others, and is not strictly necessary per se,
20 # but it exercises a real use case (from gnulib, see:
21 #  <http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00005.html>
22 # for more info).
23
24 required=cc
25 . test-init.sh
26
27 cat >> configure.ac <<'END'
28 AC_CONFIG_HEADERS([config.h])
29 AC_PROG_CC
30 MY_MACROS
31 AC_OUTPUT
32 END
33
34 cat > Makefile.am <<'END'
35 ACLOCAL_AMFLAGS = -I .
36 noinst_PROGRAMS = foo
37 foo_SOURCES = foo.c
38 BUILT_SOURCES = $(STDIO_H)
39 stdio.h: stdio.in.h
40         cp $(srcdir)/stdio.in.h $@
41 MOSTLYCLEANFILES = stdio.h
42 EXTRA_DIST = stdio.in.h
43 check-local:
44         ls -l . $(srcdir)
45         if test -n '$(STDIO_H)'; then \
46             test -f stdio.h || exit 1; \
47         else \
48             test ! -f stdio.h || exit 1; \
49         fi
50 END
51
52 cat > macros.m4 <<'END'
53 AC_DEFUN([MY_MACROS], [
54   override_stdio=false
55   if $override_stdio; then
56     STDIO_H=stdio.h
57     use_dummies=1
58   else
59     STDIO_H=
60     use_dummies=0
61   fi
62   AC_SUBST([STDIO_H])
63   AC_DEFINE_UNQUOTED([USE_DUMMIES], [$use_dummies],
64     [Whether to use dummy types.])
65 ])
66 END
67
68 cat > stdio.in.h <<'END'
69 typedef struct dummyfile { void *p; } DUMMYFILE;
70 END
71
72 cat > foo.c <<'END'
73 #include <config.h>
74 #include <stdio.h>
75 #if USE_DUMMIES
76 DUMMYFILE *f;
77 #else
78 FILE *f;
79 #endif
80 int main () { return 0; }
81 END
82
83 $ACLOCAL -I .
84 $AUTOHEADER
85 $AUTOMAKE
86 $AUTOCONF
87
88 ./configure
89
90 $MAKE
91 ls -l
92 test ! -e stdio.h
93 # Also try our build rules in a VPATH build.
94 $MAKE distcheck
95
96 # No need to sleep here: "./configure" and "make distcheck" above
97 # have already slept enough.
98
99 sed -e 's/^\( *override_stdio\)=.*$/\1=:/' macros.m4 > t
100 mv -f t macros.m4
101
102 using_gmake || $MAKE Makefile
103 $MAKE
104 ls -l
105 test -f stdio.h
106 # Also try our build rules in a VPATH build.
107 $MAKE distcheck
108
109 :