diff --git a/core/c/jbigi/build.sh b/core/c/jbigi/build.sh
index 98ee1d168162f2bc6a312eeaf144e33181ebf724..0ec3e26b70ad0dd2c7bbcba3d076d554b9bae547 100644
--- a/core/c/jbigi/build.sh
+++ b/core/c/jbigi/build.sh
@@ -8,7 +8,13 @@ echo "Building..."
 mkdir -p lib/
 mkdir -p bin/local
 cd bin/local
-../../gmp-4.1.4/configure
+case `uname -sr` in
+Darwin*)
+# --with-pic is required for static linking
+../../gmp-4.1.4/configure --with-pic;;
+*)
+../../gmp-4.1.4/configure;;
+esac
 make
 sh ../../build_jbigi.sh static
 cp *jbigi???* ../../lib/
diff --git a/core/c/jbigi/build_jbigi.sh b/core/c/jbigi/build_jbigi.sh
index 54b0a36739eee3a4ec807370e02a0edb28c6b45a..859eda329a16aaecd8db60e854dffb7c4b992c0e 100644
--- a/core/c/jbigi/build_jbigi.sh
+++ b/core/c/jbigi/build_jbigi.sh
@@ -17,6 +17,12 @@ CYGWIN*)
 	INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/"
 	LINKFLAGS="-shared -Wl,--kill-at"
 	LIBFILE="jbigi.dll";;
+Darwin*)
+        JAVA_HOME="/Library/Java/Home"
+        COMPILEFLAGS="-Wall"
+        INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include"
+        LINKFLAGS="-dynamiclib -framework JavaVM"
+        LIBFILE="libjbigi.jnilib";;
 *)
 	COMPILEFLAGS="-fPIC -Wall"
 	INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/linux"
diff --git a/core/java/src/net/i2p/util/NativeBigInteger.java b/core/java/src/net/i2p/util/NativeBigInteger.java
index 162ee0e89e6a5b1db2d767fb16e233fcbf2e3b85..dd22240b059844d37f0f7480850733b362c5e8cb 100644
--- a/core/java/src/net/i2p/util/NativeBigInteger.java
+++ b/core/java/src/net/i2p/util/NativeBigInteger.java
@@ -103,14 +103,22 @@ public class NativeBigInteger extends BigInteger {
     private final static String JBIGI_OPTIMIZATION_PENTIUM3   = "pentium3";
     private final static String JBIGI_OPTIMIZATION_PENTIUM4   = "pentium4";
 
+    private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
+    private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
+    private static final boolean _isLinux = System.getProperty("os.name").toLowerCase().indexOf("linux") != -1;
+    private static final boolean _isFreebsd = System.getProperty("os.name").toLowerCase().indexOf("freebsd") != -1;
+    private static final boolean _isNix = !(_isWin || _isMac);
     /* libjbigi.so vs jbigi.dll */
-    private static final String _libPrefix = (System.getProperty("os.name").startsWith("Win") ? "" : "lib");
-    private static final String _libSuffix = (System.getProperty("os.name").startsWith("Win") ? ".dll" : ".so");
+    private static final String _libPrefix = (_isWin ? "" : "lib");
+    private static final String _libSuffix = (_isWin ? ".dll" : _isMac ? ".jnilib" : ".so");
 
     private final static String sCPUType; //The CPU Type to optimize for (one of the above strings)
     
     static {
-        sCPUType = resolveCPUType();
+        if (_isMac) // replace with osx/mac friendly jni cpu type detection when we have one
+            sCPUType = null;
+        else
+            sCPUType = resolveCPUType();
         loadNative();
     }
     
@@ -518,12 +526,12 @@ public class NativeBigInteger extends BigInteger {
     }
     
     private static final String getResourceName(boolean optimized) {
-        String pref = getLibraryPrefix();
+        String pref = _libPrefix;
         String middle = getMiddleName(optimized);
-        String suff = getLibrarySuffix();
+        String suff = _libSuffix;
         if(pref == null || middle == null || suff == null)
             return null;
-        return pref+middle+"."+suff;
+        return pref+middle+suff;
     }
     
     private static final String getMiddleName(boolean optimized){
@@ -538,31 +546,14 @@ public class NativeBigInteger extends BigInteger {
         }else
                sAppend = "-none";
 
-        boolean isWindows =(System.getProperty("os.name").toLowerCase().indexOf("windows") != -1);
-        boolean isLinux =(System.getProperty("os.name").toLowerCase().indexOf("linux") != -1);
-        boolean isFreebsd =(System.getProperty("os.name").toLowerCase().indexOf("freebsd") != -1);
-        if(isWindows)
+        if(_isWin)
              return "jbigi-windows"+sAppend; // The convention on Windows
-        if(isLinux)
+        if(_isLinux)
             return "jbigi-linux"+sAppend; // The convention on linux...
-        if(isFreebsd)
+        if(_isFreebsd)
             return "jbigi-freebsd"+sAppend; // The convention on freebsd...
+        if(_isMac)
+            return "jbigi-osx"+sAppend;
         throw new RuntimeException("Dont know jbigi library name for os type '"+System.getProperty("os.name")+"'");
     }
-    private static final String getLibrarySuffix()
-    {
-        boolean isWindows =System.getProperty("os.name").toLowerCase().indexOf("windows") != -1;
-        if(isWindows)
-            return "dll";
-        else
-            return "so";
-    }
-    private static final String getLibraryPrefix()
-    {
-        boolean isWindows =System.getProperty("os.name").toLowerCase().indexOf("windows") != -1;
-        if(isWindows)
-            return "";
-        else
-            return "lib";
-    }
 }
diff --git a/history.txt b/history.txt
index 3457f875889ae946f6dd0d04f8db3b3873452178..596fee072ae5924bc3dc7da84b52124e0775b14f 100644
--- a/history.txt
+++ b/history.txt
@@ -1,4 +1,12 @@
-$Id: history.txt,v 1.129 2005/01/17 03:15:00 jrandom Exp $
+$Id: history.txt,v 1.130 2005/01/18 19:08:13 jrandom Exp $
+
+2005-01-21  Jhor
+    * Updated jbigi build scripts for OSX.
+
+2005-01-21  jrandom
+    * Added support for OSX to the NativeBigInteger code so that it will look
+      in the classpath for libjbigi-osx-none.jnilib.  At the moment, that file
+      is not bundled with the shipped jbigi.jar yet though.
 
 2005-01-18  jrandom
     * Increased the max # session tags maintained and decreased slightly the
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index 5bbe7fed9ac67dd9c161bb3bfcd3170407f3d0e8..a6d1ca3d62bd2e8ec4ab93e29ae5bbeff077892d 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
  *
  */
 public class RouterVersion {
-    public final static String ID = "$Revision: 1.134 $ $Date: 2005/01/17 03:15:03 $";
+    public final static String ID = "$Revision: 1.135 $ $Date: 2005/01/18 19:08:13 $";
     public final static String VERSION = "0.4.2.6";
-    public final static long BUILD = 4;
+    public final static long BUILD = 5;
     public static void main(String args[]) {
         System.out.println("I2P Router version: " + VERSION);
         System.out.println("Router ID: " + RouterVersion.ID);