[sane-devel] Re: Darwin/MacOSX
Peter O'Gorman
peter at pogma.com
Sun Dec 1 11:00:59 GMT 2002
On Saturday, November 30, 2002, at 11:53 PM, Karl Heinz Kremer wrote:
> Here is all the information you need to get the latest version from
> CVS:
>
> http://www.student.uit.no/~pere/linux/sane/cvs-server.html
>
Thanks, here is my diff, do with it what you will :-). There is still
the libtool archive_cmds issue, I got around it for my test just now by
patching the generated libtool script, it may be easier to recommend
using gcc-2.95 (asking users to type 'sudo gcc_select 2') but I haven't
tried it with gcc2.
Again, this is inlined and attached:
Index: configure.in
===================================================================
RCS file: /cvsroot/external/sane/sane-backends/configure.in,v
retrieving revision 1.87
diff -u -r1.87 configure.in
--- configure.in 2002/11/29 18:19:45 1.87
+++ configure.in 2002/12/01 10:47:35
@@ -206,6 +206,7 @@
SANE_V4L_VERSION
dnl Checks for dll libraries: dl
+DARWINLTMODULEFLAG=""
if test "${enable_dynamic}" != "no"; then
AC_CHECK_HEADERS(dlfcn.h,
[AC_CHECK_LIB(dl,dlopen, DL_LIB=-ldl)
@@ -223,8 +224,16 @@
AC_CHECK_FUNCS(shl_load, enable_dynamic=yes,)
LIBS="${saved_LIBS}"
],)
+
+ #Mac OS X/Darwin
+ AC_CHECK_HEADERS(mach-o/dyld.h,
+ [AC_CHECK_FUNCS(NSLinkModule, enable_dynamic=yes,)
+ DARWINLTMODULEFLAG="-module"
+ DL_LIB=""
+ ],)
fi
AC_SUBST(DL_LIB)
+AC_SUBST(DARWINLTMODULEFLAG)
dnl Checks for Backend libraries.
AC_CHECK_LIB(m,sqrt)
@@ -373,8 +382,17 @@
AC_SUBST(NET)
AC_SUBST(SANED)
if test "${HAVE_LIBUSB}" = "yes" ; then
- echo "enabling SM3600 backend"
- SM3600=sm3600
+ case "${host_os}" in
+ darwin*)
+dnl This causes segfaults for me
+ echo "disabling SM3600 backend for darwin"
+ SM3600=
+ ;;
+ *)
+ echo "enabling SM3600 backend"
+ SM3600=sm3600
+ ;;
+ esac
else
echo "disabling SM3600 backend"
SM3600=
Index: backend/Makefile.in
===================================================================
RCS file: /cvsroot/external/sane/sane-backends/backend/Makefile.in,v
retrieving revision 1.64
diff -u -r1.64 Makefile.in
--- Makefile.in 2002/11/25 20:38:20 1.64
+++ Makefile.in 2002/12/01 10:47:36
@@ -32,7 +32,7 @@
DLL_PRELOAD = @DLL_PRELOAD@
DLL_PRELOAD_EXTRAS = $(foreach be,$(DLL_PRELOAD),$($(addprefix
EXTRA_,$(be))))\
@DJPEG@
-
+DARWINLTMODULEFLAG = @DARWINLTMODULEFLAG@
MKDIR = $(top_srcdir)/mkinstalldirs
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
@@ -148,7 +148,7 @@
libsane-%.la: %.lo %-s.lo $(EXTRA) $(LIBOBJS)
@$(LIBTOOL) $(MLINK) $(CC) -export-dynamic -o $@ $($*_LIBS) \
$(LDFLAGS) $(BACKENDLIBS) $^ -rpath $(libsanedir) \
- -version-info $(V_MAJOR):$(V_REV):$(V_MINOR)
+ -version-info $(V_MAJOR):$(V_REV):$(V_MINOR) $(DARWINLTMODULEFLAG)
%-s.lo: %-s.c
@$(LIBTOOL) $(MCOMP) $(COMPILE) -DSTUBS -DBACKEND_NAME=$* $<
Index: backend/dll.c
===================================================================
RCS file: /cvsroot/external/sane/sane-backends/backend/dll.c,v
retrieving revision 1.15
diff -u -r1.15 dll.c
--- dll.c 2002/11/29 18:19:49 1.15
+++ dll.c 2002/12/01 10:47:36
@@ -81,6 +81,12 @@
# define HAVE_DLL
#endif
+/* Mac OS X/Darwin support */
+#if defined (HAVE_NSLINKMODULE) && defined(HAVE_MACH_O_DYLD_H)
+# include <mach-o/dyld.h>
+# define HAVE_DLL
+#endif
+
#include <sys/types.h>
#include "sane/sane.h"
@@ -93,6 +99,8 @@
# define PATH_MAX 1024
#endif
+
+
#include "sane/sanei_config.h"
#define DLL_CONFIG_FILE "dll.conf"
#define DLL_ALIASES_FILE "dll.aliases"
@@ -250,6 +258,20 @@
*bep = be;
return SANE_STATUS_GOOD;
}
+#if defined(HAVE_NSLINKMODULE)
+
+static const char *dyld_get_error_str();
+static const char *dyld_get_error_str()
+{
+ NSLinkEditErrors c;
+ int errorNumber;
+ const char *fileName;
+ const char *errorString;
+ NSLinkEditError(&c,&errorNumber,&fileName,&errorString);
+ return errorString;
+}
+#endif
+
static SANE_Status
load (struct backend *be)
@@ -274,6 +296,11 @@
# define PREFIX "libsane-"
# define POSTFIX ".sl.%u"
mode = BIND_DEFERRED;
+#elif defined(HAVE_NSLINKMODULE)
+# define PREFIX "libsane-"
+# define POSTFIX ".%u.so"
+ mode = NSLINKMODULE_OPTION_RETURN_ON_ERROR +
+ NSLINKMODULE_OPTION_PRIVATE;
#else
# error "Tried to compile unsupported DLL."
#endif /* HAVE_DLOPEN */
@@ -344,6 +371,15 @@
be->handle = dlopen (libname, mode);
#elif defined(HAVE_SHL_LOAD)
be->handle = (shl_t)shl_load (libname, mode, 0L);
+#elif defined(HAVE_NSLINKMODULE)
+ {
+ NSObjectFileImage objectfile_img=NULL;
+ if ( NSCreateObjectFileImageFromFile( libname, &objectfile_img )
== NSObjectFileImageSuccess)
+ {
+ be->handle = NSLinkModule( objectfile_img, libname, mode );
+ NSDestroyObjectFileImage( objectfile_img );
+ }
+ }
#else
# error "Tried to compile unsupported DLL."
#endif /* HAVE_DLOPEN */
@@ -351,6 +387,8 @@
{
#ifdef HAVE_DLOPEN
DBG(1, "load: dlopen() failed (%s)\n", dlerror());
+#elif defined(HAVE_NSLINKMODULE)
+ DBG(1, "load: dyld error (%s)\n", dyld_get_error_str());
#else
DBG(1, "load: dlopen() failed (%s)\n", strerror (errno));
#endif
@@ -370,6 +408,18 @@
op = (void *(*)(void)) dlsym (be->handle, funcname + 1);
#elif defined(HAVE_SHL_LOAD)
shl_findsym ((shl_t*)&(be->handle), funcname + 1,
TYPE_UNDEFINED, &op);
+#elif defined(HAVE_NSLINKMODULE)
+ {
+ NSSymbol *nssym=NSLookupSymbolInModule( be->handle, funcname )
;
+ if (!nssym)
+ {
+ DBG(15, "dyld error: %s\n", dyld_get_error_str());
+ }
+ else
+ {
+ op = (void *(*)(void))NSAddressOfSymbol( nssym );
+ }
+ }
#else
# error "Tried to compile unsupported DLL."
#endif /* HAVE_DLOPEN */
@@ -382,6 +432,18 @@
op = (void *(*)(void)) dlsym (be->handle, funcname);
#elif defined(HAVE_SHL_LOAD)
shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
+#elif defined(HAVE_NSLINKMODULE)
+ {
+ NSSymbol *nssym=NSLookupSymbolInModule( be->handle, funcname )
;
+ if (!nssym)
+ {
+ DBG(15, "dyld error: %s\n", dyld_get_error_str());
+ }
+ else
+ {
+ op = (void *(*)(void))NSAddressOfSymbol( nssym );
+ }
+ }
#else
# error "Tried to compile unsupported DLL."
#endif /* HAVE_DLOPEN */
@@ -619,6 +681,14 @@
#elif defined(HAVE_SHL_LOAD)
if (be->handle)
shl_unload(be->handle);
+#elif defined(HAVE_NSLINKMODULE)
+ if (be->handle)
+ NSUnLinkModule(be->handle,
+ NSUNLINKMODULE_OPTION_NONE
+# ifdef __ppc__
+ | NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES
+# endif
+ );
#else
# error "Tried to compile unsupported DLL."
#endif /* HAVE_DLOPEN */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nsmodule.diff.gz
Type: application/x-gzip
Size: 2174 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20021201/534cd038/attachment.bin>
-------------- next part --------------
More information about the sane-devel
mailing list