Skip to content

Commit

Permalink
apply PR #114, support for gnu/kfreebsd
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed Oct 6, 2012
1 parent eaff9bd commit 7a583b1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
<echo>java.home=${java.home}</echo>
<echo>java.library.path=${java.library.path}</echo>
<echo>os.prefix=${os.prefix}</echo>
<echo>os.name=${os.name}</echo>
<echo>os.arch=${os.arch}</echo>
<echo>build=${build}</echo>
<echo>build.native=${build.native}</echo>

Expand Down
45 changes: 26 additions & 19 deletions src/com/sun/jna/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ static double parseVersion(String ver) {
// on 64bit machines, so we have to explicitly search the 64bit
// one when running a 64bit JVM.
//
if (Platform.isLinux() || Platform.isSolaris() || Platform.isFreeBSD()) {
if (Platform.isLinux() || Platform.isSolaris()
|| Platform.isFreeBSD() || Platform.iskFreeBSD()) {
// Linux & FreeBSD use /usr/lib32, solaris uses /usr/lib/32
archPath = (Platform.isSolaris() ? "/" : "") + Pointer.SIZE * 8;
}
Expand All @@ -693,28 +694,13 @@ static double parseVersion(String ver) {
"/usr/lib",
"/lib",
};
// Fix for multi-arch support on Ubuntu (and other
// Multi-arch support on Ubuntu (and other
// multi-arch distributions)
// paths is scanned against real directory
// so for platforms which are not multi-arch
// this should continue to work.
if (Platform.isLinux()) {
// Defaults - overridden below
String cpu = "";
String kernel = "linux";
String libc = "gnu";

if (Platform.isIntel()) {
cpu = (Platform.is64Bit() ? "x86_64" : "i386");
} else if (Platform.isPPC()) {
cpu = (Platform.is64Bit() ? "powerpc64" : "powerpc");
} else if (Platform.isARM()) {
cpu = "arm";
libc = "gnueabi";
}

String multiArchPath =
cpu + "-" + kernel + "-" + libc;
if (Platform.isLinux() || Platform.iskFreeBSD() || Platform.isGNU()) {
String multiArchPath = getMultiArchPath();

// Assemble path with all possible options
paths = new String[] {
Expand All @@ -739,4 +725,25 @@ static double parseVersion(String ver) {
}
librarySearchPath.addAll(initPaths("jna.platform.library.path"));
}

private static String getMultiArchPath() {
String cpu = System.getProperty("os.arch").toLowerCase().trim();
String kernel = Platform.iskFreeBSD()
? "-kfreebsd"
: (Platform.isGNU() ? "" : "-linux");
String libc = "-gnu";

if (Platform.isIntel()) {
cpu = (Platform.is64Bit() ? "x86_64" : "i386");
}
else if (Platform.isPPC()) {
cpu = (Platform.is64Bit() ? "powerpc64" : "powerpc");
}
else if (Platform.isARM()) {
cpu = "arm";
libc = "-gnueabi";
}

return cpu + kernel + libc;
}
}
15 changes: 15 additions & 0 deletions src/com/sun/jna/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public final class Platform {
public static final int WINDOWSCE = 6;
public static final int AIX = 7;
public static final int ANDROID = 8;
public static final int GNU = 9;
public static final int KFREEBSD = 10;

/** Whether read-only (final) fields within Structures are supported. */
public static final boolean RO_FIELDS;
Expand Down Expand Up @@ -68,6 +70,12 @@ else if (osName.startsWith("FreeBSD")) {
else if (osName.startsWith("OpenBSD")) {
osType = OPENBSD;
}
else if (osName.equalsIgnoreCase("gnu")) {
osType = GNU;
}
else if (osName.equalsIgnoreCase("gnu/kfreebsd")) {
osType = KFREEBSD;
}
else {
osType = UNSPECIFIED;
}
Expand Down Expand Up @@ -125,6 +133,12 @@ public static final boolean isFreeBSD() {
public static final boolean isOpenBSD() {
return osType == OPENBSD;
}
public static final boolean isGNU() {
return osType == GNU;
}
public static final boolean iskFreeBSD() {
return osType == KFREEBSD;
}
public static final boolean isX11() {
// TODO: check filesystem for /usr/X11 or some other X11-specific test
return !Platform.isWindows() && !Platform.isMac();
Expand Down Expand Up @@ -155,6 +169,7 @@ public static final boolean isIntel() {
String arch =
System.getProperty("os.arch").toLowerCase().trim();
if (arch.equals("i386")
|| arch.startsWith("i686")
|| arch.equals("x86")
|| arch.equals("x86_64")
|| arch.equals("amd64")) {
Expand Down

0 comments on commit 7a583b1

Please sign in to comment.