# vim: set ts=2 sw=2 tw=99 noet ft=python: import os, sys, shutil def ResolveEnvPath(env, folder=None): if env in os.environ: path = os.environ[env] if os.path.isdir(path): return path return None if folder: 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 AcceleratorConfig(object): def __init__(self): self.mms_root = None self.sm_root = None self.extension = None self.libz = None self.libbreakpad_client = None self.libbreakpad = None self.libdisasm = None self.breakpad_patch = None self.targets = [] self.target_archs = set() self.breakpad_config = dict() self.breakpad_patch = None 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: if builder.options.targets: raise print('Skipping target {}: {}'.format(arch, e)) continue self.targets.append(cxx) if not self.targets: raise Exception('No suitable C/C++ compiler was found.') @property def tag(self): if builder.options.debug == '1': return 'Debug' return 'Release' def retrieve_sm(self): if builder.options.sm_path: self.sm_root = builder.options.sm_path else: self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') 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 use_auto_versioning(self): return not builder.options.disable_auto_versioning def configure_cxx(self, cxx): if cxx.like('gcc'): self.configure_gcc(cxx) elif cxx.family == 'msvc': self.configure_msvc(cxx) # Optimization if builder.options.opt == '1': cxx.defines += ['NDEBUG'] # Debugging if builder.options.debug == '1': cxx.defines += ['DEBUG', '_DEBUG'] # Platform-specifics if cxx.target.platform == 'linux': self.configure_linux(cxx) elif cxx.target.platform == 'windows': self.configure_windows(cxx) if self.use_auto_versioning(): cxx.defines += ['GIT_ACTION_BUILD'] def configure_gcc(self, cxx): cxx.cflags += [ '-fPIC', '-pipe', '-fno-strict-aliasing', '-fvisibility=hidden', '-fvisibility-inlines-hidden', '-Wall', '-Werror', '-msse' ] cxx.cxxflags += [ '-std=c++17', '-fno-threadsafe-statics', '-Wno-non-virtual-dtor', '-Wno-overloaded-virtual', '-Wno-implicit-exception-spec-mismatch' ] cxx.postlink += ['-pthread', '-static-libstdc++', '-static-libgcc'] if builder.options.opt == '1': cxx.cflags += ['-O3'] return def configure_msvc(self, cxx): cxx.cxxflags += [ '/EHsc', '/std:c++17' ] return def configure_linux(self, cxx): cxx.defines += ['_LINUX', 'POSIX', '_GLIBCXX_USE_CXX11_ABI=0'] return def configure_windows(self, cxx): cxx.defines += ['_WINDOWS'] if cxx.target.arch == 'x86': cxx.defines += ['WIN32'] elif cxx.target.arch == 'x86_64': cxx.defines += ['WIN64'] return def configure(self): self.retrieve_sm() for cxx in self.targets: self.configure_cxx(cxx) def configure_extension(self, compiler, context): compiler.cxxincludes += [ os.path.join(context.currentSourcePath), os.path.join(self.sm_root, 'public'), os.path.join(self.sm_root, 'public', 'extensions'), os.path.join(self.sm_root, 'public', 'amtl', 'amtl'), os.path.join(self.sm_root, 'public', 'amtl'), os.path.join(self.sm_root, 'sourcepawn', 'include') ] def link_libz(self, compiler, context): for task in self.libz: if task.target.arch == compiler.target.arch: compiler.postlink += [os.path.join(context.buildPath, task.binary.path)] compiler.linkdeps += [task.binary] return raise Exception('No suitable build of libz was found.') def link_libbreakpad_client(self, compiler, context): for task in self.libbreakpad_client: if task.target.arch == compiler.target.arch: compiler.postlink += [os.path.join(context.buildPath, task.binary.path)] compiler.linkdeps += [task.binary] return raise Exception('No suitable build of libbreakpad_client was found.') def link_libbreakpad(self, compiler, context): for task in self.libbreakpad: if task.target.arch == compiler.target.arch: compiler.postlink += [os.path.join(context.buildPath, task.binary.path)] compiler.linkdeps += [task.binary] return raise Exception('No suitable build of libbreakpad was found.') def link_libdisasm(self, compiler, context): for task in self.libdisasm: if task.target.arch == compiler.target.arch: compiler.postlink += [os.path.join(context.buildPath, task.binary.path)] compiler.linkdeps += [task.binary] return raise Exception('No suitable build of libdisasm was found.') def ConfigureLibrary(self, project, compiler, context): binary = project.Configure(compiler, project.name, '{0} - {1}'.format(self.tag, compiler.target.arch)) binary.compiler.cxxincludes += [ os.path.join(context.currentSourcePath) ] return binary def ConfigureExtension(self, project, compiler, context): binary = self.ConfigureLibrary(project, compiler, context) self.configure_extension(binary.compiler, context) return binary Accelerator = AcceleratorConfig() Accelerator.configure() builder.Build(['third_party/Patch', 'third_party/Configure', 'third_party/AMBuilder'], { 'Accelerator': Accelerator }) BuildScripts = ['extension/AMBuilder', 'buildbot/PackageScript'] builder.Build(BuildScripts, { 'Accelerator': Accelerator })