lex-line.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 automake lex support ensures that lex-generated C
  17. # files use correct "#line" directives. Try also with the
  18. # 'subdir-object' option enabled.
  19. # See also sister test 'yacc-line.sh'.
  20. required='cc lex'
  21. . test-init.sh
  22. cat >> configure.ac << 'END'
  23. AC_CONFIG_FILES([sub/Makefile])
  24. AC_PROG_CC
  25. AC_PROG_LEX
  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. LDADD = $(LEXLIB)
  33. bar_LFLAGS = -v
  34. foo_SOURCES = zardoz.l
  35. bar_SOURCES = dir/quux.l
  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. ## We already used $(LEXLIB) above, so try @LEXLIB@ now.
  44. LDADD = @LEXLIB@
  45. foo_LFLAGS = -v
  46. foo_SOURCES = zardoz.l
  47. bar_SOURCES = dir/quux.l
  48. ## Avoid spurious failures with Solaris make.
  49. foo-zardoz.@OBJEXT@: foo-zardoz.c
  50. dir/quux.@OBJEXT@: dir/quux.c
  51. END
  52. cat > zardoz.l << 'END'
  53. %{
  54. #define YY_NO_UNISTD_H 1
  55. %}
  56. %%
  57. "END" return EOF;
  58. .
  59. %%
  60. int main ()
  61. {
  62. while (yylex () != EOF)
  63. ;
  64. return 0;
  65. }
  66. /* Avoid possible link errors. */
  67. int yywrap (void)
  68. {
  69. return 1;
  70. }
  71. END
  72. cp zardoz.l dir/quux.l
  73. cp zardoz.l sub/zardoz.l
  74. cp zardoz.l sub/dir/quux.l
  75. c_outputs='zardoz.c bar-quux.c sub/foo-zardoz.c sub/dir/quux.c'
  76. $ACLOCAL
  77. $AUTOCONF
  78. # FIXME: stop disabling the warnings in the 'unsupported' category
  79. # FIXME: once the 'subdir-objects' option has been mandatory.
  80. $AUTOMAKE -a -Wno-unsupported
  81. for vpath in : false; do
  82. if $vpath; then
  83. srcdir=..
  84. mkdir build
  85. cd build
  86. else
  87. srcdir=.
  88. fi
  89. $srcdir/configure
  90. $MAKE
  91. # For debugging,
  92. ls -l . sub sub/dir
  93. $EGREP 'line|\.l' $c_outputs
  94. grep '#.*line.*build.*\.l' $c_outputs && exit 1
  95. # Adjusted "#line" should not contain reference to the absolute
  96. # srcdir.
  97. $EGREP '#.*line *"?/.*\.l' $c_outputs && exit 1
  98. # Adjusted "#line" should not contain reference to the default
  99. # output file names, e.g., 'lex.yy.c'.
  100. grep '#.*line.*lex\.yy' $c_outputs && exit 1
  101. # Look out for a silly regression.
  102. grep "#.*\.l.*\.l" $c_outputs && exit 1
  103. if $vpath; then
  104. grep '#.*line.*"\.\./zardoz\.l"' zardoz.c
  105. grep '#.*line.*"\.\./dir/quux\.l"' bar-quux.c
  106. grep '#.*line.*"\.\./\.\./sub/zardoz\.l"' sub/foo-zardoz.c
  107. grep '#.*line.*"\.\./\.\./sub/dir/quux\.l"' sub/dir/quux.c
  108. else
  109. grep '#.*line.*"zardoz\.l"' zardoz.c
  110. grep '#.*line.*"dir/quux\.l"' bar-quux.c
  111. grep '#.*line.*"zardoz\.l"' sub/foo-zardoz.c
  112. grep '#.*line.*"dir/quux\.l"' sub/dir/quux.c
  113. fi
  114. cd $srcdir
  115. done
  116. :