Add option --compdir to specify the compilation directory.
authorJean Privat <jean@pryen.org>
Fri, 26 Dec 2008 02:40:03 +0000 (21:40 -0500)
committerJean Privat <jean@pryen.org>
Fri, 26 Dec 2008 02:40:03 +0000 (21:40 -0500)
By the way, rename the badly named 'base_dir' attrbute to 'compdir'.

src/compiling/compiling.nit
src/compiling/compiling_base.nit
src/nitc.nit

index 59503a7..43372c8 100644 (file)
@@ -35,14 +35,14 @@ redef class MMSrcModule
 
                var ga = global_analysis(tc)
 
-               tc.base_dir.mkdir
+               tc.compdir.mkdir
 
                var files = new Array[String]
                var includes = new ArraySet[String]
                files.add("$CLIBDIR/nit_main.c")
                for m in mhe.greaters_and_self do
                        assert m isa MMSrcModule
-                       files.add("{tc.base_dir}/{m.name}.{tc.ext_prefix}_sep.c")
+                       files.add("{tc.compdir}/{m.name}.{tc.ext_prefix}_sep.c")
                        m.compile_separate_module(tc, ga)
                        var native_name = m.filename.strip_extension(".nit")
                        if (native_name + "_nit.h").file_exists then
@@ -52,15 +52,15 @@ redef class MMSrcModule
                        if native_name.file_exists then files.add(native_name)
                end
 
-               files.add("{tc.base_dir}/{name}.{tc.ext_prefix}_tables.c")
+               files.add("{tc.compdir}/{name}.{tc.ext_prefix}_tables.c")
                compile_main(tc, ga)
 
-               var fn = "{tc.base_dir}/{name}.{tc.ext_prefix}_build.sh"
+               var fn = "{tc.compdir}/{name}.{tc.ext_prefix}_build.sh"
                var f = new OFStream.open(fn)
                f.write("#!/bin/sh\n")
                f.write("# This shell script is generated by NIT to compile the program {name}.\n")
                f.write("CLIBDIR=\"{tc.clibdir}\"\n")
-               f.write("{tc.bindir}/gccx -d {tc.base_dir} -I $CLIBDIR {includes.join(" ")}")
+               f.write("{tc.bindir}/gccx -d {tc.compdir} -I $CLIBDIR {includes.join(" ")}")
                if tc.output_file != null then 
                        f.write(" -o {tc.output_file}")
                else if tc.ext_prefix.is_empty then
@@ -86,7 +86,7 @@ redef class MMSrcModule
                v.add_decl("#include <nit_common.h>")
                compile_tables_to_c(v)
                compile_main_part(v)
-               var f = new OFStream.open("{tc.base_dir}/{name}.{tc.ext_prefix}_tables.c")
+               var f = new OFStream.open("{tc.compdir}/{name}.{tc.ext_prefix}_tables.c")
                f.write("/* This C file is generated by NIT to compile program {name}. */\n")
                for m in mhe.greaters_and_self do
                        f.write("#include \"{m.name}.{tc.ext_prefix}_sep.h\"\n")
@@ -107,7 +107,7 @@ redef class MMSrcModule
                if native_name.file_exists then v.add_decl("#include <{native_name.basename("")}>")
                declare_class_tables_to_c(v)
                compile_mod_to_c(v)
-               var f = new OFStream.open("{tc.base_dir}/{name}.{tc.ext_prefix}_sep.h")
+               var f = new OFStream.open("{tc.compdir}/{name}.{tc.ext_prefix}_sep.h")
                f.write("/* This C header file is generated by NIT to compile modules and programs that requires {name}. */\n")
                f.write("#ifndef {name}_sep\n")
                f.write("#define {name}_sep\n")
@@ -115,7 +115,7 @@ redef class MMSrcModule
                f.write(v.ctx.decls.join("\n"))
                f.write("\n#endif\n")
                f.close
-               var f = new OFStream.open("{tc.base_dir}/{name}.{tc.ext_prefix}_sep.c")
+               var f = new OFStream.open("{tc.compdir}/{name}.{tc.ext_prefix}_sep.c")
                f.write("/* This C file is generated by NIT to compile module {name}. */\n")
                f.write("#include \"{name}.{tc.ext_prefix}_sep.h\"\n")
                f.write(v.ctx.instrs.join("\n"))
index c5bf61d..5785775 100644 (file)
@@ -23,7 +23,7 @@ private import utils
 redef class ToolContext
        readable writable attr _global: Bool 
        readable writable attr _attr_sim: Bool 
-       readable writable attr _base_dir: String
+       readable writable attr _compdir: String
        readable writable attr _clibdir: String
        readable writable attr _bindir: String
        readable writable attr _output_file: String
index a3c9fa6..d288e81 100644 (file)
@@ -30,12 +30,13 @@ special AbstractCompiler
        readable attr _opt_global: OptionBool = new OptionBool("Use global compilation", "--global")
        readable attr _opt_clibdir: OptionString = new OptionString("NIT C library directory", "--clibdir")
        readable attr _opt_bindir: OptionString = new OptionString("NIT tools directory", "--bindir")
+       readable attr _opt_compdir: OptionString = new OptionString("Intermediate compilation directory", "--compdir")
        readable attr _opt_extension_prefix: OptionString = new OptionString("Append prefix to file extension", "-p", "--extension-prefix")
 
        init
        do
                super
-               option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_attr_sim, opt_global, opt_clibdir, opt_bindir, opt_extension_prefix)
+               option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_attr_sim, opt_global, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix)
        end
 
        redef meth process_options
@@ -48,7 +49,17 @@ special AbstractCompiler
                if ext_prefix == null then ext_prefix = ""
                attr_sim = opt_attr_sim.value
                global = opt_global.value
-               base_dir = ".nit_compile"
+               compdir = opt_compdir.value
+               if compdir == null then
+                       var dir = once ("NIT_COMPDIR".to_symbol).environ
+                       if not dir.is_empty then 
+                               compdir = dir
+                       end
+                       if compdir == null then
+                               compdir = ".nit_compile"
+                       end
+               end
+
                clibdir = opt_clibdir.value
                if clibdir == null then
                        var dir = once ("NIT_DIR".to_symbol).environ
@@ -65,6 +76,7 @@ special AbstractCompiler
                        end
                end
                bindir = opt_bindir.value
+
                if bindir == null then
                        var dir = once ("NIT_DIR".to_symbol).environ
                        if dir.is_empty then