Merge branch 'msvc' into maint
[platform/upstream/automake.git] / tests / spy.test
1 #! /bin/sh
2 # Copyright (C) 2003, 2011 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 whether double colon rules work.  The Unix V7 make manual
18 # mentions double-colon rules, but POSIX does not.  They seem to be
19 # supported by all Make implementation as far as we can tell. This test
20 # case is a spy: we want to detect if there exist implementations where
21 # these do not work.  We might use these rules to simplify the rebuild
22 # rules (instead of the $? hack).
23
24 # Tom Tromey write:
25 # | In the distant past we used :: rules extensively.
26 # | Fran?ois convinced me to get rid of them:
27 # |
28 # | Thu Nov 23 18:02:38 1995  Tom Tromey  <tromey@cambric>
29 # | [ ... ]
30 # |         * subdirs.am: Removed "::" rules
31 # |         * header.am, libraries.am, mans.am, texinfos.am, footer.am:
32 # |         Removed "::" rules
33 # |         * scripts.am, programs.am, libprograms.am: Removed "::" rules
34 # |
35 # |
36 # | I no longer remember the rationale for this.  It may have only been a
37 # | belief that they were unportable.
38
39 # On a related topic, the Autoconf manual has the following text:
40 # |     `VPATH' and double-colon rules
41 # |           Any assignment to `VPATH' causes Sun `make' to only execute
42 # |           the first set of double-colon rules.  (This comment has been
43 # |           here since 1994 and the context has been lost.  It's probably
44 # |           about SunOS 4.  If you can reproduce this, please send us a
45 # |           test case for illustration.)
46
47 # We already know that overlapping ::-rule like
48 #
49 #   a :: b
50 #       echo rule1 >> $@
51 #   a :: c
52 #       echo rule2 >> $@
53 #   a :: b c
54 #       echo rule3 >> $@
55 #
56 # do not work equally on all platforms.  It seems that in all cases
57 # Make attempts to run all matching rules.  However at least GNU Make,
58 # NetBSD Make, and FreeBSD Make will detect that $@ was updated by the
59 # first matching rule and skip remaining matches (with the above
60 # example that means that unless `a' was declared PHONY, only "rule1"
61 # will be appended to `a' if both b and c have changed).  Other
62 # implementations like OSF1 Make and HP-UX Make do not perform such a
63 # check and execute all matching rules whatever they do ("rule1",
64 # "rule2", abd "rule3" will all be appended to `a' if b and c have
65 # changed).
66
67 # So it seems only non-overlapping ::-rule may be portable.  This is
68 # what we check now.
69
70 . ./defs || Exit 1
71
72 set -e
73
74 cat >Makefile <<\EOF
75 a :: b
76         echo rule1 >> $@
77 a :: c
78         echo rule2 >> $@
79 EOF
80
81 touch b c
82 $sleep
83 : > a
84 $MAKE
85 test "`cat a`" = ''
86 $sleep
87 touch b
88 $MAKE
89 test "`cat a`" = rule1
90 # Ensure a is strictly newer than b, so HP-UX make does not execute rule2.
91 $sleep
92 : > a
93 $sleep
94 touch c
95 $MAKE
96 test "`cat a`" = rule2
97
98 # Unfortunately, the following is not portable to FreeBSD/NetBSD/OpenBSD
99 # make, see explanation above.
100
101 #: > a
102 #$sleep
103 #touch b c
104 #$MAKE
105 #grep rule1 a
106 #grep rule2 a
107
108 :