yacc-d-basic.sh 3.7 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 Yacc support with yacc-generated headers
  17. # (i.e., '-d' in *YFLAGS).
  18. # Keep in sync with sister test 'yacc-d-cxx.sh'.
  19. required='cc yacc'
  20. . test-init.sh
  21. cat >> configure.ac << 'END'
  22. AC_PROG_CC
  23. AC_PROG_YACC
  24. AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile])
  25. AC_OUTPUT
  26. END
  27. cat > Makefile.am <<'END'
  28. SUBDIRS = foo bar baz
  29. END
  30. mkdir foo bar baz
  31. cat > foo/Makefile.am <<'END'
  32. bin_PROGRAMS = zardoz
  33. zardoz_SOURCES = parse.y main.c
  34. .PHONY: echo-distcom
  35. echo-distcom:
  36. @echo ' ' $(DIST_COMMON) ' '
  37. END
  38. cp foo/Makefile.am bar/Makefile.am
  39. cp foo/Makefile.am baz/Makefile.am
  40. cat > foo/parse.y << 'END'
  41. %{
  42. #include "parse.h"
  43. int yylex () { return 0; }
  44. void yyerror (char *s) {}
  45. %}
  46. %%
  47. x : 'x' {};
  48. %%
  49. END
  50. # Using ylwrap, we actually generate y.tab.[ch]. Unfortunately, we
  51. # forgot to rename #include "y.tab.h" into #include "parse.h" during
  52. # the conversion from y.tab.c to parse.c. This was OK when Bison was
  53. # not issuing such an #include (up to 2.6).
  54. #
  55. # To make sure that we perform this conversion even with version of
  56. # Bison that do not generate this include, in bar/parse.y, use y.tab.h
  57. # instead of parse.h, and check the ylwrap does replace "y.tab.h" with
  58. # "parse.h".
  59. sed -e 's/parse\.h/y.tab.h/' <foo/parse.y >bar/parse.y
  60. cat > foo/main.c << 'END'
  61. #include "parse.h"
  62. int main ()
  63. {
  64. return yyparse ();
  65. }
  66. END
  67. cp foo/main.c bar/main.c
  68. # Even the generated header file is renamed when target-specific YFLAGS
  69. # are used. This might not be the best behavior, but it has been in
  70. # place for quite a long time, so just go along with it for now.
  71. sed 's/"parse\.h"/"zardoz-parse.h"/' foo/parse.y > baz/parse.y
  72. sed 's/"parse\.h"/"zardoz-parse.h"/' foo/main.c > baz/main.c
  73. $ACLOCAL
  74. $AUTOCONF
  75. $AUTOMAKE -a
  76. $FGREP parse.h foo/Makefile.in bar/Makefile.in baz/Makefile.in && exit 1
  77. cat >> foo/Makefile.am <<END
  78. BUILT_SOURCES = parse.h
  79. YFLAGS=\
  80. -d
  81. END
  82. $AUTOMAKE -Wno-gnu foo/Makefile
  83. sed 's/EOL$//' >> bar/Makefile.am <<END
  84. AM_YFLAGS${tab}= -d EOL
  85. BUILT_SOURCES = parse.h
  86. END
  87. $AUTOMAKE bar/Makefile
  88. cat >> baz/Makefile.am <<END
  89. BUILT_SOURCES = zardoz-parse.h
  90. zardoz_YFLAGS =-d${tab}
  91. END
  92. $AUTOMAKE baz/Makefile
  93. ./configure
  94. $MAKE
  95. generated="
  96. foo/parse.c
  97. foo/parse.h
  98. bar/parse.c
  99. bar/parse.h
  100. baz/zardoz-parse.c
  101. baz/zardoz-parse.h
  102. "
  103. for i in $generated; do
  104. test -f $i
  105. done
  106. # There must remain no obsolete header guard.
  107. grep Y_TAB_H $generated && exit 1
  108. # The generated C source and header files must be shipped.
  109. for dir in foo bar; do
  110. cd $dir
  111. $MAKE echo-distcom
  112. $MAKE -s echo-distcom | grep '[ /]parse.c '
  113. $MAKE -s echo-distcom | grep '[ /]parse.h '
  114. cd ..
  115. done
  116. cd baz
  117. $MAKE echo-distcom
  118. $MAKE -s echo-distcom | grep '[ /]zardoz-parse.c '
  119. $MAKE -s echo-distcom | grep '[ /]zardoz-parse.h '
  120. cd ..
  121. $MAKE distdir
  122. ls -l $distdir
  123. for i in $generated; do
  124. test -f $distdir/$i
  125. done
  126. # Sanity check the distribution.
  127. yl_distcheck
  128. # While we are at it, make sure that 'parse.c' and 'parse.h' are erased
  129. # by maintainer-clean, and not by distclean.
  130. $MAKE distclean
  131. for i in $generated; do
  132. test -f $i
  133. done
  134. ./configure # Re-create 'Makefile'.
  135. $MAKE maintainer-clean
  136. for i in $generated; do
  137. test ! -e $i
  138. done
  139. :