tests: never source test-defs.sh directly, source test-lib.sh instead
[automake.git] / t / link_cond.sh
bloba5ac4b1019f4cd56e1173539ea799b350508e4b3
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 # Test that automatic determination of the linker works well with
18 # conditional use of languages in a single program.
19 # This currently doesn't truly work, but we have an easy workaround
20 # at least, that is tested here.
21 # See automake bug#11089.
23 required='cc c++'
24 . ./defs || exit 1
26 cat >> configure.ac << 'END'
27 AC_PROG_CC
28 AC_PROG_CXX
29 AM_CONDITIONAL([HAVE_CXX], [test $have_cxx = yes])
30 AC_OUTPUT
31 END
33 cat > Makefile.am << 'END'
34 bin_PROGRAMS = foo
35 if HAVE_CXX
36 foo_SOURCES = more.c++
37 else
38 foo_SOURCES = less.c
39 endif
40 ## FIXME: ideally, this workaround shouldn't be needed.
41 if HAVE_CXX
42 foo_LINK = $(CXXLINK)
43 else
44 foo_LINK = $(LINK)
45 endif
46 END
48 $ACLOCAL
49 $AUTOMAKE
50 $AUTOCONF
52 rm -f *.c++
53 cat > less.c <<'END'
54 /* Valid C but deliberately invalid C++ */
55 main ()
57 int new = 0;
58 return new;
60 END
62 ./configure have_cxx=no
63 CXX=false $MAKE -e
65 # Sanity check.
66 rm -f foo foo.exe
67 CC=false $MAKE -e && exit 99
69 $MAKE distclean
71 rm -f *.c
72 cat > more.c++ <<'END'
73 /* Valid C++ but deliberately invalid C */
74 using namespace std;
75 int main (void)
77 return 0;
79 END
81 ./configure have_cxx=yes
82 CC=false $MAKE -e
84 # Sanity check.
85 rm -f foo foo.exe
86 CXX=false $MAKE -e && exit 99