yacc-cxx.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. # Basic semantic checks on Yacc + C++ support (when yacc-generated
  17. # headers are not involved).
  18. # Keep in sync with sister test 'yacc-basic.sh'.
  19. required='c++ yacc'
  20. . test-init.sh
  21. cat >> configure.ac << 'END'
  22. AC_PROG_CXX
  23. AC_PROG_YACC
  24. AC_OUTPUT
  25. END
  26. cat > Makefile.am << 'END'
  27. bin_PROGRAMS = foo1 foo2 foo3 foo4
  28. foo1_SOURCES = parse1.yy foo.cc
  29. foo2_SOURCES = parse2.y++ bar.c++
  30. foo3_SOURCES = parse3.yxx foo.cc
  31. foo4_SOURCES = parse4.ypp bar2.cxx
  32. foo3_YFLAGS = -v
  33. foo4_YFLAGS = $(foo3_YFLAGS)
  34. .PHONY: echo-distcom
  35. echo-distcom:
  36. @echo ' ' $(DIST_COMMON) ' '
  37. END
  38. cat > parse1.yy << 'END'
  39. %{
  40. // Valid C++, but deliberately invalid C.
  41. #include <cstdio>
  42. #include <cstdlib>
  43. // "std::" qualification required by Sun C++ 5.9.
  44. int yylex (void) { return std::getchar (); }
  45. void yyerror (const char *s) { return; }
  46. %}
  47. %%
  48. a : 'a' { exit(0); };
  49. END
  50. cp parse1.yy parse2.y++
  51. cp parse1.yy parse3.yxx
  52. cp parse1.yy parse4.ypp
  53. cat > foo.cc << 'END'
  54. // Valid C++, but deliberately invalid C.
  55. using namespace std;
  56. int main (int argc, char **argv)
  57. {
  58. int yyparse (void);
  59. yyparse ();
  60. return 1;
  61. }
  62. END
  63. cp foo.cc bar.c++
  64. cp foo.cc bar2.cxx
  65. $ACLOCAL
  66. $AUTOCONF
  67. $AUTOMAKE -a
  68. ./configure
  69. $MAKE
  70. # The Yacc-derived C++ sources must be created, and not removed once
  71. # compiled (i.e., not treated like "intermediate files" in the GNU
  72. # make sense).
  73. test -f parse1.cc
  74. test -f parse2.c++
  75. test -f foo3-parse3.cxx
  76. test -f foo4-parse4.cpp
  77. # Check that per-object flags are honored.
  78. test -f foo3-parse3.output
  79. test -f foo4-parse4.output
  80. if ! cross_compiling; then
  81. for i in 1 2 3 4; do
  82. echo a | ./foo$i
  83. echo b | ./foo$i && exit 1
  84. : For shells with busted 'set -e'.
  85. done
  86. fi
  87. # The Yacc-derived C++ sources must be shipped.
  88. $MAKE echo-distcom
  89. $MAKE -s echo-distcom | grep '[ /]parse1\.cc '
  90. $MAKE -s echo-distcom | grep '[ /]parse2\.c++ '
  91. $MAKE -s echo-distcom | grep '[ /]foo3-parse3\.cxx '
  92. $MAKE -s echo-distcom | grep '[ /]foo4-parse4\.cpp '
  93. $MAKE distdir
  94. ls -l $distdir
  95. test -f $distdir/parse1.cc
  96. test -f $distdir/parse2.c++
  97. test -f $distdir/foo3-parse3.cxx
  98. test -f $distdir/foo4-parse4.cpp
  99. # Sanity check on distribution.
  100. # Note that, for this to succeed, foo3-parse3.output and foo4-parse4.output
  101. # must either not be distributed, or properly cleaned by automake-generated
  102. # rules. We don't want to set the exact semantics yet, but want to ensure
  103. # they are are consistent.
  104. yl_distcheck
  105. # Make sure that the Yacc-derived C++ sources are erased by
  106. # maintainer-clean, and not by distclean.
  107. test -f parse1.cc
  108. test -f parse2.c++
  109. test -f foo3-parse3.cxx
  110. test -f foo4-parse4.cpp
  111. $MAKE distclean
  112. ls -l
  113. test -f parse1.cc
  114. test -f parse2.c++
  115. test -f foo3-parse3.cxx
  116. test -f foo4-parse4.cpp
  117. ./configure # Re-create 'Makefile'.
  118. $MAKE maintainer-clean
  119. ls -l
  120. test ! -e parse1.cc
  121. test ! -e parse2.c++
  122. test ! -e foo3-parse3.cxx
  123. test ! -e foo4-parse4.cpp
  124. :