Merge branch 'maint'
[platform/upstream/automake.git] / t / multlib.sh
1 #! /bin/sh
2 # Copyright (C) 2003-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 # Check multilib support.
18 # Based on a test case from Ralf Corsepius.
19 # FIXME: the features tested by this script has been moved in contrib.
20 # FIXME: We should move this script accordingly.
21
22 required='gcc GNUmake'
23 . ./defs || exit 1
24
25 mldir=$am_top_srcdir/contrib/multilib
26 mkdir m4
27 cp "$mldir"/config-ml.in "$mldir"/symlink-tree .
28 cp "$mldir"/multi.m4 m4
29
30 ACLOCAL_PATH=${ACLOCAL_PATH+"$ACLOCAL_PATH:"}$(pwd)/m4
31 export ACLOCAL_PATH
32
33 cat >configure.ac <<'END'
34 AC_INIT([multlib], [1.0])
35 AC_CONFIG_SRCDIR(libfoo/foo.c)
36 AC_CONFIG_AUX_DIR(.)
37 AM_INIT_AUTOMAKE
38 AC_CONFIG_FILES([Makefile])
39 AC_CONFIG_SUBDIRS(libfoo)
40 AC_CONFIG_SUBDIRS(libbar)
41 AC_OUTPUT
42 END
43
44 cat >mycc <<'END'
45 #! /bin/sh
46 case ${1+"$@"} in
47  *-print-multi-lib*)
48   echo ".;"
49   echo "debug;@g"
50   exit 0 ;;
51 esac
52 gcc ${1+"$@"}
53 END
54
55 chmod +x mycc
56 PATH=$(pwd)$PATH_SEPARATOR$PATH; export PATH
57
58 cat >Makefile.am <<'EOF'
59 SUBDIRS = @subdirs@
60 EXTRA_DIST = config-ml.in symlink-tree
61 check-all:
62         test -f debug/libfoo/libfoo.a
63         test -f debug/libbar/libbar.a
64         test -f libfoo/libfoo.a
65         test -f libbar/libbar.a
66 EOF
67
68 # libfoo tests multilib supports when there are no subdirectories
69 # libbar tests multilib supports when there are subdirectories
70
71 mkdir libfoo
72 cp "$mldir"/multilib.am libfoo/
73
74 cat >libfoo/configure.ac <<'END'
75 AC_PREREQ(2.57)
76 AC_INIT(libfoo, 0.1, nobody@localhost)
77 AC_CONFIG_SRCDIR(foo.c)
78 # Apparently it doesn't work to have auxdir=.. when
79 # multilib uses symlinked trees.
80 AC_CONFIG_AUX_DIR(.)
81 AM_INIT_AUTOMAKE
82 AC_PROG_CC
83 AM_PROG_AR
84 AC_PROG_RANLIB
85 AM_ENABLE_MULTILIB(Makefile,[..])
86 AC_CONFIG_FILES([Makefile])
87 AC_OUTPUT
88 END
89
90 cat >libfoo/Makefile.am <<'END'
91 noinst_LIBRARIES = libfoo.a
92 libfoo_a_SOURCES = foo.c
93 include $(top_srcdir)/multilib.am
94 END
95
96 : > libfoo/foo.c
97
98 mkdir libbar
99 cp "$mldir"/multilib.am libbar/
100
101 cat >libbar/configure.ac <<'END'
102 AC_PREREQ(2.57)
103 AC_INIT(libbar, 0.1, nobody@localhost)
104 # Apparently it doesn't work to have auxdir=.. when
105 # multilib uses symlinked trees.
106 AC_CONFIG_AUX_DIR(.)
107 AM_INIT_AUTOMAKE
108 AC_PROG_CC
109 AM_PROG_AR
110 AC_PROG_RANLIB
111 AM_ENABLE_MULTILIB(Makefile,[..])
112 AC_CONFIG_FILES([Makefile sub/Makefile])
113 AC_OUTPUT
114 END
115
116 cat >libbar/Makefile.am <<'END'
117 SUBDIRS = sub
118 noinst_LIBRARIES = libbar.a
119 libbar_a_SOURCES = bar.c
120 include $(top_srcdir)/multilib.am
121 END
122
123 mkdir libbar/sub
124 echo 'include $(top_srcdir)/multilib.am' >libbar/sub/Makefile.am
125 : > libbar/bar.c
126
127 $ACLOCAL
128 $AUTOCONF
129 $AUTOMAKE --add-missing
130
131 cd libfoo
132 $ACLOCAL
133 $AUTOCONF
134 $AUTOMAKE --add-missing
135 cd ..
136
137 cd libbar
138 $ACLOCAL
139 $AUTOCONF
140 $AUTOMAKE --add-missing
141 cd ..
142
143 # Check VPATH builds
144 mkdir build
145 cd build
146 ../configure --enable-multilib CC=mycc
147 $MAKE
148 test -f debug/libfoo/libfoo.a
149 test -f debug/libbar/libbar.a
150 test -f libfoo/libfoo.a
151 test -f libbar/libbar.a
152 $MAKE install
153 $MAKE distcleancheck
154
155 # Check standard builds.
156 cd ..
157 # Why to I have to specify --with-target-subdir?
158 ./configure --enable-multilib --with-target-subdir=. CC=mycc
159 $MAKE check
160 DISTCHECK_CONFIGURE_FLAGS='--enable-multilib CC=mycc' $MAKE distcheck
161
162 :