1 # This file is part of NIT ( http://www.nitlanguage.org )
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Compile to JavaScript using the Emscripten SDK
18 module emscripten_platform
21 import abstract_compiler
23 redef class ToolContext
24 redef fun platform_from_name
(name
)
26 if name
== "emscripten" then return new EmscriptenPlatform
31 class EmscriptenPlatform
34 redef fun supports_libunwind
do return false
35 redef fun supports_libgc
do return false
36 redef fun toolchain
(toolcontext
) do return new EnscriptenToolchain(toolcontext
)
39 class EnscriptenToolchain
40 super MakefileToolchain
42 redef fun makefile_name
(mainmodule
) do return "{mainmodule.name}.js.mk"
44 redef fun default_outname
(mainmodule
) do return "{super}.js"
46 redef fun write_makefile
(compiler
, compile_dir
, cfiles
)
50 var emcc_make_flags
= "CC=emcc CXX=em++ CFLAGS='-Wno-unused-value -Wno-switch -Qunused-arguments -s ALLOW_MEMORY_GROWTH=1"
52 var release
= toolcontext
.opt_release
.value
54 emcc_make_flags
+= "' LDFLAGS='--minify 1'"
55 else emcc_make_flags
+= " -g'"
57 var make_flags
= self.toolcontext
.opt_make_flags
.value
or else ""
58 make_flags
+= emcc_make_flags
59 self.toolcontext
.opt_make_flags
.value
= make_flags