subobj-clean-pr10697.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #! /bin/sh
  2. # Copyright (C) 1998-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. # Removing subdir objects does not cause too much 'rm' invocations.
  17. # Also, if we rename a source file in a subdirectory, the stale
  18. # compiled object corresponding to the old name still gets removed by
  19. # "make mostlyclean". See automake bug#10697.
  20. # This is the non-libtool case. Keep this test in sync with sister test
  21. # 'subobj-clean-lt-pr10697.sh', which deals with the libtool case.
  22. required=cc
  23. . test-init.sh
  24. cat >> configure.ac << 'END'
  25. AC_PROG_CC
  26. AC_CONFIG_FILES([get-objext.sh:get-objext.in])
  27. AC_OUTPUT
  28. END
  29. echo "OBJEXT='@OBJEXT@'" > get-objext.in
  30. oPATH=$PATH
  31. ocwd=$(pwd) || fatal_ "getting current working directory"
  32. # An rm(1) wrapper that fails when invoked too many times.
  33. mkdir rm-wrap
  34. max_rm_invocations=3
  35. count_file=$ocwd/rm-wrap/count
  36. cat > rm-wrap/rm <<END
  37. #!$AM_TEST_RUNNER_SHELL -e
  38. count=\$((\$(cat '$count_file') + 1))
  39. test \$count -le $max_rm_invocations || {
  40. echo "rm invoked more than $max_rm_invocations times" >&2
  41. exit 1
  42. }
  43. echo "\$count" > '$count_file'
  44. PATH='$oPATH'; export PATH
  45. exec rm "\$@"
  46. END
  47. chmod a+x rm-wrap/rm
  48. echo "0" > rm-wrap/count
  49. cat > Makefile.am <<'END'
  50. .PHONY: sanity-check-rm
  51. sanity-check-rm:
  52. rm -f 1
  53. rm -f 2
  54. rm -f 3
  55. rm -f x && exit 1; :
  56. echo "0" > rm-wrap/count
  57. AUTOMAKE_OPTIONS = subdir-objects
  58. bin_PROGRAMS = foo
  59. foo_SOURCES = \
  60. sub1/a.c \
  61. sub1/b.c \
  62. sub1/c.c \
  63. sub1/d.c \
  64. sub1/e.c \
  65. sub1/f.c \
  66. sub2/a.c \
  67. sub2/b.c \
  68. sub2/c.c \
  69. sub2/d.c \
  70. sub2/e.c \
  71. sub2/f.c \
  72. main.c
  73. END
  74. mkdir sub1 sub2
  75. echo 'int main (void)' > main.c
  76. echo '{' >> main.c
  77. for i in 1 2; do
  78. for j in a b c d e f; do
  79. echo "void $j$i (void) { }" > sub$i/$j.c
  80. echo " $j$i ();" >> main.c
  81. done
  82. done
  83. echo ' return 0;' >> main.c
  84. echo '}' >> main.c
  85. cat main.c # For debugging.
  86. $ACLOCAL
  87. $AUTOCONF
  88. $AUTOMAKE -a
  89. ./configure
  90. test -f get-objext.sh
  91. . ./get-objext.sh
  92. $MAKE
  93. # This must go after configure, since that will invoke rm many times.
  94. PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
  95. $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
  96. $MAKE mostlyclean
  97. ls -l . sub1 sub2
  98. for i in 1 2; do
  99. for j in a b c d e f; do
  100. test ! -e sub$i/$j.o
  101. test ! -e sub$i/$j.obj
  102. test -f sub$i/$j.c || exit 99 # Sanity check
  103. done
  104. done
  105. PATH=$oPATH; export PATH
  106. rm -rf rm-wrap
  107. $MAKE clean
  108. $MAKE
  109. test -f sub1/a.$OBJEXT
  110. test -f sub2/d.$OBJEXT
  111. $sleep
  112. mv -f sub2/d.c sub2/x.c
  113. rm -f sub1/a.c
  114. sed -e '/ a1 ()/d' main.c > t
  115. mv -f t main.c
  116. sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
  117. mv -f t Makefile.am
  118. using_gmake || $MAKE Makefile
  119. $MAKE
  120. test -f sub2/x.$OBJEXT
  121. # The stale objects are still there after a mere "make all" ...
  122. test -f sub1/a.$OBJEXT
  123. test -f sub2/a.$OBJEXT
  124. # ... but they get removed by "make mostlyclean" ...
  125. $MAKE mostlyclean
  126. test ! -e sub1/a.$OBJEXT
  127. test ! -e sub2/d.$OBJEXT
  128. # ... and do not get rebuilt ...
  129. $MAKE clean
  130. $MAKE all
  131. test ! -e sub1/a.$OBJEXT
  132. test ! -e sub2/d.$OBJEXT
  133. # ... while the non-stale files do.
  134. test -f sub1/b.$OBJEXT
  135. test -f sub2/x.$OBJEXT
  136. :