Merge branch 'msvc' into maint
[platform/upstream/automake.git] / tests / subcond3.test
1 #! /bin/sh
2 # Copyright (C) 2002, 2003  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 # The for conditional SUBDIRS.
18 # SUBDIRS + AC_SUBST setup from the manual.
19 # Lots of lines here are duplicated in subcond2.test.
20
21 . ./defs || Exit 1
22
23 set -e
24
25 cat >>configure.in <<'END'
26 if test "$want_opt" = yes; then
27   MAYBE_OPT=opt
28 else
29   MAYBE_OPT=
30 fi
31 AC_SUBST([MAYBE_OPT])
32 AC_CONFIG_FILES([src/Makefile opt/Makefile])
33 AC_OUTPUT
34 END
35
36 cat >Makefile.am << 'END'
37 SUBDIRS = src $(MAYBE_OPT)
38 DIST_SUBDIRS = src opt
39
40 # Testing targets.
41 #
42 # We want to ensure that
43 #      - src/source and opt/source are always distributed.
44 #      - src/result is always built
45 #      - opt/result is built conditionally
46 #
47 # We rely on `distcheck' to run `check-local' and use
48 # `sanity1' and `sanity2' as evidences that test-build was run.
49
50 test-build: all
51         test -f src/result
52         if test -n "$(MAYBE_OPT)"; then \
53            test -f opt/result || exit 1; \
54            : > $(top_builddir)/../../sanity2 || exit 1; \
55         else \
56            test ! -f opt/result || exit 1; \
57            : > $(top_builddir)/../../sanity1 || exit 1; \
58         fi
59
60 test-dist: distdir
61         test -f $(distdir)/src/source
62         test -f $(distdir)/opt/source
63
64 check-local: test-build test-dist
65 END
66
67 mkdir src opt
68 : > src/source
69 : > opt/source
70
71 cat >src/Makefile.am << 'END'
72 EXTRA_DIST = source
73 all-local: result
74 CLEANFILES = result
75
76 result: source
77         cp $(srcdir)/source result
78 END
79
80 # We want in opt/ the same Makefile as in src/.  Let's exercise `include'.
81 cat >opt/Makefile.am << 'END'
82 include ../src/Makefile.am
83 END
84
85 $ACLOCAL
86 $AUTOCONF
87 $AUTOMAKE --add-missing
88 ./configure
89 $MAKE distcheck
90 test -f sanity1
91 DISTCHECK_CONFIGURE_FLAGS=want_opt=yes $MAKE distcheck
92 test -f sanity2