lex-header.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. # Automake lex support can work with flex '--header-file' option (see
  17. # bugs #8844 and #9933).
  18. required='cc flex'
  19. . test-init.sh
  20. # Here, we need to use the use flex option '--header-file', but some
  21. # older flex versions don't support is (see automake bug#11524 and
  22. # bug#12836). Skip this test if such an old flex version is detected.
  23. $LEX --help | grep '.*--header-file' \
  24. || skip_ "flex doesn't support the '--header-file' option"
  25. cat >> configure.ac << 'END'
  26. AC_PROG_CC
  27. AC_PROG_LEX
  28. AC_OUTPUT
  29. END
  30. cat > Makefile.am << 'END'
  31. bin_PROGRAMS = foo
  32. foo_SOURCES = lexer.l main.c mylex.h
  33. foo_LFLAGS = --header-file=mylex.h
  34. BUILT_SOURCES = mylex.h
  35. # Recover from removal of header.
  36. mylex.h: foo-lexer.c
  37. test -f $@ || rm -f foo-lexer.c
  38. test -f $@ || $(MAKE) $(AM_MAKEFLAGS) foo-lexer.c
  39. END
  40. cat > lexer.l << 'END'
  41. %option noyywrap
  42. %{
  43. #define YY_NO_UNISTD_H 1
  44. %}
  45. %%
  46. "GOOD" return EOF;
  47. .
  48. %%
  49. END
  50. cat > main.c <<'END'
  51. #define YY_NO_UNISTD_H 1
  52. #include "mylex.h"
  53. int main (void)
  54. {
  55. /* We don't use a 'while' loop here (like a real lexer would do)
  56. to avoid possible hangs. */
  57. if (yylex () == EOF)
  58. return 0;
  59. else
  60. return 1;
  61. }
  62. END
  63. $ACLOCAL
  64. $AUTOCONF
  65. $AUTOMAKE -a
  66. ./configure
  67. # Program should build and run.
  68. $MAKE
  69. if ! cross_compiling; then
  70. echo GOOD | ./foo
  71. echo BAD | ./foo && exit 1
  72. : For shells with busted 'set -e'.
  73. fi
  74. # Recovering from header removal.
  75. rm -f mylex.h
  76. $MAKE
  77. test -f mylex.h
  78. # Sanity check on distribution.
  79. yl_distcheck
  80. :