1#! /bin/sh
2# Copyright (C) 2010-2021 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 <https://www.gnu.org/licenses/>.
16
17# This test checks that dependent files are updated before including
18# in the distribution.  'lexer.c' depends on 'lexer.l'.  The latter is
19# updated so that 'lexer.c' should be rebuild.  Then we are running
20# 'make' and 'make distdir' and check whether the version of 'lexer.c'
21# to be distributed is up to date.
22
23# Please keep this in sync with sister test 'yaccvapth.sh'.
24
25required='cc lex'
26. test-init.sh
27
28cat > lexoutroot.in << 'END'
29LEX_OUTPUT_ROOT='@LEX_OUTPUT_ROOT@'
30END
31
32cat >> configure.ac << 'END'
33AC_CONFIG_FILES([lexoutroot])
34AC_PROG_CC
35AC_PROG_LEX
36AC_OUTPUT
37END
38
39cat > Makefile.am << 'END'
40bin_PROGRAMS = foo
41foo_SOURCES = lexer.l foo.c
42LDADD = $(LEXLIB)
43END
44
45# Original lexer, with a "foobar" comment
46cat > lexer.l << 'END'
47%{
48#define YY_NO_UNISTD_H 1
49%}
50%%
51"END" return EOF;
52.
53%%
54/*foobar*/
55END
56
57cat > foo.c << 'END'
58int main (void)
59{
60  return 0;
61}
62/* Avoid possible link errors. */
63int yywrap (void)
64{
65  return 1;
66}
67END
68
69$ACLOCAL
70$AUTOCONF
71$AUTOMAKE -a
72
73mkdir sub
74
75# We must run configure early, to find out why $LEX_OUTPUT_ROOT is.
76cd sub
77../configure
78. ./lexoutroot
79test -n "$LEX_OUTPUT_ROOT" # Sanity check.
80cd ..
81
82$LEX lexer.l
83mv "$LEX_OUTPUT_ROOT".c lexer.c
84
85cd sub
86
87# Ensure that lexer.l will be newer than lexer.c.
88$sleep
89
90# New lexer, with 'fubar' comment.
91cat > ../lexer.l << 'END'
92%{
93#define YY_NO_UNISTD_H 1
94%}
95%%
96"END" return EOF;
97.
98%%
99/*fubar*/
100END
101
102$MAKE
103$MAKE distdir
104$FGREP '/*fubar*/' $distdir/lexer.c
105
106#
107# Now check to make sure that 'make dist' will rebuilt the parser.
108#
109
110# Ensure that lexer.l will be newer than lexer.c.
111$sleep
112
113# New lexer, with 'maude' comment.
114cat > ../lexer.l << 'END'
115%{
116#define YY_NO_UNISTD_H 1
117%}
118%%
119"END" return EOF;
120.
121%%
122/*maude*/
123END
124
125$MAKE distdir
126$FGREP '/*maude*/' $distdir/lexer.c
127
128:
129