yacc-basic.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #! /bin/sh
  2. # Copyright (C) 2010-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 support (without yacc-generated headers).
  17. # Keep in sync with sister test 'yacc-cxx.sh'.
  18. required='cc yacc'
  19. . test-init.sh
  20. cat >> configure.ac << 'END'
  21. AC_PROG_CC
  22. AC_PROG_YACC
  23. AC_OUTPUT
  24. END
  25. cat > Makefile.am << 'END'
  26. bin_PROGRAMS = foo bar
  27. foo_SOURCES = parse.y foo.c
  28. bar_SOURCES = $(foo_SOURCES)
  29. bar_YFLAGS = -v
  30. .PHONY: echo-distcom
  31. echo-distcom:
  32. @echo ' ' $(DIST_COMMON) ' '
  33. END
  34. cat > parse.y << 'END'
  35. %{
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. int yylex () { return getchar (); }
  39. void yyerror (char *s) {}
  40. %}
  41. %%
  42. a : 'a' { exit(0); };
  43. END
  44. cat > foo.c << 'END'
  45. int main () { yyparse (); return 1; }
  46. END
  47. $ACLOCAL
  48. $AUTOCONF
  49. $AUTOMAKE -a
  50. ./configure
  51. $MAKE
  52. ls -l
  53. # The Yacc-derived C sources must be created, and not removed once
  54. # compiled (i.e., not treated like "intermediate files" in the GNU
  55. # make sense).
  56. test -f parse.c
  57. test -f bar-parse.c
  58. # Check that per-object flags are honored.
  59. test -f bar-parse.output
  60. if ! cross_compiling; then
  61. echo a | ./foo
  62. echo b | ./foo && exit 1
  63. echo a | ./bar
  64. echo b | ./bar && exit 1
  65. : For shells with busted 'set -e'.
  66. fi
  67. # The Yacc-derived C sources must be shipped.
  68. $MAKE echo-distcom
  69. $MAKE -s echo-distcom | grep '[ /]parse\.c '
  70. $MAKE -s echo-distcom | grep '[ /]bar-parse\.c '
  71. $MAKE distdir
  72. ls -l $distdir
  73. test -f $distdir/parse.c
  74. test -f $distdir/bar-parse.c
  75. # Sanity check on distribution.
  76. # Note that, for this to succeed, bar-parse.output must either not
  77. # be distributed, or properly cleaned by automake-generated rules.
  78. # We don't want to set the exact semantics yet, but want to ensure
  79. # they are are consistent.
  80. yl_distcheck
  81. # Make sure that the Yacc-derived C sources are erased by
  82. # maintainer-clean, and not by distclean.
  83. test -f parse.c
  84. test -f bar-parse.c
  85. $MAKE distclean
  86. ls -l
  87. test -f parse.c
  88. test -f bar-parse.c
  89. ./configure # We must re-create 'Makefile'.
  90. $MAKE maintainer-clean
  91. ls -l
  92. test ! -e parse.c
  93. test ! -e bar-parse.c
  94. :