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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
#! /bin/sh
# Copyright (C) 2011-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/>.
# Various tests on Yacc/C++ support with yacc-generated headers
# (i.e., '-d' in *YFLAGS).
# Keep in sync with sister test 'yacc-d-basic.sh'.
required='c++ yacc'
. test-init.sh
write_parse ()
{
header=$1
unindent <<END
%{
// Valid C++, but deliberately invalid C.
#include <cstdlib>
#include "$header"
int yylex (void) { return 0; }
void yyerror (const char *s) {}
%}
%%
x : 'x' {};
%%
END
}
write_main ()
{
header=$1
unindent <<END
// Valid C++, but deliberately invalid C.
#include <cstdio>
#include "$header"
int main (int argc, char **argv)
{
int yyparse (void);
return yyparse ();
}
END
}
cat >> configure.ac << 'END'
AC_PROG_CXX
AC_PROG_YACC
AC_CONFIG_FILES([foo/Makefile bar/Makefile baz/Makefile qux/Makefile])
AC_OUTPUT
END
mkdir foo bar baz qux baz/sub
# These makefiles will be extended later.
cat > Makefile.am <<'END'
.PHONY: echo-distcom
echo-distcom:
@echo ' ' $(DIST_COMMON) ' '
END
cp Makefile.am foo/Makefile.am
cp Makefile.am bar/Makefile.am
cp Makefile.am baz/Makefile.am
cp Makefile.am qux/Makefile.am
cat >> Makefile.am <<'END'
SUBDIRS = foo bar baz qux
END
$ACLOCAL
$AUTOCONF
cp "$am_scriptdir/ylwrap" . \
|| fatal_ "cannot fetch auxiliary script 'ylwrap'"
$AUTOMAKE Makefile
# Try with -d in $(YFLAGS) (don't do this in real life!).
cat >> foo/Makefile.am <<END
bin_PROGRAMS = zardoz
zardoz_SOURCES = parse.yy main.cc
BUILT_SOURCES = parse.hh
YFLAGS=\
-d
END
$AUTOMAKE -Wno-gnu foo/Makefile
write_parse parse.hh > foo/parse.yy
write_main parse.hh > foo/main.cc
# Try with -d in $(AM_YFLAGS).
cat >> bar/Makefile.am <<END
bin_PROGRAMS = zardoz
zardoz_SOURCES = parse.ypp main.cpp
BUILT_SOURCES = parse.hpp
AM_YFLAGS${tab}= -d ${tab}
END
$AUTOMAKE bar/Makefile
write_parse parse.hpp > bar/parse.ypp
write_main parse.hpp > bar/main.cpp
# Try with -d in $(AM_YFLAGS), and a subdir parser.
cat >> baz/Makefile.am <<END
AUTOMAKE_OPTIONS = subdir-objects
bin_PROGRAMS = joe
joe_SOURCES = sub/parse.y++ sub/main.c++
BUILT_SOURCES = sub/parse.h++
AM_YFLAGS = \
${tab}-d
END
$AUTOMAKE baz/Makefile
write_parse sub/parse.h++ > baz/sub/parse.y++
write_main sub/parse.h++ > baz/sub/main.c++
# Try with -d in $(xxx_YFLAGS) (per-object flag).
cat >> qux/Makefile.am <<END
bin_PROGRAMS = maude
maude_SOURCES = parse.yxx main.cxx
maude_YFLAGS=${tab} -d${tab}
BUILT_SOURCES = maude-parse.hxx
END
$AUTOMAKE qux/Makefile
write_parse maude-parse.hxx > qux/parse.yxx
write_main maude-parse.hxx > qux/main.cxx
./configure
$MAKE
ls -l . foo bar baz baz/sub qux # For debugging.
test -f foo/parse.cc
test -f foo/parse.hh
test -f bar/parse.cpp
test -f bar/parse.hpp
test -f baz/sub/parse.c++
test -f baz/sub/parse.h++
test -f qux/maude-parse.cxx
test -f qux/maude-parse.hxx
# The ylwrap script must be shipped.
$MAKE echo-distcom
$MAKE -s echo-distcom | grep '[ /]ylwrap '
# The generated C++ source and header files must be shipped.
cd foo
$MAKE echo-distcom
$MAKE -s echo-distcom | grep '[ /]parse\.cc '
$MAKE -s echo-distcom | grep '[ /]parse\.hh '
cd ..
cd bar
$MAKE echo-distcom
$MAKE -s echo-distcom | grep '[ /]parse\.cpp '
$MAKE -s echo-distcom | grep '[ /]parse\.hpp '
cd ..
cd baz
$MAKE echo-distcom
$MAKE -s echo-distcom | grep '[ /]sub/parse\.c++ '
$MAKE -s echo-distcom | grep '[ /]sub/parse\.h++ '
cd ..
cd qux
$MAKE echo-distcom
$MAKE -s echo-distcom | grep '[ /]maude-parse\.cxx '
$MAKE -s echo-distcom | grep '[ /]maude-parse\.hxx '
cd ..
$MAKE distdir
find $distdir # For debugging.
test -f $distdir/ylwrap
test -f $distdir/foo/parse.cc
test -f $distdir/foo/parse.hh
test -f $distdir/bar/parse.cpp
test -f $distdir/bar/parse.hpp
test -f $distdir/baz/sub/parse.c++
test -f $distdir/baz/sub/parse.h++
test -f $distdir/qux/maude-parse.cxx
test -f $distdir/qux/maude-parse.hxx
# The Yacc-derived C++ sources must be created, and not removed once
# compiled (i.e., not treated like "intermediate files" in the GNU
# make sense).
yl_distcheck
# Check that we can recover from deleted headers.
$MAKE clean
rm -f foo/parse.hh bar/parse.hpp baz/sub/parse.h++ qux/maude-parse.hxx
$MAKE
test -f foo/parse.hh
test -f bar/parse.hpp
test -f baz/sub/parse.h++
test -f qux/maude-parse.hxx
# Make sure that the Yacc-derived C++ sources are erased by
# maintainer-clean, and not by distclean.
$MAKE distclean
test -f foo/parse.cc
test -f foo/parse.hh
test -f bar/parse.cpp
test -f bar/parse.hpp
test -f baz/sub/parse.c++
test -f baz/sub/parse.h++
test -f qux/maude-parse.cxx
test -f qux/maude-parse.hxx
./configure # Re-create 'Makefile'.
$MAKE maintainer-clean
test ! -e foo/parse.cc
test ! -e foo/parse.hh
test ! -e bar/parse.cpp
test ! -e bar/parse.hpp
test ! -e baz/sub/parse.c++
test ! -e baz/sub/parse.h++
test ! -e qux/maude-parse.cxx
test ! -e qux/maude-parse.hxx
:
|