test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / cxx-lt-demo.sh
blob0b87626b945c18179780b6f1819405b260988434
1 #! /bin/sh
2 # Copyright (C) 2012-2024 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 <https://www.gnu.org/licenses/>.
17 # Demo on Libtool/C++ support.
19 required='libtoolize c++'
20 am_create_testdir=empty
21 . test-init.sh
23 cat > configure.ac << 'END'
24 AC_INIT([GNU C++/Libtool Demo], [0.73], [bug-automake@gnu.org])
25 AC_CONFIG_SRCDIR([lib/libfoo.c++])
26 AC_CONFIG_AUX_DIR([ax])
27 AM_INIT_AUTOMAKE
28 AC_CANONICAL_HOST
29 AC_CANONICAL_BUILD
30 AC_PROG_CXX
31 AM_PROG_AR
32 LT_INIT
33 AC_CONFIG_FILES([
34 Makefile
35 src/Makefile
36 lib/Makefile
37 try.sh:try.in
39 AC_OUTPUT
40 END
42 mkdir ax lib src
44 cat > Makefile.am <<'END'
45 SUBDIRS = lib src
47 AUTOMAKE_OPTIONS = parallel-tests
48 TEST_EXTENSIONS = .sh
49 SH_LOG_COMPILER = $(SHELL) -ex
50 TESTS = try.sh
52 .PHONY: test-objs
53 check-local: test-objs
54 test-objs:
55 test -f src/main.$(OBJEXT)
56 test -f lib/libfoo.lo
57 END
59 cat > src/Makefile.am << 'END'
60 bin_PROGRAMS = zardoz
61 zardoz_SOURCES = main.cc
62 zardoz_LDADD = $(top_builddir)/lib/libfoo.la
63 AM_CPPFLAGS = -I$(top_builddir)/lib
64 END
66 cat > lib/Makefile.am << 'END'
67 lib_LTLIBRARIES = libfoo.la
68 nodist_libfoo_la_SOURCES = libfoo.h++
69 libfoo_la_SOURCES = libfoo.c++
70 libfoo.h++: $(srcdir)/libfoo.c++
71 echo '#include <string>' >$@-t
72 grep "target *(" "$(srcdir)/libfoo.c++" >>$@-t
73 echo ';' >>$@-t
74 chmod a-w $@-t && mv -f $@-t $@
75 BUILT_SOURCES = libfoo.h++
76 DISTCLEANFILES = $(BUILT_SOURCES)
77 END
79 cat > try.in << 'END'
80 #!/bin/sh
81 set -e
82 if test x"$host_alias" = x || test x"$build_alias" = x"$host_alias"; then
83 ./src/zardoz
84 test "`./src/zardoz`" = 'Howdy, Testsuite!'
85 else
86 echo "Skip: cannot run a cross-compiled program"
87 exit 77
89 END
91 libtoolize --copy
92 $ACLOCAL
93 $AUTOCONF
94 $AUTOMAKE --add-missing --copy
96 ls -l . ax # For debugging.
97 # Ideally, the 'compile' script should not be required by C++ compilers.
98 # But alas, LT_INIT seems to invoke AC_PROG_CC anyway, and that brings in
99 # that script.
100 for f in ltmain.sh depcomp compile config.guess config.sub; do
101 test -f ax/$f && test ! -h ax/$f || exit 1
102 done
104 cat > src/main.cc << 'END'
105 #include "libfoo.h++"
106 #include <iostream>
107 using namespace std;
108 int main (void)
110 cout << "Howdy, " << target () << "!" << endl;
111 return 0;
115 cat > lib/libfoo.c++ << 'END'
116 #include "libfoo.h++"
117 std::string target (void)
119 std::string s1 = "Test";
120 std::string s2 = "suite";
121 return (s1 + s2);
125 ./configure
126 run_make CC=false
127 ls -l . src lib # For debugging.
128 $MAKE test-objs
129 VERBOSE=yes $MAKE check-TESTS
130 grep 'Howdy.*Testsuite' try.log || grep 'Skip:.*cross-compiled' try.log
132 $MAKE distcheck