Merge: Nit for mac
authorJean Privat <jean@pryen.org>
Mon, 23 Jun 2014 19:30:53 +0000 (15:30 -0400)
committerJean Privat <jean@pryen.org>
Mon, 23 Jun 2014 19:30:53 +0000 (15:30 -0400)
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 <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

c_src/Makefile
src/Makefile
src/abstract_compiler.nit
src/global_compiler.nit
src/mkcsrc
tests/sav/nitg-s/fixme/base_attr_gen_alt1.res
tests/sav/nitg-sg/fixme/base_attr_gen_alt1.res
tests/tests.sh

index 1453943..d94866c 100644 (file)
@@ -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
 
index 211287d..2ca0fb7 100644 (file)
@@ -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 '***************************************************************'
index 99b84be..e8d0179 100644 (file)
@@ -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]
index 8c6ac6c..9e79281 100644 (file)
@@ -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
index a408697..7ba4466 100755 (executable)
@@ -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
index 5672bc1..6cfb9be 100755 (executable)
@@ -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