Here is a patch to the dll backend to use libtool ltdl instead of
native DLL methods. To test it, fetch the latest libtool distribution
(or v1.3.3 which I used for testing), copy libltdl/ into the sane
directory, applyl this patch and compile.
Please let me know which platforms you test this patch on.
Index: configure.in
===================================================================
RCS file: /cvsroot/external/sane/configure.in,v
retrieving revision 1.1.1.1.2.6
diff -u -r1.1.1.1.2.6 configure.in
--- configure.in 2000/01/05 01:05:52 1.1.1.1.2.6
+++ configure.in 2000/01/18 01:29:29
@@ -91,8 +91,23 @@
cfmakeraw tcsendbreak usleep strcasecmp strncasecmp _portaccess)
dnl initialize libtool
+dnl From Libtool v1.3.3 documentation, with addition of
+dnl AC_LIBTOOL_WIN32_DLL
+dnl
+
+dnl Enable building of the convenience library
+dnl and set LIBLTDL accordingly
+AC_LIBLTDL_CONVENIENCE
+dnl Substitute INCLTDL and LIBLTDL in the Makefiles
+AC_SUBST(INCLTDL)
+AC_SUBST(LIBLTDL)
+dnl Check for dlopen support
+AC_LIBTOOL_DLOPEN
+dnl Configure libtool
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
+dnl Configure libltdl
+AC_CONFIG_SUBDIRS(libltdl)
dnl Checks for libraries.
Index: backend/Makefile.in
===================================================================
RCS file: /cvsroot/external/sane/backend/Makefile.in,v
retrieving revision 1.1.1.1.2.1
diff -u -r1.1.1.1.2.1 Makefile.in
--- Makefile.in 1999/09/12 21:54:13 1.1.1.1.2.1
+++ Makefile.in 2000/01/18 01:29:29
@@ -36,10 +36,11 @@
LN_S = @LN_S@
CC = @CC@
-INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include
+INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/include \
+ -I$(top_srcdir)/libltdl
CPPFLAGS = @CPPFLAGS@
-CFLAGS = @CFLAGS@
-LDFLAGS = @LDFLAGS@
+CFLAGS = @CFLAGS@ @INCLTDL@
+LDFLAGS = @LDFLAGS@ @LIBLTDL@
DEFS = @DEFS@
LIBTOOL = ../libtool
@@ -66,7 +68,7 @@
LIBOBJS = $(addprefix ../lib/,$(addsuffix .lo,$(LIBLIB_FUNCS)))
libsane-%.la: %.lo %-s.lo $(EXTRA) $(LIBOBJS)
- @$(LIBTOOL) $(MLINK) $(CC) -export-dynamic -o $@ $($*_LIBS) \
+ @$(LIBTOOL) $(MLINK) $(CC) -export-dynamic -module -o $@ $($*_LIBS) \
$(LDFLAGS) $^ -rpath $(libsanedir) \
-version-info $(V_MAJOR):$(V_REV):$(V_MINOR)
@@ -124,28 +126,9 @@
fi; \
done
-dll.lo: dll-preload.c
-
-dll-preload.c:
- rm -f $@
- list="$(DLL_PRELOAD)"; for be in $$list; do \
- echo "PRELOAD_DECL($$be)" >> $@; \
- done
- echo "static struct backend preloaded_backends[] = {" >> $@
- sep=""; \
- list="$(DLL_PRELOAD)"; \
- if test -z "$${list}"; then \
- echo { 0 } >> $@; \
- else \
- for be in $$list; do \
- echo "$${sep}PRELOAD_DEFN($$be)" >> $@; \
- sep=","; \
- done; \
- fi
- echo "};" >> $@
-
libsane.la: dll.lo dll-s.lo $(EXTRA) $(addsuffix .lo,$(DLL_PRELOAD)) $(LIBOBJS)
@$(LIBTOOL) $(MLINK) $(CC) -o $@ $(LDFLAGS) $^ \
+ -module -dlopen libsane-net.la \
$(addsuffix .lo,$(DLL_PRELOAD_EXTRAS)) \
-rpath $(libdir) -version-info $(V_MAJOR):$(V_REV):$(V_MINOR)
Index: backend/dll.c
===================================================================
RCS file: /cvsroot/external/sane/backend/dll.c,v
retrieving revision 1.1.1.1.2.1
diff -u -r1.1.1.1.2.1 dll.c
--- dll.c 1999/08/12 09:53:03 1.1.1.1.2.1
+++ dll.c 2000/01/18 01:29:31
@@ -55,28 +55,8 @@
#include <stdlib.h>
#include <string.h>
-#if defined(HAVE_DLOPEN) && defined(HAVE_DLFCN_H)
-# include <dlfcn.h>
+#include <ltdl.h>
- /* Older versions of dlopen() don't define RTLD_NOW and RTLD_LAZY.
- They all seem to use a mode of 1 to indicate RTLD_NOW and some do
- not support RTLD_LAZY at all. Hence, unless defined, we define
- both macros as 1 to play it safe. */
-# ifndef RTLD_NOW
-# define RTLD_NOW 1
-# endif
-# ifndef RTLD_LAZY
-# define RTLD_LAZY 1
-# endif
-# define HAVE_DLL
-#endif
-
-/* HP/UX DLL support */
-#if defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
-# include <dl.h>
-# define HAVE_DLL
-#endif
-
#include <sys/types.h>
#include <sane/sane.h>
@@ -114,56 +94,12 @@
{
struct backend *next;
const char *name;
- u_int permanent : 1; /* is the backend preloaded? */
u_int loaded : 1; /* are the functions available? */
u_int inited : 1; /* has the backend been initialized? */
void *handle; /* handle returned by dlopen() */
void *(*op[NUM_OPS]) ();
};
-#define BE_ENTRY(be,func) sane_##be##_##func
-
-#define PRELOAD_DECL(name) \
- extern void *BE_ENTRY(name,init) (); \
- extern void *BE_ENTRY(name,exit) (); \
- extern void *BE_ENTRY(name,get_devices) (); \
- extern void *BE_ENTRY(name,open) (); \
- extern void *BE_ENTRY(name,close) (); \
- extern void *BE_ENTRY(name,get_option_descriptor) (); \
- extern void *BE_ENTRY(name,control_option) (); \
- extern void *BE_ENTRY(name,get_parameters) (); \
- extern void *BE_ENTRY(name,start) (); \
- extern void *BE_ENTRY(name,read) (); \
- extern void *BE_ENTRY(name,cancel) (); \
- extern void *BE_ENTRY(name,set_io_mode) (); \
- extern void *BE_ENTRY(name,get_select_fd) ();
-
-#define PRELOAD_DEFN(name) \
-{ \
- 0 /* next */, #name, \
- 1 /* permanent */, \
- 1 /* loaded */, \
- 0 /* inited */, \
- 0 /* handle */, \
- { \
- BE_ENTRY(name,init), \
- BE_ENTRY(name,exit), \
- BE_ENTRY(name,get_devices), \
- BE_ENTRY(name,open), \
- BE_ENTRY(name,close), \
- BE_ENTRY(name,get_option_descriptor), \
- BE_ENTRY(name,control_option), \
- BE_ENTRY(name,get_parameters), \
- BE_ENTRY(name,start), \
- BE_ENTRY(name,read), \
- BE_ENTRY(name,cancel), \
- BE_ENTRY(name,set_io_mode), \
- BE_ENTRY(name,get_select_fd) \
- } \
-}
-
-#include "dll-preload.c"
-
struct meta_scanner
{
struct backend *be;
@@ -224,28 +160,19 @@
*bep = be;
return SANE_STATUS_GOOD;
}
+/* Generate the dll name to load. */
+static void
+map_dll_filename(char *buf, int bufsize, char *backendname)
+{
+ snprintf(buf, bufsize, "libsane-%s", backendname);
+}
static SANE_Status
load (struct backend *be)
{
-#ifdef HAVE_DLL
- int mode = 0;
- char *funcname, *src, *dir, *path = 0;
+ char *funcname;
char libname[PATH_MAX];
int i;
- FILE *fp = 0;
-
-#if defined(HAVE_DLOPEN)
-# define PREFIX "libsane-"
-# define POSTFIX ".so.%u"
- mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
-#elif defined(HAVE_SHL_LOAD)
-# define PREFIX "libsane-"
-# define POSTFIX ".sl.%u"
- mode = BIND_DEFERRED;
-#else
-# error "Tried to compile unsupported DLL."
-#endif /* HAVE_DLOPEN */
DBG(1, "loading backend %s\n", be->name);
@@ -256,56 +183,15 @@
for (i = 0; i < NUM_OPS; ++i)
be->op[i] = op_unsupported;
- dir = STRINGIFY(LIBDIR);
- while (dir)
- {
- snprintf (libname, sizeof (libname), "%s/"PREFIX"%s"POSTFIX,
- dir, be->name, V_MAJOR);
- fp = fopen (libname, "r");
- if (fp)
- break;
-
- if (!path)
- {
- path = getenv ("LD_LIBRARY_PATH");
- if (!path)
- {
- path = getenv ("SHLIB_PATH"); /* for HP-UX */
- if (!path)
- path = getenv ("LIBPATH"); /* for AIX */
- }
- if (!path)
- break;
+ map_dll_filename(libname, sizeof(libname), be->name);
- path = strdup (path);
- src = path;
- }
- dir = strsep (&src, ":");
- }
- if (path)
- free (path);
- if (!fp)
- {
- DBG(2, "load: couldn't find %s (%s)\n",
- libname, strerror (errno));
- return SANE_STATUS_INVAL;
- }
DBG(2, "dlopen()ing `%s'\n", libname);
-#ifdef HAVE_DLOPEN
- be->handle = dlopen (libname, mode);
-#elif defined(HAVE_SHL_LOAD)
- be->handle = (shl_t)shl_load (libname, mode, 0L);
-#else
-# error "Tried to compile unsupported DLL."
-#endif /* HAVE_DLOPEN */
+ be->handle = lt_dlopenext(libname);
+
if (!be->handle)
{
-#ifdef HAVE_DLOPEN
- DBG(2, "dlopen() failed (%s)\n", dlerror());
-#else
- DBG(2, "dlopen() failed (%s)\n", strerror (errno));
-#endif
+ DBG(2, "dlopen() failed (%s)\n", lt_dlerror());
return SANE_STATUS_INVAL;
}
@@ -314,45 +200,15 @@
for (i = 0; i < NUM_OPS; ++i)
{
void *(*op) ();
-
- sprintf (funcname, "_sane_%s_%s", be->name, op_name[i]);
-
- /* First try looking up the symbol without a leading underscore. */
-#ifdef HAVE_DLOPEN
- op = (void *(*)()) dlsym (be->handle, funcname + 1);
-#elif defined(HAVE_SHL_LOAD)
- shl_findsym ((shl_t*)&(be->handle), funcname + 1, TYPE_UNDEFINED, &op);
-#else
-# error "Tried to compile unsupported DLL."
-#endif /* HAVE_DLOPEN */
+ sprintf (funcname, "sane_%s_%s", be->name, op_name[i]);
+ op = lt_dlsym(be->handle, funcname);
if (op)
be->op[i] = op;
else
- {
- /* Try again, with an underscore prepended. */
-#ifdef HAVE_DLOPEN
- op = (void *(*)()) dlsym (be->handle, funcname);
-#elif defined(HAVE_SHL_LOAD)
- shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
-#else
-# error "Tried to compile unsupported DLL."
-#endif /* HAVE_DLOPEN */
- if (op)
- be->op[i] = op;
- }
- if (NULL == op)
DBG(2, "unable to find %s\n", funcname);
}
return SANE_STATUS_GOOD;
-
-# undef PREFIX
-# undef POSTFIX
-#else /* HAVE_DLL */
- DBG(1, "load: ignoring attempt to load `%s'; compiled without dl support\n",
- be->name);
- return SANE_STATUS_UNSUPPORTED;
-#endif /* HAVE_DLL */
}
static SANE_Status
@@ -388,24 +244,20 @@
char backend_name[PATH_MAX];
size_t len;
FILE *fp;
- int i;
DBG_INIT();
auth_callback = authorize;
- /* chain preloaded backends together: */
- for (i = 0; i < NELEMS(preloaded_backends); ++i)
- {
- if (!preloaded_backends[i].name)
- continue;
- preloaded_backends[i].next = first_backend;
- first_backend = &preloaded_backends[i];
- }
-
if (version_code)
*version_code = SANE_VERSION_CODE (V_MAJOR, V_MINOR, 0);
+ lt_dlinit();
+ lt_dladdsearchdir(STRINGIFY(LIBDIR));
+
+ DBG(1, "entering (added %s)\n result path %s\n", STRINGIFY(LIBDIR),
+ lt_dlgetsearchpath());
+
fp = sanei_config_open (DLL_CONFIG_FILE);
if (!fp)
return SANE_STATUS_GOOD; /* don't insist on config file */
@@ -442,28 +294,15 @@
{
DBG(2, "calling backend `%s's exit function\n", be->name);
(*be->op[OP_EXIT]) ();
-#ifdef HAVE_DLL
-
-#ifdef HAVE_DLOPEN
- if (be->handle)
- dlclose (be->handle);
-#elif defined(HAVE_SHL_LOAD)
if (be->handle)
- shl_unload(be->handle);
-#else
-# error "Tried to compile unsupported DLL."
-#endif /* HAVE_DLOPEN */
-
-#endif /* HAVE_DLL */
- }
- if (!be->permanent)
- {
- if (be->name)
- free ((void *) be->name);
- free (be);
+ {
+ lt_dlclose(be->handle);
+ be->handle = NULL;
+ }
}
}
first_backend = 0;
+ lt_dlexit();
}
/* Note that a call to get_devices() implies that we'll have to load
-- ##> Petter Reinholdtsen <## | pere@td.org.uit.no-- Source code, list archive, and docs: http://www.mostang.com/sane/ To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com
This archive was generated by hypermail 2b29 : Mon Jan 17 2000 - 17:38:12 PST