1 # bindir.at - Test the -bindir option
3 # Copyright (C) 2009, 2010 Free Software Foundation, Inc.
4 # Written by Dave Korn, 2009
6 # This file is part of GNU Libtool.
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.
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.
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.
26 # In this testcase, and in the chunk of code that makes use
27 # of $bindir in ltmain.m4sh, we would very much have liked to
28 # automatically decide which systems require dynamically-loaded
29 # libraries to be installed to a directory in $PATH according
30 # to the libtool properties that tell us that "the system provides
31 # no way to hard-code library paths into executables, and also
32 # has no $shlibpath_var independent of the PATH variable", in
33 # Ralf's words. But it turns out this is not possible, as:-
35 #> * Dave Korn wrote on Fri, Aug 14, 2009 at 04:30:27AM CEST:
36 #>>> Ralf Wildenhues wrote:
38 #>>>>> But in this particular case, I would argue that either you look at
39 #>>>>> the libtool variables shlibpath_var and hardcode_action for "PATH"
40 #>>>>> and "unsupported".
42 #>>> On Cygwin, $hardcode_action = "immediate" in the generated libtool
43 #>>> script. Did you perhaps mean $hardcode_shlibpath_var, which is indeed
46 #> Oh brother, yes, I forgot about those bogus hardcode_libdir_flag_spec
47 #> settings. They fool _LT_LINKER_HARDCODE_LIBPATH. I don't remember whether
48 #> they were needed in order to not break some semantics in ltmain (they
51 #> Anyway, $hardcode_action = "immediate" is definitely wrong, but fixing that
52 #> now is also way out of scope of this patch. So I guess we need to stick to
53 #> host matching in the code, and work out a separate fix for the setting of
54 #> $hardcode_libdir_flag_spec.
56 # So alas we punt for now, and just hardcode the relevant OSs that require
57 # this functionality. That's Cygwin, MinGW and CeGCC for now; see the case
58 # statement in libtool.m4sh around where the 'tdlname' variable is set.
61 # First a simple test that we can build and run an executable with a couple of
64 AT_SETUP([bindir basic lib test])
68 cygwin*|mingw*|cegcc*)
76 # These routines save the PATH before a test and restore it after,
77 # prepending a chosen directory to the path on the platforms where
78 # -bindir is needed after saving.
81 func_save_and_prepend_path ()
84 if $bindirneeded ; then
103 int baz (void) { return x;}
107 extern int baz (void);
110 int bar (void) { return y + baz ();}
115 extern int baz (void);
116 extern int bar (void);
118 if (baz () + bar () - 25) abort ();
125 eval "`$LIBTOOL --config | grep '^objdir='`"
127 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o foo.lo $CPPFLAGS $CFLAGS foo.c],[0],[ignore],[ignore])
128 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o baz.lo $CPPFLAGS $CFLAGS baz.c],[0],[ignore],[ignore])
129 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -no-undefined -o libfoo.la $CPPFLAGS $CFLAGS $LDFLAGS foo.lo baz.lo -rpath $curdir/$objdir],[0],[ignore],[ignore])
131 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o bar.lo $CPPFLAGS $CFLAGS bar.c],[0],[ignore],[ignore])
132 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -no-undefined -o libbar.la $CPPFLAGS $CFLAGS $LDFLAGS bar.lo libfoo.la -rpath $curdir/$objdir],[0],[ignore],[ignore])
134 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o main.lo $CPPFLAGS $CFLAGS main.c],[0],[ignore],[ignore])
135 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o main$EXEEXT $CPPFLAGS $CFLAGS $LDFLAGS main.lo libbar.la libfoo.la],[0],[ignore],[ignore])
137 # Check both static and shared versions run. We don't install them
138 # here, that will be covered by the later tests; we've rpath'd things
139 # so that they can all be run in situ.
141 LT_AT_NOINST_EXEC_CHECK([./main])
143 # Ensure libraries can be found on PATH, if we are on one
144 # of the affected platforms, before testing the shared version.
146 func_save_and_prepend_path $curdir/$objdir
148 LT_AT_NOINST_EXEC_CHECK([$objdir/main])
151 # In fact, prepending the PATH as above is superfluous on the windows
152 # platforms that this feature is primarily aimed at, as the DLL search
153 # path always includes the directory from which the app was launched.
154 # To make sure it still works even when not side-by-side, we'll install
155 # the main executable and execute it from there while the PATH still
156 # points to the shared libs in the .libs subdir. On other platforms,
157 # the rpaths we set at link time will guarantee it runs from the bindir.
160 AT_CHECK([$LIBTOOL --mode=install $lt_INSTALL main$EXEEXT $curdir/bin/main$EXEEXT], [], [ignore], [ignore])
161 LT_AT_EXEC_CHECK([$curdir/bin/main$EXEEXT], [0], [ignore], [ignore], [])
167 # This is the main testcase. For a variety of bindir and libdir
168 # settings, it verifies that all the files get installed exactly
169 # where we want them to go, and that they can be executed once
173 AT_SETUP([bindir install tests])
177 cygwin*|mingw*|cegcc*)
184 eval "`$LIBTOOL --config | grep '^build_libtool_libs='`"
185 AT_CHECK([test "$build_libtool_libs" = yes || exit 77])
188 # These routines save the PATH before a test and restore it after,
189 # prepending a chosen directory to the path on the platforms where
190 # -bindir is needed after saving.
193 func_save_and_prepend_path ()
196 if $bindirneeded ; then
215 int baz (void) { return x;}
219 extern int baz (void);
222 int bar (void) { return y + baz ();}
227 extern int baz (void);
228 extern int bar (void);
230 if (baz () + bar () - 25) abort ();
235 # We only need to compile once, but we'll need to relink for each different value
236 # of libdir in order to set the rpath, and we'll install for each combination of
239 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o foo.lo $CPPFLAGS $CFLAGS foo.c],[0],[ignore],[ignore])
240 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o baz.lo $CPPFLAGS $CFLAGS baz.c],[0],[ignore],[ignore])
241 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o bar.lo $CPPFLAGS $CFLAGS bar.c],[0],[ignore],[ignore])
242 AT_CHECK([$LIBTOOL --mode=compile --tag=CC $CC -c -o main.lo $CPPFLAGS $CFLAGS main.c],[0],[ignore],[ignore])
244 # Now try installing the libs. There are the following cases:
246 # -bindir below lib install dir
247 # -bindir is lib install dir
248 # -bindir beside lib install dir
249 # -bindir above lib dir
250 # -bindir above and beside lib dir
251 # -bindir in entirely unrelated prefix.
255 $curdir/usr/lib/gcc/i686-pc-cygwin/4.5.0 \
256 $curdir/usr/lib/gcc/../gcc/.//i686-pc-cygwin/4.5.0/../../././//. \
263 # Do a basic install with no -bindir option for reference. We use the sbin/
264 # dir for the main exe to avoid the potential "this only works because it's
265 # side-by-side with the libs" default DLL search path problem mentioned above.
266 rm -rf $libdir $curdir/bin $curdir/sbin $curdir/baz $curdir/usr
268 AS_MKDIR_P($curdir/sbin)
269 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -no-undefined -o libfoo.la $CPPFLAGS $CFLAGS $LDFLAGS foo.lo bar.lo baz.lo -rpath $libdir],[0],[ignore],[ignore])
270 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o main$EXEEXT $CPPFLAGS $CFLAGS $LDFLAGS main.lo libfoo.la -rpath $libdir],[0],[ignore],[ignore])
271 AT_CHECK([$LIBTOOL --mode=install $lt_INSTALL libfoo.la $libdir], [], [ignore], [ignore])
272 AT_CHECK([$LIBTOOL --mode=install $lt_INSTALL main$EXEEXT $curdir/sbin/main$EXEEXT], [], [ignore], [ignore])
274 # And ensure it went where we expect. Could be looking for any of
275 # 'cygfoo-0.dll', 'libfoo-0.dll', 'foo-0.dll', or 'libfoo.so.0'. We'll
276 # simplify this check by taking advantage of the fact that if it's a DLL,
277 # it has to go in bindir, so we'll not check for both forms in libdir.
278 if $bindirneeded; then
279 AT_CHECK([test -f $libdir/../bin/???foo-0.dll || ls $libdir/../bin/*foo*0*], [], [ignore], [ignore])
281 AT_CHECK([ls $libdir/*foo*], [], [ignore], [ignore])
284 # And that it can be executed.
286 $bindirneeded && extrapath=$libdir/../bin
287 func_save_and_prepend_path $extrapath
288 LT_AT_EXEC_CHECK([$curdir/sbin/main$EXEEXT], [0], [ignore], [ignore], [])
292 $curdir/usr/lib/gcc/i686-pc-cygwin/4.5.0/bin/ \
293 $curdir/usr/lib/gcc/i686-pc-cygwin/4.5.0/bin \
294 $curdir/usr/lib/gcc/i686-pc-cygwin/bin \
295 $curdir/usr/lib/bin \
301 # Clear any old stuff out before we install. Because bindir
302 # may be in /tmp, we have to take care to create it securely
303 # and not to delete and recreate it if we do.
304 rm -rf $libdir $curdir/bin $curdir/sbin $curdir/baz $curdir/usr
309 # Create a temporary directory $tmp in $TMPDIR (default /tmp).
310 # Use mktemp if possible; otherwise fall back on mkdir,
311 # with $RANDOM to make collisions less likely.
315 (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
317 test -n "$tmp" && test -d "$tmp"
319 tmp=$TMPDIR/foo$$-$RANDOM
320 (umask 077 && mkdir "$tmp")
321 } || AT_CHECK([exit 77])
325 # Clear any old stuff out before we install.
331 # Relink with new rpaths.
332 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -no-undefined -bindir $bindir -o libfoo.la $CPPFLAGS $CFLAGS $LDFLAGS foo.lo bar.lo baz.lo -rpath $libdir],[0],[ignore],[ignore])
333 AT_CHECK([$LIBTOOL --mode=link --tag=CC $CC -o main$EXEEXT $CPPFLAGS $CFLAGS $LDFLAGS main.lo libfoo.la],[0],[ignore],[ignore])
335 # Recreate directories (bindir already done) and install.
337 AS_MKDIR_P($curdir/sbin)
338 AT_CHECK([$LIBTOOL --mode=install $lt_INSTALL libfoo.la $libdir], [], [ignore], [ignore])
339 AT_CHECK([$LIBTOOL --mode=install $lt_INSTALL main$EXEEXT $curdir/sbin/main$EXEEXT], [], [ignore], [ignore])
341 # Ensure it went to bindir rather than default dir this time.
342 if $bindirneeded; then
343 AT_CHECK([test -f $bindir/???foo-0.dll || ls $bindir/*foo*0*], [], [ignore], [ignore])
345 AT_CHECK([ls $libdir/*foo*], [], [ignore], [ignore])
348 # And that it can be executed.
350 $bindirneeded && extrapath=$bindir
351 func_save_and_prepend_path $extrapath
352 LT_AT_EXEC_CHECK([$curdir/sbin/main$EXEEXT], [0], [ignore], [ignore], [])
355 # Clean up if we made a temp dir. Subdirs under our testdir get rm'd
356 # and recreated at the top of the loop. Securely created subdirs under
357 # /tmp get created precisely once and rm'd when we're done with them.
358 if test ! -z "$tmp" ; then