maint: run "make update-copyright"
[platform/upstream/automake.git] / tests / maken3.test
1 #! /bin/sh
2 # Copyright (C) 2009-2012 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 `make -n' for various targets, to ensure that:
18 #
19 #  1. no files or directories are created or removed, and
20 #
21 #  2. if using GNU make or a make implementation supporting the .MAKE
22 #     special target, the output from make is sufficiently complete.
23 #
24 # This test exercises the GCS-mandated targets (except for dist)
25 # as well as tags, TAGS.
26
27 . ./defs || Exit 1
28
29 # Does $MAKE support the '.MAKE' special target?
30 have_dotmake=false
31 if using_gmake; then
32   have_dotmake=: # GNU make must support it.
33 else
34   unindent > mk.tmp << 'END'
35     targ.tmp:
36         : > $@
37     .MAKE: targ.tmp
38 END
39   if $MAKE -n -f mk.tmp targ.tmp && test -f targ.tmp; then
40     have_dotmake=:
41   fi
42 fi
43
44 mkdir sub sub2
45
46 cat >> configure.in << 'END'
47 AC_CONFIG_FILES([sub/Makefile sub2/Makefile])
48 AC_OUTPUT
49 END
50
51 cat > Makefile.am <<'END'
52 TESTS = foo.test
53 SUBDIRS = sub sub2
54 ##BUILT_SOURCES = foo
55 foo:
56 foo.test:
57 all-local:
58         @: > stamp-all
59 install-data-local:
60         @: > stamp-install
61 uninstall-local:
62         @: > stamp-uninstall
63 clean-local:
64         @: > stamp-clean
65 distclean-local:
66         @: > stamp-distclean
67 info-local:
68         @: > stamp-info
69 html-local:
70         @: > stamp-html
71 dvi-local:
72         @: > stamp-dvi
73 ps-local:
74         @: > stamp-ps
75 pdf-local:
76         @: > stamp-pdf
77 check-local:
78         @: > stamp-check
79 installcheck-local:
80         @: > stamp-installcheck
81 mostlyclean-local:
82         @: > stamp-mostlyclean
83 maintainer-clean-local:
84         @: > stamp-maintainer-clean
85 END
86 cat >sub/Makefile.am <<'END'
87 all-local:
88         @: > stamp-all-sub
89 install-data-local:
90         @: > stamp-install-sub
91 uninstall-local:
92         @: > stamp-uninstall-sub
93 clean-local:
94         @: > stamp-clean-sub
95 distclean-local:
96         @: > stamp-distclean-sub
97 info-local:
98         @: > stamp-info-sub
99 html-local:
100         @: > stamp-html-sub
101 dvi-local:
102         @: > stamp-dvi-sub
103 ps-local:
104         @: > stamp-ps-sub
105 pdf-local:
106         @: > stamp-pdf-sub
107 check-local:
108         @: > stamp-check-sub
109 installcheck-local:
110         @: > stamp-installcheck-sub
111 tags:
112         @: > stamp-tags-sub
113 TAGS:
114         @: > stamp-TAGS-sub
115 mostlyclean-local:
116         @: > stamp-mostlyclean-sub
117 maintainer-clean-local:
118         @: > stamp-maintainer-clean-sub
119 END
120 cat >sub2/Makefile.am <<'END'
121 all install uninstall clean check:
122         @: > sub2-$@-should-not-be-executed
123 info dvi pdf ps:
124         @: > sub2-$@-should-not-be-executed
125 html:
126         @: > sub2-$@-should-not-be-executed
127 install-info install-html install-dvi install-pdf install-ps:
128         @: > sub2-$@-should-not-be-executed
129 installcheck installdirs tags TAGS mostlyclean:
130         @: > sub2-$@-should-not-be-executed
131 ## These targets cannot be overridden like this:
132 ## install-strip distclean maintainer-clean
133 END
134
135 $ACLOCAL
136 $AUTOCONF
137
138 check_targets ()
139 {
140   for target in \
141     all install install-strip uninstall clean distclean check \
142     info html dvi pdf ps \
143     install-info install-html install-dvi install-pdf install-ps \
144     installcheck installdirs tags TAGS mostlyclean maintainer-clean
145   do
146     $MAKE -n $target >stdout || { cat stdout; Exit 1; }
147     cat stdout
148     case $target in
149     install-* | installdirs | tags | TAGS ) ;;
150     *)
151       if $have_dotmake; then
152         grep "stamp-$target$" stdout || Exit 1
153       fi
154       test ! -f "stamp-$target$" || Exit 1
155       ;;
156     esac
157     case $target in
158     install-* | installdirs ) ;;
159     *)
160       if $have_dotmake; then
161         grep "stamp-$target-sub" stdout || Exit 1
162       fi
163       test ! -f "sub/stamp-$target-sub" || Exit 1
164       ;;
165     esac
166     case $target in
167     distclean | maintainer-clean ) ;;
168     *)
169       if $have_dotmake; then
170         grep "should-not-be-executed" stdout || Exit 1
171       fi
172       test ! -f "sub2/sub2-$target-should-not-be-executed" || Exit 1
173       ;;
174     esac
175   done
176 }
177
178 $AUTOMAKE -a -Wno-override
179 ./configure
180 check_targets || Exit 1
181
182 # Now, introduce BUILT_SOURCES into the toplevel Makefile
183 # TODO: add BUILT_SOURCES to sub2, fix fallout.
184 sed 's/##//' < Makefile.am > t
185 mv -f t Makefile.am
186 $AUTOMAKE -Wno-override --force Makefile
187 ./configure
188 check_targets || Exit 1
189
190 Exit 0