tests: rename 'tests/' => 't/', '*.test' => '*.sh'
[platform/upstream/automake.git] / t / link_cond.sh
1 #! /bin/sh
2 # Copyright (C) 2012 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 <http://www.gnu.org/licenses/>.
16
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.
22
23 required='cc c++'
24 . ./defs || Exit 1
25
26 set -e
27
28 cat >> configure.ac << 'END'
29 AC_PROG_CC
30 AC_PROG_CXX
31 AM_CONDITIONAL([HAVE_CXX], [test $have_cxx = yes])
32 AC_OUTPUT
33 END
34
35 cat > Makefile.am << 'END'
36 bin_PROGRAMS = foo
37 if HAVE_CXX
38 foo_SOURCES = more.c++
39 else
40 foo_SOURCES = less.c
41 endif
42 ## FIXME: ideally, this workaround shouldn't be needed.
43 if HAVE_CXX
44 foo_LINK = $(CXXLINK)
45 else
46 foo_LINK = $(LINK)
47 endif
48 END
49
50 $ACLOCAL
51 $AUTOMAKE
52 $AUTOCONF
53
54 rm -f *.c++
55 cat > less.c <<'END'
56 /* Valid C but deliberately invalid C++ */
57 main ()
58 {
59   int new = 0;
60   return new;
61 }
62 END
63
64 ./configure have_cxx=no
65 CXX=false $MAKE -e
66
67 # Sanity check.
68 rm -f foo foo.exe
69 CC=false $MAKE -e && Exit 99
70
71 $MAKE distclean
72
73 rm -f *.c
74 cat > more.c++ <<'END'
75 /* Valid C++ but deliberately invalid C */
76 using namespace std;
77 int main (void)
78 {
79   return 0;
80 }
81 END
82
83 ./configure have_cxx=yes
84 CC=false $MAKE -e
85
86 # Sanity check.
87 rm -f foo foo.exe
88 CXX=false $MAKE -e && Exit 99
89
90 :