1 # need-lib-prefix.at -- test libltdl functionality -*- Autotest -*-
3 # Copyright (C) 2007, 2008 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])
32 typedef int fun (int);
34 static int errors = 0;
37 complain (const char *msg)
39 const char *errmsg = lt_dlerror ();
40 fprintf (stderr, "%s", msg);
42 fprintf (stderr, ": %s\n", errmsg);
44 fprintf (stderr, ".\n");
49 moduleopen (const char *filename)
53 handle = lt_dlopen (filename);
56 fprintf (stderr, "can't open the module %s!\n", filename);
57 complain ("error was");
64 moduletest (lt_dlhandle handle)
66 const lt_dlinfo *info = lt_dlgetinfo (handle);
67 fun *f = (fun *) lt_dlsym (handle, "f");
68 int *v = (int *) lt_dlsym (handle, "i");
72 complain ("function `f' not found");
77 complain ("variable `i' not found");
80 printf ("%s: %d\n", info->name, f (*v));
86 main (int argc, char **argv)
90 LTDL_SET_PRELOADED_SYMBOLS();
94 fprintf (stderr, "error during initialization: %s\n", lt_dlerror());
98 if (lt_dlpreload_open (0, moduletest) != 0)
99 complain ("error during preloading");
101 if (lt_dlexit () != 0)
102 complain ("error during exit");
104 return (errors != 0);
109 [[#define f foo1_LTX_f
114 int f (int x) { return x / 3; }
122 [[#define f libfoo2_LTX_f
123 #define i libfoo2_LTX_i
127 int f (int x) { return (x * x) / 10; }
134 LT_AT_HOST_DATA([expout],
139 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
140 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
142 # Skip this test when called from:
143 # make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
144 AT_CHECK([case $LIBLTDL in #(
145 */_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
148 CPPFLAGS="$LTDLINCL $CPPFLAGS"
151 # Create our own libtool, forcing need_lib_prefix setting
152 sed 's,^\(need_lib_prefix\)=.*$,\1=unknown,' $LIBTOOL > ./libtool
153 LIBTOOL="$SHELL ./libtool"
155 # Installation directory:
158 $CC $CPPFLAGS $CFLAGS -c main.c
159 for file in foo1 foo2; do
160 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file.c
163 AT_CHECK([$LIBTOOL --mode=link $CC -module -avoid-version $CFLAGS $LDFLAGS -o foo1.la foo1.lo -rpath $instdir/lib],
164 [], [ignore], [ignore])
165 AT_CHECK([$LIBTOOL --mode=link $CC -module -avoid-version $CFLAGS $LDFLAGS -o libfoo2.la foo2.lo -rpath $instdir/lib],
166 [], [ignore], [ignore])
167 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT -dlpreopen foo1.la -dlpreopen libfoo2.la $LIBLTDL],
168 [], [ignore], [ignore])
170 LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen foo1.la -dlopen libfoo2.la],
173 # Install the libraries.
176 $LIBTOOL --mode=install cp foo1.la $instdir/lib/foo1.la
177 $LIBTOOL --mode=install cp libfoo2.la $instdir/lib/libfoo2.la
181 $LIBTOOL --mode=install cp main$EXEEXT $instdir/bin/main$EXEEXT
183 LT_AT_EXEC_CHECK([$instdir/bin/main], [], [expout], [])