updated build environment, can atm only build on 32bit, also needs hl2sdk-manifests in the folder
This commit is contained in:
		
							parent
							
								
									2eb343d6e0
								
							
						
					
					
						commit
						b17de382d8
					
				
							
								
								
									
										454
									
								
								AMBuildScript
									
									
									
									
									
								
							
							
						
						
									
										454
									
								
								AMBuildScript
									
									
									
									
									
								
							| @ -1,26 +1,5 @@ | ||||
| # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: | ||||
| import os, sys | ||||
| 
 | ||||
| # Simple extensions do not need to modify this file. | ||||
| 
 | ||||
| class SDK(object): | ||||
|   def __init__(self, sdk, ext, aDef, name, platform, dir): | ||||
|     self.folder = 'hl2sdk-' + dir | ||||
|     self.envvar = sdk | ||||
|     self.ext = ext | ||||
|     self.code = aDef | ||||
|     self.define = name | ||||
|     self.platform = platform | ||||
|     self.name = dir | ||||
|     self.path = None # Actual path | ||||
| 
 | ||||
| WinOnly = ['windows'] | ||||
| WinLinux = ['windows', 'linux'] | ||||
| WinLinuxMac = ['windows', 'linux', 'mac'] | ||||
| 
 | ||||
| PossibleSDKs = { | ||||
|   'css':  SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'), | ||||
| } | ||||
| import os | ||||
| 
 | ||||
| def ResolveEnvPath(env, folder): | ||||
|   if env in os.environ: | ||||
| @ -43,14 +22,71 @@ def ResolveEnvPath(env, folder): | ||||
| def Normalize(path): | ||||
|   return os.path.abspath(os.path.normpath(path)) | ||||
|    | ||||
| def SetArchFlags(compiler): | ||||
|   if compiler.behavior == 'gcc': | ||||
|     if compiler.target.arch == 'x86_64': | ||||
|       compiler.cflags += ['-fPIC'] | ||||
|   elif compiler.like('msvc'): | ||||
|     if compiler.target.arch == 'x86_64': | ||||
|       compiler.defines += ['WIN64'] | ||||
| 
 | ||||
| hl2sdk_manifests_path = None | ||||
| 
 | ||||
| # First we check if the manifest exists in the current path | ||||
| hl2sdk_manifests_path = os.path.join(builder.sourcePath, 'hl2sdk-manifests/SdkHelpers.ambuild') | ||||
| 
 | ||||
| if not os.path.exists(hl2sdk_manifests_path): | ||||
|   # manifests does not exists in the project file, use the path from --hl2sdk-manifest-path | ||||
|   if not builder.options.hl2sdk_manifest: | ||||
|     raise Exception('HL2SDK Manifest root path not set! (--hl2sdk-manifest-path)') | ||||
|   else: | ||||
|     hl2sdk_manifests_path = os.path.join(builder.options.hl2sdk_manifest, 'SdkHelpers.ambuild') | ||||
| 
 | ||||
|     if not os.path.exists(hl2sdk_manifests_path): | ||||
|       raise Exception('Could not find SdkHelpers.ambuild in the given HL2SDK Manifest path!') | ||||
| 
 | ||||
| 
 | ||||
| SdkHelpers = builder.Eval(hl2sdk_manifests_path, { | ||||
|     'Project': 'sm-extension' | ||||
| }) | ||||
| 
 | ||||
| class ExtensionConfig(object): | ||||
|   def __init__(self): | ||||
|     self.sdk_manifests = [] | ||||
|     self.sdks = {} | ||||
|     self.binaries = [] | ||||
|     self.sdk_targets = [] | ||||
|     self.extensions = [] | ||||
|     self.generated_headers = None | ||||
|     self.mms_root = None | ||||
|     self.sm_root = None | ||||
|     self.all_targets = [] | ||||
|     self.target_archs = set() | ||||
|     self.libsafetyhook = {} | ||||
| 
 | ||||
|     if builder.options.targets: | ||||
|       target_archs = builder.options.targets.split(',') | ||||
|     else: | ||||
|       target_archs = ['x86', 'x86_64'] | ||||
| 
 | ||||
|     for arch in target_archs: | ||||
|         try: | ||||
|             cxx = builder.DetectCxx(target_arch = arch) | ||||
|             self.target_archs.add(cxx.target.arch) | ||||
|         except Exception as e: | ||||
|             # Error if archs were manually overridden. | ||||
|             if builder.options.targets: | ||||
|                 raise | ||||
|             print('Skipping target {}: {}'.format(arch, e)) | ||||
|             continue | ||||
|         self.all_targets.append(cxx) | ||||
| 
 | ||||
|     if not self.all_targets: | ||||
|         raise Exception('No suitable C/C++ compiler was found.') | ||||
| 
 | ||||
|   def use_auto_versioning(self): | ||||
|     if builder.backend != 'amb2': | ||||
|       return False | ||||
|     return not getattr(builder.options, 'disable_auto_versioning', False) | ||||
| 
 | ||||
|   @property | ||||
|   def tag(self): | ||||
| @ -58,48 +94,35 @@ class ExtensionConfig(object): | ||||
|       return 'Debug' | ||||
|     return 'Release' | ||||
| 
 | ||||
|   def detectSDKs(self): | ||||
|     sdk_list = builder.options.sdks.split(',') | ||||
|     use_all = sdk_list[0] == 'all' | ||||
|     use_present = sdk_list[0] == 'present' | ||||
| 
 | ||||
|     for sdk_name in PossibleSDKs: | ||||
|       sdk = PossibleSDKs[sdk_name] | ||||
|       if builder.target_platform in sdk.platform: | ||||
|   def findSdkPath(self, sdk_name): | ||||
|     dir_name = 'hl2sdk-{}'.format(sdk_name) | ||||
|     if builder.options.hl2sdk_root: | ||||
|           sdk_path = os.path.join(builder.options.hl2sdk_root, sdk.folder) | ||||
|         else: | ||||
|           sdk_path = ResolveEnvPath(sdk.envvar, sdk.folder) | ||||
|         if sdk_path is None or not os.path.isdir(sdk_path): | ||||
|           if use_all or sdk_name in sdk_list: | ||||
|             raise Exception('Could not find a valid path for {0}'.format(sdk.envvar)) | ||||
|           continue | ||||
|         if use_all or use_present or sdk_name in sdk_list: | ||||
|           sdk.path = Normalize(sdk_path) | ||||
|           self.sdks[sdk_name] = sdk | ||||
|       sdk_path = os.path.join(builder.options.hl2sdk_root, dir_name) | ||||
|       if os.path.exists(sdk_path): | ||||
|         return sdk_path | ||||
|     return ResolveEnvPath('HL2SDK{}'.format(sdk_name.upper()), dir_name) | ||||
| 
 | ||||
|     if len(self.sdks) < 1: | ||||
|       raise Exception('At least one SDK must be available.') | ||||
|   def shouldIncludeSdk(self, sdk): | ||||
|     return not sdk.get('source2', False) | ||||
| 
 | ||||
|     if builder.options.sm_path: | ||||
|       self.sm_root = builder.options.sm_path | ||||
|     else: | ||||
|       self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8') | ||||
|       if not self.sm_root: | ||||
|         self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') | ||||
|       if not self.sm_root: | ||||
|         self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central') | ||||
|   def detectSDKs(self): | ||||
|     sdk_list = [s for s in builder.options.sdks.split(',') if s] | ||||
|     SdkHelpers.sdk_filter = self.shouldIncludeSdk | ||||
|     SdkHelpers.find_sdk_path = self.findSdkPath | ||||
|     SdkHelpers.findSdks(builder, self.all_targets, sdk_list) | ||||
| 
 | ||||
|     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) | ||||
|     self.sdks = SdkHelpers.sdks | ||||
|     self.sdk_manifests = SdkHelpers.sdk_manifests | ||||
|     self.sdk_targets = SdkHelpers.sdk_targets | ||||
| 
 | ||||
|     if builder.options.mms_path: | ||||
|       self.mms_root = builder.options.mms_path | ||||
|     else: | ||||
|       self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10') | ||||
|       self.mms_root = ResolveEnvPath('MMSOURCE112', 'mmsource-1.12') | ||||
|       if not self.mms_root: | ||||
|         self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source') | ||||
|       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') | ||||
| 
 | ||||
| @ -107,15 +130,48 @@ class ExtensionConfig(object): | ||||
|       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: | ||||
|       self.sm_root = ResolveEnvPath('SOURCEMOD112', 'sourcemod-1.12') | ||||
|       if not self.sm_root: | ||||
|         self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') | ||||
|       if not self.sm_root: | ||||
|         self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod') | ||||
|       if not self.sm_root: | ||||
|         self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central') | ||||
| 
 | ||||
|     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): | ||||
|     cxx = builder.DetectCompilers() | ||||
|      | ||||
|     allowed_archs = ['x86','x86_64'] | ||||
| 
 | ||||
|     if not set(self.target_archs).issubset(allowed_archs): | ||||
|       raise Exception('Unknown target architecture: {0}'.format(self.target_archs)) | ||||
| 
 | ||||
|     for cxx in self.all_targets: | ||||
|         self.configure_cxx(cxx) | ||||
| 
 | ||||
|   def configure_cxx(self, cxx): | ||||
|     if cxx.family == 'msvc': | ||||
|       if cxx.version < 1914 and builder.options.generator != 'vs': | ||||
|         raise Exception(f'Only MSVC 2017 15.7 and later are supported, full C++17 support is required. ({str(cxx.version)} < 1914)') | ||||
|     elif cxx.family == 'gcc': | ||||
|       if cxx.version < 'gcc-8': | ||||
|         raise Exception('Only GCC versions 8 or later are supported, full C++17 support is required.') | ||||
|     elif cxx.family == 'clang': | ||||
|       if cxx.version < 'clang-5': | ||||
|         raise Exception('Only clang versions 5 or later are supported, full C++17 support is required.') | ||||
| 
 | ||||
|     if cxx.like('gcc'): | ||||
|       self.configure_gcc(cxx) | ||||
|     elif cxx.vendor == 'msvc': | ||||
|     elif cxx.family == 'msvc': | ||||
|       self.configure_msvc(cxx) | ||||
| 
 | ||||
|     # Optimizaiton | ||||
|     # Optimization | ||||
|     if builder.options.opt == '1': | ||||
|       cxx.defines += ['NDEBUG'] | ||||
| 
 | ||||
| @ -124,18 +180,13 @@ class ExtensionConfig(object): | ||||
|       cxx.defines += ['DEBUG', '_DEBUG'] | ||||
| 
 | ||||
|     # Platform-specifics | ||||
|     if builder.target_platform == 'linux': | ||||
|     if cxx.target.platform == 'linux': | ||||
|       self.configure_linux(cxx) | ||||
|     elif builder.target_platform == 'mac': | ||||
|     elif cxx.target.platform == 'mac': | ||||
|       self.configure_mac(cxx) | ||||
|     elif builder.target_platform == 'windows': | ||||
|     elif cxx.target.platform == 'windows': | ||||
|       self.configure_windows(cxx) | ||||
| 
 | ||||
|     # Finish up. | ||||
|     cxx.includes += [ | ||||
|       os.path.join(self.sm_root, 'public'), | ||||
|     ] | ||||
| 
 | ||||
|   def configure_gcc(self, cxx): | ||||
|     cxx.defines += [ | ||||
|       'stricmp=strcasecmp', | ||||
| @ -149,50 +200,52 @@ class ExtensionConfig(object): | ||||
|       '-pipe', | ||||
|       '-fno-strict-aliasing', | ||||
|       '-Wall', | ||||
| #      '-Werror', | ||||
|       '-Werror', | ||||
|       '-Wno-unused', | ||||
|       '-Wno-switch', | ||||
|       '-Wno-array-bounds', | ||||
|       '-msse', | ||||
|       '-m32', | ||||
|       '-fvisibility=hidden', | ||||
|     ] | ||||
| 
 | ||||
|     if cxx.target.arch in ['x86', 'x86_64']: | ||||
|       cxx.cflags += ['-msse'] | ||||
| 
 | ||||
|     cxx.cxxflags += [ | ||||
|       '-std=c++11', | ||||
|       '-fno-exceptions', | ||||
|       '-fno-threadsafe-statics', | ||||
|       '-Wno-non-virtual-dtor', | ||||
|       '-Wno-overloaded-virtual', | ||||
|       '-Wno-register', | ||||
|       '-fvisibility-inlines-hidden', | ||||
|       '-std=c++17', | ||||
|     ] | ||||
|     cxx.linkflags += ['-m32'] | ||||
| 
 | ||||
|     have_gcc = cxx.vendor == 'gcc' | ||||
|     have_clang = cxx.vendor == 'clang' | ||||
|     if cxx.version >= 'clang-3.6': | ||||
|       cxx.cxxflags += ['-Wno-inconsistent-missing-override'] | ||||
|     if have_clang or (cxx.version >= 'gcc-4.6'): | ||||
|       cxx.cflags += ['-Wno-narrowing'] | ||||
|     if have_clang or (cxx.version >= 'gcc-4.7'): | ||||
|       cxx.cxxflags += ['-Wno-delete-non-virtual-dtor'] | ||||
|     if cxx.version >= 'gcc-4.8': | ||||
|       cxx.cflags += ['-Wno-unused-result'] | ||||
|      | ||||
|     have_gcc = cxx.family == 'gcc' | ||||
|     have_clang = cxx.family == 'clang' | ||||
| 
 | ||||
|     # Work around errors from smsdk_ext.cpp | ||||
|     if have_clang: | ||||
|       cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch'] | ||||
|       if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4': | ||||
|         cxx.cxxflags += ['-Wno-deprecated-register'] | ||||
|       else: | ||||
|         cxx.cxxflags += ['-Wno-deprecated'] | ||||
|       cxx.cflags += ['-Wno-sometimes-uninitialized'] | ||||
| 
 | ||||
|     # Work around SDK warnings. | ||||
|     if cxx.version >= 'clang-10.0' or cxx.version >= 'apple-clang-12.0': | ||||
|         cxx.cflags += [ | ||||
|             '-Wno-implicit-int-float-conversion', | ||||
|             '-Wno-tautological-overlap-compare', | ||||
|         ] | ||||
| 
 | ||||
|     if have_gcc: | ||||
|       cxx.cflags += ['-mfpmath=sse'] | ||||
|       cxx.cflags += ['-Wno-maybe-uninitialized'] | ||||
| 
 | ||||
|     if builder.options.opt == '1': | ||||
|         cxx.cflags += ['-O3'] | ||||
| 
 | ||||
|     # Don't omit the frame pointer. | ||||
|     cxx.cflags += ['-fno-omit-frame-pointer'] | ||||
| 
 | ||||
|   def configure_msvc(self, cxx): | ||||
| 
 | ||||
|     if builder.options.debug == '1': | ||||
|       cxx.cflags += ['/MTd'] | ||||
|       cxx.linkflags += ['/NODEFAULTLIB:libcmt'] | ||||
| @ -211,9 +264,9 @@ class ExtensionConfig(object): | ||||
|       '/EHsc', | ||||
|       '/GR-', | ||||
|       '/TP', | ||||
|       '/std:c++17', | ||||
|     ] | ||||
|     cxx.linkflags += [ | ||||
|       '/MACHINE:X86', | ||||
|       'kernel32.lib', | ||||
|       'user32.lib', | ||||
|       'gdi32.lib', | ||||
| @ -240,27 +293,40 @@ class ExtensionConfig(object): | ||||
|     cxx.cflags += ['/Oy-'] | ||||
| 
 | ||||
|   def configure_linux(self, cxx): | ||||
|     cxx.defines += ['_LINUX', 'POSIX'] | ||||
|     cxx.linkflags += ['-Wl,--exclude-libs,ALL', '-lm'] | ||||
|     if cxx.vendor == 'gcc': | ||||
|     cxx.defines += ['LINUX', '_LINUX', 'POSIX', '_FILE_OFFSET_BITS=64'] | ||||
|     cxx.linkflags += ['-lm'] | ||||
|     if cxx.family == 'gcc': | ||||
|       cxx.linkflags += ['-static-libgcc'] | ||||
|     elif cxx.vendor == 'clang': | ||||
|     elif cxx.family == 'clang': | ||||
|       cxx.linkflags += ['-lgcc_eh'] | ||||
|     cxx.linkflags += ['-static-libstdc++'] | ||||
| 
 | ||||
|   def configure_mac(self, cxx): | ||||
|     cxx.defines += ['OSX', '_OSX', 'POSIX'] | ||||
|     cxx.cflags += ['-mmacosx-version-min=10.5'] | ||||
|     cxx.defines += ['OSX', '_OSX', 'POSIX', 'KE_ABSOLUTELY_NO_STL'] | ||||
|     cxx.cflags += ['-mmacosx-version-min=10.15'] | ||||
|     cxx.linkflags += [ | ||||
|       '-mmacosx-version-min=10.5', | ||||
|       '-arch', 'i386', | ||||
|       '-lstdc++', | ||||
|       '-stdlib=libstdc++', | ||||
|       '-mmacosx-version-min=10.15', | ||||
|       '-stdlib=libc++', | ||||
|       '-lc++', | ||||
|     ] | ||||
|     cxx.cxxflags += ['-stdlib=libstdc++'] | ||||
|     cxx.cxxflags += ['-stdlib=libc++'] | ||||
| 
 | ||||
|   def configure_windows(self, cxx): | ||||
|     cxx.defines += ['WIN32', '_WINDOWS'] | ||||
|      | ||||
|   def LibraryBuilder(self, compiler, name): | ||||
|     binary = compiler.Library(name) | ||||
|     self.AddVersioning(binary) | ||||
|     if binary.compiler.like('msvc'): | ||||
|       binary.compiler.linkflags += ['/SUBSYSTEM:WINDOWS'] | ||||
|     self.AddCxxCompat(binary) | ||||
|     return binary | ||||
| 
 | ||||
|   def Library(self, context, compiler, name): | ||||
|     compiler = compiler.clone() | ||||
|     SetArchFlags(compiler) | ||||
|     return self.LibraryBuilder(compiler, name) | ||||
| 
 | ||||
|   def ConfigureForExtension(self, context, compiler): | ||||
|     compiler.cxxincludes += [ | ||||
|       os.path.join(context.currentSourcePath), | ||||
| @ -273,156 +339,84 @@ class ExtensionConfig(object): | ||||
|     ] | ||||
|     return compiler | ||||
| 	 | ||||
|   def ConfigureForHL2(self, binary, sdk): | ||||
|     compiler = binary.compiler | ||||
|   def AddCDetour(self, binary): | ||||
|     public_path = os.path.join(self.sm_root, 'public') | ||||
|     binary.sources += [  | ||||
|       os.path.join(public_path, 'CDetour', 'detours.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'allocator.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'easy.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'inline_hook.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'mid_hook.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'os.linux.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'utility.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'src', 'vmt_hook.cpp'), | ||||
|       os.path.join(public_path, 'safetyhook', 'zydis', 'Zydis.c') | ||||
|     ] | ||||
| 	 | ||||
|     if sdk.name == 'episode1': | ||||
|       mms_path = os.path.join(self.mms_root, 'core-legacy') | ||||
|     else: | ||||
|       mms_path = os.path.join(self.mms_root, 'core') | ||||
|     binary.compiler.includes += [ | ||||
|       os.path.join(public_path, 'safetyhook', 'include'), | ||||
|       os.path.join(public_path, 'safetyhook', 'zydis'), | ||||
|     ] | ||||
| 
 | ||||
|   def ExtLibrary(self, context, compiler, name): | ||||
|     binary = self.Library(context, compiler, name) | ||||
|     SetArchFlags(compiler) | ||||
|     self.ConfigureForExtension(context, binary.compiler) | ||||
|     return binary | ||||
| 
 | ||||
|   def AddCxxCompat(self, binary): | ||||
|     if binary.compiler.target.platform == 'linux': | ||||
|       binary.sources += [ | ||||
|         os.path.join(self.sm_root, 'public', 'amtl', 'compat', 'stdcxx.cpp'), | ||||
|       ] | ||||
| 
 | ||||
|   def ConfigureForHL2(self, context, binary, sdk): | ||||
|     compiler = binary.compiler | ||||
|     SetArchFlags(compiler) | ||||
| 
 | ||||
|     compiler.cxxincludes += [ | ||||
|       os.path.join(mms_path), | ||||
|       os.path.join(mms_path, 'sourcehook'), | ||||
|       os.path.join(self.mms_root, 'core'), | ||||
|       os.path.join(self.mms_root, 'core', 'sourcehook'), | ||||
|     ] | ||||
| 
 | ||||
|     defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs] | ||||
|     compiler.defines += defines | ||||
|     for other_sdk in self.sdk_manifests: | ||||
|       compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])] | ||||
| 
 | ||||
|     paths = [ | ||||
|       ['public'], | ||||
|       ['public', 'engine'], | ||||
|       ['public', 'mathlib'], | ||||
|       ['public', 'vstdlib'], | ||||
|       ['public', 'tier0'], | ||||
|       ['public', 'tier1'] | ||||
|     ] | ||||
|     if sdk.name == 'episode1' or sdk.name == 'darkm': | ||||
|       paths.append(['public', 'dlls']) | ||||
|       paths.append(['game_shared']) | ||||
|     else: | ||||
|       paths.append(['public', 'game', 'server']) | ||||
|       paths.append(['public', 'toolframework']) | ||||
|       paths.append(['game', 'shared']) | ||||
|       paths.append(['common']) | ||||
| 
 | ||||
|     compiler.defines += ['SOURCE_ENGINE=' + sdk.code] | ||||
| 
 | ||||
|     if sdk.name in ['sdk2013', 'bms'] and compiler.like('gcc'): | ||||
|       # The 2013 SDK already has these in public/tier0/basetypes.h | ||||
|       compiler.defines.remove('stricmp=strcasecmp') | ||||
|       compiler.defines.remove('_stricmp=strcasecmp') | ||||
|       compiler.defines.remove('_snprintf=snprintf') | ||||
|       compiler.defines.remove('_vsnprintf=vsnprintf') | ||||
| 
 | ||||
|     if compiler.like('msvc'): | ||||
|       compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32'] | ||||
|     else: | ||||
|       compiler.defines += ['COMPILER_GCC'] | ||||
| 
 | ||||
|     # For everything after Swarm, this needs to be defined for entity networking | ||||
|     # to work properly with sendprop value changes. | ||||
|     if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']: | ||||
|       compiler.defines += ['NETWORK_VARS_ENABLED'] | ||||
| 
 | ||||
|     if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'bms', 'tf2', 'l4d', 'nucleardawn', 'l4d2']: | ||||
|       if builder.target_platform in ['linux', 'mac']: | ||||
|         compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE'] | ||||
| 
 | ||||
|     if sdk.name == 'csgo' and builder.target_platform == 'linux': | ||||
|       compiler.linkflags += ['-lstdc++'] | ||||
| 
 | ||||
|     for path in paths: | ||||
|       compiler.cxxincludes += [os.path.join(sdk.path, *path)] | ||||
| 
 | ||||
|     if builder.target_platform == 'linux': | ||||
|       if sdk.name == 'episode1': | ||||
|         lib_folder = os.path.join(sdk.path, 'linux_sdk') | ||||
|       elif sdk.name in ['sdk2013', 'bms']: | ||||
|         lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32') | ||||
|       else: | ||||
|         lib_folder = os.path.join(sdk.path, 'lib', 'linux') | ||||
|     elif builder.target_platform == 'mac': | ||||
|       if sdk.name in ['sdk2013', 'bms']: | ||||
|         lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32') | ||||
|       else: | ||||
|         lib_folder = os.path.join(sdk.path, 'lib', 'mac') | ||||
| 
 | ||||
|     if builder.target_platform in ['linux', 'mac']: | ||||
|       if sdk.name in ['sdk2013', 'bms']: | ||||
|         compiler.postlink += [ | ||||
|           compiler.Dep(os.path.join(lib_folder, 'tier1.a')), | ||||
|           compiler.Dep(os.path.join(lib_folder, 'mathlib.a')) | ||||
|         ] | ||||
|       else: | ||||
|         compiler.postlink += [ | ||||
|           compiler.Dep(os.path.join(lib_folder, 'tier1_i486.a')), | ||||
|           compiler.Dep(os.path.join(lib_folder, 'mathlib_i486.a')) | ||||
|         ] | ||||
| 
 | ||||
|       if sdk.name in ['blade', 'insurgency', 'doi', 'csgo']: | ||||
|         compiler.postlink += [compiler.Dep(os.path.join(lib_folder, 'interfaces_i486.a'))] | ||||
| 
 | ||||
|     dynamic_libs = [] | ||||
|     if builder.target_platform == 'linux': | ||||
|       if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'bms', 'nucleardawn', 'l4d2', 'insurgency', 'doi']: | ||||
|         dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so'] | ||||
|       elif sdk.name in ['l4d', 'blade', 'insurgency', 'doi', 'csgo']: | ||||
|         dynamic_libs = ['libtier0.so', 'libvstdlib.so'] | ||||
|       else: | ||||
|         dynamic_libs = ['tier0_i486.so', 'vstdlib_i486.so'] | ||||
|     elif builder.target_platform == 'mac': | ||||
|       compiler.linkflags.append('-liconv') | ||||
|       dynamic_libs = ['libtier0.dylib', 'libvstdlib.dylib'] | ||||
|     elif builder.target_platform == 'windows': | ||||
|       libs = ['tier0', 'tier1', 'vstdlib', 'mathlib'] | ||||
|       if sdk.name in ['swarm', 'blade', 'insurgency', 'doi', 'csgo']: | ||||
|         libs.append('interfaces') | ||||
|       for lib in libs: | ||||
|         lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib' | ||||
|         compiler.linkflags.append(compiler.Dep(lib_path)) | ||||
| 
 | ||||
|     for library in dynamic_libs: | ||||
|       source_path = os.path.join(lib_folder, library) | ||||
|       output_path = os.path.join(binary.localFolder, library) | ||||
| 
 | ||||
|       def make_linker(source_path, output_path): | ||||
|         def link(context, binary): | ||||
|           cmd_node, (output,) = context.AddSymlink(source_path, output_path) | ||||
|           return output | ||||
|         return link | ||||
| 
 | ||||
|       linker = make_linker(source_path, output_path) | ||||
|       compiler.linkflags[0:0] = [compiler.Dep(library, linker)] | ||||
|     SdkHelpers.configureCxx(context, binary, sdk) | ||||
| 
 | ||||
|     return binary | ||||
| 
 | ||||
|   def HL2Library(self, context, name, sdk): | ||||
|     binary = context.compiler.Library(name) | ||||
|   def HL2Library(self, context, compiler, name, sdk): | ||||
|     binary = self.Library(context, compiler, name) | ||||
|     self.ConfigureForExtension(context, binary.compiler) | ||||
|     return self.ConfigureForHL2(binary, sdk) | ||||
|     return self.ConfigureForHL2(context, binary, sdk) | ||||
| 
 | ||||
|   def HL2Project(self, context, name): | ||||
|     project = context.compiler.LibraryProject(name) | ||||
|     self.ConfigureForExtension(context, project.compiler) | ||||
|     return project | ||||
|   def HL2Config(self, project, context, compiler, name, sdk): | ||||
|     binary = project.Configure(compiler, name, | ||||
|                                '{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch)) | ||||
|     self.AddCxxCompat(binary) | ||||
|     return self.ConfigureForHL2(context, binary, sdk) | ||||
| 
 | ||||
|   def HL2Config(self, project, name, sdk): | ||||
|     binary = project.Configure(name, '{0} - {1}'.format(self.tag, sdk.name)) | ||||
|     return self.ConfigureForHL2(binary, sdk) | ||||
|   def HL2ExtConfig(self, project, context, compiler, name, sdk): | ||||
|     binary = project.Configure(compiler, name, | ||||
|                                '{0} - {1} {2}'.format(self.tag, sdk['name'], compiler.target.arch)) | ||||
|     self.AddCxxCompat(binary) | ||||
|     self.ConfigureForHL2(context, binary, sdk) | ||||
|     self.ConfigureForExtension(context, binary.compiler) | ||||
|     return binary | ||||
| 
 | ||||
| Extension = ExtensionConfig() | ||||
| Extension.detectSDKs() | ||||
| Extension.configure() | ||||
| 
 | ||||
| # Add additional buildscripts here | ||||
| # This will clone the list and each cxx object as we recurse, preventing child | ||||
| # scripts from messing up global state. | ||||
| builder.targets = builder.CloneableList(Extension.all_targets) | ||||
| 
 | ||||
| BuildScripts = [ | ||||
|   'AMBuilder', | ||||
| ] | ||||
| 
 | ||||
| if builder.backend == 'amb2': | ||||
|   BuildScripts += [ | ||||
|   'PackageScript', | ||||
| ] | ||||
| 
 | ||||
| builder.RunBuildScripts(BuildScripts, { 'Extension': Extension}) | ||||
| builder.Build(BuildScripts, { 'Extension': Extension }) | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										34
									
								
								AMBuilder
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								AMBuilder
									
									
									
									
									
								
							| @ -6,24 +6,33 @@ if not "SM" in globals(): | ||||
| 
 | ||||
| projectName = 'Voice' | ||||
| 
 | ||||
| project = SM.HL2Project(builder, projectName + '.ext') | ||||
| project = builder.LibraryProject(projectName) | ||||
| project.sources += [ | ||||
|   'extension.cpp', | ||||
|   'ringbuffer.cpp', | ||||
|   '../../public/smsdk_ext.cpp', | ||||
|   '../../public/CDetour/detours.cpp', | ||||
|   '../../public/asm/asm.c', | ||||
|   '../../public/libudis86/decode.c', | ||||
|   '../../public/libudis86/itab.c', | ||||
|   '../../public/libudis86/syn-att.c', | ||||
|   '../../public/libudis86/syn-intel.c', | ||||
|   '../../public/libudis86/syn.c', | ||||
|   '../../public/libudis86/udis86.c', | ||||
|   os.path.join(SM.sm_root, 'public', 'smsdk_ext.cpp') | ||||
| ] | ||||
| 
 | ||||
| for sdk_name in SM.sdks: | ||||
|   sdk = SM.sdks[sdk_name] | ||||
|   binary = SM.HL2Config(project, projectName + '.ext', sdk) | ||||
|   if sdk['name'] in ['mock']: | ||||
|     continue | ||||
| 
 | ||||
|   for cxx in builder.targets: | ||||
|     cxx.defines += ['HAVE_STRING_H']; | ||||
|     if not cxx.target.arch in sdk['platforms'][cxx.target.platform]: | ||||
|       continue | ||||
| 
 | ||||
|     binary = Extension.HL2ExtConfig(project, builder, cxx, projectName + '.ext.' + sdk['extension'], sdk) | ||||
| 	 | ||||
|     SM.AddCDetour(binary) | ||||
| 	 | ||||
|     binary.compiler.cxxflags += [ | ||||
|       '-Wno-dangling-else', | ||||
|       '-Wno-unknown-pragmas', | ||||
|       '-Wno-unused-result', | ||||
|       '-Wno-sign-compare', | ||||
| 	] | ||||
| 
 | ||||
|     binary.compiler.cxxincludes += [ | ||||
|         os.path.join(builder.sourcePath, 'celt') | ||||
|     ] | ||||
| @ -31,4 +40,5 @@ for sdk_name in SM.sdks: | ||||
|         os.path.join(builder.sourcePath, 'celt', 'libcelt0.a') | ||||
|     ] | ||||
| 
 | ||||
| 
 | ||||
| SM.extensions += builder.Add(project) | ||||
|  | ||||
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							| @ -109,7 +109,7 @@ else | ||||
| 	LIB_SUFFIX = .$(LIB_EXT) | ||||
| endif | ||||
| 
 | ||||
| INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/public/sourcepawn | ||||
| INCLUDE += -I. -I.. -Isdk -I$(SMSDK)/public -I$(SMSDK)/sourcepawn/include | ||||
| 
 | ||||
| ifeq "$(USEMETA)" "true" | ||||
| 	LINK_HL2 = $(HL2LIB)/tier1_i486.a $(LIB_PREFIX)vstdlib$(LIB_SUFFIX) $(LIB_PREFIX)tier0$(LIB_SUFFIX) | ||||
| @ -131,7 +131,7 @@ LINK += -m32 -lm -ldl | ||||
| CFLAGS += -DPOSIX -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp \
 | ||||
| 	-D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -DCOMPILER_GCC -Wall -Werror \
 | ||||
| 	-Wno-overloaded-virtual -Wno-switch -Wno-unused -msse -DSOURCEMOD_BUILD -DHAVE_STDINT_H -m32 | ||||
| CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti | ||||
| CPPFLAGS += -Wno-non-virtual-dtor -fno-exceptions -fno-rtti -std=c++11 | ||||
| 
 | ||||
| ################################################
 | ||||
| ### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
 | ||||
|  | ||||
| @ -7,9 +7,14 @@ builder.SetBuildFolder('package') | ||||
| 
 | ||||
| # Add any folders you need to this list | ||||
| folder_list = [ | ||||
|   'addons/sourcemod/extensions' | ||||
|   'addons/sourcemod/extensions', | ||||
| ] | ||||
| 
 | ||||
| if 'x86_64' in Extension.target_archs: | ||||
|   folder_list.extend([ | ||||
|     'addons/sourcemod/extensions/x64', | ||||
|   ]) | ||||
| 
 | ||||
| # Create the distribution folder hierarchy. | ||||
| folder_map = {} | ||||
| for folder in folder_list: | ||||
| @ -25,6 +30,10 @@ def CopyFiles(src, dest, files): | ||||
|     source_path = os.path.join(builder.sourcePath, src, source_file) | ||||
|     builder.AddCopy(source_path, dest_entry) | ||||
| 
 | ||||
| 
 | ||||
| # Copy binaries. | ||||
| for cxx_task in Extension.extensions: | ||||
|   if cxx_task.target.arch == 'x86_64': | ||||
|     builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions/x64']) | ||||
|   else: | ||||
|     builder.AddCopy(cxx_task.binary, folder_map['addons/sourcemod/extensions']) | ||||
|  | ||||
							
								
								
									
										32
									
								
								configure.py
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								configure.py
									
									
									
									
									
								
							| @ -4,20 +4,24 @@ from ambuild2 import run | ||||
| 
 | ||||
| # Simple extensions do not need to modify this file. | ||||
| 
 | ||||
| builder = run.PrepareBuild(sourcePath = sys.path[0]) | ||||
| 
 | ||||
| builder.options.add_option('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None, | ||||
| parser = run.BuildParser(sourcePath=sys.path[0], api='2.2') | ||||
| parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None, | ||||
|                        help='Root search folder for HL2SDKs') | ||||
| builder.options.add_option('--mms-path', type=str, dest='mms_path', default=None, | ||||
|                        help='Path to Metamod:Source') | ||||
| builder.options.add_option('--sm-path', type=str, dest='sm_path', default=None, | ||||
| parser.options.add_argument('--hl2sdk-manifest-path', type=str, dest='hl2sdk_manifest', default=None, | ||||
|                        help='Path to HL2SDK Manifests') | ||||
| parser.options.add_argument('--sm-path', type=str, dest='sm_path', default=None, | ||||
|                        help='Path to SourceMod') | ||||
| builder.options.add_option('--enable-debug', action='store_const', const='1', dest='debug', | ||||
|                        help='Enable debugging symbols') | ||||
| builder.options.add_option('--enable-optimize', action='store_const', const='1', dest='opt', | ||||
|                        help='Enable optimization') | ||||
| builder.options.add_option('-s', '--sdks', default='all', dest='sdks', | ||||
|                        help='Build against specified SDKs; valid args are "all", "present", or ' | ||||
|                             'comma-delimited list of engine names (default: %default)') | ||||
| parser.options.add_argument('--mms-path', type=str, dest='mms_path', default=None, | ||||
|                        help='Path to Metamod:Source') | ||||
| 
 | ||||
| parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug', | ||||
|                        help='Enable debugging symbols') | ||||
| parser.options.add_argument('--enable-optimize', action='store_const', const='1', dest='opt', | ||||
|                        help='Enable optimization') | ||||
| parser.options.add_argument('-s', '--sdks', default='present', dest='sdks', | ||||
|                        help='Build against specified SDKs; valid args are "none", "all", "present",' | ||||
|                             ' or comma-delimited list of engine names') | ||||
| parser.options.add_argument('--targets', type=str, dest='targets', default=None, | ||||
|                           help="Override the target architecture (use commas to separate multiple targets).") | ||||
| parser.Configure() | ||||
| 
 | ||||
| builder.Configure() | ||||
|  | ||||
| @ -62,7 +62,7 @@ ConVar g_SmVoicePort("sm_voice_port", "27020", FCVAR_PROTECTED, "Voice server li | ||||
|  * @brief Implement extension code here. | ||||
|  */ | ||||
| 
 | ||||
| template <typename T> inline T min(T a, T b) { return a<b?a:b; } | ||||
| template <typename T> inline T min_ext(T a, T b) { return a<b?a:b; } | ||||
| 
 | ||||
| CVoice g_Interface; | ||||
| SMEXT_LINK(&g_Interface); | ||||
| @ -483,7 +483,7 @@ void CVoice::HandleNetwork() | ||||
| 		if(Client != MAX_CLIENTS) | ||||
| 		{ | ||||
| 			sockaddr_in addr; | ||||
| 			size_t size = sizeof(sockaddr_in); | ||||
| 			socklen_t size = sizeof(sockaddr_in); | ||||
| 			int Socket = accept(m_ListenSocket, (sockaddr *)&addr, &size); | ||||
| 
 | ||||
| 			m_aClients[Client].m_Socket = Socket; | ||||
| @ -546,7 +546,7 @@ void CVoice::HandleNetwork() | ||||
| 
 | ||||
| 		// Don't recv() when we can't fit data into the ringbuffer
 | ||||
| 		unsigned char aBuf[32768]; | ||||
| 		if(min(BytesAvailable, sizeof(aBuf)) > m_Buffer.CurrentFree() * sizeof(int16_t)) | ||||
| 		if(min_ext(BytesAvailable, sizeof(aBuf)) > m_Buffer.CurrentFree() * sizeof(int16_t)) | ||||
| 			continue; | ||||
| 
 | ||||
| 		// Edge case: previously received data is uneven and last recv'd byte has to be prepended
 | ||||
| @ -657,7 +657,7 @@ void CVoice::HandleVoiceData() | ||||
| 		return; | ||||
| 
 | ||||
| 	// 5 = max frames per packet
 | ||||
| 	FramesAvailable = min(FramesAvailable, 5); | ||||
| 	FramesAvailable = min_ext(FramesAvailable, 5); | ||||
| 
 | ||||
| 	// 0 = SourceTV
 | ||||
| 	IClient *pClient = iserver->GetClient(0); | ||||
| @ -675,7 +675,7 @@ void CVoice::HandleVoiceData() | ||||
| 
 | ||||
| 		if(!m_Buffer.Pop(aBuffer, SamplesPerFrame)) | ||||
| 		{ | ||||
| 			printf("Buffer pop failed!!! Samples: %u, Length: %u\n", SamplesPerFrame, m_Buffer.TotalLength()); | ||||
| 			printf("Buffer pop failed!!! Samples: %u, Length: %zu\n", SamplesPerFrame, m_Buffer.TotalLength()); | ||||
| 			return; | ||||
| 		} | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user