yacc-deleted-headers.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. # Tests that we can recover from deleted headers generated by 'yacc -d'.
  17. required='cc yacc'
  18. . test-init.sh
  19. cat >> configure.ac << 'END'
  20. AC_PROG_CC
  21. AC_PROG_YACC
  22. AC_OUTPUT
  23. END
  24. cat > Makefile.am <<'END'
  25. bin_PROGRAMS = p1 p2 p3 p4
  26. # The order in which files are listed in the p*_SOURCES variables
  27. # below is significant, since it causes make failures whenever
  28. # the proper definition of BUILT_SOURCES or the declaration of
  29. # extra dependencies for 'main3.o' are removed.
  30. p1_SOURCES = main1.c parse1.y
  31. p2_SOURCES = main2.c parse2.y
  32. p3_SOURCES = main3.c parse3.y parse3.h
  33. p4_SOURCES = parse4.y
  34. AM_YFLAGS = -d
  35. p2_YFLAGS = -d
  36. BUILT_SOURCES = parse1.h p2-parse2.h
  37. # When we know which files include a yacc-generated header, we
  38. # should be able to just declare dependencies directly instead
  39. # of relying on the BUILT_SOURCES hack, and things should still
  40. # work correctly.
  41. main3.@OBJEXT@ parse3.@OBJEXT@: parse3.h
  42. .PHONY: clean-p3 build-p3
  43. build-p3: p3$(EXEEXT)
  44. clean-p3:
  45. rm -f p3$(EXEEXT)
  46. END
  47. cat > parse1.y << 'END'
  48. %{
  49. #include "parse1.h"
  50. int yylex () { return 0; }
  51. void yyerror (char *s) { return; }
  52. %}
  53. %token ZARDOZ
  54. %%
  55. x : 'x' {};
  56. %%
  57. END
  58. cat > main1.c << 'END'
  59. #include "parse1.h"
  60. int main (void)
  61. {
  62. return ZARDOZ + yyparse ();
  63. }
  64. END
  65. sed 's/"parse1\.h"/"p2-parse2.h"/' parse1.y > parse2.y
  66. sed 's/"parse1\.h"/"p2-parse2.h"/' main1.c > main2.c
  67. sed 's/"parse1\.h"/"parse3.h"/' parse1.y > parse3.y
  68. sed 's/"parse1\.h"/"parse3.h"/' main1.c > main3.c
  69. cat > parse4.y << 'END'
  70. %{
  71. int yylex () { return 0; }
  72. void yyerror (char *s) { return; }
  73. %}
  74. %%
  75. x : 'x' {};
  76. %%
  77. int main (void)
  78. {
  79. return 0;
  80. }
  81. END
  82. $ACLOCAL
  83. $AUTOCONF
  84. $AUTOMAKE -a
  85. ./configure
  86. $MAKE
  87. headers='parse1.h p2-parse2.h parse3.h parse4.h'
  88. # Check that we remake only the necessary headers.
  89. rm -f $headers
  90. $MAKE parse1.h
  91. test -f parse1.h
  92. test ! -e p2-parse2.h
  93. test ! -e parse3.h
  94. test ! -e parse4.h
  95. rm -f $headers
  96. $MAKE p2-parse2.h
  97. test ! -e parse1.h
  98. test -f p2-parse2.h
  99. test ! -e parse3.h
  100. test ! -e parse4.h
  101. rm -f $headers
  102. $MAKE parse3.h
  103. test ! -e parse1.h
  104. test ! -e p2-parse2.h
  105. test -f parse3.h
  106. test ! -e parse4.h
  107. # Since we declared parse3.h into $(p3_SOURCES), make should be
  108. # able to rebuild it automatically before remaking 'p3'.
  109. rm -f $headers
  110. $MAKE clean-p3
  111. test ! -e parse3.h # Sanity check.
  112. $MAKE build-p3
  113. test -f parse3.h
  114. $MAKE
  115. rm -f $headers
  116. $MAKE parse4.h
  117. test ! -e parse1.h
  118. test ! -e p2-parse2.h
  119. test ! -e parse3.h
  120. test -f parse4.h
  121. # Now remake all the headers together.
  122. rm -f $headers
  123. $MAKE $headers
  124. test -f parse1.h
  125. test -f p2-parse2.h
  126. test -f parse3.h
  127. test -f parse4.h
  128. # Most headers should be remade by "make all".
  129. rm -f $headers
  130. $MAKE all
  131. test -f parse1.h
  132. test -f p2-parse2.h
  133. test -f parse3.h
  134. # parse4.h is not declared in any *_SOURCES variable, nor #included
  135. # by any C source file, so it shouldn't be rebuilt by "make all".
  136. test ! -e parse4.h
  137. :