yacc-d-cxx.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. # Various tests on Yacc/C++ support with yacc-generated headers
  17. # (i.e., '-d' in *YFLAGS).
  18. # Keep in sync with sister test 'yacc-d-basic.sh'.
  19. required='c++ yacc'
  20. . test-init.sh
  21. write_parse ()
  22. {
  23. header=$1
  24. unindent <<END
  25. %{
  26. // Valid C++, but deliberately invalid C.
  27. #include <cstdlib>
  28. #include "$header"
  29. int yylex (void) { return 0; }
  30. void yyerror (const char *s) {}
  31. %}
  32. %%
  33. x : 'x' {};
  34. %%
  35. END
  36. }
  37. write_main ()
  38. {
  39. header=$1
  40. unindent <<END
  41. // Valid C++, but deliberately invalid C.
  42. #include <cstdio>
  43. #include "$header"
  44. int main (int argc, char **argv)
  45. {
  46. int yyparse (void);
  47. return yyparse ();
  48. }
  49. END
  50. }
  51. cat >> configure.ac << 'END'
  52. AC_PROG_CXX
  53. AC_PROG_YACC
  54. AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile qux/Makefile])
  55. AC_OUTPUT
  56. END
  57. mkdir foo bar baz qux baz/sub
  58. # These makefiles will be extended later.
  59. cat > Makefile.am <<'END'
  60. .PHONY: echo-distcom
  61. echo-distcom:
  62. @echo ' ' $(DIST_COMMON) ' '
  63. END
  64. cp Makefile.am foo/Makefile.am
  65. cp Makefile.am bar/Makefile.am
  66. cp Makefile.am baz/Makefile.am
  67. cp Makefile.am qux/Makefile.am
  68. cat >> Makefile.am <<'END'
  69. SUBDIRS = foo bar baz qux
  70. END
  71. $ACLOCAL
  72. $AUTOCONF
  73. cp "$am_scriptdir/ylwrap" . \
  74. || fatal_ "cannot fetch auxiliary script 'ylwrap'"
  75. $AUTOMAKE Makefile
  76. # Try with -d in $(YFLAGS) (don't do this in real life!).
  77. cat >> foo/Makefile.am <<END
  78. bin_PROGRAMS = zardoz
  79. zardoz_SOURCES = parse.yy main.cc
  80. BUILT_SOURCES = parse.hh
  81. YFLAGS=\
  82. -d
  83. END
  84. $AUTOMAKE -Wno-gnu foo/Makefile
  85. write_parse parse.hh > foo/parse.yy
  86. write_main parse.hh > foo/main.cc
  87. # Try with -d in $(AM_YFLAGS).
  88. cat >> bar/Makefile.am <<END
  89. bin_PROGRAMS = zardoz
  90. zardoz_SOURCES = parse.ypp main.cpp
  91. BUILT_SOURCES = parse.hpp
  92. AM_YFLAGS${tab}= -d ${tab}
  93. END
  94. $AUTOMAKE bar/Makefile
  95. write_parse parse.hpp > bar/parse.ypp
  96. write_main parse.hpp > bar/main.cpp
  97. # Try with -d in $(AM_YFLAGS), and a subdir parser.
  98. cat >> baz/Makefile.am <<END
  99. AUTOMAKE_OPTIONS = subdir-objects
  100. bin_PROGRAMS = joe
  101. joe_SOURCES = sub/parse.y++ sub/main.c++
  102. BUILT_SOURCES = sub/parse.h++
  103. AM_YFLAGS = \
  104. ${tab}-d
  105. END
  106. $AUTOMAKE baz/Makefile
  107. write_parse sub/parse.h++ > baz/sub/parse.y++
  108. write_main sub/parse.h++ > baz/sub/main.c++
  109. # Try with -d in $(xxx_YFLAGS) (per-object flag).
  110. cat >> qux/Makefile.am <<END
  111. bin_PROGRAMS = maude
  112. maude_SOURCES = parse.yxx main.cxx
  113. maude_YFLAGS=${tab} -d${tab}
  114. BUILT_SOURCES = maude-parse.hxx
  115. END
  116. $AUTOMAKE qux/Makefile
  117. write_parse maude-parse.hxx > qux/parse.yxx
  118. write_main maude-parse.hxx > qux/main.cxx
  119. ./configure
  120. $MAKE
  121. ls -l . foo bar baz baz/sub qux # For debugging.
  122. test -f foo/parse.cc
  123. test -f foo/parse.hh
  124. test -f bar/parse.cpp
  125. test -f bar/parse.hpp
  126. test -f baz/sub/parse.c++
  127. test -f baz/sub/parse.h++
  128. test -f qux/maude-parse.cxx
  129. test -f qux/maude-parse.hxx
  130. # The ylwrap script must be shipped.
  131. $MAKE echo-distcom
  132. $MAKE -s echo-distcom | grep '[ /]ylwrap '
  133. # The generated C++ source and header files must be shipped.
  134. cd foo
  135. $MAKE echo-distcom
  136. $MAKE -s echo-distcom | grep '[ /]parse\.cc '
  137. $MAKE -s echo-distcom | grep '[ /]parse\.hh '
  138. cd ..
  139. cd bar
  140. $MAKE echo-distcom
  141. $MAKE -s echo-distcom | grep '[ /]parse\.cpp '
  142. $MAKE -s echo-distcom | grep '[ /]parse\.hpp '
  143. cd ..
  144. cd baz
  145. $MAKE echo-distcom
  146. $MAKE -s echo-distcom | grep '[ /]sub/parse\.c++ '
  147. $MAKE -s echo-distcom | grep '[ /]sub/parse\.h++ '
  148. cd ..
  149. cd qux
  150. $MAKE echo-distcom
  151. $MAKE -s echo-distcom | grep '[ /]maude-parse\.cxx '
  152. $MAKE -s echo-distcom | grep '[ /]maude-parse\.hxx '
  153. cd ..
  154. $MAKE distdir
  155. find $distdir # For debugging.
  156. test -f $distdir/ylwrap
  157. test -f $distdir/foo/parse.cc
  158. test -f $distdir/foo/parse.hh
  159. test -f $distdir/bar/parse.cpp
  160. test -f $distdir/bar/parse.hpp
  161. test -f $distdir/baz/sub/parse.c++
  162. test -f $distdir/baz/sub/parse.h++
  163. test -f $distdir/qux/maude-parse.cxx
  164. test -f $distdir/qux/maude-parse.hxx
  165. # The Yacc-derived C++ sources must be created, and not removed once
  166. # compiled (i.e., not treated like "intermediate files" in the GNU
  167. # make sense).
  168. yl_distcheck
  169. # Check that we can recover from deleted headers.
  170. $MAKE clean
  171. rm -f foo/parse.hh bar/parse.hpp baz/sub/parse.h++ qux/maude-parse.hxx
  172. $MAKE
  173. test -f foo/parse.hh
  174. test -f bar/parse.hpp
  175. test -f baz/sub/parse.h++
  176. test -f qux/maude-parse.hxx
  177. # Make sure that the Yacc-derived C++ sources are erased by
  178. # maintainer-clean, and not by distclean.
  179. $MAKE distclean
  180. test -f foo/parse.cc
  181. test -f foo/parse.hh
  182. test -f bar/parse.cpp
  183. test -f bar/parse.hpp
  184. test -f baz/sub/parse.c++
  185. test -f baz/sub/parse.h++
  186. test -f qux/maude-parse.cxx
  187. test -f qux/maude-parse.hxx
  188. ./configure # Re-create 'Makefile'.
  189. $MAKE maintainer-clean
  190. test ! -e foo/parse.cc
  191. test ! -e foo/parse.hh
  192. test ! -e bar/parse.cpp
  193. test ! -e bar/parse.hpp
  194. test ! -e baz/sub/parse.c++
  195. test ! -e baz/sub/parse.h++
  196. test ! -e qux/maude-parse.cxx
  197. test ! -e qux/maude-parse.hxx
  198. :