subobj-clean-lt-pr10697.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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
  19. # by "make mostlyclean". See automake bug#10697.
  20. # This is the libtool case. Keep this test in sync with sister test
  21. # 'subobj-clean-pr10697.sh', which deals with the non-libtool case.
  22. required='cc libtoolize'
  23. . test-init.sh
  24. cat >> configure.ac << 'END'
  25. AM_PROG_AR
  26. AC_PROG_LIBTOOL
  27. AC_PROG_CC
  28. AC_OUTPUT
  29. END
  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=6
  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. if ! test \$count -le $max_rm_invocations; then
  40. echo "rm invoked more than $max_rm_invocations times" >&2
  41. exit 1
  42. fi
  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 4
  56. rm -f 5
  57. rm -f 6
  58. rm -f x && exit 1; :
  59. echo "0" > rm-wrap/count
  60. AUTOMAKE_OPTIONS = subdir-objects
  61. lib_LTLIBRARIES = libfoo.la
  62. libfoo_la_SOURCES = \
  63. sub1/a.c \
  64. sub1/b.c \
  65. sub1/c.c \
  66. sub1/d.c \
  67. sub1/e.c \
  68. sub1/f.c \
  69. sub2/a.c \
  70. sub2/b.c \
  71. sub2/c.c \
  72. sub2/d.c \
  73. sub2/e.c \
  74. sub2/f.c \
  75. main.c
  76. END
  77. mkdir sub1 sub2
  78. echo 'int libmain (void)' > main.c
  79. echo '{' >> main.c
  80. for i in 1 2; do
  81. for j in a b c d e f; do
  82. echo "void $j$i (void) { }" > sub$i/$j.c
  83. echo " $j$i ();" >> main.c
  84. done
  85. done
  86. echo ' return 0;' >> main.c
  87. echo '}' >> main.c
  88. cat main.c # For debugging.
  89. libtoolize
  90. $ACLOCAL
  91. $AUTOCONF
  92. $AUTOMAKE -a
  93. ./configure
  94. # The use of this variable is only meant to keep us better in sync
  95. # with the sister test 'subobj-clean-pr10697.sh'.
  96. OBJEXT=lo
  97. $MAKE
  98. # This must go after configure, since that will invoke rm many times.
  99. PATH=$ocwd/rm-wrap$PATH_SEPARATOR$PATH; export PATH
  100. $MAKE sanity-check-rm || fatal_ "rm wrapper doesn't work as expected"
  101. $MAKE mostlyclean
  102. ls -l . sub1 sub2
  103. for i in 1 2; do
  104. for j in a b c d e f; do
  105. test ! -e sub$i/$j.o
  106. test ! -e sub$i/$j.obj
  107. test ! -e sub$i/$j.lo
  108. test -f sub$i/$j.c || exit 99 # Sanity check
  109. done
  110. done
  111. PATH=$oPATH; export PATH
  112. rm -rf rm-wrap
  113. $MAKE clean
  114. $MAKE
  115. test -f sub1/a.$OBJEXT
  116. test -f sub2/d.$OBJEXT
  117. $sleep
  118. mv -f sub2/d.c sub2/x.c
  119. rm -f sub1/a.c
  120. sed -e '/ a1 ()/d' main.c > t
  121. mv -f t main.c
  122. sed -e '/sub1\/a\.c/d' -e 's|sub2/d\.c|sub2/x.c|' Makefile.am > t
  123. mv -f t Makefile.am
  124. using_gmake || $MAKE Makefile
  125. $MAKE
  126. test -f sub2/x.$OBJEXT
  127. # The stale objects are still there after a mere "make all" ...
  128. test -f sub1/a.$OBJEXT
  129. test -f sub2/a.$OBJEXT
  130. # ... but they get removed by "make mostlyclean" ...
  131. $MAKE mostlyclean
  132. test ! -e sub1/a.$OBJEXT
  133. test ! -e sub2/d.$OBJEXT
  134. # ... and do not get rebuilt ...
  135. $MAKE clean
  136. $MAKE all
  137. test ! -e sub1/a.$OBJEXT
  138. test ! -e sub2/d.$OBJEXT
  139. # ... while the non-stale files do.
  140. test -f sub1/b.$OBJEXT
  141. test -f sub2/x.$OBJEXT
  142. :