|
| 1 | +# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: |
| 2 | +import os, sys |
| 3 | + |
| 4 | +# Simple extensions do not need to modify this file. |
| 5 | + |
| 6 | +def ResolveEnvPath(env, folder): |
| 7 | + if env in os.environ: |
| 8 | + path = os.environ[env] |
| 9 | + if os.path.isdir(path): |
| 10 | + return path |
| 11 | + return None |
| 12 | + |
| 13 | + head = os.getcwd() |
| 14 | + oldhead = None |
| 15 | + while head != None and head != oldhead: |
| 16 | + path = os.path.join(head, folder) |
| 17 | + if os.path.isdir(path): |
| 18 | + return path |
| 19 | + oldhead = head |
| 20 | + head, tail = os.path.split(head) |
| 21 | + |
| 22 | + return None |
| 23 | + |
| 24 | +def Normalize(path): |
| 25 | + return os.path.abspath(os.path.normpath(path)) |
| 26 | + |
| 27 | +class ExtensionConfig(object): |
| 28 | + def __init__(self): |
| 29 | + self.binaries = [] |
| 30 | + self.extensions = [] |
| 31 | + self.generated_headers = None |
| 32 | + self.mms_root = None |
| 33 | + self.sm_root = None |
| 34 | + |
| 35 | + @property |
| 36 | + def tag(self): |
| 37 | + if builder.options.debug == '1': |
| 38 | + return 'Debug' |
| 39 | + return 'Release' |
| 40 | + |
| 41 | + def detectSDKs(self): |
| 42 | + if builder.options.sm_path: |
| 43 | + self.sm_root = builder.options.sm_path |
| 44 | + else: |
| 45 | + self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8') |
| 46 | + if not self.sm_root: |
| 47 | + self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod') |
| 48 | + if not self.sm_root: |
| 49 | + self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central') |
| 50 | + |
| 51 | + if not self.sm_root or not os.path.isdir(self.sm_root): |
| 52 | + raise Exception('Could not find a source copy of SourceMod') |
| 53 | + self.sm_root = Normalize(self.sm_root) |
| 54 | + |
| 55 | + if builder.options.mms_path: |
| 56 | + self.mms_root = builder.options.mms_path |
| 57 | + else: |
| 58 | + self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10') |
| 59 | + if not self.mms_root: |
| 60 | + self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source') |
| 61 | + if not self.mms_root: |
| 62 | + self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central') |
| 63 | + |
| 64 | + if not self.mms_root or not os.path.isdir(self.mms_root): |
| 65 | + raise Exception('Could not find a source copy of Metamod:Source') |
| 66 | + self.mms_root = Normalize(self.mms_root) |
| 67 | + |
| 68 | + def configure(self): |
| 69 | + cxx = builder.DetectCompilers() |
| 70 | + |
| 71 | + if cxx.like('gcc'): |
| 72 | + self.configure_gcc(cxx) |
| 73 | + elif cxx.vendor == 'msvc': |
| 74 | + self.configure_msvc(cxx) |
| 75 | + |
| 76 | + # Optimization |
| 77 | + if builder.options.opt == '1': |
| 78 | + cxx.defines += ['NDEBUG'] |
| 79 | + |
| 80 | + # Debugging |
| 81 | + if builder.options.debug == '1': |
| 82 | + cxx.defines += ['DEBUG', '_DEBUG'] |
| 83 | + |
| 84 | + # Platform-specifics |
| 85 | + if builder.target_platform == 'linux': |
| 86 | + self.configure_linux(cxx) |
| 87 | + elif builder.target_platform == 'mac': |
| 88 | + self.configure_mac(cxx) |
| 89 | + elif builder.target_platform == 'windows': |
| 90 | + self.configure_windows(cxx) |
| 91 | + |
| 92 | + # Finish up. |
| 93 | + cxx.includes += [ |
| 94 | + os.path.join(self.sm_root, 'public'), |
| 95 | + ] |
| 96 | + |
| 97 | + def configure_gcc(self, cxx): |
| 98 | + cxx.defines += [ |
| 99 | + 'stricmp=strcasecmp', |
| 100 | + '_stricmp=strcasecmp', |
| 101 | + '_snprintf=snprintf', |
| 102 | + '_vsnprintf=vsnprintf', |
| 103 | + 'HAVE_STDINT_H', |
| 104 | + 'GNUC', |
| 105 | + ] |
| 106 | + cxx.cflags += [ |
| 107 | + '-pipe', |
| 108 | + '-fno-strict-aliasing', |
| 109 | + '-Wall', |
| 110 | + '-Werror', |
| 111 | + '-Wno-unused', |
| 112 | + '-Wno-switch', |
| 113 | + '-Wno-array-bounds', |
| 114 | + '-msse', |
| 115 | + '-m32', |
| 116 | + '-fvisibility=hidden', |
| 117 | + ] |
| 118 | + cxx.cxxflags += [ |
| 119 | + '-std=c++14', |
| 120 | + '-fno-exceptions', |
| 121 | + '-fno-threadsafe-statics', |
| 122 | + '-Wno-non-virtual-dtor', |
| 123 | + '-Wno-overloaded-virtual', |
| 124 | + '-fvisibility-inlines-hidden', |
| 125 | + ] |
| 126 | + cxx.linkflags += ['-m32'] |
| 127 | + |
| 128 | + have_gcc = cxx.vendor == 'gcc' |
| 129 | + have_clang = cxx.vendor == 'clang' |
| 130 | + if cxx.version >= 'clang-3.6': |
| 131 | + cxx.cxxflags += ['-Wno-inconsistent-missing-override'] |
| 132 | + if have_clang or (cxx.version >= 'gcc-4.6'): |
| 133 | + cxx.cflags += ['-Wno-narrowing'] |
| 134 | + if have_clang or (cxx.version >= 'gcc-4.7'): |
| 135 | + cxx.cxxflags += ['-Wno-delete-non-virtual-dtor'] |
| 136 | + if cxx.version >= 'gcc-4.8': |
| 137 | + cxx.cflags += ['-Wno-unused-result'] |
| 138 | + |
| 139 | + if have_clang: |
| 140 | + cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch'] |
| 141 | + if cxx.version >= 'apple-clang-5.1' or cxx.version >= 'clang-3.4': |
| 142 | + cxx.cxxflags += ['-Wno-deprecated-register'] |
| 143 | + else: |
| 144 | + cxx.cxxflags += ['-Wno-deprecated'] |
| 145 | + cxx.cflags += ['-Wno-sometimes-uninitialized'] |
| 146 | + |
| 147 | + if have_gcc: |
| 148 | + cxx.cflags += ['-mfpmath=sse'] |
| 149 | + |
| 150 | + if builder.options.opt == '1': |
| 151 | + cxx.cflags += ['-O3'] |
| 152 | + |
| 153 | + def configure_msvc(self, cxx): |
| 154 | + if builder.options.debug == '1': |
| 155 | + cxx.cflags += ['/MTd'] |
| 156 | + cxx.linkflags += ['/NODEFAULTLIB:libcmt'] |
| 157 | + else: |
| 158 | + cxx.cflags += ['/MT'] |
| 159 | + cxx.defines += [ |
| 160 | + '_CRT_SECURE_NO_DEPRECATE', |
| 161 | + '_CRT_SECURE_NO_WARNINGS', |
| 162 | + '_CRT_NONSTDC_NO_DEPRECATE', |
| 163 | + '_ITERATOR_DEBUG_LEVEL=0', |
| 164 | + ] |
| 165 | + cxx.cflags += [ |
| 166 | + '/W3', |
| 167 | + ] |
| 168 | + cxx.cxxflags += [ |
| 169 | + '/EHsc', |
| 170 | + '/GR-', |
| 171 | + '/TP', |
| 172 | + ] |
| 173 | + cxx.linkflags += [ |
| 174 | + '/MACHINE:X86', |
| 175 | + 'kernel32.lib', |
| 176 | + 'user32.lib', |
| 177 | + 'gdi32.lib', |
| 178 | + 'winspool.lib', |
| 179 | + 'comdlg32.lib', |
| 180 | + 'advapi32.lib', |
| 181 | + 'shell32.lib', |
| 182 | + 'ole32.lib', |
| 183 | + 'oleaut32.lib', |
| 184 | + 'uuid.lib', |
| 185 | + 'odbc32.lib', |
| 186 | + 'odbccp32.lib', |
| 187 | + ] |
| 188 | + |
| 189 | + if builder.options.opt == '1': |
| 190 | + cxx.cflags += ['/Ox', '/Zo'] |
| 191 | + cxx.linkflags += ['/OPT:ICF', '/OPT:REF'] |
| 192 | + |
| 193 | + if builder.options.debug == '1': |
| 194 | + cxx.cflags += ['/Od', '/RTC1'] |
| 195 | + |
| 196 | + # This needs to be after our optimization flags which could otherwise disable it. |
| 197 | + # Don't omit the frame pointer. |
| 198 | + cxx.cflags += ['/Oy-'] |
| 199 | + |
| 200 | + def configure_linux(self, cxx): |
| 201 | + cxx.defines += ['_LINUX', 'POSIX'] |
| 202 | + cxx.linkflags += ['-Wl,--exclude-libs,ALL', '-lm'] |
| 203 | + if cxx.vendor == 'gcc': |
| 204 | + cxx.linkflags += ['-static-libgcc'] |
| 205 | + elif cxx.vendor == 'clang': |
| 206 | + cxx.linkflags += ['-lgcc_eh'] |
| 207 | + |
| 208 | + def configure_mac(self, cxx): |
| 209 | + cxx.defines += ['OSX', '_OSX', 'POSIX'] |
| 210 | + cxx.cflags += ['-mmacosx-version-min=10.5'] |
| 211 | + cxx.linkflags += [ |
| 212 | + '-mmacosx-version-min=10.5', |
| 213 | + '-arch', 'i386', |
| 214 | + '-lstdc++', |
| 215 | + '-stdlib=libstdc++', |
| 216 | + ] |
| 217 | + cxx.cxxflags += ['-stdlib=libstdc++'] |
| 218 | + |
| 219 | + def configure_windows(self, cxx): |
| 220 | + cxx.defines += ['WIN32', '_WINDOWS'] |
| 221 | + |
| 222 | + def ConfigureForExtension(self, context, compiler): |
| 223 | + compiler.cxxincludes += [ |
| 224 | + os.path.join(context.currentSourcePath), |
| 225 | + os.path.join(context.currentSourcePath, 'sdk'), |
| 226 | + os.path.join(self.sm_root, 'public'), |
| 227 | + os.path.join(self.sm_root, 'public', 'extensions'), |
| 228 | + os.path.join(self.sm_root, 'sourcepawn', 'include'), |
| 229 | + os.path.join(self.sm_root, 'public', 'amtl', 'amtl'), |
| 230 | + os.path.join(self.sm_root, 'public', 'amtl'), |
| 231 | + ] |
| 232 | + return compiler |
| 233 | + |
| 234 | + def ConfigureForHL2(self, binary): |
| 235 | + compiler = binary.compiler |
| 236 | + |
| 237 | + mms_path = os.path.join(self.mms_root, 'core') |
| 238 | + |
| 239 | + compiler.cxxincludes += [ |
| 240 | + os.path.join(mms_path), |
| 241 | + os.path.join(mms_path, 'sourcehook'), |
| 242 | + ] |
| 243 | + |
| 244 | + compiler.defines += ['META_NO_HL2SDK'] |
| 245 | + |
| 246 | + if compiler.like('msvc'): |
| 247 | + compiler.defines += ['COMPILER_MSVC', 'COMPILER_MSVC32'] |
| 248 | + else: |
| 249 | + compiler.defines += ['COMPILER_GCC'] |
| 250 | + |
| 251 | + if builder.target_platform == 'linux': |
| 252 | + compiler.linkflags += ['-lstdc++'] |
| 253 | + elif builder.target_platform == 'mac': |
| 254 | + compiler.linkflags.append('-liconv') |
| 255 | + |
| 256 | + return binary |
| 257 | + |
| 258 | + def HL2Library(self, context, name): |
| 259 | + binary = context.compiler.Library(name) |
| 260 | + self.ConfigureForExtension(context, binary.compiler) |
| 261 | + return self.ConfigureForHL2(binary) |
| 262 | + |
| 263 | + def HL2Project(self, context, name): |
| 264 | + project = context.compiler.LibraryProject(name) |
| 265 | + self.ConfigureForExtension(context, project.compiler) |
| 266 | + return project |
| 267 | + |
| 268 | + def HL2Config(self, project, name): |
| 269 | + binary = project.Configure(name, '{0}'.format(self.tag)) |
| 270 | + return self.ConfigureForHL2(binary) |
| 271 | + |
| 272 | +Extension = ExtensionConfig() |
| 273 | +Extension.detectSDKs() |
| 274 | +Extension.configure() |
| 275 | + |
| 276 | +# Add additional buildscripts here |
| 277 | +BuildScripts = [ |
| 278 | + 'AMBuilder', |
| 279 | +] |
| 280 | + |
| 281 | +if builder.backend == 'amb2': |
| 282 | + BuildScripts += [ |
| 283 | + 'PackageScript', |
| 284 | + ] |
| 285 | + |
| 286 | +builder.RunBuildScripts(BuildScripts, { 'Extension': Extension}) |
0 commit comments