remake-timing-bug-pr8365.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #! /bin/sh
  2. # Copyright (C) 2011-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. # Test for automake bug#8365, related to Makefile remake rules.
  17. # The bug is due to subtle timestamp issues and limitations in
  18. # make's behaviour, and is very unlikely to be triggered (we have
  19. # to resort to timestamp edit hacks to consistently expose it); in
  20. # any account, it is nigh to impossible to trigger it by running
  21. # make by hand. Thus, fixing it would not be worth the hassle, but
  22. # we prefer to keep it exposed anyway.
  23. . test-init.sh
  24. # We'll use calls to stat to get debugging information.
  25. if stat /dev/null; then stat=stat; else stat=:; fi
  26. cat >> configure.ac << 'END'
  27. FOOBAR=zardoz
  28. AC_OUTPUT
  29. END
  30. : > Makefile.am
  31. $ACLOCAL
  32. # Run automake *before* autoconf, because we want to ensure that
  33. # Makefile.in is not newer than configure.
  34. $AUTOMAKE
  35. $AUTOCONF
  36. ./configure
  37. $MAKE Makefile
  38. # Sanity check.
  39. $EGREP 'FOOBAR|zardoz' Makefile && fatal_ 'unexpected AC_SUBST in Makefile'
  40. echo 'AC_SUBST([FOOBAR])' >> configure.ac
  41. # Modified configure dependencies must have the same timestamp of
  42. # config.status and Makefile in order to trigger the bug.
  43. # We also re-touch config.status, because "touch -r" can truncate
  44. # timestamps on file systems with sub-second resolutions (see the
  45. # autoconf manual). Finally, we also sleep before touching, to ensure
  46. # that the (possibly truncated) timestamps of config.status etc. are
  47. # strictly newer than the non-truncated configure timestamp.
  48. $stat config.status Makefile configure.ac
  49. $sleep
  50. touch config.status
  51. touch -r config.status config.status Makefile configure.ac
  52. $stat config.status Makefile configure.ac
  53. # Also, the race condition is triggered only when aclocal, automake
  54. # and aclocal run fast enough to keep the timestamp of the generated
  55. # aclocal.m4, Makefile.in and configure equal to the timestamp of
  56. # Makefile & config.status. To reproduce this race consistently, we
  57. # need the following hackish wrappers.
  58. cat > aclocal-wrap <<END
  59. #!/bin/sh
  60. set -ex
  61. # aclocal shouldn't use our autoconf wrapper when extracting
  62. # the races from configure.ac.
  63. AUTOCONF='$AUTOCONF'; export AUTOCONF
  64. $ACLOCAL "\$@"
  65. touch -r config.status aclocal.m4
  66. $stat aclocal.m4
  67. END
  68. cat > automake-wrap <<END
  69. #!/bin/sh
  70. set -ex
  71. # automake shouldn't use our autoconf wrapper when extracting
  72. # the races from configure.ac.
  73. AUTOCONF='$AUTOCONF'; export AUTOCONF
  74. $AUTOMAKE "\$@"
  75. touch -r config.status Makefile.in
  76. $stat Makefile.in
  77. END
  78. cat > autoconf-wrap <<END
  79. #!/bin/sh
  80. set -ex
  81. $AUTOCONF "\$@"
  82. touch -r config.status configure
  83. $stat configure
  84. END
  85. chmod a+x aclocal-wrap automake-wrap autoconf-wrap
  86. run_make Makefile \
  87. ACLOCAL=./aclocal-wrap AUTOMAKE=./automake-wrap AUTOCONF=./autoconf-wrap
  88. grep '^FOOBAR =' Makefile.in
  89. grep '^FOOBAR *= *zardoz *$' Makefile
  90. :