From: Jean Privat Date: Mon, 23 Jun 2014 19:30:53 +0000 (-0400) Subject: Merge: Nit for mac X-Git-Tag: v0.6.6~20 X-Git-Url: http://nitlanguage.org?hp=c44a0753f42c5cea1ab6f458f547d9a954ede29d Merge: Nit for mac Some minor, but needed, tweaks to allow the compilation of Nit on Mac OS X A special page is also created: http://nitlanguage.org/on_mac/ Currenlty, only 31 tests does not pass, most of them are platform or FFI related (some SDK are missing). Pull-Request: #517 Reviewed-by: Lucas Bajolet Reviewed-by: Alexandre Terrasa --- diff --git a/c_src/Makefile b/c_src/Makefile index 1453943..d94866c 100644 --- a/c_src/Makefile +++ b/c_src/Makefile @@ -1,8 +1,22 @@ CC = ccache cc -CFLAGS = -g -O2 +CFLAGS = -g -O2 -Wno-unused-value -Wno-switch CINCL = -I "clib" LDFLAGS ?= -LDLIBS ?= -lm -lgc -lunwind +LDLIBS ?= -lm -lgc + +NEED_LIBUNWIND := YesPlease +uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') +ifeq ($(uname_S),Darwin) + NEED_LIBUNWIND := +endif + +clang_check := $(shell sh -c '$(CC) -v 2>&1 | grep -q clang; echo $$?') +ifeq ($(clang_check), 0) + CFLAGS += -Qunused-arguments +endif +ifdef NEED_LIBUNWIND + LDLIBS += -lunwind +endif all: nitg diff --git a/src/Makefile b/src/Makefile index 211287d..2ca0fb7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,6 +15,7 @@ # limitations under the License. NITCOPT= +OLDNITCOPT= --no-stacktrace all: ../bin/nitdoc ../bin/nitmetrics ../bin/nitg ../bin/nit ../bin/nitx ../bin/nitunit ../bin/nitlight ../bin/nitls ../bin/nitdbg_client @@ -23,7 +24,7 @@ nitg_0: ../c_src/nitg parser/parser.nit @echo '* Compile nitg_0 from NIT source files *' @echo '***************************************************************' ./git-gen-version.sh - ../c_src/nitg ${NITCOPT} -o nitg_0 -v nitg.nit + ../c_src/nitg ${OLDNITCOPT} -o nitg_0 -v nitg.nit ../bin/nitg: nitg_0 parser/parser.nit @echo '***************************************************************' diff --git a/src/abstract_compiler.nit b/src/abstract_compiler.nit index 99b84be..e8d0179 100644 --- a/src/abstract_compiler.nit +++ b/src/abstract_compiler.nit @@ -320,10 +320,28 @@ class MakefileToolchain 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] diff --git a/src/global_compiler.nit b/src/global_compiler.nit index 8c6ac6c..9e79281 100644 --- a/src/global_compiler.nit +++ b/src/global_compiler.nit @@ -124,8 +124,8 @@ class GlobalCompiler # Compile class names (for the class_name and output_class_name methods) protected fun compile_class_names do var v = new_visitor - self.header.add_decl("extern const char const * class_names[];") - v.add("const char const * class_names[] = \{") + self.header.add_decl("extern const char *class_names[];") + v.add("const char *class_names[] = \{") for t in self.runtime_type_analysis.live_types do v.add("\"{t}\", /* {self.classid(t)} */") end diff --git a/src/mkcsrc b/src/mkcsrc index a408697..7ba4466 100755 --- a/src/mkcsrc +++ b/src/mkcsrc @@ -21,3 +21,6 @@ done perl -i -npe 's#"\.\./.*?([^/]*.h)"#"\1"#' "$out"/*.[ch] perl -i -npe 's#\S*/([^/]*.[ch])#\1#' "$out/Makefile" perl -i -npe 's#\.\./clib#.#' "$out/Makefile" + +# Remove old compilation flags +sed -i -e 's/OLDNITCOPT=.*/OLDNITCOPT=/' src/Makefile diff --git a/tests/sav/nitg-s/fixme/base_attr_gen_alt1.res b/tests/sav/nitg-s/fixme/base_attr_gen_alt1.res index 2c8186c..4ad3dc3 100644 --- a/tests/sav/nitg-s/fixme/base_attr_gen_alt1.res +++ b/tests/sav/nitg-s/fixme/base_attr_gen_alt1.res @@ -1 +1 @@ -Caught signal : Segmentation fault +UNDEFINED diff --git a/tests/sav/nitg-sg/fixme/base_attr_gen_alt1.res b/tests/sav/nitg-sg/fixme/base_attr_gen_alt1.res index 2c8186c..4ad3dc3 100644 --- a/tests/sav/nitg-sg/fixme/base_attr_gen_alt1.res +++ b/tests/sav/nitg-sg/fixme/base_attr_gen_alt1.res @@ -1 +1 @@ -Caught signal : Segmentation fault +UNDEFINED diff --git a/tests/tests.sh b/tests/tests.sh index 5672bc1..6cfb9be 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -19,6 +19,7 @@ # Set lang do default to avoid failed tests because of locale export LANG=C +export LC_ALL=C export NIT_TESTING=true unset NIT_DIR