Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / sysroot.at
1 # static.at -- test flags for sysrooting          -*- Autotest -*-
2 #
3 #   Copyright (C) 2009 Free Software Foundation, Inc.
4 #   Written by Paolo Bonzini, 2009
5 #
6 #   This file is part of GNU Libtool.
7 #
8 # GNU Libtool is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of
11 # the License, or (at your option) any later version.
12 #
13 # GNU Libtool is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Libtool; see the file COPYING.  If not, a copy
20 # can be downloaded from  http://www.gnu.org/licenses/gpl.html,
21 # or obtained by writing to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ####
24
25 m4_define([SYSROOT_TEST], [
26 AT_SETUP([$1])
27 AT_KEYWORDS([libtool sysroot])
28
29 gcc_sysroot=`$CC --print-sysroot 2> /dev/null`
30 if test $? != 0; then
31   gcc_sysroot=
32 fi
33 AT_CHECK([test -n "$gcc_sysroot" || exit 77])
34
35 # Detect installation prefix for the compiler
36 prefix=
37 for i in crt0.o crt1.o crt2.o crti.o; do
38   j=`$CC --print-file-name $i 2> /dev/null`
39   test $? = 0 || continue
40   case "$j" in
41     $gcc_sysroot*/lib/$i)
42       prefix=`echo "$j" | sed "s,^$gcc_sysroot\\(.*\\)/lib/$i\$,\\1,"`
43       break ;;
44   esac
45 done
46 AT_CHECK([test -n "$prefix" || exit 77])
47
48 sysroot=`pwd`/sys-root
49
50 # difficult to use AS_DIRNAME inside the AT_CHECK macro, so
51 # encapsulate as a shell function.
52 local_dirname() {
53   AS_DIRNAME(["$[]1"])
54 }
55
56 AT_CHECK([
57 (cd "$gcc_sysroot" && find ".$prefix/bin" ".$prefix/include" ".$prefix/lib" \! -type d) | \
58 while read file; do
59   dir=`local_dirname "$sysroot/$file"`
60   test -d "$dir" || mkdir -p "$dir"
61   rm -f "$sysroot/$file"
62   ln -s "$gcc_sysroot/$file" "$sysroot/$file" || \
63     cp "$gcc_sysroot/$file" "$sysroot/$file"
64 done])
65
66 LDFLAGS="$LDFLAGS --sysroot=$sysroot -no-undefined"
67 configure_options="$configure_options --with-sysroot=$sysroot --prefix=$prefix"
68
69 #???
70 if test "$shlibpath_var" = PATH; then
71   configure_options="$configure_options --libdir=/$prefix/bin"
72 fi
73
74 AT_CHECK([mkdir lib1 lib2 prog])
75
76 # Build and install package 1.
77 AT_DATA([lib1/configure.ac],
78 [[AC_INIT([lib1], [1.0])
79 AM_INIT_AUTOMAKE([foreign])
80 AC_PROG_CC
81 AC_CONFIG_SRCDIR([lib1.c])
82 LT_INIT
83 AC_OUTPUT(Makefile)
84 ]])
85
86 AT_DATA([lib1/Makefile.am],
87 [[lib_LTLIBRARIES = lib1.la
88 lib1_la_SOURCES = lib1.c
89 lib1_la_LDFLAGS = -rpath $(libdir)
90 ]])
91
92 AT_DATA([lib1/lib1.c],
93 [[#include <string.h>
94 #include <stdlib.h>
95 char *f(const char *s)
96 {
97   return strdup (s);
98 }
99 ]])
100
101 cd lib1
102 LT_AT_BOOTSTRAP([], [-I $abs_top_srcdir/libltdl/m4], [ignore],
103                 [--add-missing], [], [], [all])
104
105 AT_CHECK([$MAKE install DESTDIR=$sysroot], [0], [ignore], [ignore])
106 AT_CHECK([test -f "$sysroot/$prefix/lib/lib1.la"])
107 AT_CHECK([grep -F "$sysroot" "$sysroot/$prefix/lib/lib1.la"], [1])
108 cd ..
109
110 # Build and install package 2.
111 AT_DATA([lib2/configure.ac],
112 [[AC_INIT([lib2], [1.0])
113 AM_INIT_AUTOMAKE([foreign])
114 AC_PROG_CC
115 AC_CONFIG_SRCDIR([lib2.c])
116 LT_INIT
117 sysroot=$with_sysroot
118 AC_SUBST([sysroot])
119 AC_OUTPUT(Makefile)
120 ]])
121
122 AT_DATA([lib2/Makefile.am],
123 [[lib_LTLIBRARIES = lib2.la
124 lib2_la_SOURCES = lib2.c
125 lib2_la_LDFLAGS = -rpath $(libdir)
126 lib2_la_LIBADD = $2]1[$3
127 ]])
128
129 AT_DATA([lib2/lib2.c],
130 [[#include <stdio.h>
131 #include <string.h>
132 #include <stdlib.h>
133 extern char *f(const char *s);
134 char *g(const char *s)
135 {
136   char *q = f(s);
137   puts (q);
138   return q;
139 }
140 ]])
141
142 cd lib2
143 LT_AT_BOOTSTRAP([], [-I $abs_top_srcdir/libltdl/m4], [ignore],
144                 [--add-missing], [], [], [all])
145
146 AT_CHECK([$MAKE install DESTDIR=$sysroot], [0], [ignore], [ignore])
147 AT_CHECK([test -f $sysroot/$prefix/lib/lib2.la])
148 AT_CHECK([grep -F "$sysroot" "$sysroot/$prefix/lib/lib2.la"], [1])
149 cd ..
150
151 # Build and install a program.
152 AT_DATA([prog/configure.ac],
153 [[AC_INIT([prog], [1.0])
154 AM_INIT_AUTOMAKE([foreign])
155 AC_PROG_CC
156 AC_CONFIG_SRCDIR([prog.c])
157 LT_INIT
158 sysroot=$with_sysroot
159 AC_SUBST([sysroot])
160 AC_OUTPUT(Makefile)
161 ]])
162
163 AT_DATA([prog/Makefile.am],
164 [[bin_PROGRAMS = prog
165 prog_SOURCES = prog.c
166 prog_LDADD = $2]2[$3
167 ]])
168
169 AT_DATA([prog/prog.c],
170 [[#include <stdio.h>
171 #include <string.h>
172 #include <stdlib.h>
173 extern char *g(const char *s);
174 int main()
175 {
176   char *q = g("hello world");
177   free (q);
178   return 0;
179 }
180 ]])
181
182 cd prog
183 LT_AT_BOOTSTRAP([], [-I $abs_top_srcdir/libltdl/m4], [ignore],
184                 [--add-missing], [], [], [all])
185
186 AT_CHECK([$MAKE install DESTDIR=$sysroot], [0], [ignore], [ignore])
187 AT_CHECK([test -f $sysroot/$prefix/bin/prog$EXEEXT])
188 AT_CHECK([grep -F "$sysroot" "$sysroot/$prefix/bin/prog$EXEEXT"], [1])
189 AT_CHECK([grep "'.*=" $sysroot/$prefix/lib/lib2.la], [0], [ignore])
190 AT_CHECK([./libtool --mode=finish $sysroot/$prefix/lib/lib@<:@12@:>@.la], [0], [ignore])
191 AT_CHECK([grep "'.*=" $sysroot/$prefix/lib/lib@<:@12@:>@.la], [1])
192
193 # missing tests
194 # 1) pass absolute .la files
195 # 2) pass absolute -L
196 # 2) pass relative .la files
197
198 cd ..
199 AT_CLEANUP
200 ])
201
202 AT_BANNER([sysroot tests])
203 SYSROOT_TEST([-L=.../lib -l],         [-L=$(libdir) -l], [])
204 SYSROOT_TEST([-L SYSROOT/.../lib -l], [-L$(sysroot)$(libdir) -l], [])
205 SYSROOT_TEST([SYSROOT/.../*.la],      [$(sysroot)$(libdir)/lib], [.la])
206
207 dnl This one does not make sense.
208 dnl SYSROOT_TEST([=.../*.la],         [=$(libdir)/lib], [.la])