diff options
-rwxr-xr-x | t/cxx-demo.sh | 177 | ||||
-rwxr-xr-x | t/cxx-lt-demo.sh | 133 | ||||
-rw-r--r-- | t/list-of-tests.mk | 2 |
3 files changed, 312 insertions, 0 deletions
diff --git a/t/cxx-demo.sh b/t/cxx-demo.sh new file mode 100755 index 000000000..869c2b3b2 --- /dev/null +++ b/t/cxx-demo.sh @@ -0,0 +1,177 @@ +#! /bin/sh +# Copyright (C) 2012 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/>. + +# Demo on C++ support. + +required=c++ +am_create_testdir=empty +. ./defs || Exit 1 + +cat > configure.ac << 'END' +AC_INIT([GNU C++ Demo], [1.3], [bug-automake@gnu.org]) +AC_CONFIG_SRCDIR([play.c++]) +AC_CONFIG_AUX_DIR([build-aux]) +AM_INIT_AUTOMAKE +# The C compiler shouldn't be required in any way. +CC=false; AC_SUBST([CC]) +AC_PROG_CXX +AH_BOTTOM([ +#ifndef GREETINGS +# define GREETINGS "Howdy" +#endif]) +AC_DEFINE([OK_AC], [1], + [Give "good to go" declaration from configure.ac]) +AC_CONFIG_HEADERS([config.hxx]) +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +AUTOMAKE_OPTIONS = subdir-objects + +bin_PROGRAMS = work play +common_sources = common.hpp foo.cpp sub/bar.cc +AM_CPPFLAGS = -DOK_AM=1 +play_SOURCES = play.c++ play.hh $(common_sources) +work_SOURCES = work.cxx work.h++ $(common_sources) +work_CXXFLAGS = -D'GREETINGS="Good morning"' + +.PHONY: test-objs +check-local: test-objs +test-objs: + test -f play.$(OBJEXT) + test -f foo.$(OBJEXT) + test -f sub/bar.$(OBJEXT) + test -f work-foo.$(OBJEXT) + test -f sub/work-bar.$(OBJEXT) + test -f work-work.$(OBJEXT) +END + +mkdir sub build-aux + +$ACLOCAL +$AUTOHEADER +test -f config.hxx.in +$AUTOCONF +$AUTOMAKE --add-missing +test -f build-aux/depcomp +# Not needed by C++ compilers. +test ! -f build-aux/compile + +cat > work.h++ << 'END' +#define ACTION "work" +class Hello_CXX +{ + public: + Hello_CXX() { } + virtual ~Hello_CXX () { } + void hello_cxx_class (); +}; +END + +cat > play.hh << 'END' +#define ACTION "play" +void hello_cxx_function (void); +END + +cat > common.hpp << 'END' +/* Common header. */ + +#include <config.hxx> + +#if !OK_AM +#error "missing OK from Makefile.am" +choke me +#endif + +#if !OK_AC +#error "missing OK from configure.ac" +choke me +#endif + +#include <iostream> +END + +cat > work.cxx << 'END' +#include "common.hpp" +#include "work.h++" +#include <cstdlib> +using namespace std; +int main (void) +{ + cout << "We are working :-(" << endl; + Hello_CXX *hello = new Hello_CXX; + hello->hello_cxx_class (); + return EXIT_SUCCESS; +} +END + +cat > play.c++ << 'END' +#include "common.hpp" +#include "play.hh" +int main (void) +{ + std::cout << "We are playing :-)" << std::endl; + hello_cxx_function (); + return 0; +} +END + +cat > foo.cpp <<'END' +#include <config.hxx> +#include "work.h++" +#include <iostream> +using namespace std; +void Hello_CXX::hello_cxx_class (void) +{ + cout << GREETINGS << ", " << ACTION << "." << endl; +} +END + +cat > sub/bar.cc << 'END' +#include <config.hxx> +#include "play.hh" +#include <stdio.h> +void hello_cxx_function (void) +{ + printf ("%s, %s!\n", GREETINGS, ACTION); +} +END + +./configure +$MAKE +$MAKE test-objs + +if ! cross_compiling; then + unindent > exp.play << 'END' + We are playing :-) + Howdy, play! +END + unindent > exp.work << 'END' + We are working :-( + Good morning, work. +END + for p in play work; do + ./$p > got.$p || { cat got.$p; Exit 1; } + cat exp.$p + cat got.$p + diff exp.$p got.$p + done +fi + +$MAKE distcheck + +: diff --git a/t/cxx-lt-demo.sh b/t/cxx-lt-demo.sh new file mode 100755 index 000000000..ef2bc7871 --- /dev/null +++ b/t/cxx-lt-demo.sh @@ -0,0 +1,133 @@ +#! /bin/sh +# Copyright (C) 2012 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/>. + +# Demo on Libtool/C++ support. + +required='libtoolize c++' +am_create_testdir=empty +. ./defs || Exit 1 + +cat > configure.ac << 'END' +AC_INIT([GNU C++/Libtool Demo], [0.73], [bug-automake@gnu.org]) +AC_CONFIG_SRCDIR([lib/libfoo.c++]) +AC_CONFIG_AUX_DIR([ax]) +AM_INIT_AUTOMAKE +AC_CANONICAL_HOST +AC_CANONICAL_BUILD +AC_PROG_CXX +AM_PROG_AR +LT_INIT +AC_CONFIG_FILES([ + Makefile + src/Makefile + lib/Makefile + try.sh:try.in +]) +AC_OUTPUT +END + +mkdir ax lib src + +cat > Makefile.am <<'END' +SUBDIRS = lib src + +AUTOMAKE_OPTIONS = parallel-tests +TEST_EXTENSIONS = .sh +SH_LOG_COMPILER = $(SHELL) -ex +TESTS = try.sh + +.PHONY: test-objs +check-local: test-objs +test-objs: + test -f src/main.$(OBJEXT) + test -f lib/libfoo.$(OBJEXT) +END + +cat > src/Makefile.am << 'END' +bin_PROGRAMS = zardoz +zardoz_SOURCES = main.cc +zardoz_LDADD = $(top_builddir)/lib/libfoo.la +AM_CPPFLAGS = -I$(top_builddir)/lib +END + +cat > lib/Makefile.am << 'END' +lib_LTLIBRARIES = libfoo.la +nodist_libfoo_la_SOURCES = libfoo.h++ +libfoo_la_SOURCES = libfoo.c++ +libfoo.h++: $(srcdir)/libfoo.c++ + echo '#include <string>' >$@-t + grep "target *(" "$(srcdir)/libfoo.c++" >>$@-t + echo ';' >>$@-t + chmod a-w $@-t && mv -f $@-t $@ +BUILT_SOURCES = libfoo.h++ +DISTCLEANFILES = $(BUILT_SOURCES) +END + +cat > try.in << 'END' +#!/bin/sh +set -e +if test x"$host_alias" = x || test x"$build_alias" = x"$host_alias"; then + ./src/zardoz + test "`./src/zardoz`" = 'Howdy, Testsuite!' +else + echo "Skip: cannot run a cross-compiled program" + exit 77 +fi +END + +libtoolize --copy +$ACLOCAL +$AUTOCONF +$AUTOMAKE --add-missing --copy + +ls -l . ax # For debugging. +for f in ltmain.sh depcomp config.guess config.sub; do + test -f ax/$f && test ! -h ax/$f || Exit 1 +done +test ! -f ax/compile # Not required by C++ compilers. + +cat > src/main.cc << 'END' +#include "libfoo.h++" +#include <iostream> +using namespace std; +int main (void) +{ + cout << "Howdy, " << target () << "!" << endl; + return 0; +} +END + +cat > lib/libfoo.c++ << 'END' +#include "libfoo.h++" +#include <string> +std::string target (void) +{ + std::string s1 = "Test"; + std::string s2 = "suite"; + return (s1 + s2); +} +END + +./configure +CC=false $MAKE -e +ls -l . src lib # For debugging. +$MAKE test-objs +VERBOSE=yes $MAKE check-TESTS +grep 'Howdy.*Testsuite' try.log || grep 'Skip:.*cross-compiled' try.log + +$MAKE -e CC=false distcheck + +: diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index 52bdaf904..446157c2d 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -332,6 +332,8 @@ t/cscope3.sh \ t/cxx.sh \ t/cxx2.sh \ t/cxxcpp.sh \ +t/cxx-demo.sh \ +t/cxx-lt-demo.sh \ t/cxxlibobj.sh \ t/cxxlink.sh \ t/cxxnoc.sh \ |