yacc-clean-cxx.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. # Check that C++ source and header files derived from non-distributed
  17. # Yacc sources are cleaned by "make clean", while C++ source and
  18. # header files derived from distributed Yacc sources are cleaned by
  19. # "make maintainer-clean".
  20. # See also sister test 'yacc-clean.sh'.
  21. required='c++ yacc'
  22. . test-init.sh
  23. cat >> configure.ac << 'END'
  24. AC_PROG_CXX
  25. AC_PROG_YACC
  26. AC_CONFIG_FILES([sub1/Makefile sub2/Makefile])
  27. AC_OUTPUT
  28. END
  29. cat > Makefile.am << 'END'
  30. # Use two subdirectories, one to test with '-d' in YFLAGS, the
  31. # other one to test with empty YFLAGS.
  32. SUBDIRS = sub1 sub2
  33. END
  34. mkdir sub1 sub2
  35. cat > sub1/Makefile.am << 'END'
  36. bin_PROGRAMS = foo bar baz qux
  37. foo_SOURCES = mainfoo.cc parsefoo.yxx
  38. bar_SOURCES = mainbar.cpp parsebar.yy
  39. bar_YFLAGS = $(AM_YFLAGS)
  40. baz_SOURCES = mainbaz.c++
  41. nodist_baz_SOURCES = parsebaz.y++
  42. qux_SOURCES = mainqux.cxx
  43. nodist_qux_SOURCES = parsequx.ypp
  44. qux_YFLAGS = $(AM_YFLAGS)
  45. parsebaz.y++ parsequx.ypp:
  46. cp $(srcdir)/parsefoo.yxx $@
  47. CLEANFILES = parsebaz.y++ parsequx.ypp
  48. END
  49. cat > sub2/Makefile.am << 'END'
  50. include $(top_srcdir)/sub1/Makefile.am
  51. AM_YFLAGS = -d
  52. END
  53. cat > sub1/parsefoo.yxx << 'END'
  54. %{
  55. // This file should contain valid C++ but invalid C.
  56. #include <cstdio>
  57. // "std::" qualification required by Sun C++ 5.9.
  58. int yylex (void) { return std::getchar (); }
  59. void yyerror (const char *s) { return; }
  60. %}
  61. %%
  62. x : 'x' { };
  63. END
  64. cp sub1/parsefoo.yxx sub1/parsebar.yy
  65. cp sub1/parsefoo.yxx sub2/parsefoo.yxx
  66. cp sub1/parsefoo.yxx sub2/parsebar.yy
  67. cat > sub1/mainfoo.cc << 'END'
  68. // This file should contain valid C++ but invalid C.
  69. using namespace std;
  70. int main (int argc, char **argv)
  71. {
  72. extern int yyparse (void);
  73. return yyparse ();
  74. }
  75. END
  76. cp sub1/mainfoo.cc sub1/mainbar.cpp
  77. cp sub1/mainfoo.cc sub1/mainbaz.c++
  78. cp sub1/mainfoo.cc sub1/mainqux.cxx
  79. cp sub1/main???.c* sub2
  80. $ACLOCAL
  81. $AUTOCONF
  82. $AUTOMAKE -a
  83. ./configure
  84. cp config.status config.sav
  85. $MAKE
  86. ls -l . sub1 sub2
  87. # Sanity checks.
  88. test -f sub1/parsefoo.cxx
  89. test -f sub1/bar-parsebar.cc
  90. test -f sub1/parsebaz.y++
  91. test -f sub1/parsebaz.c++
  92. test -f sub1/parsequx.ypp
  93. test -f sub1/qux-parsequx.cpp
  94. test -f sub2/parsefoo.cxx
  95. test -f sub2/parsefoo.hxx
  96. test -f sub2/bar-parsebar.cc
  97. test -f sub2/bar-parsebar.hh
  98. test -f sub2/parsebaz.y++
  99. test -f sub2/parsebaz.c++
  100. test -f sub2/parsebaz.h++
  101. test -f sub2/parsequx.ypp
  102. test -f sub2/qux-parsequx.cpp
  103. test -f sub2/qux-parsequx.hpp
  104. for target in clean distclean; do
  105. $MAKE $target
  106. ls -l . sub1 sub2
  107. test -f sub1/parsefoo.cxx
  108. test -f sub1/bar-parsebar.cc
  109. test ! -e sub1/parsebaz.y++
  110. test ! -e sub1/parsebaz.c++
  111. test ! -e sub1/parsequx.ypp
  112. test ! -e sub1/qux-parsequx.cpp
  113. test -f sub2/parsefoo.cxx
  114. test -f sub2/parsefoo.hxx
  115. test -f sub2/bar-parsebar.cc
  116. test -f sub2/bar-parsebar.hh
  117. test ! -e sub2/parsebaz.y++
  118. test ! -e sub2/parsebaz.c++
  119. test ! -e sub2/parsebaz.h++
  120. test ! -e sub2/parsequx.ypp
  121. test ! -e sub2/qux-parsequx.cpp
  122. test ! -e sub2/qux-parsequx.hpp
  123. done
  124. cp config.sav config.status
  125. ./config.status # re-create Makefile
  126. $MAKE maintainer-clean
  127. ls -l . sub1 sub2
  128. test -f sub1/parsefoo.yxx
  129. test -f sub1/parsebar.yy
  130. test ! -e sub1/parsefoo.cxx
  131. test ! -e sub1/bar-parsebar.cc
  132. test -f sub2/parsefoo.yxx
  133. test -f sub2/parsebar.yy
  134. test ! -e sub2/parsefoo.cxx
  135. test ! -e sub2/parsefoo.hxx
  136. test ! -e sub2/bar-parsebar.cc
  137. test ! -e sub2/bar-parsebar.hh
  138. :