Add suppport for FreeBSD (x86, x86_64, arm64)
This commit is contained in:
parent
4093e47170
commit
b44e972ffe
|
@ -11,9 +11,13 @@ COMPILE_OSX_X86 := o32-clang
|
|||
COMPILE_OSX_X86_64 := o64-clang
|
||||
COMPILE_OSX_ARM64 := oa64-clang
|
||||
COMPILE_ANDROID := ndk-build
|
||||
COMPILE_FREEBSD_X86 := clang -target i386-unknown-freebsd11.2 --sysroot=$(HOME)/x-tools/i386-unknown-freebsd11.2
|
||||
COMPILE_FREEBSD_X86_64 := clang -target x86_64-unknown-freebsd11.2 --sysroot=$(HOME)/x-tools/x86_64-unknown-freebsd11.2
|
||||
COMPILE_FREEBSD_ARM64 := clang -target arm64-unknown-freebsd11.2 --sysroot=$(HOME)/x-tools/arm64-unknown-freebsd11.2
|
||||
CFLAGS_POSIX := -fPIC -Os -flto -static-libgcc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fuse-linker-plugin
|
||||
CFLAGS_APPLE := -fPIC -Os -flto -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
|
||||
LDFLAGS_POSIX := -Os -flto -static-libgcc -shared -fuse-linker-plugin -s
|
||||
LDFLAGS_FREEBSD := -fuse-ld=lld -O3 -flto -shared -s -fuse-linker-plugin
|
||||
LDFLAGS_APPLE := -Os -dynamiclib -flto -shared -fuse-linker-plugin
|
||||
JDK_HOME := $(shell if [ "`uname`" = "Darwin" ]; then echo "`/usr/libexec/java_home`"; else echo "$$JDK_HOME"; fi)
|
||||
INCLUDES := -I"$(JDK_HOME)/include" -I"$(JDK_HOME)/include/linux" -I"$(JDK_HOME)/include/darwin" -I"$(JDK_HOME)/include/solaris"
|
||||
|
@ -32,6 +36,7 @@ BUILD_DIR := ../../../../build
|
|||
RESOURCE_DIR_LINUX := ../../../../src/main/resources/Linux
|
||||
RESOURCE_DIR_SOLARIS := ../../../../src/main/resources/Solaris
|
||||
RESOURCE_DIR_OSX := ../../../../src/main/resources/OSX
|
||||
RESOURCE_DIR_FREEBSD := ../../../../src/main/resources/FreeBSD
|
||||
JAVA_SOURCE_DIR := ../../../../src/main/java/com/fazecast/jSerialComm
|
||||
FULL_CLASS := com.fazecast.jSerialComm.SerialPort
|
||||
JAVA_CLASS_DIR := $(BUILD_DIR)/com/fazecast/jSerialComm
|
||||
|
@ -55,6 +60,9 @@ OBJECTSsolaris32 := $(BUILD_DIR)/solaris_x86/SerialPort_Posix.o $(BUI
|
|||
OBJECTSsolaris64 := $(BUILD_DIR)/solaris_x86_64/SerialPort_Posix.o $(BUILD_DIR)/solaris_x86_64/PosixHelperFunctions.o
|
||||
OBJECTSsolarisSparc32 := $(BUILD_DIR)/solaris_sparc32/SerialPort_Posix.o $(BUILD_DIR)/solaris_sparc32/PosixHelperFunctions.o
|
||||
OBJECTSsolarisSparc64 := $(BUILD_DIR)/solaris_sparc64/SerialPort_Posix.o $(BUILD_DIR)/solaris_sparc64/PosixHelperFunctions.o
|
||||
OBJECTSfreebsd32 := $(BUILD_DIR)/freebsd_x86/SerialPort_Posix.o $(BUILD_DIR)/freebsd_x86/PosixHelperFunctions.o
|
||||
OBJECTSfreebsd64 := $(BUILD_DIR)/freebsd_x86_64/SerialPort_Posix.o $(BUILD_DIR)/freebsd_x86_64/PosixHelperFunctions.o
|
||||
OBJECTSfreebsdArm64 := $(BUILD_DIR)/freebsd_arm64/SerialPort_Posix.o $(BUILD_DIR)/freebsd_arm64/PosixHelperFunctions.o
|
||||
OBJECTSosx86 := $(BUILD_DIR)/osx_x86/SerialPort_Posix.o $(BUILD_DIR)/osx_x86/PosixHelperFunctions.o
|
||||
OBJECTSosx64 := $(BUILD_DIR)/osx_x86_64/SerialPort_Posix.o $(BUILD_DIR)/osx_x86_64/PosixHelperFunctions.o
|
||||
OBJECTSosxaarch64 := $(BUILD_DIR)/osx_aarch64/SerialPort_Posix.o $(BUILD_DIR)/osx_aarch64/PosixHelperFunctions.o
|
||||
|
@ -72,18 +80,21 @@ FLAGSsolaris32 := -m32
|
|||
FLAGSsolaris64 := -m64
|
||||
FLAGSsolarisSparc32 := -mno-app-regs -mcpu=v8 -mv8plus -m32
|
||||
FLAGSsolarisSparc64 := -mno-app-regs -mcpu=v9 -m64
|
||||
FLAGSfreebsd32 := -m32
|
||||
FLAGSfreebsd64 := -m64
|
||||
FLAGSfreebsdArm64 := -m64
|
||||
FLAGSosx86 := -arch i386 -m32
|
||||
FLAGSosx64 := -arch x86_64 -m64
|
||||
FLAGSosxaarch64 := -arch arm64
|
||||
|
||||
# Define phony and suffix rules
|
||||
.PHONY: all clean linux linux32 linux64 arm armv5 armv6 armv6hf armv7 armv7hf armv8_32 armv8_64 powerpc ppc64le solaris solaris32 solaris64 solarisSparc32 solarisSparc64 osx osx32 osx64 osxaarch64 android
|
||||
.PHONY: all clean linux linux32 linux64 arm armv5 armv6 armv6hf armv7 armv7hf armv8_32 armv8_64 powerpc ppc64le solaris solaris32 solaris64 solarisSparc32 solarisSparc64 osx osx32 osx64 osxaarch64 android freebsd freebsd32 freebsd64 freebsdArm64
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cpp .c .o .class .java .h
|
||||
|
||||
# Default build target does nothing
|
||||
all :
|
||||
$(PRINT) You must specify either linux, arm, solaris, osx, powerpc, or android!
|
||||
$(PRINT) You must specify either linux, arm, powerpc, solaris, freebsd, osx, or android!
|
||||
clean :
|
||||
$(DELETE) -rf "$(BUILD_DIR)"
|
||||
$(DELETE) -rf ../*.h
|
||||
|
@ -108,6 +119,11 @@ solaris : solaris32 solaris64 solarisSparc32 solarisSparc64
|
|||
$(DELETE) -rf "`readlink -f $(BUILD_DIR)`"
|
||||
$(DELETE) -rf ../*.h
|
||||
|
||||
# Build all FreeBSD libraries
|
||||
freebsd : freebsd32 freebsd64 freebsdArm64
|
||||
$(DELETE) -rf "`readlink -f $(BUILD_DIR)`"
|
||||
$(DELETE) -rf ../*.h
|
||||
|
||||
# Build all OSX libraries
|
||||
osx : osx32 osx64 osxaarch64
|
||||
$(DELETE) -rf "$(BUILD_DIR)"
|
||||
|
@ -163,6 +179,17 @@ solarisSparc64 : $(JAVA_CLASS_DIR) $(BUILD_DIR)/solaris_sparc64 $(BUILD_DIR)/sol
|
|||
$(DELETE) -rf $(BUILD_DIR)/solaris_sparc64/*.o
|
||||
$(COPY) $(BUILD_DIR)/solaris_sparc64/*.* $(RESOURCE_DIR_SOLARIS)/sparcv9_64/
|
||||
|
||||
# Build architecture-specific FreeBSD libraries
|
||||
freebsd32 : $(JAVA_CLASS_DIR) $(BUILD_DIR)/freebsd_x86 $(BUILD_DIR)/freebsd_x86/$(LIBRARY_NAME_POSIX)
|
||||
$(DELETE) -rf $(BUILD_DIR)/freebsd_x86/*.o
|
||||
$(COPY) $(BUILD_DIR)/freebsd_x86/*.* $(RESOURCE_DIR_FREEBSD)/x86/
|
||||
freebsd64 : $(JAVA_CLASS_DIR) $(BUILD_DIR)/freebsd_x86_64 $(BUILD_DIR)/freebsd_x86_64/$(LIBRARY_NAME_POSIX)
|
||||
$(DELETE) -rf $(BUILD_DIR)/freebsd_x86_64/*.o
|
||||
$(COPY) $(BUILD_DIR)/freebsd_x86_64/*.* $(RESOURCE_DIR_FREEBSD)/x86_64/
|
||||
freebsdArm64 : $(JAVA_CLASS_DIR) $(BUILD_DIR)/freebsd_arm64 $(BUILD_DIR)/freebsd_arm64/$(LIBRARY_NAME_POSIX)
|
||||
$(DELETE) -rf $(BUILD_DIR)/freebsd_arm64/*.o
|
||||
$(COPY) $(BUILD_DIR)/freebsd_arm64/*.* $(RESOURCE_DIR_FREEBSD)/arm64/
|
||||
|
||||
# Build architecture-specific OSX libraries
|
||||
osx32 : $(JAVA_CLASS_DIR) $(BUILD_DIR)/osx_x86 $(BUILD_DIR)/osx_x86/$(LIBRARY_NAME_APPLE)
|
||||
$(DELETE) -rf $(BUILD_DIR)/osx_x86/*.o
|
||||
|
@ -207,6 +234,12 @@ $(BUILD_DIR)/solaris_sparc32 :
|
|||
$(MKDIR) -p $@
|
||||
$(BUILD_DIR)/solaris_sparc64 :
|
||||
$(MKDIR) -p $@
|
||||
$(BUILD_DIR)/freebsd_x86 :
|
||||
$(MKDIR) -p $@
|
||||
$(BUILD_DIR)/freebsd_x86_64 :
|
||||
$(MKDIR) -p $@
|
||||
$(BUILD_DIR)/freebsd_arm64 :
|
||||
$(MKDIR) -p $@
|
||||
$(BUILD_DIR)/osx_x86 :
|
||||
$(MKDIR) -p $@
|
||||
$(BUILD_DIR)/osx_x86_64 :
|
||||
|
@ -245,6 +278,12 @@ $(BUILD_DIR)/solaris_sparc32/$(LIBRARY_NAME_POSIX) : $(JNI_HEADER) $(OBJECTSsola
|
|||
$(COMPILE_SOLARIS_SPARC) $(LDFLAGS_POSIX) $(FLAGSsolarisSparc32) -o $@ $(OBJECTSsolarisSparc32) $(LIBRARIES_POSIX)
|
||||
$(BUILD_DIR)/solaris_sparc64/$(LIBRARY_NAME_POSIX) : $(JNI_HEADER) $(OBJECTSsolarisSparc64)
|
||||
$(COMPILE_SOLARIS_SPARC) $(LDFLAGS_POSIX) $(FLAGSsolarisSparc64) -o $@ $(OBJECTSsolarisSparc64) $(LIBRARIES_POSIX)
|
||||
$(BUILD_DIR)/freebsd_x86/$(LIBRARY_NAME_POSIX) : $(JNI_HEADER) $(OBJECTSfreebsd32)
|
||||
$(COMPILE_FREEBSD_X86) $(LDFLAGS_FREEBSD) $(FLAGSfreebsd32) -o $@ $(OBJECTSfreebsd32) $(LIBRARIES_POSIX)
|
||||
$(BUILD_DIR)/freebsd_x86_64/$(LIBRARY_NAME_POSIX) : $(JNI_HEADER) $(OBJECTSfreebsd64)
|
||||
$(COMPILE_FREEBSD_X86_64) $(LDFLAGS_FREEBSD) $(FLAGSfreebsd64) -o $@ $(OBJECTSfreebsd64) $(LIBRARIES_POSIX)
|
||||
$(BUILD_DIR)/freebsd_arm64/$(LIBRARY_NAME_POSIX) : $(JNI_HEADER) $(OBJECTSfreebsdArm64)
|
||||
$(COMPILE_FREEBSD_ARM64) $(LDFLAGS_FREEBSD) $(FLAGSfreebsdArm64) -o $@ $(OBJECTSfreebsdArm64) $(LIBRARIES_POSIX)
|
||||
$(BUILD_DIR)/osx_x86/$(LIBRARY_NAME_APPLE) : $(JNI_HEADER) $(OBJECTSosx86)
|
||||
$(COMPILE_OSX_X86) $(LDFLAGS_APPLE) $(FLAGSosx86) -o $@ $(OBJECTSosx86) $(LIBRARIES_APPLE)
|
||||
$(BUILD_DIR)/osx_x86_64/$(LIBRARY_NAME_APPLE) : $(JNI_HEADER) $(OBJECTSosx64)
|
||||
|
@ -281,6 +320,12 @@ $(BUILD_DIR)/solaris_sparc32/%.o : %.c
|
|||
$(COMPILE_SOLARIS_SPARC) $(INCLUDES) $(CFLAGS_POSIX) $(FLAGSsolarisSparc32) -c $< -o $@
|
||||
$(BUILD_DIR)/solaris_sparc64/%.o : %.c
|
||||
$(COMPILE_SOLARIS_SPARC) $(INCLUDES) $(CFLAGS_POSIX) $(FLAGSsolarisSparc64) -c $< -o $@
|
||||
$(BUILD_DIR)/freebsd_x86/%.o : %.c
|
||||
$(COMPILE_FREEBSD_X86) $(INCLUDES) $(CFLAGS_APPLE) $(FLAGSfreebsd32) -c $< -o $@
|
||||
$(BUILD_DIR)/freebsd_x86_64/%.o : %.c
|
||||
$(COMPILE_FREEBSD_X86_64) $(INCLUDES) $(CFLAGS_APPLE) $(FLAGSfreebsd64) -c $< -o $@
|
||||
$(BUILD_DIR)/freebsd_arm64/%.o : %.c
|
||||
$(COMPILE_FREEBSD_ARM64) $(INCLUDES) $(CFLAGS_APPLE) $(FLAGSfreebsdArm64) -c $< -o $@
|
||||
$(BUILD_DIR)/osx_x86/%.o : %.c
|
||||
$(COMPILE_OSX_X86) $(INCLUDES) $(CFLAGS_APPLE) $(FLAGSosx86) -c $< -o $@
|
||||
$(BUILD_DIR)/osx_x86_64/%.o : %.c
|
||||
|
@ -290,6 +335,7 @@ $(BUILD_DIR)/osx_aarch64/%.o : %.c
|
|||
|
||||
# Rule to build JNI header file
|
||||
$(JNI_HEADER) : $(JAVA_CLASS)
|
||||
$(COPY) $@ ./
|
||||
|
||||
# Suffix rule to get from *.java -> *.class
|
||||
$(JAVA_CLASS) :
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* PosixHelperFunctions.c
|
||||
*
|
||||
* Created on: Mar 10, 2015
|
||||
* Last Updated on: Nov 14, 2021
|
||||
* Last Updated on: Dec 06, 2021
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2021 Fazecast, Inc.
|
||||
|
@ -855,6 +855,69 @@ int setBaudRateCustom(int portFD, baud_rate baudRate)
|
|||
return -1;
|
||||
}
|
||||
|
||||
// FreeBSD-specific functionality
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
void searchForComPorts(serialPortVector* comPorts)
|
||||
{
|
||||
// Open the FreeBSD dev directory
|
||||
DIR *directoryIterator = opendir("/dev/");
|
||||
if (directoryIterator)
|
||||
{
|
||||
// Read all files in the current directory
|
||||
struct dirent *directoryEntry = readdir(directoryIterator);
|
||||
while (directoryEntry)
|
||||
{
|
||||
// See if the file names a potential serial port
|
||||
if ((strlen(directoryEntry->d_name) >= 3) && (directoryEntry->d_name[0] != '.') &&
|
||||
(((directoryEntry->d_name[0] == 't') && (directoryEntry->d_name[1] == 't') && (directoryEntry->d_name[2] == 'y')) ||
|
||||
((directoryEntry->d_name[0] == 'c') && (directoryEntry->d_name[1] == 'u') && (directoryEntry->d_name[2] == 'a'))))
|
||||
{
|
||||
// Ensure that the file is not an init or a lock file
|
||||
if ((strlen(directoryEntry->d_name) < 5) ||
|
||||
(memcmp(".init", directoryEntry->d_name + strlen(directoryEntry->d_name) - 5, 5) &&
|
||||
memcmp(".lock", directoryEntry->d_name + strlen(directoryEntry->d_name) - 5, 5)))
|
||||
{
|
||||
// Determine system name of port
|
||||
char* systemName = (char*)malloc(256);
|
||||
strcpy(systemName, "/dev/");
|
||||
strcat(systemName, directoryEntry->d_name);
|
||||
|
||||
// Check if port is already enumerated
|
||||
serialPort *port = fetchPort(comPorts, systemName);
|
||||
if (port)
|
||||
port->enumerated = 1;
|
||||
else
|
||||
{
|
||||
// Set static friendly name
|
||||
char* friendlyName = (char*)malloc(256);
|
||||
if (directoryEntry->d_name[0] == 'c')
|
||||
strcpy(friendlyName, "Serial Port");
|
||||
else
|
||||
strcpy(friendlyName, "Serial Port (Dial-In)");
|
||||
|
||||
// Add the port to the list if it is not a directory
|
||||
struct stat fileStats;
|
||||
stat(systemName, &fileStats);
|
||||
if (!S_ISDIR(fileStats.st_mode))
|
||||
pushBack(comPorts, systemName, friendlyName, friendlyName);
|
||||
|
||||
// Clean up memory
|
||||
free(friendlyName);
|
||||
}
|
||||
|
||||
// Clean up memory
|
||||
free(systemName);
|
||||
}
|
||||
}
|
||||
directoryEntry = readdir(directoryIterator);
|
||||
}
|
||||
|
||||
// Close the directory
|
||||
closedir(directoryIterator);
|
||||
}
|
||||
}
|
||||
|
||||
// Apple-specific functionality
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* PosixHelperFunctions.h
|
||||
*
|
||||
* Created on: Mar 10, 2015
|
||||
* Last Updated on: Nov 29, 2021
|
||||
* Last Updated on: Nov 30, 2021
|
||||
* Author: Will Hedgecock
|
||||
*
|
||||
* Copyright (C) 2012-2021 Fazecast, Inc.
|
||||
|
@ -27,7 +27,7 @@
|
|||
#define __POSIX_HELPER_FUNCTIONS_HEADER_H__
|
||||
|
||||
// Serial port JNI header file
|
||||
#include "../com_fazecast_jSerialComm_SerialPort.h"
|
||||
#include "com_fazecast_jSerialComm_SerialPort.h"
|
||||
|
||||
// Serial port data structure
|
||||
typedef struct serialPort
|
||||
|
@ -84,6 +84,12 @@ extern int ioctl(int __fd, int __request, ...);
|
|||
int flock(int fd, int op);
|
||||
void searchForComPorts(serialPortVector* comPorts);
|
||||
|
||||
// FreeBSD-specific functionality
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
typedef int baud_rate;
|
||||
void searchForComPorts(serialPortVector* comPorts);
|
||||
|
||||
// Apple-specific functionality
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
|
|
|
@ -90,11 +90,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommP
|
|||
driverBasedSearchForComPorts(&serialPorts, "/proc/tty/driver/mvebu_serial", "/dev/ttyMV");
|
||||
lastDitchSearchForComPorts(&serialPorts);
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
recursiveSearchForComPorts(&serialPorts, "/sys/devices/");
|
||||
|
||||
#elif defined(__sun__) || defined(__APPLE__)
|
||||
#elif defined(__sun__) || defined(__APPLE__) || defined(__FreeBSD__)
|
||||
|
||||
searchForComPorts(&serialPorts);
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ public final class SerialPort
|
|||
static private final String versionString = "2.8.0";
|
||||
static private final String tmpdirAppIdProperty = "fazecast.jSerialComm.appid";
|
||||
static private volatile boolean isAndroid = false;
|
||||
static private volatile boolean isUnixBased = false;
|
||||
static private volatile boolean isWindows = false;
|
||||
static
|
||||
{
|
||||
|
@ -120,7 +119,6 @@ public final class SerialPort
|
|||
libraryPath = "OSX/x86_64";
|
||||
else
|
||||
libraryPath = "OSX/x86";
|
||||
isUnixBased = true;
|
||||
fileName = "libjSerialComm.jnilib";
|
||||
}
|
||||
else if ((OS.indexOf("sunos") >= 0) || (OS.indexOf("solaris") >= 0))
|
||||
|
@ -129,7 +127,16 @@ public final class SerialPort
|
|||
libraryPath = (System.getProperty("os.arch").indexOf("sparc") >= 0) ? "Solaris/sparcv9_64" : "Solaris/x86_64";
|
||||
else
|
||||
libraryPath = (System.getProperty("os.arch").indexOf("sparc") >= 0) ? "Solaris/sparcv8plus_32" : "Solaris/x86";
|
||||
isUnixBased = true;
|
||||
fileName = "libjSerialComm.so";
|
||||
}
|
||||
else if (OS.indexOf("freebsd") >= 0)
|
||||
{
|
||||
if (System.getProperty("os.arch").equals("aarch64") || System.getProperty("os.arch").equals("arm64"))
|
||||
libraryPath = "FreeBSD/arm64";
|
||||
if (System.getProperty("os.arch").indexOf("64") >= 0)
|
||||
libraryPath = "FreeBSD/x86_64";
|
||||
else
|
||||
libraryPath = "FreeBSD/x86";
|
||||
fileName = "libjSerialComm.so";
|
||||
}
|
||||
else if ((OS.indexOf("nix") >= 0) || (OS.indexOf("nux") >= 0) || (OS.indexOf("bsd") >= 0))
|
||||
|
@ -211,7 +218,6 @@ public final class SerialPort
|
|||
libraryPath = "Linux/x86_64";
|
||||
else
|
||||
libraryPath = "Linux/x86";
|
||||
isUnixBased = true;
|
||||
fileName = "libjSerialComm.so";
|
||||
}
|
||||
else
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue