tests: never source test-defs.sh directly, source test-lib.sh instead
[automake.git] / t / cxx-lt-demo.sh
bloba060fc851533da72d0c9c82b40109f501a990c9b
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 Libtool/C++ support.
19 required='libtoolize c++'
20 am_create_testdir=empty
21 . ./defs || exit 1
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 for f in ltmain.sh depcomp config.guess config.sub; do
98 test -f ax/$f && test ! -h ax/$f || exit 1
99 done
100 test ! -e ax/compile # Not required by C++ compilers.
102 cat > src/main.cc << 'END'
103 #include "libfoo.h++"
104 #include <iostream>
105 using namespace std;
106 int main (void)
108 cout << "Howdy, " << target () << "!" << endl;
109 return 0;
113 cat > lib/libfoo.c++ << 'END'
114 #include "libfoo.h++"
115 #include <string>
116 std::string target (void)
118 std::string s1 = "Test";
119 std::string s2 = "suite";
120 return (s1 + s2);
124 ./configure
125 CC=false $MAKE -e
126 ls -l . src lib # For debugging.
127 $MAKE test-objs
128 VERBOSE=yes $MAKE check-TESTS
129 grep 'Howdy.*Testsuite' try.log || grep 'Skip:.*cross-compiled' try.log
131 $MAKE distcheck