1 # lt_dlexit.at -- test libltdl functionality -*- Autotest -*-
3 # Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
4 # Written by Dave Brolley & Ralf Wildenhues, 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 # Try to keep the new interfaces of HEAD separate from those of
26 # branch-1-5 to facilitate testing of older releases.
28 AT_BANNER([Libltdl functionality.])
30 AT_SETUP([lt_dlexit unloading libs])
31 AT_KEYWORDS([libltdl])
34 # http://lists.gnu.org/archive/html/bug-libtool/2007-01/msg00014.html
35 # http://lists.gnu.org/archive/html/bug-libtool/2008-03/msg00013.html
42 typedef int (*pfun_T) (int);
45 /* lt_dlopen wrapper */
47 xdlopen (const char *filename)
49 lt_dlhandle handle = lt_dlopen (filename);
51 fprintf (stderr, "can't open the module %s!\n", filename);
52 fprintf (stderr, "error was: %s\n", lt_dlerror());
57 /* lt_dlsym wrapper: try one function and one variable */
59 xdlsymtest (lt_dlhandle handle, const char *func, const char *var)
61 pfun_T pf = (pfun_T) lt_dlsym (handle, func);
62 pvar_T pv = (pvar_T) lt_dlsym (handle, var);
64 fprintf (stderr, "function `%s' not found\n", func);
68 fprintf (stderr, "variable `%s' not found\n", var);
79 LTDL_SET_PRELOADED_SYMBOLS();
80 if (lt_dlinit() != 0) {
81 fprintf (stderr, "error during initialization: %s\n", lt_dlerror());
84 if (lt_dlexit() != 0) {
85 fprintf (stderr, "error during first lt_dlexit: %s\n", lt_dlerror());
88 if (lt_dlinit() != 0) {
89 fprintf (stderr, "error during second initialization: %s\n", lt_dlerror());
92 if (!(b1 = xdlopen ("modb1.la"))) return 1;
93 if (xdlsymtest (b1, "fb1", "vb1")) return 1;
94 /* do not lt_dlclose here on purpose. */
96 if (lt_dlexit() != 0) {
97 fprintf (stderr, "error during exit: %s\n", lt_dlerror());
109 int f1 (int x) { return x - 1; }
120 #if defined DLL_EXPORT && defined _WIN32 && defined _MSC_VER
121 # define LIBA1_SCOPE extern __declspec (dllimport)
123 #if !defined LIBA1_SCOPE
124 # define LIBA1_SCOPE extern
126 LIBA1_SCOPE int f1 (int);
128 int fb1 (int x) { return f1 (v1) + x - 3; }
136 : ${LTDLINCL="-I$abs_top_srcdir/libltdl"}
137 : ${LIBLTDL="$abs_builddir/../libltdl/libltdlc.la"}
139 # Skip this test when called from:
140 # make distcheck DISTCHECK_CONFIGURE_FLAGS=--disable-ltdl-install
141 AT_CHECK([case $LIBLTDL in #(
142 */_inst/lib/*) test -f $LIBLTDL || (exit 77) ;;
145 CPPFLAGS="$LTDLINCL $CPPFLAGS"
146 LDFLAGS="$LDFLAGS -no-undefined"
148 for file in a1 b1; do
149 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c $file.c
151 $CC $CPPFLAGS $CFLAGS -c main.c
152 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba1.la a1.lo \
153 -rpath /foo -avoid-version], [], [ignore], [ignore])
154 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o modb1.la b1.lo \
155 -rpath /foo -module -avoid-version liba1.la], [], [ignore], [ignore])
157 # TODO: test -dlpreopen
158 for dlopen in -dlopen; do
159 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT \
160 $dlopen modb1.la $LIBLTDL], [], [ignore], [ignore])
161 LT_AT_NOINST_EXEC_CHECK([./main], [-dlopen modb1.la])