Merge branch 'micro' into maint
[platform/upstream/automake.git] / t / yacc-subdir.sh
1 #! /bin/sh
2 # Copyright (C) 2002-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 # Test for subdir parsers.
18
19 required='cc yacc'
20
21 . test-init.sh
22
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_PROG_YACC
26 AC_OUTPUT
27 END
28
29 cat > Makefile.am << 'END'
30 AUTOMAKE_OPTIONS = subdir-objects
31 bin_PROGRAMS = foo/foo
32 foo_foo_SOURCES = foo/parse.y
33 AM_YFLAGS = -d
34
35 .PHONY: obj
36 obj: foo/parse.$(OBJEXT)
37
38 .PHONY: test1 test2
39 test1: foo/parse.$(OBJEXT)
40         test -f foo/parse.c
41         test -f foo/parse.$(OBJEXT)
42 test2: foo/parse2.$(OBJEXT)
43         test -f foo/parse2.c
44         test -f foo/parse2.$(OBJEXT)
45 END
46
47 mkdir foo
48
49 cat > foo/parse.y << 'END'
50 %{
51 int yylex () { return 0; }
52 void yyerror (char *s) {}
53 %}
54 %%
55 foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
56 END
57
58 $ACLOCAL
59 $AUTOCONF
60 $AUTOMAKE -a
61
62 mkdir sub
63 cd sub
64
65 ../configure
66 $MAKE test1
67
68 # Aside of the rest of this test, let's see if we can recover from
69 # parse.h removal.
70 test -f foo/parse.h
71 rm -f foo/parse.h
72 $MAKE foo/parse.h
73 test -f foo/parse.h
74
75 # Make sure foo/parse.h is not updated, unless when needed.
76 $sleep
77 touch ../foo/parse.y
78 $MAKE obj
79 is_newest ../foo/parse.y foo/parse.h
80 $sleep
81 sed 's/%%/%token TOKEN\n%%/g' ../foo/parse.y >../foo/parse.yt
82 mv -f ../foo/parse.yt ../foo/parse.y
83 $MAKE obj
84 is_newest foo/parse.h ../foo/parse.y
85
86 # Now, adds another parser to test ylwrap.
87
88 cd ..
89
90 # Sleep some to make sure timestamp of Makefile.am will change.
91 $sleep
92
93 cp foo/parse.y foo/parse2.y
94 cat >> Makefile.am << 'END'
95 EXTRA_foo_foo_SOURCES = foo/parse2.y
96 END
97
98 $AUTOMAKE -a
99 test -f ./ylwrap
100
101 cd sub
102 # Regenerate Makefile (automatic in GNU Make, but not in other Makes).
103 ./config.status
104 $MAKE test2
105
106 :