111 lines
4.1 KiB
Python
111 lines
4.1 KiB
Python
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
|
import os
|
|
|
|
def ResolveEnvPath(env, folder):
|
|
if env in os.environ and os.path.isdir(os.environ[env]):
|
|
return os.environ[env]
|
|
head = os.getcwd()
|
|
oldhead = None
|
|
while head != oldhead:
|
|
path = os.path.join(head, folder)
|
|
if os.path.isdir(path):
|
|
return path
|
|
oldhead = head
|
|
head = os.path.dirname(head)
|
|
return None
|
|
|
|
mms_root = os.path.abspath(builder.options.mms_path)
|
|
SdkHelpers = builder.Eval(os.path.join(builder.options.hl2sdk_manifests, 'SdkHelpers.ambuild'), {
|
|
'Project': 'metamod'
|
|
})
|
|
|
|
class SendProxyConfig(object):
|
|
def __init__(self):
|
|
self.plugin_name = 'sendproxy'
|
|
self.plugin_alias = 'sendproxy'
|
|
self.binaries = []
|
|
self.all_targets = []
|
|
for arch in builder.options.targets.split(','):
|
|
self.all_targets.append(builder.DetectCxx(target_arch=arch))
|
|
|
|
def findSdkPath(self, sdk_name):
|
|
path = os.path.join(builder.options.hl2sdk_root, 'hl2sdk-{}'.format(sdk_name))
|
|
if os.path.exists(path):
|
|
return path
|
|
return ResolveEnvPath('HL2SDK{}'.format(sdk_name.upper()), 'hl2sdk-{}'.format(sdk_name))
|
|
|
|
def configure(self):
|
|
SdkHelpers.find_sdk_path = self.findSdkPath
|
|
SdkHelpers.findSdks(builder, self.all_targets, [s for s in builder.options.sdks.split(',') if s])
|
|
if len(SdkHelpers.sdks) != 1:
|
|
raise Exception('Build exactly one SDK, expected cs2.')
|
|
|
|
for sdk_target in SdkHelpers.sdk_targets:
|
|
self.configureTarget(sdk_target.cxx, sdk_target.sdk)
|
|
|
|
def configureCommon(self, cxx):
|
|
if cxx.behavior == 'gcc':
|
|
cxx.defines += [
|
|
'stricmp=strcasecmp', '_stricmp=strcasecmp', '_snprintf=snprintf',
|
|
'_vsnprintf=vsnprintf', 'HAVE_STDINT_H', 'GNUC',
|
|
]
|
|
cxx.cflags += ['-pipe', '-fno-strict-aliasing', '-Wall', '-Wno-unused', '-Wno-switch', '-msse', '-fPIC', '-fno-omit-frame-pointer']
|
|
cxx.cxxflags += ['-std=c++20', '-fno-exceptions', '-fno-threadsafe-statics', '-Wno-non-virtual-dtor', '-Wno-overloaded-virtual', '-Wno-register', '-Wno-invalid-offsetof']
|
|
cxx.cflags += ['-fvisibility=hidden']
|
|
cxx.cxxflags += ['-fvisibility-inlines-hidden']
|
|
if cxx.family == 'gcc':
|
|
cxx.cflags += ['-mfpmath=sse']
|
|
if builder.options.opt == '1':
|
|
cxx.defines += ['NDEBUG']
|
|
cxx.cflags += ['-O2']
|
|
if builder.options.debug == '1':
|
|
cxx.defines += ['DEBUG', '_DEBUG']
|
|
cxx.cflags += ['-g3']
|
|
|
|
if cxx.target.platform == 'linux':
|
|
cxx.defines += ['LINUX', '_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64', 'META_IS_SOURCE2']
|
|
cxx.linkflags += ['-static-libgcc', '-static-libstdc++']
|
|
|
|
def configureTarget(self, cxx, sdk):
|
|
self.configureCommon(cxx)
|
|
binary = cxx.Library(self.plugin_name)
|
|
cxx = binary.compiler
|
|
|
|
cxx.cxxincludes += [
|
|
os.path.join(builder.sourcePath, 'src'),
|
|
os.path.join(mms_root, 'core'),
|
|
os.path.join(mms_root, 'core', 'sourcehook'),
|
|
os.path.join(sdk['path'], 'public'),
|
|
os.path.join(sdk['path'], 'public', 'tier0'),
|
|
os.path.join(sdk['path'], 'public', 'tier1'),
|
|
os.path.join(sdk['path'], 'public', 'entity2'),
|
|
os.path.join('/home/csgo/am/STFixes-metamod/vendor/funchook/include'),
|
|
os.path.join('/home/csgo/am/STFixes-metamod/protobuf/generated'),
|
|
]
|
|
for manifest in SdkHelpers.sdk_manifests:
|
|
cxx.defines += ['SE_{}={}'.format(manifest['define'], manifest['code'])]
|
|
|
|
SdkHelpers.configureCxx(builder, binary, sdk)
|
|
binary.sources += [
|
|
os.path.join(sdk['path'], 'public', 'tier0', 'memoverride.cpp'),
|
|
os.path.join(sdk['path'], 'tier1', 'convar.cpp'),
|
|
'src/plugin.cpp',
|
|
'src/module.cpp',
|
|
'src/gameconfig.cpp',
|
|
'src/schema.cpp',
|
|
'src/overrides.cpp',
|
|
'src/detour.cpp',
|
|
]
|
|
binary.compiler.postlink += [
|
|
'/home/csgo/am/STFixes-metamod/vendor/funchook/lib/Release/libfunchook.a',
|
|
'/home/csgo/am/STFixes-metamod/vendor/funchook/lib/Release/libdistorm.a',
|
|
]
|
|
nodes = builder.Add(binary)
|
|
self.binaries += [nodes]
|
|
|
|
SendProxy = SendProxyConfig()
|
|
SendProxy.configure()
|
|
|
|
BuildScripts = ['PackageScript']
|
|
builder.Build(BuildScripts, {'MMSPlugin': SendProxy})
|