2022-06-06 13:09:32 +00:00
|
|
|
import os
|
2024-02-14 14:32:27 +00:00
|
|
|
import common_compiler_flags
|
2023-09-20 08:08:09 +00:00
|
|
|
from SCons.Util import WhereIs
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
2023-09-20 08:08:09 +00:00
|
|
|
return WhereIs("emcc") is not None
|
2022-06-06 13:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate(env):
|
|
|
|
if env["arch"] not in ("wasm32"):
|
|
|
|
print("Only wasm32 supported on web. Exiting.")
|
2023-09-09 08:55:53 +00:00
|
|
|
env.Exit(1)
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2023-10-15 10:01:45 +00:00
|
|
|
# Emscripten toolchain
|
2022-06-06 13:09:32 +00:00
|
|
|
env["CC"] = "emcc"
|
|
|
|
env["CXX"] = "em++"
|
|
|
|
env["AR"] = "emar"
|
|
|
|
env["RANLIB"] = "emranlib"
|
2023-10-15 10:01:45 +00:00
|
|
|
|
2022-06-06 13:09:32 +00:00
|
|
|
# Use TempFileMunge since some AR invocations are too long for cmd.exe.
|
|
|
|
# Use POSIX-style paths, required with TempFileMunge.
|
|
|
|
env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix")
|
|
|
|
env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}"
|
|
|
|
|
2023-10-15 10:01:45 +00:00
|
|
|
# All intermediate files are just object files.
|
|
|
|
env["OBJSUFFIX"] = ".o"
|
|
|
|
env["SHOBJSUFFIX"] = ".o"
|
|
|
|
|
|
|
|
# Static libraries clang-style.
|
|
|
|
env["LIBPREFIX"] = "lib"
|
|
|
|
env["LIBSUFFIX"] = ".a"
|
|
|
|
|
|
|
|
# Shared library as wasm.
|
|
|
|
env["SHLIBSUFFIX"] = ".wasm"
|
|
|
|
|
2023-09-20 08:08:09 +00:00
|
|
|
# Thread support (via SharedArrayBuffer).
|
|
|
|
env.Append(CCFLAGS=["-s", "USE_PTHREADS=1"])
|
|
|
|
env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"])
|
|
|
|
|
2023-10-15 10:01:45 +00:00
|
|
|
# Build as side module (shared library).
|
|
|
|
env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"])
|
|
|
|
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"])
|
2022-06-06 13:09:32 +00:00
|
|
|
|
2023-07-22 12:46:14 +00:00
|
|
|
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])
|
2024-02-14 14:32:27 +00:00
|
|
|
|
|
|
|
common_compiler_flags.generate(env)
|