am-ft: make the environment available earlier
[platform/upstream/automake.git] / t / mmodely.sh
1 #! /bin/sh
2 # Copyright (C) 2004-2013 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
17 # Verify that intermediate files are only built from Yacc and Lex
18 # sources in maintainer mode.
19 # From Derek R. Price.
20
21 required=cc
22 . test-init.sh
23
24 cat >> configure.ac << 'END'
25 AM_MAINTAINER_MODE
26 AC_PROG_CC
27 AM_PROG_LEX
28 AC_PROG_YACC
29 AC_OUTPUT
30 END
31
32 cat > Makefile.am <<'END'
33 YACC = false
34 LEX = false
35 bin_PROGRAMS = zardoz
36 zardoz_SOURCES = zardoz.y joe.l
37 LDADD = @LEXLIB@
38 END
39
40 # The point of this test is that it is not dependent on a working lex
41 # or yacc.
42 cat > joe.c <<EOF
43 int joe (int arg)
44 {
45     return arg * 2;
46 }
47 EOF
48 # On systems which link in libraries non-lazily and whose linkers
49 # complain about unresolved symbols by default, such as Solaris, an
50 # yylex function needs to be defined to avoid an error due to an
51 # unresolved symbol.
52 cat > zardoz.c <<EOF
53 int joe (int arg);
54 int yylex (void)
55 {
56     return 0;
57 }
58 int main (int argc, char **argv)
59 {
60     return joe (argc);
61 }
62 EOF
63
64 # Ensure a later timestamp for our Lex & Yacc sources.
65 $sleep
66 : > joe.l
67 : > zardoz.y
68
69 $ACLOCAL
70 $AUTOCONF
71 $AUTOMAKE -a
72
73 ./configure
74 $MAKE
75
76 cat >myyacc.sh <<'END'
77 #! /bin/sh
78 echo "$@" >y.tab.c
79 END
80 cat >mylex.sh <<'END'
81 echo "$@" >lex.yy.c
82 END
83 chmod +x myyacc.sh mylex.sh
84 PATH=$(pwd)$PATH_SEPARATOR$PATH; export PATH
85
86 # "make maintainer-clean; ./configure; make" should always work,
87 # per GNU Standard.
88 $MAKE maintainer-clean
89 ./configure
90 run_make YACC=myyacc.sh LEX=mylex.sh LEX_OUTPUT_ROOT=lex.yy zardoz.c joe.c
91 $FGREP zardoz.y zardoz.c
92 $FGREP joe.l joe.c
93
94 :