1 # need-lib-prefix.at -- test libltdl functionality -*- Autotest -*-
3 # Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
4 # Written by Gary V. Vaughan, 2007
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.
25 AT_SETUP([enforced lib prefix])
26 AT_KEYWORDS([libltdl libtool])
28 # Originally written to simulate a failure visible on systems
29 # which need a library prefix like 'lib', such as BeOS. Currently
30 # the prefix is hardcoded as 'lib', so systems that require a
31 # different prefix skips the test.
37 typedef int fun (int);
39 static int errors = 0;
42 complain (const char *msg)
44 const char *errmsg = lt_dlerror ();
45 fprintf (stderr, "%s", msg);
47 fprintf (stderr, ": %s\n", errmsg);
49 fprintf (stderr, ".\n");
54 moduleopen (const char *filename)
58 handle = lt_dlopen (filename);
61 fprintf (stderr, "can't open the module %s!\n", filename);
62 complain ("error was");
69 moduletest (lt_dlhandle handle)
71 const lt_dlinfo *info = lt_dlgetinfo (handle);
72 fun *f = (fun *) lt_dlsym (handle, "f");
73 int *v = (int *) lt_dlsym (handle, "i");
77 complain ("function `f' not found");
82 complain ("variable `i' not found");
85 printf ("%s: %d\n", info->name, f (*v));
91 main (int argc, char **argv)
95 LTDL_SET_PRELOADED_SYMBOLS();
99 fprintf (stderr, "error during initialization: %s\n", lt_dlerror());
103 if (lt_dlpreload_open (0, moduletest) != 0)
104 complain ("error during preloading");
106 if (lt_dlexit () != 0)
107 complain ("error during exit");
109 return (errors != 0);
114 [[#define f foo1_LTX_f
119 int f (int x) { return x / 3; }
127 [[#define f libfoo2_LTX_f
128 #define i libfoo2_LTX_i
132 int f (int x) { return (x * x) / 10; }
139 LT_AT_HOST_DATA([expout],
144 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
145 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
147 # Skip this test when called from:
148 # make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
149 AT_CHECK([case $LIBLTDL in #(
150 */_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
153 CPPFLAGS="$LTDLINCL $CPPFLAGS"
156 # Skip this test when libraries are not normally prefixed with lib.
157 # E.g., for MSVC and OS/2.
158 eval "`$LIBTOOL --config | $EGREP '^(libname_spec)='`"
160 eval libname=\"$libname_spec\"
161 AT_CHECK([test "$libname" = lib || exit 77])
163 # Create our own libtool, forcing need_lib_prefix setting
164 sed 's,^\(need_lib_prefix\)=.*$,\1=unknown,' $LIBTOOL > ./libtool
165 LIBTOOL="$SHELL ./libtool"
167 # Installation directory:
170 $CC $CPPFLAGS $CFLAGS -c main.c
171 for file in foo1 foo2; do
172 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file.c
175 AT_CHECK([$LIBTOOL --mode=link $CC -module -avoid-version $CFLAGS $LDFLAGS -o foo1.la foo1.lo -rpath $instdir/lib],
176 [], [ignore], [ignore])
177 AT_CHECK([$LIBTOOL --mode=link $CC -module -avoid-version $CFLAGS $LDFLAGS -o libfoo2.la foo2.lo -rpath $instdir/lib],
178 [], [ignore], [ignore])
179 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT -dlpreopen foo1.la -dlpreopen libfoo2.la $LIBLTDL],
180 [], [ignore], [ignore])
182 LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen foo1.la -dlopen libfoo2.la],
185 # Install the libraries.
188 $LIBTOOL --mode=install cp foo1.la $instdir/lib/foo1.la
189 $LIBTOOL --mode=install cp libfoo2.la $instdir/lib/libfoo2.la
193 $LIBTOOL --mode=install cp main$EXEEXT $instdir/bin/main$EXEEXT
195 LT_AT_EXEC_CHECK([$instdir/bin/main], [], [expout], [])