aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-07-25 02:24:01 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-07-26 23:54:58 +0200
commitbe1d0545c2f7a85a63d05b4bdc1020ee284e72cb (patch)
tree09cb0fa0a1dbe83d4833bcd62dc8832161e4329b /tools
parent65443efcc2f4c7d687b2bd9c631f6bb426688bbf (diff)
Initial structural commit
Diffstat (limited to 'tools')
-rw-r--r--tools/linux.py35
-rw-r--r--tools/macos.py51
-rw-r--r--tools/macos_osxcross.py29
-rw-r--r--tools/my_spawn.py53
-rw-r--r--tools/targets.py93
-rw-r--r--tools/windows.py73
6 files changed, 334 insertions, 0 deletions
diff --git a/tools/linux.py b/tools/linux.py
new file mode 100644
index 0000000..0a2c35c
--- /dev/null
+++ b/tools/linux.py
@@ -0,0 +1,35 @@
+# Copied from https://github.com/godotengine/godot-cpp/blob/2bf983e6382f5236948f7740faf130a3568f9dd0/tools/linux.py
+from SCons.Variables import *
+from SCons.Tool import clang, clangxx
+
+
+def options(opts):
+ opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux", False))
+
+
+def exists(env):
+ return True
+
+
+def generate(env):
+ if env["use_llvm"]:
+ clang.generate(env)
+ clangxx.generate(env)
+
+ env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
+ env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
+
+ if env["arch"] == "x86_64":
+ # -m64 and -m32 are x86-specific already, but it doesn't hurt to
+ # be clear and also specify -march=x86-64. Similar with 32-bit.
+ env.Append(CCFLAGS=["-m64", "-march=x86-64"])
+ env.Append(LINKFLAGS=["-m64", "-march=x86-64"])
+ elif env["arch"] == "x86_32":
+ env.Append(CCFLAGS=["-m32", "-march=i686"])
+ env.Append(LINKFLAGS=["-m32", "-march=i686"])
+ elif env["arch"] == "arm64":
+ env.Append(CCFLAGS=["-march=armv8-a"])
+ env.Append(LINKFLAGS=["-march=armv8-a"])
+ elif env["arch"] == "rv64":
+ env.Append(CCFLAGS=["-march=rv64gc"])
+ env.Append(LINKFLAGS=["-march=rv64gc"])
diff --git a/tools/macos.py b/tools/macos.py
new file mode 100644
index 0000000..f0fb81a
--- /dev/null
+++ b/tools/macos.py
@@ -0,0 +1,51 @@
+# Copied from https://github.com/godotengine/godot-cpp/blob/2bf983e6382f5236948f7740faf130a3568f9dd0/tools/macos.py
+import os
+import sys
+import macos_osxcross
+
+
+def options(opts):
+ opts.Add("macos_deployment_target", "macOS deployment target", "default")
+ opts.Add("macos_sdk_path", "macOS SDK path", "")
+ macos_osxcross.options(opts)
+
+
+def exists(env):
+ return sys.platform == "darwin" or macos_osxcross.exists(env)
+
+
+def generate(env):
+ if env["arch"] not in ("universal", "arm64", "x86_64"):
+ print("Only universal, arm64, and x86_64 are supported on macOS. Exiting.")
+ Exit()
+
+ if sys.platform == "darwin":
+ # Use clang on macOS by default
+ env["CXX"] = "clang++"
+ env["CC"] = "clang"
+ else:
+ # Use osxcross
+ macos_osxcross.generate(env)
+
+ if env["arch"] == "universal":
+ env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"])
+ env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"])
+ else:
+ env.Append(LINKFLAGS=["-arch", env["arch"]])
+ env.Append(CCFLAGS=["-arch", env["arch"]])
+
+ if env["macos_deployment_target"] != "default":
+ env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
+ env.Append(LINKFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]])
+
+ if env["macos_sdk_path"]:
+ env.Append(CCFLAGS=["-isysroot", env["macos_sdk_path"]])
+ env.Append(LINKFLAGS=["-isysroot", env["macos_sdk_path"]])
+
+ env.Append(
+ LINKFLAGS=[
+ "-framework",
+ "Cocoa",
+ "-Wl,-undefined,dynamic_lookup",
+ ]
+ )
diff --git a/tools/macos_osxcross.py b/tools/macos_osxcross.py
new file mode 100644
index 0000000..8ed9a5d
--- /dev/null
+++ b/tools/macos_osxcross.py
@@ -0,0 +1,29 @@
+# Copied from https://github.com/godotengine/godot-cpp/blob/0ee980abae91c481009152cdccab8e61c9625303/tools/macos_osxcross.py
+import os
+
+
+def options(opts):
+ opts.Add("osxcross_sdk", "OSXCross SDK version", "darwin16")
+
+
+def exists(env):
+ return "OSXCROSS_ROOT" in os.environ
+
+
+def generate(env):
+ root = os.environ.get("OSXCROSS_ROOT", "")
+ if env["arch"] == "arm64":
+ basecmd = root + "/target/bin/arm64-apple-" + env["osxcross_sdk"] + "-"
+ else:
+ basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
+
+ env["CC"] = basecmd + "clang"
+ env["CXX"] = basecmd + "clang++"
+ env["AR"] = basecmd + "ar"
+ env["RANLIB"] = basecmd + "ranlib"
+ env["AS"] = basecmd + "as"
+
+ binpath = os.path.join(root, "target", "bin")
+ if binpath not in env["ENV"]["PATH"]:
+ # Add OSXCROSS bin folder to PATH (required for linking).
+ env["ENV"]["PATH"] = "%s:%s" % (binpath, env["ENV"]["PATH"])
diff --git a/tools/my_spawn.py b/tools/my_spawn.py
new file mode 100644
index 0000000..915f972
--- /dev/null
+++ b/tools/my_spawn.py
@@ -0,0 +1,53 @@
+# Copied from https://github.com/godotengine/godot-cpp/blob/93f2091185ff4390ca8fc8901ebc68ebc35a218f/tools/my_spawn.py
+import os
+
+
+def exists(env):
+ return os.name == "nt"
+
+
+# Workaround for MinGW. See:
+# http://www.scons.org/wiki/LongCmdLinesOnWin32
+def configure(env):
+ import subprocess
+
+ def mySubProcess(cmdline, env):
+ # print "SPAWNED : " + cmdline
+ startupinfo = subprocess.STARTUPINFO()
+ startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+ proc = subprocess.Popen(
+ cmdline,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ startupinfo=startupinfo,
+ shell=False,
+ env=env,
+ )
+ data, err = proc.communicate()
+ rv = proc.wait()
+ if rv:
+ print("=====")
+ print(err.decode("utf-8"))
+ print("=====")
+ return rv
+
+ def mySpawn(sh, escape, cmd, args, env):
+
+ newargs = " ".join(args[1:])
+ cmdline = cmd + " " + newargs
+
+ rv = 0
+ if len(cmdline) > 32000 and cmd.endswith("ar"):
+ cmdline = cmd + " " + args[1] + " " + args[2] + " "
+ for i in range(3, len(args)):
+ rv = mySubProcess(cmdline + args[i], env)
+ if rv:
+ break
+ else:
+ rv = mySubProcess(cmdline, env)
+
+ return rv
+
+ env["SPAWN"] = mySpawn
+ env.Replace(ARFLAGS=["q"])
diff --git a/tools/targets.py b/tools/targets.py
new file mode 100644
index 0000000..5c33555
--- /dev/null
+++ b/tools/targets.py
@@ -0,0 +1,93 @@
+# Copied from https://github.com/godotengine/godot-cpp/blob/edf02f83194b58408ca241459c986e32c52fd9c7/tools/targets.py
+import os
+import sys
+from SCons.Script import ARGUMENTS
+from SCons.Variables import *
+from SCons.Variables.BoolVariable import _text2bool
+
+
+def get_cmdline_bool(option, default):
+ """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
+ and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
+ """
+ cmdline_val = ARGUMENTS.get(option)
+ if cmdline_val is not None:
+ return _text2bool(cmdline_val)
+ else:
+ return default
+
+
+def options(opts):
+ opts.Add(
+ EnumVariable(
+ "optimize",
+ "The desired optimization flags",
+ "speed_trace",
+ ("none", "custom", "debug", "speed", "speed_trace", "size"),
+ )
+ )
+ opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", True))
+ opts.Add(BoolVariable("dev_build", "Developer build with dev-only debugging code (DEV_ENABLED)", False))
+
+
+def exists(env):
+ return True
+
+
+def generate(env):
+ env.dev_build = env["dev_build"]
+ env.debug_features = env["target"] in ["editor", "template_debug"]
+ env.editor_build = env["target"] == "editor"
+
+ if env.editor_build:
+ env.AppendUnique(CPPDEFINES=["TOOLS_ENABLED"])
+
+ if env.debug_features:
+ env.AppendUnique(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
+
+ if env.dev_build:
+ opt_level = "none"
+ env.AppendUnique(CPPDEFINES=["DEV_ENABLED"])
+ elif env.debug_features:
+ opt_level = "speed_trace"
+ else: # Release
+ opt_level = "speed"
+
+ env["optimize"] = ARGUMENTS.get("optimize", opt_level)
+ env["debug_symbols"] = get_cmdline_bool("debug_symbols", env.dev_build)
+
+ if env.get("is_msvc", False):
+ if env["debug_symbols"]:
+ env.Append(CCFLAGS=["/Zi", "/FS"])
+ env.Append(LINKFLAGS=["/DEBUG:FULL"])
+
+ if env["optimize"] == "speed" or env["optimize"] == "speed_trace":
+ env.Append(CCFLAGS=["/O2"])
+ env.Append(LINKFLAGS=["/OPT:REF"])
+ elif env["optimize"] == "size":
+ env.Append(CCFLAGS=["/O1"])
+ env.Append(LINKFLAGS=["/OPT:REF"])
+
+ if env["optimize"] == "debug" or env["optimize"] == "none":
+ env.Append(CCFLAGS=["/MDd", "/Od"])
+ else:
+ env.Append(CCFLAGS=["/MD"])
+
+ else:
+ if env["debug_symbols"]:
+ if env.dev_build:
+ env.Append(CCFLAGS=["-g3"])
+ else:
+ env.Append(CCFLAGS=["-g2"])
+
+ if env["optimize"] == "speed":
+ env.Append(CCFLAGS=["-O3"])
+ # `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces.
+ elif env["optimize"] == "speed_trace":
+ env.Append(CCFLAGS=["-O2"])
+ elif env["optimize"] == "size":
+ env.Append(CCFLAGS=["-Os"])
+ elif env["optimize"] == "debug":
+ env.Append(CCFLAGS=["-Og"])
+ elif env["optimize"] == "none":
+ env.Append(CCFLAGS=["-O0"])
diff --git a/tools/windows.py b/tools/windows.py
new file mode 100644
index 0000000..0fd86a6
--- /dev/null
+++ b/tools/windows.py
@@ -0,0 +1,73 @@
+# Copied from https://github.com/godotengine/godot-cpp/blob/edf02f83194b58408ca241459c986e32c52fd9c7/tools/windows.py
+import sys
+
+import my_spawn
+
+from SCons.Tool import msvc, mingw
+from SCons.Variables import *
+
+
+def options(opts):
+ opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
+ opts.Add(BoolVariable("use_clang_cl", "Use the clang driver instead of MSVC - only effective on Windows", False))
+
+
+def exists(env):
+ return True
+
+
+def generate(env):
+ base = None
+ if not env["use_mingw"] and msvc.exists(env):
+ if env["arch"] == "x86_64":
+ env["TARGET_ARCH"] = "amd64"
+ elif env["arch"] == "x86_32":
+ env["TARGET_ARCH"] = "x86"
+ env["is_msvc"] = True
+
+ # MSVC, linker, and archiver.
+ msvc.generate(env)
+ env.Tool("mslib")
+ env.Tool("mslink")
+
+ env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
+ env.Append(CCFLAGS=["/EHsc", "/utf-8"])
+ env.Append(LINKFLAGS=["/WX"])
+
+ if env["use_clang_cl"]:
+ env["CC"] = "clang-cl"
+ env["CXX"] = "clang-cl"
+
+ elif sys.platform == "win32" or sys.platform == "msys":
+ env["use_mingw"] = True
+ mingw.generate(env)
+ # Don't want lib prefixes
+ env["IMPLIBPREFIX"] = ""
+ env["SHLIBPREFIX"] = ""
+ # Want dll suffix
+ env["SHLIBSUFFIX"] = ".dll"
+ # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
+ my_spawn.configure(env)
+
+ else:
+ env["use_mingw"] = True
+ # Cross-compilation using MinGW
+ prefix = "i686" if env["arch"] == "x86_32" else env["arch"]
+ env["CXX"] = prefix + "-w64-mingw32-g++"
+ env["CC"] = prefix + "-w64-mingw32-gcc"
+ env["AR"] = prefix + "-w64-mingw32-ar"
+ env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
+ env["LINK"] = prefix + "-w64-mingw32-g++"
+ # Want dll suffix
+ env["SHLIBSUFFIX"] = ".dll"
+
+ # These options are for a release build even using target=debug
+ env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
+ env.Append(
+ LINKFLAGS=[
+ "--static",
+ "-Wl,--no-undefined",
+ "-static-libgcc",
+ "-static-libstdc++",
+ ]
+ )