From b0021a24ff3b8c6493173a63b8a3681223819f68 Mon Sep 17 00:00:00 2001 From: PerfectCarl Date: Sun, 8 Jun 2014 12:15:08 +0200 Subject: [PATCH] Patch for windows I'm not sure that those changes are compatible with cross compiling for windows. Also added better logging in case of error --- .../java/org/robovm/llvm/NativeLibrary.java | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/llvm/src/main/java/org/robovm/llvm/NativeLibrary.java b/llvm/src/main/java/org/robovm/llvm/NativeLibrary.java index 658ed818d..c1032089d 100644 --- a/llvm/src/main/java/org/robovm/llvm/NativeLibrary.java +++ b/llvm/src/main/java/org/robovm/llvm/NativeLibrary.java @@ -38,22 +38,37 @@ public class NativeLibrary { static { String osProp = System.getProperty("os.name").toLowerCase(); String archProp = System.getProperty("os.arch").toLowerCase(); - if (osProp.startsWith("mac") || osProp.startsWith("darwin")) { +if (osProp.startsWith("mac") || osProp.startsWith("darwin")) { os = "macosx"; + libName = "librobovm-llvm" + ".dylib"; } else if (osProp.startsWith("linux")) { os = "linux"; + libName = "librobovm-llvm" + ".so"; + } else if (osProp.startsWith("windows")) { + os = "windows"; + libName = "librobovm-llvm" + ".dll"; } else { throw new Error("Unsupported OS: " + System.getProperty("os.name")); } - if (archProp.matches("amd64|x86[-_]64")) { - arch = "x86_64"; - } else if (archProp.matches("i386|x86")) { - arch = "x86"; + if ("windows".equals(os)) { + String model = System.getProperty("sun.arch.data.model"); + if ("32".equals(model)) + arch = "x86"; + else if ("64".equals(model)) + arch = "x86_64"; + else + throw new Error("Unsupported sun.arch.data.model: " + model); + } else { - throw new Error("Unsupported arch: " + System.getProperty("os.arch")); + if (archProp.matches("amd64|x86[-_]64")) { + arch = "x86_64"; + } else if (archProp.matches("i386|x86")) { + arch = "x86"; + } else { + throw new Error("Unsupported arch: " + + System.getProperty("os.arch")); + } } - - libName = "librobovm-llvm" + (os.equals("macosx") ? ".dylib" : ".so"); } public static synchronized void load() { @@ -64,9 +79,11 @@ public static synchronized void load() { String prefix = libName.substring(0, libName.lastIndexOf('.')); String ext = libName.substring(libName.lastIndexOf('.')); - InputStream in = NativeLibrary.class.getResourceAsStream("binding/" + os + "/" + arch + "/" + libName); + String path = "binding/" + os + "/" + arch + "/" + libName; + InputStream in = NativeLibrary.class.getResourceAsStream(path); if (in == null) { - throw new UnsatisfiedLinkError("Native library for " + os + "-" + arch + " not found"); + throw new UnsatisfiedLinkError("Native library for " + os + "-" + + arch + " not found. Path: " + path); } OutputStream out = null; File tmpLibFile = null; @@ -82,11 +99,22 @@ public static synchronized void load() { closeQuietly(out); } - Runtime.getRuntime().load(tmpLibFile.getAbsolutePath()); - if (!LLVM.StartMultithreaded()) { - throw new UnsatisfiedLinkError("LLVMStartMultithreaded failed"); + path= tmpLibFile.getAbsolutePath() ; + + boolean result=true; + try { + Runtime.getRuntime().load(path); + result = !LLVM.StartMultithreaded(); + } catch (Throwable e) { + String message = "Error while loading: " +path ; + throw new RuntimeException(message, e) ; + } + if (result) { + String message = "LLVMStartMultithreaded failed while loading: " +path ; + throw new UnsatisfiedLinkError(message); } + LLVM.InitializeAllTargets(); LLVM.InitializeAllTargetInfos(); LLVM.InitializeAllTargetMCs();