--- configure.in.orig	2006-01-28 17:53:15.000000000 -0800
+++ configure.in	2006-01-28 18:13:45.000000000 -0800
@@ -312,7 +318,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([
@@ -332,4 +338,42 @@
 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
+

