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