Skip to content

Commit

Permalink
Updated the code slightly to work to compile my Mac OS X jnilib and w…
Browse files Browse the repository at this point in the history
…ork with Lein2
  • Loading branch information
tel committed Apr 25, 2012
1 parent 4d9ebbf commit 3abb627
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pom.xml
.lein-deps-sum
.lein-failures
.lein-plugins
*.swp
8 changes: 4 additions & 4 deletions config/config_cc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
EOS
end
when 'Mac\ OS\ X'
Path.check_cmd('gcc-mp-4.3', 'make')
Path.check_cmd('gcc', 'make')
Config::CONFIG << <<EOS
CC = gcc-mp-4.3
LD = gcc-mp-4.3
CC = gcc
LD = gcc
CFLAGS = -fPIC
INCDIRS += -Iinclude -I#{java_home}/include
SO = jnilib
Expand All @@ -120,4 +120,4 @@

if __FILE__ == $0
ConfigureTask.run :cc
end
end
8 changes: 4 additions & 4 deletions config/config_libs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
CONFIG[:libpath] = $opts[:libpath].split(':')
else
if CONFIG['OS_NAME'] == 'Mac\ OS\ X'
CONFIG[:libpath] = ['/opt/local/lib']
CONFIG[:libpath] = %w(/usr/lib /usr/local/lib)
else
CONFIG[:libpath] = %w(/usr/lib /lib /usr/lib/sse2)
end
Expand Down Expand Up @@ -160,9 +160,9 @@
CONFIG['LOADLIBES'] += ['-l:libgfortran.a']
end
end
if CONFIG['OS_NAME'] == 'Mac\ OS\ X'
CONFIG['LOADLIBES'] += ['/opt/local/lib/gcc43/libgfortran.a']
end
if CONFIG['OS_NAME'] == 'Mac\ OS\ X'
CONFIG['LOADLIBES'] += ['/usr/local/lib/libgfortran.dylib']
end
end
ok
end
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/org/jblas/util/LibraryLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,19 @@ public void loadLibrary(String libname, boolean withFlavor) {
fatJarLibraryPathNonUnified("static", flavor),
fatJarLibraryPath("dynamic", flavor),
fatJarLibraryPathNonUnified("dynamic", flavor),
fatJarLibraryPathNoLinkage(flavor),
fatJarLibraryPathNoLinkageNoLib(flavor)
};

InputStream is = findLibrary(paths, libname);

// Oh man, have to get out of here!
if (is == null) {
throw new UnsatisfiedLinkError("Couldn't find the resource " + libname + ".");
String res = "";
for (String path: paths) {
res = res + path + "\n";
}
throw new UnsatisfiedLinkError("Couldn't find the resource " + libname + res + ".");
}

logger.config("Loading " + libname + " from " + libpath + ".");
Expand Down Expand Up @@ -141,6 +147,28 @@ private String fatJarLibraryPathNonUnified(String linkage, String flavor) {
return path;
}

/** Full path without linkages. */
private String fatJarLibraryPathNoLinkage(String flavor) {
String sep = "/"; //System.getProperty("file.separator");
String os_name = System.getProperty("os.name");
String os_arch = System.getProperty("os.arch");
String path = sep + "lib" + sep + os_name + sep + os_arch + sep;
if (null != flavor)
path += flavor + sep;
return path;
}

/** Full path without linkages or lib-prefix. */
private String fatJarLibraryPathNoLinkageNoLib(String flavor) {
String sep = "/"; //System.getProperty("file.separator");
String os_name = System.getProperty("os.name");
String os_arch = System.getProperty("os.arch");
String path = sep + os_name + sep + os_arch + sep;
if (null != flavor)
path += flavor + sep;
return path;
}

/** Try to open a file at the given position. */
private InputStream tryPath(String path) {
Logger.getLogger().debug("Trying path \"" + path + "\".");
Expand Down

0 comments on commit 3abb627

Please sign in to comment.