maint: Update HACKING
[automake.git] / t / link_cond.sh
blob382e4a6e1aca1c945ea29f1419faab72e0093c0a
1 #! /bin/sh
2 # Copyright (C) 2012-2017 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 # 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 . test-init.sh
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 run_make CXX=false
65 # Sanity check.
66 rm -f foo foo.exe
67 run_make CC=false && fatal_ '"make CC=false" succeeded unexpectedly'
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 run_make CC=false
84 # Sanity check.
85 rm -f foo foo.exe
86 run_make CXX=false && fatal_ '"make CXX=false" succeeded unexpectedly'