nitc: `Toolchain` keeps the compiler as an attribute
[nit.git] / src / platform / emscripten.nit
1 # This file is part of NIT ( http://www.nitlanguage.org )
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Compile to JavaScript using the Emscripten SDK
18 module emscripten
19
20 import platform
21 import compiler::abstract_compiler
22
23 redef class ToolContext
24 redef fun platform_from_name(name)
25 do
26 if name == "emscripten" then return new EmscriptenPlatform
27 return super
28 end
29 end
30
31 class EmscriptenPlatform
32 super Platform
33
34 redef fun name do return "emscripten"
35 redef fun supports_libunwind do return false
36 redef fun supports_libgc do return false
37 redef fun supports_linker_script do return false
38 redef fun toolchain(toolcontext, compiler) do return new EnscriptenToolchain(toolcontext, compiler)
39 end
40
41 class EnscriptenToolchain
42 super MakefileToolchain
43
44 redef fun makefile_name do return "{super}.js.mk"
45
46 redef fun default_outname do return "{super}.js"
47
48 redef fun write_makefile(compile_dir, cfiles)
49 do
50 super
51
52 var emcc_make_flags = "CC=emcc CXX=em++ CFLAGS='-Wno-unused-value -Wno-switch -Qunused-arguments -s ALLOW_MEMORY_GROWTH=1"
53
54 var release = toolcontext.opt_release.value
55 if release then
56 emcc_make_flags += "' LDFLAGS='--minify 1'"
57 else emcc_make_flags += " -g'"
58
59 var make_flags = self.toolcontext.opt_make_flags.value or else ""
60 make_flags += emcc_make_flags
61 self.toolcontext.opt_make_flags.value = make_flags
62 end
63 end