spy-double-colon.sh 3.3 KB

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