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)
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.
20 am_create_testdir
=empty
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
])
28 # The C compiler shouldn't be required in any way.
29 CC
=false
; AC_SUBST
([CC
])
33 # define GREETINGS "Howdy"
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
])
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"'
53 check-local
: test-objs
55 test -f play.$
(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
)
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'
80 virtual ~Hello_CXX
() { }
81 void hello_cxx_class
();
85 cat > play.hh
<< 'END'
87 void hello_cxx_function
(void
);
90 cat > common.hpp
<< 'END'
96 #error "missing OK from Makefile.am"
101 #error "missing OK from configure.ac"
108 cat > work.cxx
<< 'END'
109 #include "common.hpp"
115 cout
<< "We are working :-(" << endl;
116 Hello_CXX *hello = new Hello_CXX;
117 hello->hello_cxx_class ();
122 cat > play.c++ << 'END'
123 #include "common.hpp"
127 std::cout << "We are playing :-)" << std::endl;
128 hello_cxx_function
();
133 cat > foo.cpp
<<'END'
134 #include <config.hxx>
138 void Hello_CXX::hello_cxx_class (void)
140 cout << GREETINGS << ", " << ACTION << "." << endl;
144 cat > sub
/bar.cc
<< 'END'
145 #include <config.hxx>
148 void hello_cxx_function
(void
)
150 printf ("%s, %s!\n", GREETINGS
, ACTION
);
158 if ! cross_compiling
; then
159 unindent
> exp.play
<< 'END'
163 unindent
> exp.work
<< 'END'
167 for p
in play work
; do
168 .
/$p > got.
$p ||
{ cat got.
$p; exit 1; }