tests: never source test-defs.sh directly, source test-lib.sh instead
[automake.git] / t / cxx-demo.sh
blob77f7c83b6ffbe00f2a21a83cfa2b5b1c6e69905c
1 #! /bin/sh
2 # Copyright (C) 2012 Free Software Foundation, Inc.
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.
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.
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/>.
17 # Demo on C++ support.
19 required=c++
20 am_create_testdir=empty
21 . ./defs || exit 1
23 cat > configure.ac << 'END'
24 AC_INIT([GNU C++ Demo], [1.3], [bug-automake@gnu.org])
25 AC_CONFIG_SRCDIR([play.c++])
26 AC_CONFIG_AUX_DIR([build-aux])
27 AM_INIT_AUTOMAKE
28 # The C compiler shouldn't be required in any way.
29 CC=false; AC_SUBST([CC])
30 AC_PROG_CXX
31 AH_BOTTOM([
32 #ifndef GREETINGS
33 # define GREETINGS "Howdy"
34 #endif])
35 AC_DEFINE([OK_AC], [1],
36 [Give "good to go" declaration from configure.ac])
37 AC_CONFIG_HEADERS([config.hxx])
38 AC_CONFIG_FILES([Makefile])
39 AC_OUTPUT
40 END
42 cat > Makefile.am << 'END'
43 AUTOMAKE_OPTIONS = subdir-objects
45 bin_PROGRAMS = work play
46 common_sources = common.hpp foo.cpp sub/bar.cc
47 AM_CPPFLAGS = -DOK_AM=1
48 play_SOURCES = play.c++ play.hh $(common_sources)
49 work_SOURCES = work.cxx work.h++ $(common_sources)
50 work_CXXFLAGS = -D'GREETINGS="Good morning"'
52 .PHONY: test-objs
53 check-local: test-objs
54 test-objs:
55 test -f play.$(OBJEXT)
56 test -f foo.$(OBJEXT)
57 test -f sub/bar.$(OBJEXT)
58 test -f work-foo.$(OBJEXT)
59 test -f sub/work-bar.$(OBJEXT)
60 test -f work-work.$(OBJEXT)
61 END
63 mkdir sub build-aux
65 $ACLOCAL
66 $AUTOHEADER
67 test -f config.hxx.in
68 $AUTOCONF
69 $AUTOMAKE --add-missing
70 test -f build-aux/depcomp
71 # Not needed by C++ compilers.
72 test ! -e build-aux/compile
74 cat > work.h++ << 'END'
75 #define ACTION "work"
76 class Hello_CXX
78 public:
79 Hello_CXX() { }
80 virtual ~Hello_CXX () { }
81 void hello_cxx_class ();
83 END
85 cat > play.hh << 'END'
86 #define ACTION "play"
87 void hello_cxx_function (void);
88 END
90 cat > common.hpp << 'END'
91 /* Common header. */
93 #include <config.hxx>
95 #if !OK_AM
96 #error "missing OK from Makefile.am"
97 choke me
98 #endif
100 #if !OK_AC
101 #error "missing OK from configure.ac"
102 choke me
103 #endif
105 #include <iostream>
108 cat > work.cxx << 'END'
109 #include "common.hpp"
110 #include "work.h++"
111 #include <cstdlib>
112 using namespace std;
113 int main (void)
115 cout << "We are working :-(" << endl;
116 Hello_CXX *hello = new Hello_CXX;
117 hello->hello_cxx_class ();
118 return EXIT_SUCCESS;
122 cat > play.c++ << 'END'
123 #include "common.hpp"
124 #include "play.hh"
125 int main (void)
127 std::cout << "We are playing :-)" << std::endl;
128 hello_cxx_function ();
129 return 0;
133 cat > foo.cpp <<'END'
134 #include <config.hxx>
135 #include "work.h++"
136 #include <iostream>
137 using namespace std;
138 void Hello_CXX::hello_cxx_class (void)
140 cout << GREETINGS << ", " << ACTION << "." << endl;
144 cat > sub/bar.cc << 'END'
145 #include <config.hxx>
146 #include "play.hh"
147 #include <stdio.h>
148 void hello_cxx_function (void)
150 printf ("%s, %s!\n", GREETINGS, ACTION);
154 ./configure
155 $MAKE
156 $MAKE test-objs
158 if ! cross_compiling; then
159 unindent > exp.play << 'END'
160 We are playing :-)
161 Howdy, play!
163 unindent > exp.work << 'END'
164 We are working :-(
165 Good morning, work.
167 for p in play work; do
168 ./$p > got.$p || { cat got.$p; exit 1; }
169 cat exp.$p
170 cat got.$p
171 diff exp.$p got.$p
172 done
175 $MAKE distcheck