yacc-line.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #! /bin/sh
  2. # Copyright (C) 2001-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 automake yacc support ensures that yacc-generated C
  17. # files use correct "#line" directives. Try also with the
  18. # 'subdir-object' option enabled.
  19. # See also sister test 'lex-line.sh'.
  20. required='cc yacc'
  21. . test-init.sh
  22. cat >> configure.ac << 'END'
  23. AC_CONFIG_FILES([sub/Makefile])
  24. AC_PROG_CC
  25. AC_PROG_YACC
  26. AC_OUTPUT
  27. END
  28. mkdir dir sub sub/dir
  29. cat > Makefile.am << 'END'
  30. SUBDIRS = sub
  31. bin_PROGRAMS = foo bar
  32. AM_YFLAGS = -d
  33. bar_YFLAGS =
  34. foo_SOURCES = zardoz.y
  35. bar_SOURCES = dir/quux.y
  36. ## Avoid spurious failures with Solaris make.
  37. zardoz.@OBJEXT@: zardoz.c
  38. bar-quux.@OBJEXT@: bar-quux.c
  39. END
  40. cat > sub/Makefile.am << 'END'
  41. AUTOMAKE_OPTIONS = subdir-objects
  42. noinst_PROGRAMS = foo bar
  43. foo_YFLAGS = -d
  44. foo_SOURCES = zardoz.y
  45. bar_SOURCES = dir/quux.y
  46. ## Avoid spurious failures with Solaris make.
  47. foo-zardoz.@OBJEXT@: foo-zardoz.c
  48. dir/quux.@OBJEXT@: dir/quux.c
  49. END
  50. cat > zardoz.y << 'END'
  51. %{
  52. int yylex () { return 0; }
  53. void yyerror (char *s) { return; }
  54. %}
  55. %%
  56. x : 'x' {};
  57. %%
  58. int main(void)
  59. {
  60. return yyparse ();
  61. }
  62. END
  63. cp zardoz.y dir/quux.y
  64. cp zardoz.y sub/zardoz.y
  65. cp zardoz.y sub/dir/quux.y
  66. c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
  67. $ACLOCAL
  68. $AUTOCONF
  69. # FIXME: stop disabling the warnings in the 'unsupported' category
  70. # FIXME: once the 'subdir-objects' option has been mandatory.
  71. $AUTOMAKE -a -Wno-unsupported
  72. for vpath in : false; do
  73. if $vpath; then
  74. srcdir=..
  75. mkdir build
  76. cd build
  77. else
  78. srcdir=.
  79. fi
  80. $srcdir/configure
  81. $MAKE
  82. # For debugging,
  83. ls -l . sub sub/dir
  84. $EGREP 'line|\.y' $c_outputs
  85. # Adjusted "#line" should not contain reference to the builddir.
  86. grep '#.*line.*build.*\.y' $c_outputs && exit 1
  87. # Adjusted "#line" should not contain reference to the absolute
  88. # srcdir.
  89. $EGREP '#.*line *"?/.*\.y' $c_outputs && exit 1
  90. # Adjusted "#line" should not contain reference to the default
  91. # output file names, e.g., 'y.tab.c' and 'y.tab.h'.
  92. grep '#.*line.*y\.tab\.' $c_outputs && exit 1
  93. # Look out for a silly regression.
  94. grep "#.*\.y.*\.y" $c_outputs && exit 1
  95. if $vpath; then
  96. grep '#.*line.*"\.\./zardoz\.y"' zardoz.c
  97. grep '#.*line.*"\.\./dir/quux\.y"' bar-quux.c
  98. grep '#.*line.*"\.\./\.\./sub/zardoz\.y"' sub/foo-zardoz.c
  99. grep '#.*line.*"\.\./\.\./sub/dir/quux\.y"' sub/dir/quux.c
  100. else
  101. grep '#.*line.*"zardoz\.y"' zardoz.c
  102. grep '#.*line.*"dir/quux\.y"' bar-quux.c
  103. grep '#.*line.*"zardoz\.y"' sub/foo-zardoz.c
  104. grep '#.*line.*"dir/quux\.y"' sub/dir/quux.c
  105. fi
  106. cd $srcdir
  107. done
  108. :