do
if self.toolcontext.opt_stacktrace.value == "nitstack" then compiler.build_c_to_nit_bindings
+ var platform = compiler.mainmodule.target_platform
+ var cc_opt_with_libgc = "-DWITH_LIBGC"
+ if platform != null and not platform.supports_libgc then cc_opt_with_libgc = ""
+
# Add gc_choser.h to aditionnal bodies
- var gc_chooser = new ExternCFile("gc_chooser.c", "-DWITH_LIBGC")
+ var gc_chooser = new ExternCFile("gc_chooser.c", cc_opt_with_libgc)
compiler.extern_bodies.add(gc_chooser)
compiler.files_to_copy.add "{cc_paths.first}/gc_chooser.c"
compiler.files_to_copy.add "{cc_paths.first}/gc_chooser.h"
self.toolcontext.info("Total C source files to compile: {cfiles.length}", 2)
end
+ fun makefile_name(mainmodule: MModule): String do return "{mainmodule.name}.mk"
+
+ fun default_outname(mainmodule: MModule): String do return mainmodule.name
+
fun write_makefile(compiler: AbstractCompiler, compile_dir: String, cfiles: Array[String])
do
var mainmodule = compiler.mainmodule
- var outname = self.toolcontext.opt_output.value
- if outname == null then
- outname = "{mainmodule.name}"
- end
+ var outname = self.toolcontext.opt_output.value or else default_outname(mainmodule)
var orig_dir=".." # FIXME only works if `compile_dir` is a subdirectory of cwd
var outpath = orig_dir.join_path(outname).simplify_path
- var makename = "{mainmodule.name}.mk"
+ var makename = makefile_name(mainmodule)
var makepath = "{compile_dir}/{makename}"
var makefile = new OFStream.open(makepath)
if libs != null then linker_options.add_all(libs)
end
+ makefile.write("CC = ccache cc\nCFLAGS = -g -O2 -Wno-unused-value -Wno-switch\nCINCL = {cc_includes}\nLDFLAGS ?= \nLDLIBS ?= -lm -lgc {linker_options.join(" ")}\n\n")
+
var ost = toolcontext.opt_stacktrace.value
- if ost == "libunwind" or ost == "nitstack" then linker_options.add("-lunwind")
+ if ost == "libunwind" or ost == "nitstack" then makefile.write("NEED_LIBUNWIND := YesPlease\n")
+
+ # Dynamic adaptations
+ # While `platform` enable complex toolchains, they are statically applied
+ # For a dynamic adaptsation of the compilation, the generated Makefile should check and adapt things itself
+
+ # Check and adapt the targeted system
+ makefile.write("uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')\n")
+ makefile.write("ifeq ($(uname_S),Darwin)\n")
+ # remove -lunwind since it is already included on macosx
+ makefile.write("\tNEED_LIBUNWIND :=\n")
+ makefile.write("endif\n\n")
+
+ # Check and adapt for the compiler used
+ # clang need an additionnal `-Qunused-arguments`
+ makefile.write("clang_check := $(shell sh -c '$(CC) -v 2>&1 | grep -q clang; echo $$?')\nifeq ($(clang_check), 0)\n\tCFLAGS += -Qunused-arguments\nendif\n")
+
+ makefile.write("ifdef NEED_LIBUNWIND\n\tLDLIBS += -lunwind\nendif\n")
- makefile.write("CC = ccache cc\nCFLAGS = -g -O2\nCINCL = {cc_includes}\nLDFLAGS ?= \nLDLIBS ?= -lm -lgc {linker_options.join(" ")}\n\n")
makefile.write("all: {outpath}\n\n")
var ofiles = new Array[String]
fun compile_c_code(compiler: AbstractCompiler, compile_dir: String)
do
- var makename = "{compiler.mainmodule.name}.mk" # FIXME duplicated from write_makefile
+ var makename = makefile_name(compiler.mainmodule)
var makeflags = self.toolcontext.opt_make_flags.value
if makeflags == null then makeflags = ""