Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support all Debian multi-arch directories in library lookups #114

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 16 additions & 11 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 @@ -698,23 +699,27 @@ static double parseVersion(String ver) {
// paths is scanned against real directory
// so for platforms which are not multi-arch
// this should continue to work.
if (Platform.isLinux()) {
if (Platform.isLinux() || Platform.iskFreeBSD() || Platform.isGNU()) {
// Defaults - overridden below
String cpu = "";
String cpu = Platform.getBaseArch();
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";
if (Platform.isARM()) {
libc = "gnueabi";
}

String multiArchPath =
cpu + "-" + kernel + "-" + libc;
if (Platform.iskFreeBSD()) {
kernel = "kfreebsd";
}

String multiArchPath;

if (Platform.isGNU()) {
multiArchPath = cpu + "-" + libc;
} else {
multiArchPath = cpu + "-" + kernel + "-" + libc;
}

// Assemble path with all possible options
paths = new String[] {
Expand Down
28 changes: 28 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,11 @@ 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 @@ -180,4 +193,19 @@ public static final boolean isARM() {
System.getProperty("os.arch").toLowerCase().trim();
return arch.startsWith("arm");
}

public static final String getBaseArch() {
String arch =
System.getProperty("os.arch").toLowerCase().trim();
if("amd64".equals(arch))
arch = "x86_64";
if("i686-at386".equals(arch))
arch = "i386";
if("ppc".equals(arch))
arch = "powerpc";
if("ppc64".equals(arch))
arch = "powerpc64";
return arch;
}

}