end
redef class ModelBuilder
+ redef init(model, toolcontext)
+ do
+ if toolcontext.opt_no_stacktrace.value and toolcontext.opt_stacktrace.value then
+ print "Cannot use --nit-stacktrace when --no-stacktrace is activated"
+ exit(1)
+ end
+
+ super
+ end
+
+ # The compilation directory
+ var compile_dir: String
+
+ # Simple indirection to `Toolchain::write_and_make`
+ protected fun write_and_make(compiler: AbstractCompiler)
+ do
+ var toolchain = new MakefileToolchain(toolcontext)
+ compile_dir = toolchain.compile_dir
+ toolchain.write_and_make compiler
+ end
+end
+
+class MakefileToolchain
# The list of directories to search for included C headers (-I for C compilers)
# The list is initially set with :
# * the toolcontext --cc-path option
# * some heuristics including the NIT_DIR environment variable and the progname of the process
# Path can be added (or removed) by the client
var cc_paths = new Array[String]
+ var toolcontext: ToolContext
- redef init(model, toolcontext)
+ fun compile_dir: String
do
- super
+ var compile_dir = toolcontext.opt_compile_dir.value
+ if compile_dir == null then compile_dir = ".nit_compile"
+ return compile_dir
+ end
+ protected fun gather_cc_paths
+ do
# Look for the the Nit clib path
var path_env = "NIT_DIR".environ
if not path_env.is_empty then
toolcontext.error(null, "Cannot determine the nit clib path. define envvar NIT_DIR.")
end
- if toolcontext.opt_no_stacktrace.value and toolcontext.opt_stacktrace.value then
- print "Cannot use --nit-stacktrace when --no-stacktrace is activated"
- exit(1)
- end
-
# Add user defined cc_paths
cc_paths.append(toolcontext.opt_cc_path.value)
if not path_env.is_empty then
cc_paths.append(path_env.split_with(':'))
end
-
- var compile_dir = toolcontext.opt_compile_dir.value
- if compile_dir == null then compile_dir = ".nit_compile"
- self.compile_dir = compile_dir
end
- # The compilation directory
- var compile_dir: String
-
- protected fun write_and_make(compiler: AbstractCompiler)
+ fun write_and_make(compiler: AbstractCompiler)
do
+ gather_cc_paths
+
var mainmodule = compiler.mainmodule
+ var compile_dir = compile_dir
# Generate the .h and .c files
# A single C file regroups many compiled rumtime functions
compiler.files_to_copy.add "{cc_paths.first}/gc_chooser.h"
# FFI
- for m in compiler.mainmodule.in_importation.greaters do if mmodule2nmodule.keys.has(m) then
- var amodule = mmodule2nmodule[m]
+ var m2m = toolcontext.modelbuilder.mmodule2nmodule
+ for m in compiler.mainmodule.in_importation.greaters do if m2m.keys.has(m) then
+ var amodule = m2m[m]
if m.uses_ffi or amodule.uses_legacy_ni then
compiler.finalize_ffi_for_module(amodule)
end
end
var linker_options = new HashSet[String]
- for m in mainmodule.in_importation.greaters do if mmodule2nmodule.keys.has(m) then
- var amod = mmodule2nmodule[m]
+ var m2m = toolcontext.modelbuilder.mmodule2nmodule
+ for m in mainmodule.in_importation.greaters do if m2m.keys.has(m) then
+ var amod = m2m[m]
linker_options.add(amod.c_linker_options)
end