mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-22 17:50:25 +01:00
630e0104d5
Tested on NixOS, Ubuntu and Arch Linux. Not yet able to compile for Windows 32-bit on NixOS or on Windows itself. Part of #5
294 lines
8.6 KiB
Python
294 lines
8.6 KiB
Python
#!/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
|
|
|
|
if sys.version_info < (3,):
|
|
def decode_utf8(x):
|
|
return x
|
|
else:
|
|
import codecs
|
|
def decode_utf8(x):
|
|
return codecs.utf_8_decode(x)[0]
|
|
|
|
# Workaround for MinGW. See:
|
|
# http://www.scons.org/wiki/LongCmdLinesOnWin32
|
|
if (os.name=="nt"):
|
|
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
|
|
|
|
def add_sources(sources, dir, extension):
|
|
for f in os.listdir(dir):
|
|
if f.endswith('.' + extension):
|
|
sources.append(dir + '/' + f)
|
|
|
|
|
|
# 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>'
|
|
)
|
|
|
|
VariantDir('./external/libtsm/build', './external/libtsm/src', duplicate=0)
|
|
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
|
|
|
|
opts = Variables([], ARGUMENTS)
|
|
|
|
opts.Add(EnumVariable(
|
|
'platform',
|
|
'Target platform',
|
|
host_platform,
|
|
allowed_values=('linux', 'osx', 'windows'),
|
|
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))
|
|
|
|
# Add PATH to environment so scons can find commands such as g++, etc.
|
|
env.AppendENVPath('PATH', os.getenv('PATH'))
|
|
|
|
# Generate godot-cpp bindings.
|
|
# Options such as platform, target, etc. will be forwarded to the godot-cpp SConscript.
|
|
ARGUMENTS['generate_bindings'] = True
|
|
SConscript('external/godot-cpp/SConstruct')
|
|
|
|
|
|
# Compile for Linux.
|
|
if env['platform'] == 'linux':
|
|
env.Append(CPPDEFINES=['PLATFORM_LINUX'])
|
|
|
|
env['CC'] = 'gcc'
|
|
env['CXX'] = 'g++'
|
|
|
|
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'])
|
|
|
|
|
|
# Compile for OSX.
|
|
elif env['platform'] == 'osx':
|
|
env.Append(CPPDEFINES=['PLATFORM_OSX'])
|
|
|
|
env['CC'] = 'clang'
|
|
env['CXX'] = 'clang++'
|
|
|
|
if env['bits'] == '32':
|
|
raise ValueError(
|
|
'Only 64-bit builds are supported for the macOS target.'
|
|
)
|
|
|
|
env.Append(CCFLAGS=['-arch', 'x86_64'])
|
|
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':
|
|
env.Append(CPPDEFINES=['PLATFORM_WINDOWS'])
|
|
|
|
env.Append(CCFLAGS=['-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'])
|
|
|
|
# On Windows.
|
|
if host_platform == 'windows':
|
|
env = env.Clone(tools=['mingw'])
|
|
env["SPAWN"] = mySpawn
|
|
|
|
# On Linux or MacOS.
|
|
elif host_platform == 'linux' or host_platform == 'osx':
|
|
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([
|
|
Delete('external/libtsm/build/src'),
|
|
Delete('external/libtsm/build/external'),
|
|
Copy('external/libtsm/build/src', 'external/libtsm/src'),
|
|
Copy('external/libtsm/build/external', 'external/libtsm/external'),
|
|
])
|
|
|
|
env.Append(CPPPATH=[
|
|
'external/libtsm/src/shared',
|
|
'external/libtsm/external',
|
|
])
|
|
|
|
sources = []
|
|
sources.append('external/libtsm/build/src/shared/shl-htable.c')
|
|
sources.append(Glob('external/libtsm/build/src/tsm/*.c'))
|
|
sources.append(Glob('external/libtsm/build/external/wcwidth/*.c'))
|
|
|
|
libtsm = env.StaticLibrary(
|
|
target='external/libtsm/build/bin/libtsm.{}.{}.{}{}'.format(
|
|
env['platform'],
|
|
env['target'],
|
|
env['bits'],
|
|
env['LIBSUFFIX']
|
|
), source=sources
|
|
)
|
|
Default(libtsm)
|
|
|
|
|
|
# Build libgodot-xterm.
|
|
#env.Append(CCFLAGS=['-std=c++14'])
|
|
|
|
env.Append(CPPPATH=[
|
|
'src/',
|
|
'external/libtsm/build/src/tsm',
|
|
'external/godot-cpp/include/',
|
|
'external/godot-cpp/include/core/',
|
|
'external/godot-cpp/include/gen/',
|
|
'external/godot-cpp/godot_headers/'
|
|
])
|
|
env.Append(LIBPATH=[
|
|
'external/godot-cpp/bin/',
|
|
'external/libtsm/build/bin/',
|
|
])
|
|
env.Append(LIBS=[
|
|
'libgodot-cpp.{}.{}.{}'.format(
|
|
env['platform'],
|
|
env['target'],
|
|
env['bits']
|
|
),
|
|
'libtsm.{}.{}.{}'.format(
|
|
env['platform'],
|
|
env['target'],
|
|
env['bits']
|
|
),
|
|
])
|
|
|
|
sources = []
|
|
sources.append('src/libgodotxtermnative.cpp')
|
|
sources.append('src/terminal.cpp')
|
|
|
|
# Psuedoterminal not supported on windows yet.
|
|
if env['platform'] != 'windows':
|
|
sources.append('src/pseudoterminal.cpp')
|
|
env.Append(LIBS=['util'])
|
|
|
|
if env['platform'] == 'linux':
|
|
suffix = "so"
|
|
elif env['platform'] == 'windows':
|
|
suffix = "dll"
|
|
elif env['platform'] == 'osx':
|
|
suffix = "dylib"
|
|
|
|
library = env.SharedLibrary(
|
|
target='bin/libgodot-xterm.{}.{}.{}'.format(
|
|
env['platform'],
|
|
env['bits'],
|
|
suffix,
|
|
), source=sources
|
|
)
|
|
Default(library)
|