2
0

lex-multiple.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #! /bin/sh
  2. # Copyright (C) 2012-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 we can build a program using several lexers at once
  17. # (assuming Flex is used). That is a little tricky, but possible.
  18. # See:
  19. # <http://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
  20. # <http://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>
  21. required='cc flex'
  22. . test-init.sh
  23. cat >> configure.ac << 'END'
  24. AC_PROG_CC
  25. AC_PROG_LEX
  26. AM_PROG_AR
  27. AC_PROG_RANLIB
  28. AC_OUTPUT
  29. END
  30. cat > Makefile.am << 'END'
  31. bin_PROGRAMS = zardoz
  32. zardoz_SOURCES = main.c
  33. # Convenience libraries.
  34. noinst_LIBRARIES = liblex.a liblex-foo.a liblex-bar.a
  35. zardoz_LDADD = $(noinst_LIBRARIES)
  36. liblex_a_SOURCES = 0.l
  37. # We need the output to always be named 'lex.yy.c', in order for
  38. # ylwrap to pick it up.
  39. liblex_foo_a_LFLAGS = -Pfoo -olex.yy.c
  40. liblex_foo_a_SOURCES = a.l
  41. # Ditto.
  42. liblex_bar_a_LFLAGS = -Pbar_ -olex.yy.c
  43. liblex_bar_a_SOURCES = b.l
  44. END
  45. cat > main.c << 'END'
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. int main (int argc, char *argv[])
  50. {
  51. if (argc != 2)
  52. abort ();
  53. else if (!strcmp(argv[1], "--vanilla"))
  54. return (yylex () != 121);
  55. else if (!strcmp(argv[1], "--foo"))
  56. return (foolex () != 121);
  57. else if (!strcmp(argv[1], "--bar"))
  58. return (bar_lex () != 121);
  59. else
  60. abort ();
  61. }
  62. END
  63. cat > 0.l << 'END'
  64. %{
  65. #define YY_NO_UNISTD_H 1
  66. %}
  67. %%
  68. "VANILLA" { printf (":%s:\n", yytext); return 121; }
  69. . { printf (":%s:\n", yytext); return 1; }
  70. %%
  71. /* Avoid possible link errors. */
  72. int yywrap (void) { return 1; }
  73. END
  74. sed 's/VANILLA/FOO/' 0.l > a.l
  75. sed 's/VANILLA/BAR/' 0.l > b.l
  76. $ACLOCAL
  77. $AUTOCONF
  78. $AUTOMAKE --add-missing
  79. ./configure
  80. $MAKE
  81. if ! cross_compiling; then
  82. echo VANILLA | ./zardoz --vanilla
  83. echo FOO | ./zardoz --foo
  84. echo BAR | ./zardoz --bar
  85. ./zardoz --vanilla </dev/null && exit 1
  86. echo BAR | ./zardoz --foo && exit 1
  87. : For shells with busted 'set -e'.
  88. fi
  89. yl_distcheck
  90. :