| 1 | #! /bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # Copyright (C) 2012-2025 Free Software Foundation, Inc. |
| 3 | # |
| 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. |
| 8 | # |
| 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. |
| 13 | # |
| 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/>. |
| 16 | |
| 17 | # Demo on Libtool/C++ support. |
| 18 | |
| 19 | required='libtoolize c++' |
| 20 | am_create_testdir=empty |
| 21 | . test-init.shscip-shell source . . `test-init.sh`. |
| 22 | |
| 23 | catscip-shell system . . cat. > configure.ac << 'END' |
| 24 | AC_INIT([GNU C++/Libtool Demo], [0.73], [[email protected]]) |
| 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 |
| 38 | ]) |
| 39 | AC_OUTPUT |
| 40 | END |
| 41 | |
| 42 | mkdirscip-shell system . . mkdir. ax lib src |
| 43 | |
| 44 | catscip-shell system . . cat. > Makefile.am <<'END' |
| 45 | SUBDIRS = lib src |
| 46 | |
| 47 | AUTOMAKE_OPTIONS = parallel-tests |
| 48 | TEST_EXTENSIONS = .sh |
| 49 | SH_LOG_COMPILER = $(SHELL) -ex |
| 50 | TESTS = try.sh |
| 51 | |
| 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 |
| 58 | |
| 59 | catscip-shell system . . 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 |
| 65 | |
| 66 | catscip-shell system . . 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 |
| 78 | |
| 79 | catscip-shell system . . 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 |
| 88 | fi |
| 89 | END |
| 90 | |
| 91 | libtoolizescip-shell system . . libtoolize. --copy |
| 92 | $ACLOCAL |
| 93 | $AUTOCONF |
| 94 | $AUTOMAKE --add-missing --copy |
| 95 | |
| 96 | lsscip-shell system . . 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 | testscip-shell system . . test. -f ax/$f && testscip-shell system . . test. ! -h ax/$f || exit 1 |
| 102 | done |
| 103 | |
| 104 | catscip-shell system . . cat. > src/main.cc << 'END' |
| 105 | #include "libfoo.h++" |
| 106 | #include <iostream> |
| 107 | using namespace std; |
| 108 | int main (void) |
| 109 | { |
| 110 | cout << "Howdy, " << target () << "!" << endl; |
| 111 | return 0; |
| 112 | } |
| 113 | END |
| 114 | |
| 115 | catscip-shell system . . cat. > lib/libfoo.c++ << 'END' |
| 116 | #include "libfoo.h++" |
| 117 | std::string target (void) |
| 118 | { |
| 119 | std::string s1 = "Test"; |
| 120 | std::string s2 = "suite"; |
| 121 | return (s1 + s2); |
| 122 | } |
| 123 | END |
| 124 | |
| 125 | ./configure |
| 126 | run_make CC=false |
| 127 | lsscip-shell system . . ls. -l . src lib # For debugging. |
| 128 | $MAKE test-objs |
| 129 | VERBOSE=yes $MAKE check-TESTS |
| 130 | grepscip-shell system . . grep. 'Howdy.*Testsuite' try.log || grepscip-shell system . . grep. 'Skip:.*cross-compiled' try.log |
| 131 | |
| 132 | $MAKE distcheck |
| 133 | |
| 134 | : |