1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2025-02-21 14:54:14 +01:00

64-bit support for CSGO on Linux and macOS (#35)

This commit is contained in:
Scott Ehlert 2017-12-20 01:11:57 -06:00 committed by GitHub
parent 1f0124d499
commit 79435093d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 359 additions and 180 deletions

View File

@ -18,19 +18,24 @@ class SDK(object):
else: else:
self.platformSpec = platform self.platformSpec = platform
def shouldBuild(self, target): def shouldBuild(self, target, archs):
if target.platform not in self.platformSpec: if target.platform not in self.platformSpec:
return False return False
if target.arch not in self.platformSpec[target.platform]: if not len([i for i in self.platformSpec[target.platform] if i in archs]):
return False return False
return True return True
WinOnly = ['windows'] WinOnly = ['windows']
WinLinux = ['windows', 'linux'] WinLinux = ['windows', 'linux']
WinLinuxMac = ['windows', 'linux', 'mac'] WinLinuxMac = ['windows', 'linux', 'mac']
CSGO = {
'windows': ['x86'],
'linux': ['x86', 'x64'],
'mac': ['x64']
}
Source2 = { Source2 = {
'windows': ['x86', 'x86_64'], 'windows': ['x86', 'x64'],
'linux': ['x86_64'], 'linux': ['x64'],
} }
PossibleSDKs = { PossibleSDKs = {
@ -48,7 +53,7 @@ PossibleSDKs = {
'swarm': SDK('HL2SDK-SWARM', '2.swarm', '16', 'ALIENSWARM', WinOnly, 'swarm'), 'swarm': SDK('HL2SDK-SWARM', '2.swarm', '16', 'ALIENSWARM', WinOnly, 'swarm'),
'bgt': SDK('HL2SDK-BGT', '2.bgt', '4', 'BLOODYGOODTIME', WinOnly, 'bgt'), 'bgt': SDK('HL2SDK-BGT', '2.bgt', '4', 'BLOODYGOODTIME', WinOnly, 'bgt'),
'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'), 'eye': SDK('HL2SDK-EYE', '2.eye', '5', 'EYE', WinOnly, 'eye'),
'csgo': SDK('HL2SDKCSGO', '2.csgo', '21', 'CSGO', WinLinuxMac, 'csgo'), 'csgo': SDK('HL2SDKCSGO', '2.csgo', '21', 'CSGO', CSGO, 'csgo'),
'dota': SDK('HL2SDKDOTA', '2.dota', '22', 'DOTA', Source2, 'dota'), 'dota': SDK('HL2SDKDOTA', '2.dota', '22', 'DOTA', Source2, 'dota'),
'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '17', 'PORTAL2', [], 'portal2'), 'portal2': SDK('HL2SDKPORTAL2', '2.portal2', '17', 'PORTAL2', [], 'portal2'),
'blade': SDK('HL2SDKBLADE', '2.blade', '18', 'BLADE', WinLinux, 'blade'), 'blade': SDK('HL2SDKBLADE', '2.blade', '18', 'BLADE', WinLinux, 'blade'),
@ -73,6 +78,28 @@ def ResolveEnvPath(env, folder):
oldhead = head oldhead = head
head, tail = os.path.split(head) head, tail = os.path.split(head)
return None return None
def SetArchFlags(compiler, arch, platform):
if compiler.behavior == 'gcc':
if arch == 'x86':
compiler.cflags += ['-m32']
compiler.linkflags += ['-m32']
if platform == 'mac':
compiler.linkflags += ['-arch', 'i386']
elif arch == 'x64':
compiler.cflags += ['-m64', '-fPIC']
compiler.linkflags += ['-m64']
if platform == 'mac':
compiler.linkflags += ['-arch', 'x86_64']
elif compiler.like('msvc'):
if arch == 'x86':
compiler.linkflags += ['/MACHINE:X86']
elif arch == 'x64':
compiler.linkflags += ['/MACHINE:X64']
def AppendArchSuffix(binary, name, arch):
if arch == 'x64':
binary.localFolder = name + '.x64'
class MMSConfig(object): class MMSConfig(object):
def __init__(self): def __init__(self):
@ -80,13 +107,13 @@ class MMSConfig(object):
self.binaries = [] self.binaries = []
self.generated_headers = None self.generated_headers = None
self.versionlib = None self.versionlib = None
self.archs = builder.target.arch.replace('x86_64', 'x64').split(',')
def use_auto_versioning(self): def use_auto_versioning(self):
if builder.backend != 'amb2': if builder.backend != 'amb2':
return False return False
return not getattr(builder.options, 'disable_auto_versioning', False) return not getattr(builder.options, 'disable_auto_versioning', False)
def detectProductVersion(self): def detectProductVersion(self):
builder.AddConfigureFile('product.version') builder.AddConfigureFile('product.version')
@ -110,7 +137,7 @@ class MMSConfig(object):
for sdk_name in PossibleSDKs: for sdk_name in PossibleSDKs:
sdk = PossibleSDKs[sdk_name] sdk = PossibleSDKs[sdk_name]
if sdk.shouldBuild(builder.target): if sdk.shouldBuild(builder.target, self.archs):
if builder.options.hl2sdk_root: if builder.options.hl2sdk_root:
sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder) sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder)
else: else:
@ -130,10 +157,13 @@ class MMSConfig(object):
def configure(self): def configure(self):
builder.AddConfigureFile('pushbuild.txt') builder.AddConfigureFile('pushbuild.txt')
if builder.target.arch not in ['x86', 'x86_64']: if not set(self.archs).issubset(['x86', 'x64']):
raise Exception('Unknown target architecture: {0}'.format(builder.target.arch)) raise Exception('Unknown target architecture: {0}'.format(builder.target.arch))
cxx = builder.DetectCxx() cxx = builder.DetectCxx()
if cxx.like('msvc') and len(self.archs) > 1:
raise Exception('Building multiple archs with MSVC is not currently supported')
if cxx.behavior == 'gcc': if cxx.behavior == 'gcc':
cxx.defines += [ cxx.defines += [
@ -155,13 +185,6 @@ class MMSConfig(object):
'-msse', '-msse',
] ]
if builder.target.arch == 'x86':
cxx.cflags += ['-m32']
cxx.linkflags += ['-m32']
elif builder.target.arch == 'x86_64':
cxx.cflags += ['-m64', '-fPIC']
cxx.linkflags += ['-m64']
cxx.cxxflags += [ '-std=c++11' ] cxx.cxxflags += [ '-std=c++11' ]
if (cxx.version >= 'gcc-4.0') or cxx.family == 'clang': if (cxx.version >= 'gcc-4.0') or cxx.family == 'clang':
cxx.cflags += ['-fvisibility=hidden'] cxx.cflags += ['-fvisibility=hidden']
@ -179,7 +202,7 @@ class MMSConfig(object):
cxx.cflags += ['-mfpmath=sse'] cxx.cflags += ['-mfpmath=sse']
if cxx.family == 'clang': if cxx.family == 'clang':
cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch'] cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
if cxx.version >= 'clang-3.6': if cxx.version >= 'clang-3.6' or cxx.version >= 'apple-clang-7.0':
cxx.cxxflags += ['-Wno-inconsistent-missing-override'] cxx.cxxflags += ['-Wno-inconsistent-missing-override']
if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4': if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4':
cxx.cxxflags += ['-Wno-deprecated-register'] cxx.cxxflags += ['-Wno-deprecated-register']
@ -202,11 +225,6 @@ class MMSConfig(object):
'/Zi', '/Zi',
] ]
cxx.cxxflags += ['/TP'] cxx.cxxflags += ['/TP']
if builder.target.arch == 'x86':
cxx.linkflags += ['/MACHINE:X86']
elif builder.target.arch == 'x86_64':
cxx.linkflags += ['/MACHINE:X64']
cxx.linkflags += [ cxx.linkflags += [
'/SUBSYSTEM:WINDOWS', '/SUBSYSTEM:WINDOWS',
@ -258,8 +276,7 @@ class MMSConfig(object):
cxx.cflags += ['-mmacosx-version-min=10.5'] cxx.cflags += ['-mmacosx-version-min=10.5']
cxx.linkflags += [ cxx.linkflags += [
'-mmacosx-version-min=10.5', '-mmacosx-version-min=10.5',
'-arch', 'i386', '-lc++',
'-lstdc++',
] ]
elif builder.target.platform == 'windows': elif builder.target.platform == 'windows':
cxx.defines += ['WIN32', '_WINDOWS'] cxx.defines += ['WIN32', '_WINDOWS']
@ -276,7 +293,7 @@ class MMSConfig(object):
os.path.join(builder.sourcePath, 'versionlib'), os.path.join(builder.sourcePath, 'versionlib'),
] ]
def HL2Compiler(self, context, sdk): def HL2Compiler(self, context, sdk, arch):
compiler = context.cxx.clone() compiler = context.cxx.clone()
compiler.cxxincludes += [ compiler.cxxincludes += [
os.path.join(context.currentSourcePath), os.path.join(context.currentSourcePath),
@ -310,17 +327,17 @@ class MMSConfig(object):
if compiler.family == 'msvc': if compiler.family == 'msvc':
compiler.defines += ['COMPILER_MSVC'] compiler.defines += ['COMPILER_MSVC']
if builder.target.arch == 'x86': if arch == 'x86':
compiler.defines += ['COMPILER_MSVC32'] compiler.defines += ['COMPILER_MSVC32']
elif builder.target.arch == 'x86_64': elif arch == 'x64':
compiler.defines += ['COMPILER_MSVC64'] compiler.defines += ['COMPILER_MSVC64']
if compiler.version >= 1900: if compiler.version >= 1900:
compiler.linkflags += ['legacy_stdio_definitions.lib'] compiler.linkflags += ['legacy_stdio_definitions.lib']
else: else:
compiler.defines += ['COMPILER_GCC'] compiler.defines += ['COMPILER_GCC']
if sdk.name == 'dota' and builder.target.arch == 'x86_64': if arch == 'x64':
compiler.defines += ['X64BITS', 'PLATFORM_64BITS'] compiler.defines += ['X64BITS', 'PLATFORM_64BITS']
if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota']: if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota']:
@ -336,33 +353,35 @@ class MMSConfig(object):
return compiler return compiler
def AddVersioning(self, binary): def AddVersioning(self, binary, arch):
if builder.target.platform == 'windows': if builder.target.platform == 'windows':
binary.sources += ['version.rc'] binary.sources += ['version.rc']
binary.compiler.rcdefines += [ binary.compiler.rcdefines += [
'BINARY_NAME="{0}"'.format(binary.outputFile), 'BINARY_NAME="{0}"'.format(binary.outputFile),
'RC_COMPILE' 'RC_COMPILE'
] ]
elif builder.target.platform == 'mac': elif builder.target.platform == 'mac' and binary.type == 'library':
binary.compiler.postlink += [ binary.compiler.postlink += [
'-compatibility_version', '1.0.0', '-compatibility_version', '1.0.0',
'-current_version', self.productVersion '-current_version', self.productVersion
] ]
if self.use_auto_versioning(): if self.use_auto_versioning():
binary.compiler.linkflags += [self.versionlib] binary.compiler.linkflags += [self.versionlib[arch]]
binary.compiler.sourcedeps += MMS.generated_headers binary.compiler.sourcedeps += MMS.generated_headers
if builder.options.breakpad_dump: if builder.options.breakpad_dump:
binary.compiler.symbol_files = 'separate' binary.compiler.symbol_files = 'separate'
return binary return binary
def LibraryBuilder(self, compiler, name): def LibraryBuilder(self, compiler, name, arch):
binary = compiler.Library(name) binary = compiler.Library(name)
self.AddVersioning(binary) AppendArchSuffix(binary, name, arch)
self.AddVersioning(binary, arch)
return binary return binary
def ProgramBuilder(self, compiler, name): def ProgramBuilder(self, compiler, name, arch):
binary = compiler.Program(name) binary = compiler.Program(name)
self.AddVersioning(binary) AppendArchSuffix(binary, name, arch)
self.AddVersioning(binary, arch)
if '-static-libgcc' in binary.compiler.linkflags: if '-static-libgcc' in binary.compiler.linkflags:
binary.compiler.linkflags.remove('-static-libgcc') binary.compiler.linkflags.remove('-static-libgcc')
if '-lgcc_eh' in binary.compiler.linkflags: if '-lgcc_eh' in binary.compiler.linkflags:
@ -370,47 +389,70 @@ class MMSConfig(object):
if binary.compiler.like('gcc'): if binary.compiler.like('gcc'):
binary.compiler.linkflags += ['-lstdc++'] binary.compiler.linkflags += ['-lstdc++']
return binary return binary
def StaticLibraryBuilder(self, compiler, name, arch):
binary = compiler.StaticLibrary(name)
AppendArchSuffix(binary, name, arch)
return binary;
def Library(self, context, name): def Library(self, context, name, arch):
compiler = context.cxx.clone() compiler = context.cxx.clone()
return self.LibraryBuilder(compiler, name) SetArchFlags(compiler, arch, builder.target.platform)
return self.LibraryBuilder(compiler, name, arch)
def Program(self, context, name): def Program(self, context, name, arch):
compiler = context.cxx.clone() compiler = context.cxx.clone()
return self.ProgramBuilder(compiler, name) SetArchFlags(compiler, arch, builder.target.platform)
return self.ProgramBuilder(compiler, name, arch)
def StaticLibrary(self, context, name, arch):
compiler = context.cxx.clone()
SetArchFlags(compiler, arch, builder.target.platform)
return self.StaticLibraryBuilder(compiler, name, arch)
def HL2Library(self, context, name, sdk): def HL2Library(self, context, name, sdk, arch):
compiler = self.HL2Compiler(context, sdk) compiler = self.HL2Compiler(context, sdk, arch)
SetArchFlags(compiler, arch, builder.target.platform)
if builder.target.platform == 'linux': if builder.target.platform == 'linux':
if sdk.name == 'episode1': if sdk.name == 'episode1':
lib_folder = os.path.join(sdk.path, 'linux_sdk') lib_folder = os.path.join(sdk.path, 'linux_sdk')
elif sdk.name in ['sdk2013', 'bms']: elif sdk.name in ['sdk2013', 'bms']:
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32') lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32')
elif arch == 'x64':
lib_folder = os.path.join(sdk.path, 'lib', 'linux64')
else: else:
lib_folder = os.path.join(sdk.path, 'lib', 'linux') lib_folder = os.path.join(sdk.path, 'lib', 'linux')
elif builder.target.platform == 'mac': elif builder.target.platform == 'mac':
if sdk.name in ['sdk2013', 'bms']: if sdk.name in ['sdk2013', 'bms']:
lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32') lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32')
elif arch == 'x64':
lib_folder = os.path.join(sdk.path, 'lib', 'osx64')
else: else:
lib_folder = os.path.join(sdk.path, 'lib', 'mac') lib_folder = os.path.join(sdk.path, 'lib', 'mac')
if builder.target.platform in ['linux', 'mac']: if builder.target.platform in ['linux', 'mac']:
if sdk.name in ['sdk2013', 'bms']: if sdk.name in ['sdk2013', 'bms'] or arch == 'x64':
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'tier1.a'))] compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'tier1.a'))]
else: else:
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a'))] compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a'))]
if sdk.name in ['blade', 'insurgency', 'doi', 'csgo', 'dota']: if sdk.name in ['blade', 'insurgency', 'doi', 'csgo', 'dota']:
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))] if arch == 'x64':
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces.a'))]
else:
compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))]
binary = self.LibraryBuilder(compiler, name) binary = self.LibraryBuilder(compiler, name, arch)
dynamic_libs = [] dynamic_libs = []
if builder.target.platform == 'linux': if builder.target.platform == 'linux':
compiler.linkflags[0:0] = ['-lm'] compiler.linkflags[0:0] = ['-lm']
if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency', 'doi']: if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency', 'doi']:
dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so'] dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so']
elif arch == 'x64' and sdk.name == 'csgo':
dynamic_libs = ['libtier0_client.so', 'libvstdlib_client.so']
elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo', 'dota']: elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo', 'dota']:
dynamic_libs = ['libtier0.so', 'libvstdlib.so'] dynamic_libs = ['libtier0.so', 'libvstdlib.so']
else: else:
@ -423,9 +465,9 @@ class MMSConfig(object):
if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'csgo', 'dota']: if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'csgo', 'dota']:
libs.append('interfaces') libs.append('interfaces')
for lib in libs: for lib in libs:
if builder.target.arch == 'x86': if arch == 'x86':
lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib' lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib'
elif builder.target.arch == 'x86_64': elif arch == 'x64':
lib_path = os.path.join(sdk.path, 'lib', 'public', 'win64', lib) + '.lib' lib_path = os.path.join(sdk.path, 'lib', 'public', 'win64', lib) + '.lib'
binary.compiler.linkflags.append(binary.Dep(lib_path)) binary.compiler.linkflags.append(binary.Dep(lib_path))

View File

@ -1,7 +1,7 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et: # vim: set sts=2 ts=8 sw=2 tw=99 et:
import sys import sys
try: try:
from ambuild2 import run from ambuild2 import run, util
except: except:
try: try:
import ambuild import ambuild
@ -13,7 +13,7 @@ except:
sys.exit(1) sys.exit(1)
def make_objdir_name(p): def make_objdir_name(p):
return 'obj-linux-' + p.target_arch return 'obj-' + util.Platform() + '-' + p.target_arch
parser = run.BuildParser(sourcePath=sys.path[0], api='2.1') parser = run.BuildParser(sourcePath=sys.path[0], api='2.1')
parser.default_arch = 'x86' parser.default_arch = 'x86'

View File

@ -2,30 +2,34 @@
import os import os
for sdk_name in MMS.sdks: for sdk_name in MMS.sdks:
sdk = MMS.sdks[sdk_name] for arch in MMS.archs:
sdk = MMS.sdks[sdk_name]
name = 'metamod.' + sdk.ext if not arch in sdk.platformSpec[builder.target.platform]:
binary = MMS.HL2Library(builder, name, sdk) continue
binary.sources += [ name = 'metamod.' + sdk.ext
'metamod.cpp', binary = MMS.HL2Library(builder, name, sdk, arch)
'metamod_console.cpp',
'metamod_oslink.cpp',
'metamod_plugins.cpp',
'metamod_util.cpp',
'provider/console.cpp',
'provider/provider_ep2.cpp',
'sourcehook/sourcehook.cpp',
'sourcehook/sourcehook_impl_chookidman.cpp',
'sourcehook/sourcehook_impl_chookmaninfo.cpp',
'sourcehook/sourcehook_impl_cproto.cpp',
'sourcehook/sourcehook_impl_cvfnptr.cpp',
'gamedll_bridge.cpp',
'vsp_bridge.cpp'
]
# Source2 hack. TODO: check this more deterministically, "are we doing an x64 build?" binary.sources += [
if builder.target.arch == 'x86': 'metamod.cpp',
binary.sources += ['sourcehook/sourcehook_hookmangen.cpp'] 'metamod_console.cpp',
nodes = builder.Add(binary) 'metamod_oslink.cpp',
MMS.binaries += [nodes] 'metamod_plugins.cpp',
'metamod_util.cpp',
'provider/console.cpp',
'provider/provider_ep2.cpp',
'sourcehook/sourcehook.cpp',
'sourcehook/sourcehook_impl_chookidman.cpp',
'sourcehook/sourcehook_impl_chookmaninfo.cpp',
'sourcehook/sourcehook_impl_cproto.cpp',
'sourcehook/sourcehook_impl_cvfnptr.cpp',
'gamedll_bridge.cpp',
'vsp_bridge.cpp'
]
# Source2 hack. TODO: check this more deterministically, "are we doing an x64 build?"
if arch == 'x86':
binary.sources += ['sourcehook/sourcehook_hookmangen.cpp']
nodes = builder.Add(binary)
MMS.binaries += [nodes]

View File

@ -34,13 +34,20 @@
#include "metamod_util.h" #include "metamod_util.h"
#include "metamod_console.h" #include "metamod_console.h"
#include "provider/provider_ep2.h" #include "provider/provider_ep2.h"
#if defined __linux__
#include <sys/stat.h> #include <sys/stat.h>
#endif
#if SOURCE_ENGINE == SE_DOTA #if SOURCE_ENGINE == SE_DOTA
#include <iserver.h> #include <iserver.h>
#endif #endif
#define X64_SUFFIX ".x64"
#if defined(WIN32) || defined(_WIN32)
#define BINARY_EXT ".dll"
#elif defined(__linux__)
#define BINARY_EXT ".so"
#elif defined(__APPLE__)
#define BINARY_EXT ".dylib"
#endif
using namespace SourceMM; using namespace SourceMM;
using namespace SourceHook; using namespace SourceHook;
using namespace SourceHook::Impl; using namespace SourceHook::Impl;
@ -124,7 +131,7 @@ static ConVar *mm_basedir = NULL;
static CreateInterfaceFn engine_factory = NULL; static CreateInterfaceFn engine_factory = NULL;
static CreateInterfaceFn physics_factory = NULL; static CreateInterfaceFn physics_factory = NULL;
static CreateInterfaceFn filesystem_factory = NULL; static CreateInterfaceFn filesystem_factory = NULL;
#if !defined( __amd64__ ) #if !defined( _WIN64 ) && !defined( __amd64__ )
static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook); static CHookManagerAutoGen g_SH_HookManagerAutoGen(&g_SourceHook);
#endif #endif
static META_RES last_meta_res; static META_RES last_meta_res;
@ -997,7 +1004,7 @@ void *MetamodSource::MetaFactory(const char *iface, int *ret, PluginId *id)
} }
else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0) else if (strcmp(iface, MMIFACE_SH_HOOKMANAUTOGEN) == 0)
{ {
#if defined( __amd64__ ) #if defined( _WIN64 ) || defined( __amd64__ )
if (ret) if (ret)
{ {
*ret = META_IFACE_FAILED; *ret = META_IFACE_FAILED;
@ -1235,12 +1242,24 @@ size_t MetamodSource::GetFullPluginPath(const char *plugin, char *buffer, size_t
/* Add an extension if there's none there */ /* Add an extension if there's none there */
if (!pext) if (!pext)
{ {
#if defined WIN32 || defined _WIN32 #if defined(WIN32) || defined(_WIN32)
ext = ".dll"; #if defined(WIN64) || defined(_WIN64)
#elif defined __APPLE__ ext = X64_SUFFIX BINARY_EXT;
ext = ".dylib";
#else #else
ext = "_i486.so"; ext = BINARY_EXT;
#endif
#elif defined __APPLE__
#if defined (__x86_64__)
ext = X64_SUFFIX BINARY_EXT;
#else
ext = BINARY_EXT;
#endif
#else
#if defined(__x86_64__)
ext = X64_SUFFIX BINARY_EXT;
#else
ext = "_i486" BINARY_EXT;
#endif
#endif #endif
} }
else else
@ -1251,12 +1270,12 @@ size_t MetamodSource::GetFullPluginPath(const char *plugin, char *buffer, size_t
/* Format the new path */ /* Format the new path */
num = PathFormat(buffer, len, "%s/%s%s", mod_path.c_str(), plugin, ext); num = PathFormat(buffer, len, "%s/%s%s", mod_path.c_str(), plugin, ext);
#if defined __linux__ /* If path was passed without extension and it doesn't exist with "<suffix>.<ext>" try ".<ext>" */
/* If path was passed without extension and it doesn't exist with "_i486.so" try ".so" */ #if defined(WIN64) || defined (_WIN64) || defined(__linux__) || defined(__x86_64__)
struct stat s; struct stat s;
if (!pext && stat(buffer, &s) != 0) if (!pext && stat(buffer, &s) != 0)
{ {
num = PathFormat(buffer, len, "%s/%s.so", mod_path.c_str(), plugin); num = PathFormat(buffer, len, "%s/%s" BINARY_EXT, mod_path.c_str(), plugin);
} }
#endif #endif

View File

@ -129,13 +129,20 @@ namespace SourceHook
#elif SH_SYS == SH_SYS_APPLE #elif SH_SYS == SH_SYS_APPLE
vm_size_t ignoreSize; vm_size_t ignoreSize;
vm_address_t vmaddr = (vm_address_t)addr; vm_address_t vmaddr = (vm_address_t)addr;
memory_object_name_t obj;
#if defined(__i386__)
vm_region_basic_info_data_t info; vm_region_basic_info_data_t info;
vm_region_flavor_t flavor = VM_REGION_BASIC_INFO; vm_region_flavor_t flavor = VM_REGION_BASIC_INFO;
memory_object_name_t obj;
mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT; mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT;
kern_return_t kr = vm_region(mach_task_self(), &vmaddr, &ignoreSize, flavor, kern_return_t kr = vm_region(mach_task_self(), &vmaddr, &ignoreSize, flavor,
(vm_region_info_t)&info, &count, &obj); (vm_region_info_t)&info, &count, &obj);
#elif defined(__x86_64__)
vm_region_basic_info_data_64_t info;
vm_region_flavor_t flavor = VM_REGION_BASIC_INFO_64;
mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64;
kern_return_t kr = vm_region_64(mach_task_self(), &vmaddr, &ignoreSize, flavor,
(vm_region_info_64_t)&info, &count, &obj);
#endif
if (kr != KERN_SUCCESS) if (kr != KERN_SUCCESS)
return false; return false;
*bits = 0; *bits = 0;
@ -333,7 +340,7 @@ namespace SourceHook
return false; return false;
#elif SH_SYS == SH_SYS_APPLE #elif SH_SYS == SH_SYS_APPLE
struct sigaction sa, osa; struct sigaction sa, osa, osa2;
sa.sa_sigaction = BadReadHandler; sa.sa_sigaction = BadReadHandler;
sa.sa_flags = SA_SIGINFO | SA_RESTART; sa.sa_flags = SA_SIGINFO | SA_RESTART;
@ -344,6 +351,8 @@ namespace SourceHook
if (sigaction(SIGBUS, &sa, &osa) == -1) if (sigaction(SIGBUS, &sa, &osa) == -1)
return false; return false;
if (sigaction(SIGSEGV, &sa, &osa2) == -1)
return false;
volatile const char *p = reinterpret_cast<const char *>(addr); volatile const char *p = reinterpret_cast<const char *>(addr);
char dummy; char dummy;
@ -354,6 +363,7 @@ namespace SourceHook
g_BadReadCalled = false; g_BadReadCalled = false;
sigaction(SIGBUS, &osa, NULL); sigaction(SIGBUS, &osa, NULL);
sigaction(SIGSEGV, &osa2, NULL);
return true; return true;
#elif SH_XP == SH_XP_WINAPI #elif SH_XP == SH_XP_WINAPI

View File

@ -48,25 +48,35 @@ namespace SourceHook
#if SH_COMP==SH_COMP_GCC #if SH_COMP==SH_COMP_GCC
if ((((ptrdiff_t)m_OrigEntry) & 1) != 0) if ((((ptrdiff_t)m_OrigEntry) & 1) != 0)
{ {
// Odd orig entry.
if (SH_PTRSIZE != 4)
{
// We only have code for IA32 atm!
return false;
}
// Generate a new thunk // Generate a new thunk
m_OrigCallThunk = ms_AlignedPageAllocator.Alloc(5); m_OrigCallThunk = ms_AlignedPageAllocator.Alloc(12);
ms_AlignedPageAllocator.SetRW(m_OrigCallThunk); ms_AlignedPageAllocator.SetRW(m_OrigCallThunk);
unsigned char* thunkBase = reinterpret_cast<unsigned char*>(m_OrigCallThunk); unsigned char* thunkBase = reinterpret_cast<unsigned char*>(m_OrigCallThunk);
*(thunkBase + 0) = 0xE9; // offset jump, immediate operand ptrdiff_t offset = reinterpret_cast<unsigned char*>(m_OrigEntry) - thunkBase - 5;
ptrdiff_t *offsetAddr = reinterpret_cast<ptrdiff_t*>(thunkBase + 1);
if (offset >= INT_MIN && offset <= INT_MAX)
{
*(thunkBase + 0) = 0xE9; // offset jump, immediate operand
ptrdiff_t *offsetAddr = reinterpret_cast<ptrdiff_t*>(thunkBase + 1);
// destination = src + offset + 5 // destination = src + offset + 5
// <=> offset = destination - src - 5 // <=> offset = destination - src - 5
*offsetAddr = *offsetAddr = offset;
(reinterpret_cast<unsigned char*>(m_OrigEntry) - thunkBase) - 5; }
else
{
// mov rax, m_origEntry
*(thunkBase + 0) = 0x48;
*(thunkBase + 1) = 0xB8;
void **offsetAddr = reinterpret_cast<void**>(thunkBase + 2);
*offsetAddr = m_OrigEntry;
// jmp rax
*(thunkBase + 10) = 0xFF;
*(thunkBase + 11) = 0xE0;
}
ms_AlignedPageAllocator.SetRE(m_OrigCallThunk); ms_AlignedPageAllocator.SetRE(m_OrigCallThunk);
} }

View File

@ -1,35 +1,40 @@
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
import os import os
binary = MMS.Program(builder, "test_sourcehook") for arch in MMS.archs:
binary.compiler.cxxincludes += [ name = 'test_sourcehook'
os.path.join(builder.sourcePath, 'core', 'sourcehook'), binary = MMS.Program(builder, name, arch)
] binary.compiler.cxxincludes += [
os.path.join(builder.sourcePath, 'core', 'sourcehook'),
]
if binary.compiler.version >= 'clang-2.9' or binary.compiler.version >= 'apple-clang-3.0':
binary.compiler.cxxflags += ['-Wno-null-dereference']
binary.sources += [ binary.sources += [
'main.cpp', 'main.cpp',
'../sourcehook.cpp', '../sourcehook.cpp',
'../sourcehook_hookmangen.cpp', '../sourcehook_impl_chookmaninfo.cpp',
'../sourcehook_impl_chookmaninfo.cpp', '../sourcehook_impl_chookidman.cpp',
'../sourcehook_impl_chookidman.cpp', '../sourcehook_impl_cproto.cpp',
'../sourcehook_impl_cproto.cpp', '../sourcehook_impl_cvfnptr.cpp',
'../sourcehook_impl_cvfnptr.cpp', 'test1.cpp',
'test1.cpp', 'test2.cpp',
'test2.cpp', 'test3.cpp',
'test3.cpp', 'test4.cpp',
'test4.cpp', 'testbail.cpp',
'testbail.cpp', 'testbail2.cpp',
'testbail2.cpp', 'testhookmangen.cpp',
'testhookmangen.cpp', 'testlist.cpp',
'testlist.cpp', 'testmanual.cpp',
'testmanual.cpp', 'testmulti.cpp',
'testmulti.cpp', 'testoddthunks.cpp',
'testoddthunks.cpp', 'testrecall.cpp',
'testrecall.cpp', 'testreentr.cpp',
'testreentr.cpp', 'testref.cpp',
'testref.cpp', 'testrefret.cpp',
'testrefret.cpp', 'testvphooks.cpp',
'testvphooks.cpp', ]
] if arch == 'x86':
binary.sources += ['../sourcehook_hookmangen.cpp']
builder.Add(binary) builder.Add(binary)

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[])
DO_TEST(RefRet); DO_TEST(RefRet);
DO_TEST(VPHooks); DO_TEST(VPHooks);
DO_TEST(CPageAlloc); DO_TEST(CPageAlloc);
#if !defined( _M_AMD64 ) && !defined( __amd64__ ) // TODO: Fix for 64-bit #if !defined( _M_AMD64 ) && !defined( __amd64__ ) && !defined(__x86_64__) // TODO: Fix for 64-bit
DO_TEST(HookManGen); DO_TEST(HookManGen);
#endif #endif
DO_TEST(OddThunks); DO_TEST(OddThunks);
@ -128,6 +128,7 @@ void Test_UnpausePlugin(SourceHook::ISourceHook *shptr, SourceHook::Plugin plug)
static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug); static_cast<SourceHook::Impl::CSourceHookImpl *>(shptr)->UnpausePlugin(plug);
} }
#if !defined( _M_AMD64 ) && !defined( __amd64__ ) && !defined(__x86_64__)
SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr) SourceHook::IHookManagerAutoGen *Test_HMAG_Factory(SourceHook::ISourceHook *shptr)
{ {
return new SourceHook::Impl::CHookManagerAutoGen(shptr); return new SourceHook::Impl::CHookManagerAutoGen(shptr);
@ -137,4 +138,5 @@ void Test_HMAG_Delete(SourceHook::IHookManagerAutoGen *ptr)
{ {
delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr); delete static_cast<SourceHook::Impl::CHookManagerAutoGen*>(ptr);
} }
#endif

View File

@ -1,4 +1,5 @@
#include <string> #include <string>
#include <cstdlib>
#include "sourcehook.h" #include "sourcehook.h"
#include "sourcehook_test.h" #include "sourcehook_test.h"
#include "testevents.h" #include "testevents.h"
@ -1093,7 +1094,7 @@ namespace
} }
} }
#if !defined( _M_AMD64 ) && !defined( __amd64__ ) && !defined(__x86_64__)
bool TestHookManGen(std::string &error) bool TestHookManGen(std::string &error)
{ {
GET_SHPTR(g_SHPtr); GET_SHPTR(g_SHPtr);
@ -1133,6 +1134,7 @@ bool TestHookManGen(std::string &error)
return true; return true;
} }
#endif
bool TestCPageAlloc(std::string &error) bool TestCPageAlloc(std::string &error)
{ {
@ -1179,13 +1181,13 @@ bool TestCPageAlloc(std::string &error)
test4[i] = (char*) alloc.AllocIsolated(ps / 4); test4[i] = (char*) alloc.AllocIsolated(ps / 4);
// -> The difference is at least one page // -> The difference is at least one page
CHECK_COND(static_cast<size_t>(abs(test4[1] - test4[0])) >= ps, "Part 3.1"); CHECK_COND(static_cast<size_t>(std::abs(test4[1] - test4[0])) >= ps, "Part 3.1");
CHECK_COND(static_cast<size_t>(abs(test4[2] - test4[1])) >= ps, "Part 3.2"); CHECK_COND(static_cast<size_t>(std::abs(test4[2] - test4[1])) >= ps, "Part 3.2");
CHECK_COND(static_cast<size_t>(abs(test4[3] - test4[2])) >= ps, "Part 3.3"); CHECK_COND(static_cast<size_t>(std::abs(test4[3] - test4[2])) >= ps, "Part 3.3");
CHECK_COND(static_cast<size_t>(abs(test4[5] - test4[4])) >= ps, "Part 3.4"); CHECK_COND(static_cast<size_t>(std::abs(test4[5] - test4[4])) >= ps, "Part 3.4");
CHECK_COND(static_cast<size_t>(abs(test4[6] - test4[5])) >= ps, "Part 3.5"); CHECK_COND(static_cast<size_t>(std::abs(test4[6] - test4[5])) >= ps, "Part 3.5");
CHECK_COND(static_cast<size_t>(abs(test4[7] - test4[6])) >= ps, "Part 3.6"); CHECK_COND(static_cast<size_t>(std::abs(test4[7] - test4[6])) >= ps, "Part 3.6");
// Thus i can set everything except for test4[2] to RE and still write to test4[2] // Thus i can set everything except for test4[2] to RE and still write to test4[2]

View File

@ -1,8 +1,9 @@
# vim: set ts=8 sts=2 sw=2 tw=99 et ft=python: # vim: set ts=8 sts=2 sw=2 tw=99 et ft=python:
import os.path import os.path
def configure_library(name, linux_defines): def configure_library(name, linux_defines, arch):
binary = MMS.Library(builder, name) libname = name
binary = MMS.Library(builder, libname, arch)
binary.compiler.cxxincludes += [os.path.join(builder.sourcePath, 'core', 'sourcehook')] binary.compiler.cxxincludes += [os.path.join(builder.sourcePath, 'core', 'sourcehook')]
binary.sources += [ binary.sources += [
'loader.cpp', 'loader.cpp',
@ -17,11 +18,11 @@ def configure_library(name, linux_defines):
nodes = builder.Add(binary) nodes = builder.Add(binary)
MMS.binaries += [nodes] MMS.binaries += [nodes]
libname = 'server' for arch in MMS.archs:
if builder.target.platform == 'linux' and builder.target.arch == 'x86_64': if builder.target.platform == 'linux':
libname = 'libserver' if arch == 'x64':
configure_library('libserver', ['LIB_PREFIX="lib"', 'LIB_SUFFIX=".so"'], arch)
elif arch == 'x86':
configure_library('server_i486', ['LIB_PREFIX=""', 'LIB_SUFFIX="_i486.so"'], arch)
configure_library(libname, ['LIB_PREFIX="lib"', 'LIB_SUFFIX=".so"']) configure_library('server', ['LIB_PREFIX="lib"', 'LIB_SUFFIX=".so"'], arch)
if builder.target.platform == 'linux' and builder.target.arch == 'x86':
configure_library('server_i486', ['LIB_PREFIX=""', 'LIB_SUFFIX="_i486.so"'])

View File

@ -85,7 +85,11 @@ OS := $(shell uname -s)
ifeq "$(OS)" "Darwin" ifeq "$(OS)" "Darwin"
LIB_EXT = dylib LIB_EXT = dylib
HL2LIB = $(HL2SDK)/lib/mac ifeq "$(ENGINE)" "csgo"
HL2LIB = $(HL2SDK)/lib/osx64
else
HL2LIB = $(HL2SDK)/lib/mac
endif
else else
LIB_EXT = so LIB_EXT = so
ifeq "$(ENGINE)" "original" ifeq "$(ENGINE)" "original"
@ -111,14 +115,25 @@ else
endif endif
endif endif
ifeq "$(OS)" "Darwin"
ifeq "$(ENGINE)" "csgo"
STATIC_SUFFIX =
LIB_SUFFIX = .x64.$(LIB_EXT)
else
STATIC_SUFFIX = _i486
endif
else
STATIC_SUFFIX = _i486
endif
CFLAGS += -DSE_EPISODEONE=1 -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_BLOODYGOODTIME=4 -DSE_EYE=5 \ CFLAGS += -DSE_EPISODEONE=1 -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_BLOODYGOODTIME=4 -DSE_EYE=5 \
-DSE_CSS=6 -DSE_ORANGEBOXVALVE=7 -DSE_LEFT4DEAD=8 -DSE_LEFT4DEAD2=9 -DSE_ALIENSWARM=10 \ -DSE_CSS=6 -DSE_ORANGEBOXVALVE=7 -DSE_LEFT4DEAD=8 -DSE_LEFT4DEAD2=9 -DSE_ALIENSWARM=10 \
-DSE_PORTAL2=11 -DSE_CSGO=12 -DSE_PORTAL2=11 -DSE_CSGO=12
LINK += $(HL2LIB)/tier1_i486.a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX) LINK += $(HL2LIB)/tier1$(STATIC_SUFFIX).a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX)
ifeq "$(ENGINE)" "csgo" ifeq "$(ENGINE)" "csgo"
LINK += $(HL2LIB)/interfaces_i486.a LINK += $(HL2LIB)/interfaces$(STATIC_SUFFIX).a
endif endif
INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \ INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \
@ -141,12 +156,19 @@ endif
ifeq "$(OS)" "Darwin" ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX) CPP = $(CPP_OSX)
LIB_EXT = dylib LIB_EXT = dylib
CFLAGS += -DOSX -D_OSX CFLAGS += -DOSX -D_OSX -mmacosx-version-min=10.9
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5 LINK += -dynamiclib -lc++ -mmacosx-version-min=10.9
ifeq "$(ENGINE)" "csgo"
CFLAGS += -m64 -DX64BITS -DPLATFORM_64BITS
LINK += -m64
else
CFLAGS += -m32
LINK += -m32
endif
else else
LIB_EXT = so LIB_EXT = so
CFLAGS += -D_LINUX CFLAGS += -D_LINUX -m32
LINK += -shared LINK += -shared -m32
endif endif
IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0") IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
@ -162,7 +184,7 @@ endif
CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \
-Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \
-Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \ -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \
-Werror -fPIC -fno-exceptions -fno-rtti -msse -m32 -fno-strict-aliasing -Werror -fPIC -fno-exceptions -fno-rtti -msse -fno-strict-aliasing
# Clang || GCC >= 4 # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1" ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
@ -171,7 +193,7 @@ endif
# Clang >= 3 || GCC >= 4.7 # Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1" ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor CFLAGS += -Wno-delete-non-virtual-dtor -Wno-unused-private-field -Wno-deprecated-register
endif endif
# OS is Linux and not using clang # OS is Linux and not using clang
@ -198,7 +220,7 @@ check:
fi fi
sample_mm: check $(OBJ_BIN) sample_mm: check $(OBJ_BIN)
$(CPP) $(INCLUDE) -m32 $(OBJ_BIN) $(LINK) -ldl -lm -o $(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -ldl -lm -o $(BIN_DIR)/$(BINARY)
default: all default: all

View File

@ -26,7 +26,7 @@ OBJECTS = stub_mm.cpp
############################################## ##############################################
OPT_FLAGS = -O3 -funroll-loops -pipe OPT_FLAGS = -O3 -funroll-loops -pipe
GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden -std=c++11
DEBUG_FLAGS = -g -ggdb3 -D_DEBUG DEBUG_FLAGS = -g -ggdb3 -D_DEBUG
CPP = gcc CPP = gcc
CPP_OSX = clang CPP_OSX = clang
@ -85,7 +85,11 @@ OS := $(shell uname -s)
ifeq "$(OS)" "Darwin" ifeq "$(OS)" "Darwin"
LIB_EXT = dylib LIB_EXT = dylib
HL2LIB = $(HL2SDK)/lib/mac ifeq "$(ENGINE)" "csgo"
HL2LIB = $(HL2SDK)/lib/osx64
else
HL2LIB = $(HL2SDK)/lib/mac
endif
else else
LIB_EXT = so LIB_EXT = so
ifeq "$(ENGINE)" "original" ifeq "$(ENGINE)" "original"
@ -111,14 +115,24 @@ else
endif endif
endif endif
ifeq "$(OS)" "Darwin"
ifeq "$(ENGINE)" "csgo"
STATIC_SUFFIX =
else
STATIC_SUFFIX = _i486
endif
else
STATIC_SUFFIX = _i486
endif
CFLAGS += -DSE_EPISODEONE=1 -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_BLOODYGOODTIME=4 -DSE_EYE=5 \ CFLAGS += -DSE_EPISODEONE=1 -DSE_DARKMESSIAH=2 -DSE_ORANGEBOX=3 -DSE_BLOODYGOODTIME=4 -DSE_EYE=5 \
-DSE_CSS=6 -DSE_ORANGEBOXVALVE=7 -DSE_LEFT4DEAD=8 -DSE_LEFT4DEAD2=9 -DSE_ALIENSWARM=10 \ -DSE_CSS=6 -DSE_ORANGEBOXVALVE=7 -DSE_LEFT4DEAD=8 -DSE_LEFT4DEAD2=9 -DSE_ALIENSWARM=10 \
-DSE_PORTAL2=11 -DSE_CSGO=12 -DSE_PORTAL2=11 -DSE_CSGO=12
LINK += $(HL2LIB)/tier1_i486.a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX) LINK += $(HL2LIB)/tier1$(STATIC_SUFFIX).a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX)
ifeq "$(ENGINE)" "csgo" ifeq "$(ENGINE)" "csgo"
LINK += $(HL2LIB)/interfaces_i486.a LINK += $(HL2LIB)/interfaces$(STATIC_SUFFIX).a
endif endif
INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \ INCLUDE += -I. -I.. -I$(HL2PUB) -I$(HL2PUB)/engine -I$(HL2PUB)/mathlib -I$(HL2PUB)/vstdlib \
@ -138,16 +152,22 @@ else
CFLAGS += $(OPT_FLAGS) CFLAGS += $(OPT_FLAGS)
endif endif
ifeq "$(OS)" "Darwin" ifeq "$(OS)" "Darwin"
CPP = $(CPP_OSX) CPP = $(CPP_OSX)
LIB_EXT = dylib LIB_EXT = dylib
CFLAGS += -DOSX -D_OSX CFLAGS += -DOSX -D_OSX -mmacosx-version-min=10.9
LINK += -dynamiclib -lstdc++ -mmacosx-version-min=10.5 LINK += -dynamiclib -lc++ -mmacosx-version-min=10.9
ifeq "$(ENGINE)" "csgo"
CFLAGS += -m64 -DX64BITS -DPLATFORM_64BITS
LINK += -m64
else
CFLAGS += -m32
LINK += -m32
endif
else else
LIB_EXT = so LIB_EXT = so
CFLAGS += -D_LINUX CFLAGS += -D_LINUX -m32
LINK += -shared LINK += -shared -m32
endif endif
IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0") IS_CLANG := $(shell $(CPP) --version | head -1 | grep clang > /dev/null && echo "1" || echo "0")
@ -163,7 +183,7 @@ endif
CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \ CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp \
-Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \ -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca \
-Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \ -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Wno-non-virtual-dtor -Wno-overloaded-virtual \
-Werror -fPIC -fno-exceptions -fno-rtti -msse -m32 -fno-strict-aliasing -Werror -fPIC -fno-exceptions -fno-rtti -msse -fno-strict-aliasing
# Clang || GCC >= 4 # Clang || GCC >= 4
ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1" ifeq "$(shell expr $(IS_CLANG) \| $(CPP_MAJOR) \>= 4)" "1"
@ -172,7 +192,7 @@ endif
# Clang >= 3 || GCC >= 4.7 # Clang >= 3 || GCC >= 4.7
ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1" ifeq "$(shell expr $(IS_CLANG) \& $(CPP_MAJOR) \>= 3 \| $(CPP_MAJOR) \>= 4 \& $(CPP_MINOR) \>= 7)" "1"
CFLAGS += -Wno-delete-non-virtual-dtor CFLAGS += -Wno-delete-non-virtual-dtor -Wno-unused-private-field -Wno-deprecated-register
endif endif
# OS is Linux and not using clang # OS is Linux and not using clang
@ -199,7 +219,7 @@ check:
fi fi
stub_mm: check $(OBJ_BIN) stub_mm: check $(OBJ_BIN)
$(CPP) $(INCLUDE) -m32 $(OBJ_BIN) $(LINK) -ldl -lm -o $(BIN_DIR)/$(BINARY) $(CPP) $(INCLUDE) $(OBJ_BIN) $(LINK) -ldl -lm -o $(BIN_DIR)/$(BINARY)
default: all default: all

View File

@ -20,7 +20,7 @@ for cxx_task in cxx_tasks:
elif builder.target.platform == 'windows': elif builder.target.platform == 'windows':
argv = ['dump_syms.exe', debug_file] argv = ['dump_syms.exe', debug_file]
base_file = os.path.splitext(os.path.basename(debug_file))[0] base_file = os.path.split(os.path.dirname(debug_file))[1]
symbol_file = base_file + '.breakpad' symbol_file = base_file + '.breakpad'
argv = [sys.executable, UPLOAD_SCRIPT, symbol_file] + argv argv = [sys.executable, UPLOAD_SCRIPT, symbol_file] + argv

View File

@ -7,13 +7,31 @@ addons_folder = builder.AddFolder('addons')
metamod_folder = builder.AddFolder(os.path.join('addons', 'metamod')) metamod_folder = builder.AddFolder(os.path.join('addons', 'metamod'))
bin_folder = builder.AddFolder(os.path.join('addons', 'metamod', 'bin')) bin_folder = builder.AddFolder(os.path.join('addons', 'metamod', 'bin'))
for arch in MMS.archs:
if arch == 'x64':
if builder.target.platform == 'windows':
bin64_folder = builder.AddFolder(os.path.join('addons', 'metamod', 'bin', 'win64'))
builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metamod_win64.vdf'),
os.path.join('addons', 'metamod_x64.vdf'))
elif builder.target.platform == 'linux':
bin64_folder = builder.AddFolder(os.path.join('addons', 'metamod', 'bin', 'linux64'))
builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metamod_linux64.vdf'),
os.path.join('addons', 'metamod_x64.vdf'))
elif builder.target.platform == 'mac':
bin64_folder = builder.AddFolder(os.path.join('addons', 'metamod', 'bin', 'osx64'))
builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metamod_osx64.vdf'),
os.path.join('addons', 'metamod_x64.vdf'))
builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metamod.vdf'), addons_folder) builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metamod.vdf'), addons_folder)
builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metaplugins.ini'), metamod_folder) builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'metaplugins.ini'), metamod_folder)
builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'README.txt'), metamod_folder) builder.AddCopy(os.path.join(builder.sourcePath, 'support', 'README.txt'), metamod_folder)
pdb_list = [] pdb_list = []
for task in MMS.binaries: for task in MMS.binaries:
builder.AddCopy(task.binary, bin_folder) if '.x64' + os.sep in task.binary.path:
builder.AddCopy(task.binary, bin64_folder)
else:
builder.AddCopy(task.binary, bin_folder)
if task.debug: if task.debug:
pdb_list.append(task.debug) pdb_list.append(task.debug)

View File

@ -44,6 +44,12 @@ if ($^O =~ /darwin/) {
push(@conf_argv, '--hl2sdk-root=H:\\'); push(@conf_argv, '--hl2sdk-root=H:\\');
} }
if ($^O !~ /MSWin/) {
push(@conf_argv, '--target-arch=x86,x64');
} else {
push(@conf_argv, '--target-arch=x86');
}
my $conf_args = join(' ', @conf_argv); my $conf_args = join(' ', @conf_argv);
if ($argn > 0 && $^O !~ /MSWin/) { if ($argn > 0 && $^O !~ /MSWin/) {

View File

@ -0,0 +1,5 @@
"Plugin"
{
"file" "addons/metamod/bin/linux64/server"
}

View File

@ -0,0 +1,5 @@
"Plugin"
{
"file" "addons/metamod/bin/osx64/server"
}

View File

@ -0,0 +1,5 @@
"Plugin"
{
"file" "addons/metamod/bin/win64/server"
}

View File

@ -1,13 +1,16 @@
# vim: sts=2 ts=8 sw=2 tw=99 et ft=python: # vim: sts=2 ts=8 sw=2 tw=99 et ft=python:
lib = builder.cxx.StaticLibrary("version") rvalue = {}
lib.compiler.defines.remove('MMS_USE_VERSIONLIB') for arch in MMS.archs:
lib.compiler.sourcedeps += MMS.generated_headers libname = 'version'
lib.sources += [ lib = MMS.StaticLibrary(builder, libname, arch)
'versionlib.cpp' lib.compiler.defines.remove('MMS_USE_VERSIONLIB')
] lib.compiler.sourcedeps += MMS.generated_headers
lib.sources += [
'versionlib.cpp'
]
cmd = builder.Add(lib) cmd = builder.Add(lib)
rvalue = cmd.binary rvalue[arch] = cmd.binary