nitc: refactor MModule cflags and ldflags to support different target platforms
[nit.git] / src / ffi / java.nit
index c0070b5..7827dac 100644 (file)
@@ -242,8 +242,8 @@ redef class MModule
        # Tell the C compiler where to find jni.h and how to link with libjvm
        private fun insert_compiler_options
        do
-               c_compiler_options = "{c_compiler_options} -I $(JAVA_HOME)/include/"
-               c_linker_options = "{c_linker_options} -L $(JNI_LIB_PATH) -ljvm"
+               cflags.add_one("", "-I $(JAVA_HOME)/include/ -I $(JAVA_HOME)/include/linux/")
+               ldflags.add_one("", "-L $(JNI_LIB_PATH) -ljvm")
        end
 
        # Name of the generated Java class where to store all implementation methods of this module
@@ -334,7 +334,6 @@ class JavaClassTemplate
        super Template
 
        var java_class_name: String
-       init(name: String) do self.java_class_name = name
 
        var header = new Template
        var class_content = new Template
@@ -398,7 +397,6 @@ class ForeignJavaType
        super ForeignType
 
        var java_type: String
-       init (java_type: String) do self.java_type = java_type
 end
 
 redef class NitniCallback
@@ -520,6 +518,35 @@ redef class MClassType
                                else break
                        end
 
+                       # Change `float[]` to `[float`
+                       if jni_type.has('[') then
+                               var depth = jni_type.chars.count('[')
+                               var java_type = jni_type.replace("[]", "")
+                               var short
+
+                               if java_type == "boolean" then
+                                       short = "Z"
+                               else if java_type == "byte" then
+                                       short = "B"
+                               else if java_type == "char" then
+                                       short = "C"
+                               else if java_type == "short" then
+                                       short = "S"
+                               else if java_type == "int" then
+                                       short = "I"
+                               else if java_type == "long" then
+                                       short = "J"
+                               else if java_type == "float" then
+                                       short = "F"
+                               else if java_type == "double" then
+                                       short = "D"
+                               else
+                                       short = "L{java_type};"
+                               end
+
+                               return "["*depth + short
+                       end
+
                        return "L{jni_type};"
                end
                if mclass.name == "Bool" then return "Z"
@@ -532,6 +559,7 @@ redef class MClassType
        redef fun jni_signature_alt
        do
                var ftype = mclass.ftype
+
                if ftype isa ForeignJavaType then return "Object"
                if mclass.name == "Bool" then return "Boolean"
                if mclass.name == "Char" then return "Char"