From b9703704645b9cd0e7951670f143b70cf1c87991 Mon Sep 17 00:00:00 2001 From: Joren Six Date: Thu, 19 Jan 2023 16:34:44 +0100 Subject: [PATCH] Fixed windows compatibility issues --- .gitignore | 3 +++ gaborator/Makefile | 12 ++++++------ gaborator/gaborator-1.7/gaborator/gaborator.h | 9 +++++++++ src/main/java/be/ugent/jgaborator/JGaborator.java | 2 +- .../be/ugent/jgaborator/util/ZigNativeUtils.java | 15 +++++++-------- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 9cb83e5..f61a1d3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ bin *.raw *.class +zig-out/ +zig-cache/ + *.DS_Store .gradle gaborator/*dll diff --git a/gaborator/Makefile b/gaborator/Makefile index fdeb192..4f98786 100644 --- a/gaborator/Makefile +++ b/gaborator/Makefile @@ -24,14 +24,14 @@ clean: zig_windows_example: echo $(JNI_INCLUDES) - zig cc -target x86_64-windows-gnu -c -O3 -ffast-math -fPIC pffft/pffft.c -o pffft/pffft.o - zig cc -target x86_64-windows-gnu -c -O3 -ffast-math -fPIC -DFFTPACK_DOUBLE_PRECISION pffft/fftpack.c -o pffft/fftpack.o - zig c++ -target x86_64-windows-gnu -I"pffft" -I"gaborator-1.7" $(JNI_INCLUDES) -shared -O3 -ffast-math -DGABORATOR_USE_PFFFT -o libjgaborator.dll jgaborator.cc pffft/pffft.o pffft/fftpack.o + zig cc -target x86_64-windows-gnu -c -O3 -ffast-math -fPIC pffft/pffft.c -o pffft/pffft.o + zig cc -target x86_64-windows-gnu -c -O3 -ffast-math -fPIC -DFFTPACK_DOUBLE_PRECISION pffft/fftpack.c -o pffft/fftpack.o + zig c++ -target x86_64-windows-gnu -I"pffft" -I"gaborator-1.7" $(JNI_INCLUDES) -O3 -ffast-math -fPIC -DGABORATOR_USE_PFFFT -shared -o jgaborator.dll jgaborator.cc pffft/fftpack.o pffft/pffft.o zig: - zig cc -target $(ZIG_TARGET_PLATFORM) -c -O3 -ffast-math -fPIC pffft/pffft.c -o pffft/pffft.o - zig cc -target $(ZIG_TARGET_PLATFORM) -c -O3 -ffast-math -fPIC -DFFTPACK_DOUBLE_PRECISION pffft/fftpack.c -o pffft/fftpack.o - zig c++ -target $(ZIG_TARGET_PLATFORM) -I"pffft" -I"gaborator-1.7" $(JNI_INCLUDES) -shared -O3 -ffast-math -DGABORATOR_USE_PFFFT -o $(ZIG_OUTPUT_FILE) jgaborator.cc pffft/pffft.o pffft/fftpack.o + zig cc -target $(ZIG_TARGET_PLATFORM) -c -O3 -ffast-math -fPIC pffft/pffft.c -o pffft/pffft.o + zig cc -target $(ZIG_TARGET_PLATFORM) -c -O3 -ffast-math -fPIC -DFFTPACK_DOUBLE_PRECISION pffft/fftpack.c -o pffft/fftpack.o + zig c++ -target $(ZIG_TARGET_PLATFORM) -I"pffft" -I"gaborator-1.7" $(JNI_INCLUDES) -O3 -ffast-math -fPIC -shared -DGABORATOR_USE_PFFFT -o $(ZIG_OUTPUT_FILE) jgaborator.cc pffft/pffft.o pffft/fftpack.o diff --git a/gaborator/gaborator-1.7/gaborator/gaborator.h b/gaborator/gaborator-1.7/gaborator/gaborator.h index 358f2e2..cd39291 100644 --- a/gaborator/gaborator-1.7/gaborator/gaborator.h +++ b/gaborator/gaborator-1.7/gaborator/gaborator.h @@ -25,6 +25,14 @@ #include #include +#ifndef M_PI + #define M_PI 3.14159265358979323846 +#endif + +#ifndef M_SQRT2 + #define M_SQRT2 1.41421356237 +#endif + #include "gaborator/fft.h" #include "gaborator/gaussian.h" #include "gaborator/affine_transform.h" @@ -34,6 +42,7 @@ #include "gaborator/vector_math.h" + namespace gaborator { using std::complex; diff --git a/src/main/java/be/ugent/jgaborator/JGaborator.java b/src/main/java/be/ugent/jgaborator/JGaborator.java index 69e61d9..c22be8e 100644 --- a/src/main/java/be/ugent/jgaborator/JGaborator.java +++ b/src/main/java/be/ugent/jgaborator/JGaborator.java @@ -49,7 +49,7 @@ public class JGaborator implements AudioProcessor{ System.err.println("Loaded jgaborator library from " + System.getProperty("java.library.path")); }catch (UnsatisfiedLinkError e ){ System.err.println("Could not load 'jgaborator' JNI library. \n Will attempt to use a precompiled version packed in the JAR archive\n" + e.getMessage()); - boolean libraryLoaded = ZigNativeUtils.loadLibraryFromJarWithOSDetection("/jni/" + System.mapLibraryName("jgaborator")); + boolean libraryLoaded = ZigNativeUtils.loadLibraryFromJarWithOSDetection("/jni","jgaborator"); } } diff --git a/src/main/java/be/ugent/jgaborator/util/ZigNativeUtils.java b/src/main/java/be/ugent/jgaborator/util/ZigNativeUtils.java index 79f4174..a381032 100644 --- a/src/main/java/be/ugent/jgaborator/util/ZigNativeUtils.java +++ b/src/main/java/be/ugent/jgaborator/util/ZigNativeUtils.java @@ -28,6 +28,7 @@ import java.net.URISyntaxException; import java.nio.file.*; import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Stream; /** @@ -61,17 +62,14 @@ private ZigNativeUtils() { /** * Load a library with OS and architecture detection. The idea is that libraries are found * - * @param path the path for the libraries + * @param folder the folder of the library with forward slashes * @return True if the library is loaded successfully */ - public static boolean loadLibraryFromJarWithOSDetection(String path) { - - String[] parts = path.split(File.separator); - String filename = (parts.length > 1) ? parts[parts.length - 1] : null; - String folder = path.replace(File.separator + filename,""); + public static boolean loadLibraryFromJarWithOSDetection(String folder,String libraryName) { + String systemLibraryName = System.mapLibraryName(libraryName); List foundLibraries; - System.err.print("Trying to find libraries ending in " + filename); + System.err.print("Trying to find libraries in folder " + folder + " ending in " + systemLibraryName); try { foundLibraries = listResources(folder); @@ -83,7 +81,7 @@ public static boolean loadLibraryFromJarWithOSDetection(String path) { System.err.print("No native JNI libraries found in JAR archive"); } for(String resourceName : foundLibraries){ - if(resourceName.contains(filename)){ + if(resourceName.contains(systemLibraryName)){ System.err.println("Try to load JNI library " + resourceName + " from JAR archive."); try{ @@ -175,6 +173,7 @@ public static void loadLibraryFromJar(String path) throws IOException { try (InputStream is = ZigNativeUtils.class.getResourceAsStream(path)) { Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING); + System.err.println("Copied library to " + temp.getAbsolutePath() + " delete after use."); } catch (IOException e) { temp.delete(); throw e;