Refactor and cleanup the AMBuildScript a bit

This commit is contained in:
Arkshine 2016-02-03 23:20:08 +01:00
parent 07f87990ef
commit 23080b7455

View File

@ -120,11 +120,53 @@ class AMXXConfig(object):
def configure(self): def configure(self):
builder.AddConfigureFile('pushbuild.txt') builder.AddConfigureFile('pushbuild.txt')
cfg = builder.DetectCompilers() cxx = builder.DetectCompilers()
cxx = cfg.cxx
if cxx.like('gcc'): if cxx.like('gcc'):
cfg.cflags += [ self.configure_gcc(cxx)
elif cxx.like('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 builder.target_platform == 'linux':
self.configure_linux(cxx)
elif builder.target_platform == 'mac':
self.configure_mac(cxx)
elif builder.target_platform == 'windows':
self.configure_windows(cxx)
# Finish up.
cxx.defines += [
'AMX_NOPROPLIST',
'PAWN_CELL_SIZE=32',
'AMXMODX_BUILD',
'AMXX_USE_VERSIONLIB',
]
if self.use_auto_versioning():
cxx.defines += ['AMXX_GENERATED_BUILD']
cxx.includes += [os.path.join(builder.buildPath, 'includes')]
cxx.includes += [os.path.join(builder.sourcePath, 'support', 'versionlib')]
cxx.includes += [os.path.join(builder.sourcePath, 'public')]
cxx.includes += [os.path.join(builder.sourcePath, 'public', 'sdk')]
cxx.includes += [os.path.join(builder.sourcePath, 'public', 'amtl')]
cxx.includes += [os.path.join(builder.sourcePath, 'public', 'amtl', 'amtl')]
cxx.includes += [os.path.join(builder.sourcePath, 'public', 'memtools')]
cxx.includes += [os.path.join(builder.sourcePath, 'third_party')]
cxx.includes += [os.path.join(builder.sourcePath, 'third_party', 'hashing')]
cxx.includes += [os.path.join(builder.sourcePath, 'third_party', 'zlib')]
def configure_gcc(self, cxx):
cxx.cflags += [
'-pipe', '-pipe',
'-fno-strict-aliasing', '-fno-strict-aliasing',
'-Wall', '-Wall',
@ -136,66 +178,71 @@ class AMXXConfig(object):
'-Wno-format-security', '-Wno-format-security',
'-m32', '-m32',
] ]
cfg.cxxflags += [ cxx.cxxflags += [
'-Wno-invalid-offsetof', '-Wno-invalid-offsetof',
'-std=c++11', '-std=c++11',
] ]
cfg.linkflags += ['-m32'] cxx.linkflags += ['-m32']
have_gcc = cxx.name == 'gcc' have_gcc = cxx.vendor == 'gcc'
have_clang = cxx.name == 'clang' have_clang = cxx.vendor == 'clang'
if have_clang or (have_gcc and cxx.version >= '4'): if have_clang or (have_gcc and cxx.version >= '4'):
cfg.cflags += ['-fvisibility=hidden'] cxx.cflags += ['-fvisibility=hidden']
cfg.cxxflags += ['-fvisibility-inlines-hidden'] cxx.cxxflags += ['-fvisibility-inlines-hidden']
if have_clang or (have_gcc and cxx.version >= '4.6'): if have_clang or (have_gcc and cxx.version >= '4.6'):
cfg.cflags += ['-Wno-narrowing'] cxx.cflags += ['-Wno-narrowing']
if (have_gcc and cxx.version >= '4.7') or (have_clang and cxx.version >= '3'): if (have_gcc and cxx.version >= '4.7') or (have_clang and cxx.version >= '3'):
cfg.cxxflags += ['-Wno-delete-non-virtual-dtor'] cxx.cxxflags += ['-Wno-delete-non-virtual-dtor']
if have_gcc and cxx.version >= '4.8': if have_gcc and cxx.version >= '4.8':
cfg.cflags += ['-Wno-unused-result', '-Wno-error=sign-compare'] cxx.cflags += ['-Wno-unused-result', '-Wno-error=sign-compare']
if have_clang: if have_clang:
cfg.cxxflags += ['-Wno-implicit-exception-spec-mismatch'] cxx.cxxflags += ['-Wno-implicit-exception-spec-mismatch']
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':
cfg.cxxflags += ['-Wno-deprecated-register'] cxx.cxxflags += ['-Wno-deprecated-register']
else: else:
cfg.cxxflags += ['-Wno-deprecated'] cxx.cxxflags += ['-Wno-deprecated']
cfg.cflags += ['-Wno-sometimes-uninitialized'] cxx.cflags += ['-Wno-sometimes-uninitialized']
if builder.target_platform == 'linux' and cxx.version >= '3.6': if builder.target_platform == 'linux' and cxx.version >= '3.6':
cfg.cxxflags += ['-Wno-inconsistent-missing-override'] cxx.cxxflags += ['-Wno-inconsistent-missing-override']
if have_gcc: if have_gcc:
cfg.cflags += ['-Wno-parentheses'] cxx.cflags += ['-Wno-parentheses']
cfg.c_only_flags += ['-std=c99'] cxx.c_only_flags += ['-std=c99']
elif have_clang: elif have_clang:
cfg.cflags += ['-Wno-logical-op-parentheses'] cxx.cflags += ['-Wno-logical-op-parentheses']
cfg.cxxflags += [ cxx.cxxflags += [
'-fno-exceptions', '-fno-exceptions',
'-fno-rtti', '-fno-rtti',
] ]
elif cxx.name == 'msvc':
if builder.options.opt == '1':
cxx.cflags += ['-O2']
def configure_msvc(self, cxx):
if builder.options.debug == '1': if builder.options.debug == '1':
cfg.cflags += ['/MTd'] cxx.cflags += ['/MTd']
cfg.linkflags += ['/NODEFAULTLIB:libcmt'] cxx.linkflags += ['/NODEFAULTLIB:libcmt']
else: else:
cfg.cflags += ['/MT'] cxx.cflags += ['/MT']
cfg.defines += [
cxx.defines += [
'_CRT_SECURE_NO_DEPRECATE', '_CRT_SECURE_NO_DEPRECATE',
'_CRT_SECURE_NO_WARNINGS', '_CRT_SECURE_NO_WARNINGS',
'_CRT_NONSTDC_NO_DEPRECATE', '_CRT_NONSTDC_NO_DEPRECATE',
'_ITERATOR_DEBUG_LEVEL=0', '_ITERATOR_DEBUG_LEVEL=0',
] ]
cfg.cflags += [ cxx.cflags += [
'/W3', '/W3',
] ]
cfg.cxxflags += [ cxx.cxxflags += [
'/EHsc', '/EHsc',
'/GR-', '/GR-',
'/TP', '/TP',
] ]
cfg.linkflags += [ cxx.linkflags += [
'/MACHINE:X86', '/MACHINE:X86',
'/SUBSYSTEM:WINDOWS', '/SUBSYSTEM:WINDOWS',
'kernel32.lib', 'kernel32.lib',
@ -212,72 +259,41 @@ class AMXXConfig(object):
'odbccp32.lib', 'odbccp32.lib',
] ]
# Optimization
if builder.options.opt == '1': if builder.options.opt == '1':
cfg.defines += ['NDEBUG'] cxx.cflags += ['/Ox']
if cxx.like('gcc'): cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
cfg.cflags += ['-O2']
elif cxx.like('msvc'):
cfg.cflags += ['/Ox']
cfg.linkflags += ['/OPT:ICF', '/OPT:REF']
# Debugging
if builder.options.debug == '1': if builder.options.debug == '1':
cfg.defines += ['DEBUG', '_DEBUG'] cxx.cflags += ['/Od', '/RTC1']
if cxx.like('msvc'):
cfg.cflags += ['/Od', '/RTC1']
# This needs to be after our optimization flags which could otherwise disable it. # This needs to be after our optimization flags which could otherwise disable it.
if cxx.name == 'msvc':
# Don't omit the frame pointer. # Don't omit the frame pointer.
cfg.cflags += ['/Oy-'] cxx.cflags += ['/Oy-']
# Platform-specifics def configure_linux(self, cxx):
if builder.target_platform == 'linux': cxx.defines += ['_LINUX', 'POSIX', 'LINUX']
cfg.defines += ['_LINUX', 'POSIX', 'LINUX'] cxx.linkflags += ['-ldl', '-lm']
cfg.postlink += ['-ldl', '-lm'] if cxx.vendor == 'gcc':
if cxx.name == 'gcc': cxx.linkflags += ['-static-libgcc']
cfg.postlink += ['-static-libgcc'] elif cxx.vendor == 'clang':
elif cxx.name == 'clang': cxx.linkflags += ['-lgcc_eh']
cfg.postlink += ['-lgcc_eh']
if cxx.like('gcc'): if cxx.like('gcc'):
self.stdcxx_path = self.invokeCompiler(['-m32', '-print-file-name=' + 'libstdc++.a'])[0] self.stdcxx_path = self.invokeCompiler(['-m32', '-print-file-name=' + 'libstdc++.a'])[0]
elif builder.target_platform == 'mac':
cfg.defines += ['OSX', '_OSX', 'POSIX'] def configure_mac(self, cxx):
cfg.cflags += ['-mmacosx-version-min=10.5'] cxx.defines += ['OSX', '_OSX', 'POSIX']
cfg.postlink += [ cxx.cflags += ['-mmacosx-version-min=10.5']
cxx.linkflags += [
'-mmacosx-version-min=10.5', '-mmacosx-version-min=10.5',
'-arch', 'i386', '-arch', 'i386',
'-lstdc++', '-lstdc++',
'-stdlib=libstdc++', '-stdlib=libstdc++',
'-framework', 'CoreServices', '-framework', 'CoreServices',
] ]
cfg.cxxflags += ['-stdlib=libstdc++'] cxx.cxxflags += ['-stdlib=libstdc++']
elif builder.target_platform == 'windows':
cfg.defines += ['WIN32', '_WINDOWS']
# Finish up. def configure_windows(self, cxx):
cfg.defines += [ cxx.defines += ['WIN32', '_WINDOWS']
'AMX_NOPROPLIST',
'PAWN_CELL_SIZE=32',
'AMXMODX_BUILD',
'AMXX_USE_VERSIONLIB',
]
if self.use_auto_versioning():
cfg.defines += ['AMXX_GENERATED_BUILD']
cfg.includes += [os.path.join(builder.buildPath, 'includes')]
cfg.includes += [os.path.join(builder.sourcePath, 'support', 'versionlib')]
cfg.includes += [os.path.join(builder.sourcePath, 'public')]
cfg.includes += [os.path.join(builder.sourcePath, 'public', 'sdk')]
cfg.includes += [os.path.join(builder.sourcePath, 'public', 'amtl')]
cfg.includes += [os.path.join(builder.sourcePath, 'public', 'amtl', 'amtl')]
cfg.includes += [os.path.join(builder.sourcePath, 'public', 'memtools')]
cfg.includes += [os.path.join(builder.sourcePath, 'third_party')]
cfg.includes += [os.path.join(builder.sourcePath, 'third_party', 'hashing')]
cfg.includes += [os.path.join(builder.sourcePath, 'third_party', 'zlib')]
return
# #
# Low-level compiler and binary construction. # Low-level compiler and binary construction.