2020-11-05 09:42:00 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
This file is modified version of the godot-cpp SConstruct file: https://github.com/godotengine/godot-cpp/blob/master/SConstruct
|
|
|
|
which is published under the following license:
|
|
|
|
|
|
|
|
MIT License
|
|
|
|
Copyright (c) 2017-2020 GodotNativeTools
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
# Try to detect the host platform automatically.
|
|
|
|
# This is used if no `platform` argument is passed.
|
|
|
|
if sys.platform.startswith('linux'):
|
|
|
|
host_platform = 'linux'
|
|
|
|
elif sys.platform == 'darwin':
|
|
|
|
host_platform = 'osx'
|
|
|
|
elif sys.platform == 'win32' or sys.platform == 'msys':
|
|
|
|
host_platform = 'windows'
|
|
|
|
else:
|
|
|
|
raise ValueError(
|
|
|
|
'Could not detect platform automatically, please specify with '
|
|
|
|
'platform=<platform>'
|
|
|
|
)
|
|
|
|
|
2021-06-12 10:02:22 +02:00
|
|
|
VariantDir('./thirdparty/libtsm/build', './thirdparty/libtsm/src', duplicate=0)
|
2020-11-05 09:42:00 +01:00
|
|
|
env = Environment(ENV = os.environ)
|
|
|
|
|
|
|
|
is64 = sys.maxsize > 2**32
|
|
|
|
if (
|
|
|
|
env['TARGET_ARCH'] == 'amd64' or
|
|
|
|
env['TARGET_ARCH'] == 'emt64' or
|
|
|
|
env['TARGET_ARCH'] == 'x86_64' or
|
|
|
|
env['TARGET_ARCH'] == 'arm64-v8a'
|
|
|
|
):
|
|
|
|
is64 = True
|
2020-07-11 12:45:21 +02:00
|
|
|
|
|
|
|
opts = Variables([], ARGUMENTS)
|
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'platform',
|
|
|
|
'Target platform',
|
|
|
|
host_platform,
|
2021-06-07 08:53:43 +02:00
|
|
|
allowed_values=('linux', 'javascript', 'osx', 'windows'),
|
2020-11-05 09:42:00 +01:00
|
|
|
ignorecase=2
|
|
|
|
))
|
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'bits',
|
|
|
|
'Target platform bits',
|
|
|
|
'64' if is64 else '32',
|
|
|
|
('32', '64')
|
|
|
|
))
|
|
|
|
opts.Add(EnumVariable(
|
|
|
|
'target',
|
|
|
|
'Compilation target',
|
|
|
|
'debug',
|
|
|
|
allowed_values=('debug', 'release'),
|
|
|
|
ignorecase=2
|
|
|
|
))
|
|
|
|
|
|
|
|
opts.Update(env)
|
|
|
|
Help(opts.GenerateHelpText(env))
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-07-13 06:14:30 +02:00
|
|
|
# Add PATH to environment so scons can find commands such as g++, etc.
|
|
|
|
env.AppendENVPath('PATH', os.getenv('PATH'))
|
|
|
|
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
# Compile for Linux.
|
|
|
|
if env['platform'] == 'linux':
|
2021-06-08 17:56:57 +02:00
|
|
|
env.Append(CPPDEFINES=['__linux__'])
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
env['CC'] = 'gcc'
|
|
|
|
env['CXX'] = 'g++'
|
2021-06-07 08:53:43 +02:00
|
|
|
env['LIBSUFFIX'] = '.a'
|
2020-11-05 09:42:00 +01:00
|
|
|
|
|
|
|
env.Append(CCFLAGS=['-fPIC', '-Wwrite-strings'])
|
|
|
|
env.Append(LINKFLAGS=["-Wl,-R'$$ORIGIN'"])
|
|
|
|
|
|
|
|
if env['target'] == 'debug':
|
|
|
|
env.Append(CCFLAGS=['-Og', '-g'])
|
|
|
|
elif env['target'] == 'release':
|
|
|
|
env.Append(CCFLAGS=['-O3'])
|
|
|
|
|
|
|
|
if env['bits'] == '64':
|
|
|
|
env.Append(CCFLAGS=['-m64'])
|
|
|
|
env.Append(LINKFLAGS=['-m64'])
|
|
|
|
elif env['bits'] == '32':
|
|
|
|
env.Append(CCFLAGS=['-m32'])
|
|
|
|
env.Append(LINKFLAGS=['-m32'])
|
|
|
|
|
2021-06-07 08:53:43 +02:00
|
|
|
# Compile for HTML5.
|
|
|
|
elif env['platform'] == 'javascript':
|
2021-06-08 17:56:57 +02:00
|
|
|
env.Append(CPPDEFINES=['__EMSCRIPTEN__'])
|
2021-06-07 08:53:43 +02:00
|
|
|
|
|
|
|
env['bits'] = '32'
|
|
|
|
env['CC'] = 'emcc'
|
|
|
|
env['CXX'] = 'em++'
|
|
|
|
env['AR'] = 'emar'
|
|
|
|
env['RANLIB'] = 'emranlib'
|
|
|
|
env.Append(CPPFLAGS=['-s', 'SIDE_MODULE=1'])
|
|
|
|
env.Append(LINKFLAGS=['-s', 'SIDE_MODULE=1'])
|
|
|
|
env['SHOBJSUFFIX'] = '.bc'
|
|
|
|
env['SHLIBSUFFIX'] = '.wasm'
|
|
|
|
env['OBJPREFIX'] = ''
|
|
|
|
env['OBJSUFFIX'] = '.bc'
|
|
|
|
env['PROGPREFIX'] = ''
|
|
|
|
env['PROGSUFFIX'] = ''
|
|
|
|
env['LIBSUFFIX'] = '.bc'
|
|
|
|
env['LIBPREFIXES'] = ['$LIBPREFIX']
|
|
|
|
env['LIBSUFFIXES'] = ['$LIBSUFFIX']
|
|
|
|
env.Replace(SHLINKFLAGS='$LINKFLAGS')
|
|
|
|
env.Replace(SHLINKFLAGS='$LINKFLAGS')
|
2020-11-05 09:42:00 +01:00
|
|
|
|
|
|
|
# Compile for OSX.
|
|
|
|
elif env['platform'] == 'osx':
|
2021-06-08 17:56:57 +02:00
|
|
|
env.Append(CPPDEFINES=['__APPLE__'])
|
2020-07-11 12:45:21 +02:00
|
|
|
|
|
|
|
env['CC'] = 'clang'
|
|
|
|
env['CXX'] = 'clang++'
|
2021-06-07 08:53:43 +02:00
|
|
|
env['LIBSUFFIX'] = '.a'
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
if env['bits'] == '32':
|
|
|
|
raise ValueError(
|
|
|
|
'Only 64-bit builds are supported for the macOS target.'
|
|
|
|
)
|
|
|
|
|
2020-07-11 12:45:21 +02:00
|
|
|
env.Append(CCFLAGS=['-arch', 'x86_64'])
|
2020-11-05 09:42:00 +01:00
|
|
|
env.Append(LINKFLAGS=[
|
|
|
|
'-arch',
|
|
|
|
'x86_64',
|
|
|
|
'-Wl,-undefined,dynamic_lookup',
|
|
|
|
])
|
|
|
|
|
|
|
|
if env['target'] == 'debug':
|
|
|
|
env.Append(CCFLAGS=['-Og', '-g'])
|
|
|
|
elif env['target'] == 'release':
|
|
|
|
env.Append(CCFLAGS=['-O3'])
|
|
|
|
|
|
|
|
|
|
|
|
# Compile for Windows.
|
|
|
|
elif env['platform'] == 'windows':
|
2021-06-08 17:56:57 +02:00
|
|
|
env.Append(CPPDEFINES=['__WIN32'])
|
2021-06-07 08:53:43 +02:00
|
|
|
env['LIBSUFFIX'] = '.lib'
|
2020-11-05 09:42:00 +01:00
|
|
|
|
2020-11-10 04:04:08 +01:00
|
|
|
# On Windows using MSVC.
|
2020-11-05 09:42:00 +01:00
|
|
|
if host_platform == 'windows':
|
2020-11-10 04:04:08 +01:00
|
|
|
env.Append(LINKFLAGS=['/W3', '/GR'])
|
|
|
|
if env['target'] == 'debug':
|
|
|
|
env.Append(CCFLAGS=['/Z7', '/Od', '/EHsc', '/D_DEBUG', '/MDd'])
|
|
|
|
elif env['target'] == 'release':
|
2020-11-22 16:16:38 +01:00
|
|
|
env.Append(CCFLAGS=['/O2', '/EHsc', '/DNDEBUG', '/MT'])
|
2020-11-05 09:42:00 +01:00
|
|
|
|
2020-11-10 04:04:08 +01:00
|
|
|
# On Windows, Linux, or MacOS using MinGW.
|
2020-11-05 09:42:00 +01:00
|
|
|
elif host_platform == 'linux' or host_platform == 'osx':
|
2020-11-10 04:04:08 +01:00
|
|
|
env.Append(CCFLAGS=['-std=c++14', '-Wwrite-strings'])
|
|
|
|
env.Append(LINKFLAGS=[
|
|
|
|
'--static',
|
|
|
|
'-Wl,--no-undefined',
|
|
|
|
'-static-libgcc',
|
|
|
|
'-static-libstdc++',
|
|
|
|
])
|
|
|
|
|
|
|
|
if env['target'] == 'debug':
|
|
|
|
env.Append(CCFLAGS=['-Og', '-g'])
|
|
|
|
elif env['target'] == 'release':
|
|
|
|
env.Append(CCFLAGS=['-O3'])
|
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
if env['bits'] == '64':
|
|
|
|
env['CC'] = 'x86_64-w64-mingw32-gcc'
|
|
|
|
env['CXX'] = 'x86_64-w64-mingw32-g++'
|
|
|
|
env['AR'] = "x86_64-w64-mingw32-ar"
|
|
|
|
env['RANLIB'] = "x86_64-w64-mingw32-ranlib"
|
|
|
|
env['LINK'] = "x86_64-w64-mingw32-g++"
|
|
|
|
elif env['bits'] == '32':
|
|
|
|
env['CC'] = 'i686-w64-mingw32-gcc'
|
|
|
|
env['CXX'] = 'i686-w64-mingw32-g++'
|
|
|
|
env['AR'] = "i686-w64-mingw32-ar"
|
|
|
|
env['RANLIB'] = "i686-w64-mingw32-ranlib"
|
|
|
|
env['LINK'] = "i686-w64-mingw32-g++"
|
|
|
|
|
|
|
|
|
|
|
|
# Build libtsm as a static library.
|
|
|
|
Execute([
|
2021-06-12 10:02:22 +02:00
|
|
|
Delete('thirdparty/libtsm/build/src'),
|
|
|
|
Delete('thirdparty/libtsm/build/external'),
|
|
|
|
Copy('thirdparty/libtsm/build/src', 'thirdparty/libtsm/src'),
|
|
|
|
Copy('thirdparty/libtsm/build/external', 'thirdparty/libtsm/external'),
|
2020-11-05 09:42:00 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
env.Append(CPPPATH=[
|
2021-06-12 10:02:22 +02:00
|
|
|
'thirdparty/libtsm/src/shared',
|
|
|
|
'thirdparty/libtsm/external',
|
2020-11-05 09:42:00 +01:00
|
|
|
])
|
2020-07-11 12:45:21 +02:00
|
|
|
|
|
|
|
sources = []
|
2021-06-22 08:28:03 +02:00
|
|
|
sources.append('thirdparty/libtsm/build/external/wcwidth/wcwidth.c')
|
2021-06-12 10:02:22 +02:00
|
|
|
sources.append('thirdparty/libtsm/build/src/shared/shl-htable.c')
|
|
|
|
sources.append(Glob('thirdparty/libtsm/build/src/tsm/*.c'))
|
2020-07-11 12:45:21 +02:00
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
libtsm = env.StaticLibrary(
|
2021-06-12 10:02:22 +02:00
|
|
|
target='thirdparty/libtsm/build/bin/libtsm.{}.{}.{}{}'.format(
|
2020-11-05 09:42:00 +01:00
|
|
|
env['platform'],
|
|
|
|
env['target'],
|
|
|
|
env['bits'],
|
|
|
|
env['LIBSUFFIX']
|
|
|
|
), source=sources
|
|
|
|
)
|
|
|
|
Default(libtsm)
|
2020-07-11 12:45:21 +02:00
|
|
|
|
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
# Build libgodot-xterm.
|
2020-11-20 03:00:03 +01:00
|
|
|
env.Append(CXXFLAGS=['-std=c++14'])
|
2020-11-05 09:42:00 +01:00
|
|
|
env.Append(CPPPATH=[
|
|
|
|
'src/',
|
2021-06-12 10:02:22 +02:00
|
|
|
'thirdparty/libtsm/build/src/tsm',
|
2021-07-02 19:27:34 +02:00
|
|
|
'thirdparty/libtsm/build/src/shared',
|
2021-06-12 10:02:22 +02:00
|
|
|
'thirdparty/godot-cpp/include/',
|
|
|
|
'thirdparty/godot-cpp/include/core/',
|
|
|
|
'thirdparty/godot-cpp/include/gen/',
|
2021-07-02 19:27:34 +02:00
|
|
|
'thirdparty/godot-cpp/godot-headers/',
|
|
|
|
'thirdparty/libuv/src',
|
|
|
|
'thirdparty/libuv/include'
|
2020-11-05 09:42:00 +01:00
|
|
|
])
|
|
|
|
env.Append(LIBPATH=[
|
2021-06-12 10:02:22 +02:00
|
|
|
'thirdparty/godot-cpp/bin/',
|
|
|
|
'thirdparty/libtsm/build/bin/',
|
2020-11-05 09:42:00 +01:00
|
|
|
])
|
2021-06-07 08:53:43 +02:00
|
|
|
|
2020-11-05 09:42:00 +01:00
|
|
|
env.Append(LIBS=[
|
2021-06-12 10:02:22 +02:00
|
|
|
env.File('thirdparty/godot-cpp/bin/libgodot-cpp.{}.{}.{}{}'.format(
|
2020-11-05 09:42:00 +01:00
|
|
|
env['platform'],
|
|
|
|
env['target'],
|
2021-06-07 08:53:43 +02:00
|
|
|
'wasm' if env['platform'] == 'javascript' else env['bits'],
|
|
|
|
env['LIBSUFFIX'],
|
|
|
|
)),
|
2021-06-12 10:02:22 +02:00
|
|
|
env.File('thirdparty/libtsm/build/bin/libtsm.{}.{}.{}{}'.format(
|
2020-11-05 09:42:00 +01:00
|
|
|
env['platform'],
|
|
|
|
env['target'],
|
2021-06-07 08:53:43 +02:00
|
|
|
env['bits'],
|
|
|
|
env['LIBSUFFIX'],
|
|
|
|
)),
|
2020-11-05 09:42:00 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
sources = []
|
|
|
|
sources.append('src/libgodotxtermnative.cpp')
|
|
|
|
sources.append('src/terminal.cpp')
|
|
|
|
|
2021-07-02 19:27:34 +02:00
|
|
|
# PTY not supported on HTML5 or Windows (yet).
|
|
|
|
if env['platform'] != 'javascript' and env['platform'] != 'windows':
|
|
|
|
sources.append('src/pipe.cpp')
|
|
|
|
sources.append('src/libuv_utils.cpp')
|
|
|
|
sources.append('src/node_pty/unix/pty.cc')
|
|
|
|
env.Append(LIBS=['util', env.File('thirdparty/libuv/build/libuv_a.a')])
|
2020-11-05 09:42:00 +01:00
|
|
|
|
|
|
|
if env['platform'] == 'linux':
|
2021-06-07 08:53:43 +02:00
|
|
|
libsuffix = "a"
|
2020-11-05 09:42:00 +01:00
|
|
|
suffix = "so"
|
2021-06-07 08:53:43 +02:00
|
|
|
elif env['platform'] == 'javascript':
|
|
|
|
libsuffix = "bc"
|
|
|
|
suffix = "wasm"
|
2020-11-05 09:42:00 +01:00
|
|
|
elif env['platform'] == 'windows':
|
2021-06-07 08:53:43 +02:00
|
|
|
libsuffix = "lib"
|
2020-11-05 09:42:00 +01:00
|
|
|
suffix = "dll"
|
|
|
|
elif env['platform'] == 'osx':
|
2021-06-07 08:53:43 +02:00
|
|
|
libsuffix = "a"
|
2020-11-05 09:42:00 +01:00
|
|
|
suffix = "dylib"
|
|
|
|
|
|
|
|
library = env.SharedLibrary(
|
|
|
|
target='bin/libgodot-xterm.{}.{}.{}'.format(
|
|
|
|
env['platform'],
|
|
|
|
env['bits'],
|
|
|
|
suffix,
|
|
|
|
), source=sources
|
|
|
|
)
|
|
|
|
Default(library)
|