Skip to content

Commit

Permalink
Add support for DragonFly BSD x86_64
Browse files Browse the repository at this point in the history
DragonFly BSD is currently x86_64 only, so don't bother other
architectures at the moment.

The changes are based on the existing support for other BSDs.

One extra change is made to native/Makefile by adding the 'X11INCDIR'
variable, so that it can be easily overrided to be '/usr/local/include'
on DragonFly and FreeBSD.

Tested on DragonFly 6.5 with OpenJDK 17.0.8 and Ant 1.10.13.
  • Loading branch information
liweitianux committed Feb 21, 2024
1 parent 7da005e commit 923bc3a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ processor=S390x;osname=linux,
com/sun/jna/linux-loongarch64/libjnidispatch.so;
processor=loongarch64;osname=linux,
com/sun/jna/dragonflybsd-x86-64/libjnidispatch.so;
processor=x86-64;osname=dragonflybsd,
com/sun/jna/freebsd-x86/libjnidispatch.so;
processor=x86;osname=freebsd,
com/sun/jna/freebsd-x86-64/libjnidispatch.so;
Expand Down Expand Up @@ -528,6 +531,9 @@ osname=macosx;processor=aarch64
<zipfileset src="${lib.native}/sunos-sparcv9.jar"
includes="*jnidispatch*"
prefix="com/sun/jna/sunos-sparcv9"/>
<zipfileset src="${lib.native}/dragonflybsd-x86-64.jar"
includes="*jnidispatch*"
prefix="com/sun/jna/dragonflybsd-x86-64"/>
<zipfileset src="${lib.native}/freebsd-x86.jar"
includes="*jnidispatch*"
prefix="com/sun/jna/freebsd-x86"/>
Expand Down Expand Up @@ -723,6 +729,7 @@ osname=macosx;processor=aarch64
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-loongarch64.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-s390x.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-riscv64.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/dragonflybsd-x86-64.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-x86.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-x86-64.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-aarch64.jar" overwrite="true"/>
Expand Down Expand Up @@ -909,6 +916,7 @@ osname=macosx;processor=aarch64
</condition>
<condition property="make" value="gmake">
<or>
<equals arg1="${build.os.name}" arg2="DragonFlyBSD"/>
<equals arg1="${build.os.name}" arg2="FreeBSD"/>
<equals arg1="${build.os.name}" arg2="OpenBSD"/>
<equals arg1="${build.os.name}" arg2="NetBSD"/>
Expand Down
3 changes: 3 additions & 0 deletions common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
<condition property="os.prefix" value="sunos-${jre.arch}">
<equals arg1="${build.os.name}" arg2="SunOS"/>
</condition>
<condition property="os.prefix" value="dragonflybsd-${jre.arch}">
<equals arg1="${build.os.name}" arg2="DragonFlyBSD"/>
</condition>
<condition property="os.prefix" value="freebsd-${jre.arch}">
<equals arg1="${build.os.name}" arg2="FreeBSD"/>
</condition>
Expand Down
7 changes: 5 additions & 2 deletions native/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Linux (i386/amd64/ppc/arm)
# Solaris (i386/amd64/sparc/sparcv9)
# AIX (ppc/ppc64)
# DragonFly (x86-64)
# FreeBSD (i386/amd64/aarch64)
# OpenBSD/NetBSD (i386/amd64)
# Android (arm/armv7/aarch64/x86/x86-64/mipsel/mips64el)
Expand Down Expand Up @@ -46,6 +47,7 @@ OS=$(shell uname | sed -e 's/CYGWIN.*/win32/g' \
-e 's/NetBSD/netbsd/g' \
-e 's/GNU\/kFreeBSD/kfreebsd/g' \
-e 's/FreeBSD/freebsd/g' \
-e 's/DragonFly/dragonfly/g' \
-e 's/OpenBSD/openbsd/g' \
-e 's/Darwin.*/darwin/g' \
-e 's/AIX.*/aix/g' \
Expand Down Expand Up @@ -289,10 +291,11 @@ LDFLAGS+=-Wl,-soname,$@,-Bsymbolic
endif
endif

ifneq (,$(findstring bsd,$(OS)))
ifneq (,$(or $(findstring bsd,$(OS)),$(findstring dragonfly,$(OS))))
ARCH=$(shell uname -m | sed 's/i.86/i386/g')
PCFLAGS+=-fPIC
CINCLUDES+=-I/usr/X11R6/include
X11INCDIR?=/usr/X11R6/include
CINCLUDES+=-I$(X11INCDIR)
LDFLAGS=-o $@ -shared
CDEFINES+=-DHAVE_PROTECTION -DFFI_MMAP_EXEC_WRIT -DUSE_DEAFULT_LIBNAME_ENCODING
endif
Expand Down
4 changes: 4 additions & 0 deletions native/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<condition property="os.prefix" value="sunos-${jre.arch}">
<os name="SunOS"/>
</condition>
<condition property="os.prefix" value="dragonflybsd-${jre.arch}">
<os name="DragonFlyBSD"/>
</condition>
<condition property="os.prefix" value="freebsd-${jre.arch}">
<os name="FreeBSD"/>
</condition>
Expand Down Expand Up @@ -347,6 +350,7 @@
</condition>
<condition property="make" value="gmake">
<or>
<os name="DragonFlyBSD"/>
<os name="FreeBSD"/>
<os name="OpenBSD"/>
<os name="NetBSD"/>
Expand Down
2 changes: 1 addition & 1 deletion src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ static File getTempDir() throws IOException {
if(Platform.isMac()) {
// https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html
jnatmp = new File(System.getProperty("user.home"), "Library/Caches/JNA/temp");
} else if (Platform.isLinux() || Platform.isSolaris() || Platform.isAIX() || Platform.isFreeBSD() || Platform.isNetBSD() || Platform.isOpenBSD() || Platform.iskFreeBSD()) {
} else if (Platform.isLinux() || Platform.isSolaris() || Platform.isAIX() || Platform.isDragonFlyBSD() || Platform.isFreeBSD() || Platform.isNetBSD() || Platform.isOpenBSD() || Platform.iskFreeBSD()) {
// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
// The XDG_CACHE_DIR is expected to be per user
String xdgCacheEnvironment = System.getenv("XDG_CACHE_HOME");
Expand Down
10 changes: 10 additions & 0 deletions src/com/sun/jna/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public final class Platform {
public static final int GNU = 9;
public static final int KFREEBSD = 10;
public static final int NETBSD = 11;
public static final int DRAGONFLYBSD = 12;

/** Whether read-only (final) fields within Structures are supported. */
public static final boolean RO_FIELDS;
Expand Down Expand Up @@ -110,6 +111,9 @@ else if (osName.equalsIgnoreCase("gnu/kfreebsd")) {
else if (osName.equalsIgnoreCase("netbsd")) {
osType = NETBSD;
}
else if (osName.equalsIgnoreCase("dragonflybsd")) {
osType = DRAGONFLYBSD;
}
else {
osType = UNSPECIFIED;
}
Expand Down Expand Up @@ -160,6 +164,9 @@ public static final boolean isWindows() {
public static final boolean isSolaris() {
return osType == SOLARIS;
}
public static final boolean isDragonFlyBSD() {
return osType == DRAGONFLYBSD;
}
public static final boolean isFreeBSD() {
return osType == FREEBSD;
}
Expand Down Expand Up @@ -329,6 +336,9 @@ static String getNativeLibraryResourcePrefix(int osType, String arch, String nam
case Platform.SOLARIS:
osPrefix = "sunos-" + arch;
break;
case Platform.DRAGONFLYBSD:
osPrefix = "dragonflybsd-" + arch;
break;
case Platform.FREEBSD:
osPrefix = "freebsd-" + arch;
break;
Expand Down
1 change: 1 addition & 0 deletions test/com/sun/jna/NativeLibraryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void testMapSharedLibraryName() {
{ Platform.LINUX, "lib", ".so" },
{ Platform.WINDOWS, "", ".dll" },
{ Platform.SOLARIS, "lib", ".so" },
{ Platform.DRAGONFLYBSD, "lib", ".so" },
{ Platform.FREEBSD, "lib", ".so" },
{ Platform.OPENBSD, "lib", ".so" },
{ Platform.WINDOWSCE, "", ".dll" },
Expand Down
3 changes: 3 additions & 0 deletions test/com/sun/jna/PlatformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public void testOSPrefix() {
Platform.getNativeLibraryResourcePrefix(Platform.LINUX,
"arm", "Linux/Gnu"));
}
assertEquals("Wrong resource path DragonFlyBSD/x86-64", "dragonflybsd-x86-64",
Platform.getNativeLibraryResourcePrefix(Platform.DRAGONFLYBSD,
"x86-64", "DragonFlyBSD"));
assertEquals("Wrong resource path OpenBSD/x86", "openbsd-x86",
Platform.getNativeLibraryResourcePrefix(Platform.OPENBSD,
"x86", "OpenBSD"));
Expand Down

0 comments on commit 923bc3a

Please sign in to comment.