summaryrefslogtreecommitdiff
path: root/t/lex-multiple.sh
blob: e804bb229b76d7da4d2f30088eb36d51a7743c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#! /bin/sh
# Copyright (C) 2012-2013 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Check that we can build a program using several lexers at once
# (assuming Flex is used).  That is a little tricky, but possible.
# See:
# <http://lists.gnu.org/archive/html/automake/2010-10/msg00081.html>
# <http://lists.gnu.org/archive/html/automake/2009-03/msg00061.html>

required='cc flex'
. test-init.sh

cat >> configure.ac << 'END'
AC_PROG_CC
AC_PROG_LEX
AM_PROG_AR
AC_PROG_RANLIB
AC_OUTPUT
END

cat > Makefile.am << 'END'
bin_PROGRAMS = zardoz

zardoz_SOURCES = main.c
# Convenience libraries.
noinst_LIBRARIES = liblex.a liblex-foo.a liblex-bar.a
zardoz_LDADD = $(noinst_LIBRARIES)

liblex_a_SOURCES = 0.l

# We need the output to always be named 'lex.yy.c', in order for
# ylwrap to pick it up.
liblex_foo_a_LFLAGS = -Pfoo -olex.yy.c
liblex_foo_a_SOURCES = a.l

# Ditto.
liblex_bar_a_LFLAGS = -Pbar_ -olex.yy.c
liblex_bar_a_SOURCES = b.l
END

cat > main.c << 'END'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char *argv[])
{
  if (argc != 2)
    abort ();
  else if (!strcmp(argv[1], "--vanilla"))
    return (yylex () != 121);
  else if (!strcmp(argv[1], "--foo"))
    return (foolex () != 121);
  else if (!strcmp(argv[1], "--bar"))
    return (bar_lex () != 121);
  else
    abort ();
}
END

cat > 0.l << 'END'
%{
#define YY_NO_UNISTD_H 1
%}
%%
"VANILLA" { printf (":%s:\n", yytext); return 121; }
. { printf (":%s:\n", yytext); return 1; }
%%
/* Avoid possible link errors. */
int yywrap (void) { return 1; }
END

sed 's/VANILLA/FOO/' 0.l > a.l
sed 's/VANILLA/BAR/' 0.l > b.l

$ACLOCAL
$AUTOCONF
$AUTOMAKE --add-missing

./configure
$MAKE

if ! cross_compiling; then
  echo VANILLA | ./zardoz --vanilla
  echo FOO | ./zardoz --foo
  echo BAR | ./zardoz --bar
  ./zardoz --vanilla </dev/null && exit 1
  echo BAR | ./zardoz --foo && exit 1
  : For shells with busted 'set -e'.
fi

yl_distcheck

: