nitg: support compilation of Java files to .jar
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 14 Mar 2014 22:00:53 +0000 (18:00 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 10 Apr 2014 15:32:31 +0000 (11:32 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/abstract_compiler.nit
src/c_tools.nit
src/common_ffi/cpp.nit
src/common_ffi/java.nit

index 53648f4..1a67709 100644 (file)
@@ -324,6 +324,8 @@ class MakefileToolchain
                        dep_rules.add(o)
                end
 
+               var java_files = new Array[ExternFile]
+
                # Compile each required extern body into a specific .o
                for f in compiler.extern_bodies do
                        var o = f.makefile_rule_name
@@ -331,7 +333,21 @@ class MakefileToolchain
                        makefile.write("{o}: {ff}\n")
                        makefile.write("\t{f.makefile_rule_content}\n\n")
                        dep_rules.add(f.makefile_rule_name)
-                       ofiles.add(o)
+
+                       if f.compiles_to_o_file then ofiles.add(o)
+                       if f.add_to_jar then java_files.add(f)
+               end
+               
+               if not java_files.is_empty then
+                       var jar_file = "{outpath}.jar"
+
+                       var class_files_array = new Array[String]
+                       for f in java_files do class_files_array.add(f.makefile_rule_name)
+                       var class_files = class_files_array.join(" ")
+
+                       makefile.write("{jar_file}: {class_files}\n")
+                       makefile.write("\tjar cf {jar_file} {class_files}\n\n")
+                       dep_rules.add jar_file
                end
 
                # Link edition
index 9abb685..07934dd 100644 (file)
@@ -111,6 +111,10 @@ class ExternFile
        # The content of the rule in the make
        # Usually the one-line shell command after the tabulation
        fun makefile_rule_content: String is abstract
+
+       fun compiles_to_o_file: Bool do return false
+
+       fun add_to_jar: Bool do return false
 end
 
 # An extern C file to compile
@@ -141,5 +145,7 @@ class ExternCFile
                var o = makefile_rule_name
                return "$(CC) $(CFLAGS) {self.cflags} -c -o {o} {ff}"
        end
+
+       redef fun compiles_to_o_file do return true
 end
 
index be4d374..6aa837d 100644 (file)
@@ -190,6 +190,7 @@ class ExternCppFile
 
        redef fun makefile_rule_name do return "{filename.basename("")}.o"
        redef fun makefile_rule_content do return "g++ {mmodule.cpp_compiler_options} -c {filename.basename("")} -o {filename.basename("")}.o"
+       redef fun compiles_to_o_file do return true
 end
 
 class ForeignCppType
index 47a1d91..fbb9c2c 100644 (file)
@@ -232,8 +232,8 @@ redef class AModule
        # 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"
+               mmodule.c_compiler_options = "{mmodule.c_compiler_options} -I $(JAVA_HOME)/include/"
+               mmodule.c_linker_options = "{mmodule.c_linker_options} -L $(JNI_LIB_PATH) -ljvm"
        end
 end
 
@@ -332,6 +332,7 @@ class JavaFile
 
        redef fun makefile_rule_name do return "{filename.basename(".java")}.class"
        redef fun makefile_rule_content do return "javac {filename} -d ."
+       redef fun add_to_jar do return true
 end
 
 # Context in pure Java code