--- configure.in.orig	2007-03-28 12:26:34.000000000 +0100
+++ configure.in	2007-03-28 12:16:28.000000000 +0100
@@ -365,7 +365,7 @@
 dnl Find the correct poll prototype on this machine 
 AC_MSG_CHECKING(for correct poll prototype)
 PROTO=
-for testproto in 'struct pollfd *ufds, unsigned long nfds, int timeout' 
+for testproto in 'struct pollfd *ufds, nfds_t nfds, int timeout'
 do
   if test "${PROTO}" = ""; then
     AC_TRY_COMPILE([
@@ -393,8 +393,46 @@
 AC_DEFINE_UNQUOTED(GETIPNODEBYNAME_SIGNATURE, [${PROTO}])
 
 dnl Output the special librarys (libdl etc needed for tsocks)
-SPECIALLIBS=${LIBS}
+SPECIALLIBS="${LIBS} -lSystemStubs"
 AC_SUBST(SPECIALLIBS)
 LIBS=${SIMPLELIBS}
 
-AC_OUTPUT(Makefile)
+dnl Check if the linker accepts -dynamiclib; necessary on Mac OS X
+AC_MSG_CHECKING(if the linker accepts -dynamiclib)
+OLDLDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS -dynamiclib"
+AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[
+   LDFLAGS="$OLDLDFLAGS"
+   AC_MSG_RESULT(no)])
+
+dnl Check if the linker accepts -multiply_defined suppress; necessary on Mac OS X
+AC_MSG_CHECKING(if the linker accepts -multiply_defined suppress)
+OLDLDFLAGS="$LDFLAGS"
+LDFLAGS="$LDFLAGS -multiply_defined suppress"
+AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[
+   LDFLAGS="$OLDLDFLAGS"
+   AC_MSG_RESULT(no)])
+
+dnl Check if the linker accepts -single_module; necessary on Mac OS X
+AC_MSG_CHECKING(if the linker accepts -single_module)
+OLDLDFLAGS="$LDFLAGS"
+SHLIB_EXT="so"
+LD_PRELOAD="LD_PRELOAD"
+LDFLAGS="$LDFLAGS -single_module"
+AC_TRY_COMPILE(,,
+   [
+      SHLIB_EXT="dylib" 
+      LD_PRELOAD="DYLD_INSERT_LIBRARIES"
+      AC_MSG_RESULT(yes)
+   ], [
+      LDFLAGS="$OLDLDFLAGS"
+      AC_MSG_RESULT(no)
+   ]
+)
+
+AC_SUBST(SHLIB_EXT)
+AC_SUBST(LD_PRELOAD)
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([tsocks], [chmod +x tsocks])
+AC_OUTPUT
+
