Skip to content

Commit

Permalink
Fixed windows compatibility issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JorenSix committed Jan 19, 2023
1 parent 3a74af1 commit b970370
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ bin
*.raw
*.class

zig-out/
zig-cache/

*.DS_Store
.gradle
gaborator/*dll
Expand Down
12 changes: 6 additions & 6 deletions gaborator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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



9 changes: 9 additions & 0 deletions gaborator/gaborator-1.7/gaborator/gaborator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
#include <map>
#include <typeinfo>

#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"
Expand All @@ -34,6 +42,7 @@
#include "gaborator/vector_math.h"



namespace gaborator {

using std::complex;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/be/ugent/jgaborator/JGaborator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/be/ugent/jgaborator/util/ZigNativeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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<String> 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);
Expand All @@ -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{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b970370

Please sign in to comment.