2014-08-19 19:14:48 +02:00
|
|
|
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
|
2013-09-01 17:11:38 +02:00
|
|
|
import os
|
|
|
|
|
2014-08-19 19:14:48 +02:00
|
|
|
def ResolveEnvPath(env, folder):
|
|
|
|
if env in os.environ:
|
|
|
|
path = os.environ[env]
|
|
|
|
if os.path.isdir(path):
|
|
|
|
return path
|
|
|
|
return None
|
|
|
|
|
|
|
|
head = os.getcwd()
|
|
|
|
oldhead = None
|
|
|
|
while head != None and head != oldhead:
|
|
|
|
path = os.path.join(head, folder)
|
|
|
|
if os.path.isdir(path):
|
|
|
|
return path
|
|
|
|
oldhead = head
|
|
|
|
head, tail = os.path.split(head)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def Normalize(path):
|
|
|
|
return os.path.abspath(os.path.normpath(path))
|
|
|
|
|
|
|
|
class DHooksConfig(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.mms_root = None
|
|
|
|
self.sm_root = None
|
|
|
|
self.task = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tag(self):
|
|
|
|
if builder.options.debug == '1':
|
|
|
|
return 'Debug'
|
|
|
|
return 'Release'
|
|
|
|
|
|
|
|
def detectProductVersion(self):
|
|
|
|
builder.AddConfigureFile('product.version')
|
|
|
|
|
|
|
|
# For OS X dylib versioning
|
|
|
|
import re
|
|
|
|
with open(os.path.join(builder.sourcePath, 'product.version'), 'r') as fp:
|
|
|
|
productContents = fp.read()
|
|
|
|
m = re.match('(\d+)\.(\d+)\.(\d+).*', productContents)
|
|
|
|
if m == None:
|
|
|
|
self.productVersion = '1.0.0'
|
|
|
|
else:
|
|
|
|
major, minor, release = m.groups()
|
|
|
|
self.productVersion = '{0}.{1}.{2}'.format(major, minor, release)
|
|
|
|
|
|
|
|
def detectSDKs(self):
|
|
|
|
if builder.options.mms_path:
|
|
|
|
self.mms_root = builder.options.mms_path
|
|
|
|
else:
|
|
|
|
self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10')
|
|
|
|
if not self.mms_root:
|
|
|
|
self.mms_root = ResolveEnvPath('MMSOURCE10', 'metamod-1.10')
|
|
|
|
if not self.mms_root:
|
|
|
|
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'metamod-source')
|
|
|
|
if not self.mms_root:
|
|
|
|
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
|
|
|
|
|
|
|
|
if not self.mms_root or not os.path.isdir(self.mms_root):
|
|
|
|
raise Exception('Could not find a source copy of Metamod:Source')
|
|
|
|
self.mms_root = Normalize(self.mms_root)
|
|
|
|
|
|
|
|
if builder.options.sm_path:
|
|
|
|
self.sm_root = builder.options.sm_path
|
|
|
|
else:
|
2016-06-26 17:00:19 +02:00
|
|
|
self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8')
|
2014-08-19 19:14:48 +02:00
|
|
|
|
|
|
|
if not self.sm_root or not os.path.isdir(self.sm_root):
|
|
|
|
raise Exception('Could not find a source copy of Sourcemod')
|
|
|
|
self.sm_root = Normalize(self.sm_root)
|
|
|
|
|
|
|
|
def configure(self):
|
|
|
|
builder.AddConfigureFile('push.txt')
|
|
|
|
|
|
|
|
cxx = builder.DetectCompilers()
|
|
|
|
|
|
|
|
if cxx.like('gcc'):
|
|
|
|
cxx.defines += [
|
|
|
|
'stricmp=strcasecmp',
|
|
|
|
'_stricmp=strcasecmp',
|
|
|
|
'_snprintf=snprintf',
|
|
|
|
'_vsnprintf=vsnprintf',
|
|
|
|
'HAVE_STDINT_H',
|
|
|
|
'GNUC',
|
|
|
|
]
|
|
|
|
cxx.cflags += [
|
|
|
|
'-pipe',
|
|
|
|
'-fno-strict-aliasing',
|
|
|
|
'-Wall',
|
2019-09-21 22:16:54 +02:00
|
|
|
# '-Werror',
|
2014-08-19 19:14:48 +02:00
|
|
|
'-Wno-unused',
|
|
|
|
'-Wno-switch',
|
|
|
|
'-Wno-format',
|
|
|
|
'-Wno-format-security',
|
|
|
|
'-Wno-array-bounds',
|
|
|
|
'-Wno-sign-compare',
|
|
|
|
'-msse',
|
|
|
|
'-m32',
|
2016-06-26 19:01:06 +02:00
|
|
|
'-Wno-invalid-offsetof',
|
2014-08-19 19:14:48 +02:00
|
|
|
]
|
|
|
|
cxx.cxxflags += [
|
|
|
|
'-std=c++11',
|
|
|
|
]
|
|
|
|
|
|
|
|
have_gcc = cxx.vendor == 'gcc'
|
|
|
|
have_clang = cxx.vendor == 'clang'
|
2016-06-26 19:34:19 +02:00
|
|
|
if cxx.version >= 'clang-3.6':
|
|
|
|
cxx.cxxflags += ['-Wno-inconsistent-missing-override']
|
2014-08-19 19:14:48 +02:00
|
|
|
if have_clang or (have_gcc and cxx.version >= '4'):
|
|
|
|
cxx.cflags += ['-fvisibility=hidden']
|
|
|
|
cxx.cxxflags += ['-fvisibility-inlines-hidden']
|
|
|
|
if have_clang or (have_gcc and cxx.version >= '4.6'):
|
|
|
|
cxx.cflags += ['-Wno-narrowing']
|
|
|
|
if (have_gcc and cxx.version >= '4.7') or (have_clang and cxx.version >= '3'):
|
|
|
|
cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
|
|
|
|
if have_gcc and cxx.version >= '4.8':
|
|
|
|
cxx.cflags += ['-Wno-unused-result']
|
|
|
|
if have_clang:
|
|
|
|
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
|
|
|
|
if (builder.target_platform == 'mac' and cxx.version >= '5.1') or cxx.version >= '3.4':
|
|
|
|
cxx.cxxflags += ['-Wno-deprecated-register']
|
|
|
|
else:
|
|
|
|
cxx.cxxflags += ['-Wno-deprecated']
|
|
|
|
cxx.cflags += ['-Wno-sometimes-uninitialized']
|
|
|
|
|
|
|
|
cxx.linkflags += ['-m32']
|
|
|
|
cxx.cxxflags += [
|
|
|
|
'-fno-exceptions',
|
|
|
|
'-fno-threadsafe-statics',
|
|
|
|
'-Wno-non-virtual-dtor',
|
|
|
|
'-Wno-overloaded-virtual',
|
|
|
|
]
|
|
|
|
|
|
|
|
if have_gcc:
|
|
|
|
cxx.cflags += ['-mfpmath=sse']
|
|
|
|
elif cxx.vendor == 'msvc':
|
|
|
|
if builder.options.debug == '1':
|
|
|
|
cxx.cflags += ['/MTd']
|
|
|
|
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
|
|
|
|
else:
|
|
|
|
cxx.cflags += ['/MT']
|
|
|
|
cxx.defines += [
|
|
|
|
'_CRT_SECURE_NO_DEPRECATE',
|
|
|
|
'_CRT_SECURE_NO_WARNINGS',
|
|
|
|
'_CRT_NONSTDC_NO_DEPRECATE',
|
|
|
|
'_ITERATOR_DEBUG_LEVEL=0',
|
|
|
|
]
|
|
|
|
cxx.cflags += [
|
|
|
|
'/W3',
|
|
|
|
]
|
|
|
|
cxx.cxxflags += [
|
|
|
|
'/EHsc',
|
|
|
|
'/GR-',
|
|
|
|
'/TP',
|
|
|
|
]
|
|
|
|
cxx.linkflags += [
|
|
|
|
'/MACHINE:X86',
|
|
|
|
'/SUBSYSTEM:WINDOWS',
|
|
|
|
'kernel32.lib',
|
|
|
|
'user32.lib',
|
|
|
|
'gdi32.lib',
|
|
|
|
'winspool.lib',
|
|
|
|
'comdlg32.lib',
|
|
|
|
'advapi32.lib',
|
|
|
|
'shell32.lib',
|
|
|
|
'ole32.lib',
|
|
|
|
'oleaut32.lib',
|
|
|
|
'uuid.lib',
|
|
|
|
'odbc32.lib',
|
|
|
|
'odbccp32.lib',
|
|
|
|
]
|
|
|
|
|
|
|
|
# Optimization
|
|
|
|
if builder.options.opt == '1':
|
|
|
|
cxx.defines += ['NDEBUG']
|
|
|
|
if cxx.like('gcc'):
|
|
|
|
cxx.cflags += ['-O3']
|
|
|
|
elif cxx.like('msvc'):
|
|
|
|
cxx.cflags += ['/Ox']
|
|
|
|
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
|
|
|
|
|
|
|
|
# Debugging
|
|
|
|
if builder.options.debug == '1':
|
|
|
|
cxx.defines += ['DEBUG', '_DEBUG']
|
|
|
|
if cxx.like('msvc'):
|
|
|
|
cxx.cflags += ['/Od', '/RTC1']
|
|
|
|
if cxx.version >= 1600:
|
|
|
|
cxx.cflags += ['/d2Zi+']
|
|
|
|
|
|
|
|
# This needs to be after our optimization flags which could otherwise disable it.
|
|
|
|
if cxx.vendor == 'msvc':
|
|
|
|
# Don't omit the frame pointer.
|
|
|
|
cxx.cflags += ['/Oy-']
|
|
|
|
|
|
|
|
# Platform-specifics
|
|
|
|
if builder.target_platform == 'linux':
|
|
|
|
cxx.defines += ['_LINUX', 'POSIX']
|
|
|
|
if cxx.vendor == 'gcc':
|
|
|
|
cxx.linkflags += ['-static-libgcc']
|
|
|
|
elif cxx.vendor == 'clang':
|
|
|
|
cxx.linkflags += ['-lgcc_eh']
|
|
|
|
elif builder.target_platform == 'mac':
|
|
|
|
cxx.defines += ['OSX', '_OSX', 'POSIX']
|
|
|
|
cxx.cflags += ['-mmacosx-version-min=10.5']
|
|
|
|
cxx.linkflags += [
|
|
|
|
'-mmacosx-version-min=10.5',
|
|
|
|
'-arch', 'i386',
|
|
|
|
'-lstdc++',
|
|
|
|
'-stdlib=libstdc++',
|
|
|
|
]
|
|
|
|
cxx.cxxflags += ['-stdlib=libstdc++']
|
|
|
|
elif builder.target_platform == 'windows':
|
|
|
|
cxx.defines += ['WIN32', '_WINDOWS']
|
2014-09-12 15:40:45 +02:00
|
|
|
|
|
|
|
if cxx.vendor == 'gcc' or cxx.vendor == 'clang':
|
|
|
|
cxx.cxxflags += ['-fno-rtti']
|
|
|
|
elif cxx.vendor == 'msvc':
|
|
|
|
cxx.cxxflags += ['/GR-']
|
|
|
|
|
2014-08-19 19:14:48 +02:00
|
|
|
cxx.defines += ['META_NO_HL2SDK']
|
|
|
|
|
|
|
|
def IncludeSDKs(self, builder):
|
|
|
|
builder.compiler.cxxincludes += [
|
|
|
|
os.path.join(builder.currentSourcePath),
|
|
|
|
os.path.join(builder.currentSourcePath, 'sdk'),
|
|
|
|
os.path.join(self.mms_root, 'core'),
|
|
|
|
os.path.join(self.mms_root, 'core', 'sourcehook'),
|
|
|
|
os.path.join(self.sm_root, 'public'),
|
|
|
|
os.path.join(self.sm_root, 'public', 'extensions'),
|
|
|
|
os.path.join(self.sm_root, 'public', 'sourcepawn'),
|
|
|
|
os.path.join(self.sm_root, 'public', 'amtl'),
|
|
|
|
os.path.join(self.sm_root, 'public', 'jit'),
|
|
|
|
os.path.join(self.sm_root, 'public', 'jit', 'x86'),
|
2015-05-14 21:19:56 +02:00
|
|
|
os.path.join(self.sm_root, 'sourcepawn', 'include'),
|
|
|
|
os.path.join(self.sm_root, 'sourcepawn', 'vm'),
|
|
|
|
os.path.join(self.sm_root, 'sourcepawn', 'vm', 'x86'),
|
2016-12-12 06:02:10 +01:00
|
|
|
os.path.join(self.sm_root, 'public', 'amtl', 'include'),
|
2016-06-26 17:00:19 +02:00
|
|
|
os.path.join(self.sm_root, 'public', 'amtl', 'amtl'),
|
2016-12-12 06:02:10 +01:00
|
|
|
os.path.join(builder.currentSourcePath, 'DynamicHooks'),
|
2014-08-19 19:14:48 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
DHooks = DHooksConfig()
|
|
|
|
DHooks.detectSDKs()
|
|
|
|
DHooks.configure()
|
|
|
|
DHooks.IncludeSDKs(builder)
|
|
|
|
|
|
|
|
program = builder.compiler.Library('dhooks.ext')
|
|
|
|
|
|
|
|
program.sources += [
|
|
|
|
'extension.cpp',
|
|
|
|
'listeners.cpp',
|
|
|
|
'natives.cpp',
|
2018-01-25 17:18:30 +01:00
|
|
|
'signatures.cpp',
|
2014-08-19 19:14:48 +02:00
|
|
|
'vhook.cpp',
|
2016-08-31 17:46:25 +02:00
|
|
|
'util.cpp',
|
2016-12-12 06:02:10 +01:00
|
|
|
'dynhooks_sourcepawn.cpp',
|
|
|
|
]
|
|
|
|
|
|
|
|
# DynamicHooks
|
|
|
|
program.sources += [
|
|
|
|
os.path.join('DynamicHooks', 'asm.cpp'),
|
|
|
|
os.path.join('DynamicHooks', 'hook.cpp'),
|
|
|
|
os.path.join('DynamicHooks', 'manager.cpp'),
|
|
|
|
os.path.join('DynamicHooks', 'registers.cpp'),
|
|
|
|
os.path.join('DynamicHooks', 'utilities.cpp'),
|
|
|
|
os.path.join('DynamicHooks', 'conventions', 'x86MsCdecl.cpp'),
|
|
|
|
os.path.join('DynamicHooks', 'conventions', 'x86MsStdcall.cpp'),
|
2019-06-20 02:14:07 +02:00
|
|
|
os.path.join('DynamicHooks', 'conventions', 'x86MsFastcall.cpp'),
|
2016-12-12 06:02:10 +01:00
|
|
|
]
|
|
|
|
|
2018-06-02 13:36:52 +02:00
|
|
|
if builder.target_platform == 'windows':
|
|
|
|
program.sources += [os.path.join('DynamicHooks', 'conventions', 'x86MsThiscall.cpp')]
|
|
|
|
else:
|
|
|
|
program.sources += [os.path.join('DynamicHooks', 'conventions', 'x86GccThiscall.cpp')]
|
|
|
|
|
2016-06-26 17:39:17 +02:00
|
|
|
program.sources += [os.path.join(DHooks.sm_root, 'public', 'smsdk_ext.cpp')]
|
2016-06-26 17:00:19 +02:00
|
|
|
|
2015-05-14 21:19:56 +02:00
|
|
|
if os.path.isfile(os.path.join(DHooks.sm_root, 'sourcepawn', 'vm', 'x86', 'assembler-x86.cpp')):
|
|
|
|
program.sources += [os.path.join(DHooks.sm_root, 'sourcepawn', 'vm', 'x86', 'assembler-x86.cpp'),]
|
|
|
|
elif os.path.isfile(os.path.join(DHooks.sm_root, 'public', 'jit', 'x86', 'assembler-x86.cpp')):
|
|
|
|
program.sources += [os.path.join(DHooks.sm_root, 'public', 'jit', 'x86', 'assembler-x86.cpp'),]
|
|
|
|
else:
|
|
|
|
raise Exception('Could not find assembler-x86.cpp. Did you checkout SourceMod\'s submodules?')
|
2014-08-19 19:14:48 +02:00
|
|
|
|
|
|
|
DHooks.task = builder.Add(program)
|
|
|
|
|
|
|
|
builder.RunScript('buildbot/PackageScript', { 'DHooks': DHooks })
|