+ var platform = compiler.mainmodule.target_platform
+ var toolchain
+ if platform == null then
+ toolchain = new MakefileToolchain(toolcontext)
+ else
+ toolchain = platform.toolchain(toolcontext)
+ end
+ compile_dir = toolchain.compile_dir
+ toolchain.write_and_make compiler
+ end
+end
+
+redef class Platform
+ fun toolchain(toolcontext: ToolContext): Toolchain is abstract
+end
+
+class Toolchain
+ var toolcontext: ToolContext
+
+ fun compile_dir: String
+ do
+ var compile_dir = toolcontext.opt_compile_dir.value
+ if compile_dir == null then compile_dir = ".nit_compile"
+ return compile_dir
+ end
+
+ fun write_and_make(compiler: AbstractCompiler) is abstract
+end
+
+class MakefileToolchain
+ super Toolchain
+ # 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
+ # * the NIT_CC_PATH environment variable
+ # * 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]
+
+ 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
+ var libname = "{path_env}/clib"
+ if libname.file_exists then cc_paths.add(libname)
+ end
+
+ var libname = "{sys.program_name.dirname}/../clib"
+ if libname.file_exists then cc_paths.add(libname.simplify_path)
+
+ if cc_paths.is_empty then
+ toolcontext.error(null, "Cannot determine the nit clib path. define envvar NIT_DIR.")
+ end
+
+ # Add user defined cc_paths
+ cc_paths.append(toolcontext.opt_cc_path.value)
+
+ path_env = "NIT_CC_PATH".environ
+ if not path_env.is_empty then
+ cc_paths.append(path_env.split_with(':'))
+ end
+ end
+
+ redef fun write_and_make(compiler)
+ do
+ gather_cc_paths
+