tests: work around strangeness in MSYS
[automake.git] / tests / spy.test
blob1a97ae7eab7da431e19705f978e5fa6111f3fff6
1 #! /bin/sh
2 # Copyright (C) 2003, 2011 Free Software Foundation, Inc.
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.
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.
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/>.
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).
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.
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.)
47 # We already know that overlapping ::-rule like
49 # a :: b
50 # echo rule1 >> $@
51 # a :: c
52 # echo rule2 >> $@
53 # a :: b c
54 # echo rule3 >> $@
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).
67 # So it seems only non-overlapping ::-rule may be portable. This is
68 # what we check now.
70 . ./defs || Exit 1
72 cat >Makefile <<\EOF
73 a :: b
74 echo rule1 >> $@
75 a :: c
76 echo rule2 >> $@
77 EOF
79 touch b c
80 $sleep
81 : > a
82 $MAKE
83 test "`cat a`" = ''
84 $sleep
85 touch b
86 $MAKE
87 test "`cat a`" = rule1
88 # Ensure a is strictly newer than b, so HP-UX make does not execute rule2.
89 $sleep
90 : > a
91 $sleep
92 touch c
93 $MAKE
94 test "`cat a`" = rule2
96 # Unfortunately, the following is not portable to FreeBSD/NetBSD/OpenBSD
97 # make, see explanation above.
99 #: > a
100 #$sleep
101 #touch b c
102 #$MAKE
103 #grep rule1 a
104 #grep rule2 a