|
| 1 | +# vim: set ts=2 sw=2 tw=99 et ft=python: |
| 2 | +# |
| 3 | +# Copyright (C) 2004-2012 David Anderson |
| 4 | +# |
| 5 | +# This file is part of SourcePawn. |
| 6 | +# |
| 7 | +# SourcePawn is free software: you can redistribute it and/or modify it under |
| 8 | +# the terms of the GNU General Public License as published by the Free |
| 9 | +# Software Foundation, either version 3 of the License, or (at your option) |
| 10 | +# any later version. |
| 11 | +# |
| 12 | +# SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 | +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 14 | +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License along with |
| 17 | +# SourcePawn. If not, see http://www.gnu.org/licenses/. |
| 18 | +# |
| 19 | +import os |
| 20 | +import sys |
| 21 | + |
| 22 | +def Normalize(path): |
| 23 | + return os.path.abspath(os.path.normpath(path)) |
| 24 | + |
| 25 | +class KEConfig: |
| 26 | + def __init__(self): |
| 27 | + cfg = builder.DetectCompilers() |
| 28 | + cxx = cfg.cxx |
| 29 | + |
| 30 | + if cxx.behavior is 'gcc': |
| 31 | + cfg.cflags += [ |
| 32 | + '-pipe', |
| 33 | + '-Wall', |
| 34 | + '-Werror', |
| 35 | + '-Wno-switch', |
| 36 | + ] |
| 37 | + cfg.cxxflags += ['-std=c++11'] |
| 38 | + |
| 39 | + have_gcc = cxx.name is 'gcc' |
| 40 | + have_clang = cxx.name is 'clang' |
| 41 | + if have_clang or (have_gcc and cxx.majorVersion >= 4): |
| 42 | + cfg.cflags += ['-fvisibility=hidden'] |
| 43 | + cfg.cxxflags += ['-fvisibility-inlines-hidden'] |
| 44 | + if have_clang or (have_gcc and cxx.minorVersion >= 6): |
| 45 | + cfg.cflags += ['-Wno-narrowing'] |
| 46 | + if (have_gcc and cxx.minorVersion >= 7) or (have_clang and cxx.majorVersion >= 4): |
| 47 | + cfg.cxxflags += ['-Wno-delete-non-virtual-dtor'] |
| 48 | + |
| 49 | + cfg.cxxflags += [ |
| 50 | + '-fno-exceptions', |
| 51 | + '-fno-threadsafe-statics', |
| 52 | + '-Wno-non-virtual-dtor', |
| 53 | + '-Wno-overloaded-virtual', |
| 54 | + '-Wno-unused-private-field', |
| 55 | + ] |
| 56 | + |
| 57 | + if have_gcc: |
| 58 | + cfg.cflags += ['-mfpmath=sse'] |
| 59 | + |
| 60 | + # Disable some stuff we don't use, that gives us better binary |
| 61 | + # compatibility on Linux. |
| 62 | + cfg.cxxflags += [ |
| 63 | + '-fno-exceptions', |
| 64 | + '-fno-rtti', |
| 65 | + '-fno-threadsafe-statics', |
| 66 | + '-Wno-non-virtual-dtor', |
| 67 | + '-Wno-overloaded-virtual', |
| 68 | + '-Wno-invalid-offsetof', |
| 69 | + ] |
| 70 | + |
| 71 | + if (have_gcc and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \ |
| 72 | + (have_clang and cxx.majorVersion >= 3): |
| 73 | + cfg.cxxflags += ['-Wno-delete-non-virtual-dtor'] |
| 74 | + |
| 75 | + cfg.postlink += ['-lm'] |
| 76 | + elif cxx.name is 'msvc': |
| 77 | + if builder.options.debug == '1': |
| 78 | + cfg.cflags += ['/MTd'] |
| 79 | + cfg.linkflags += ['/NODEFAULTLIB:libcmt'] |
| 80 | + else: |
| 81 | + cfg.cflags += ['/MT'] |
| 82 | + cfg.defines += [ |
| 83 | + '_CRT_SECURE_NO_DEPRECATE', |
| 84 | + '_CRT_SECURE_NO_WARNINGS', |
| 85 | + '_CRT_NONSTDC_NO_DEPRECATE', |
| 86 | + '_ITERATOR_DEBUG_LEVEL=0', |
| 87 | + ] |
| 88 | + cfg.cflags += [ |
| 89 | + '/W3', |
| 90 | + ] |
| 91 | + cfg.cxxflags += [ |
| 92 | + '/EHsc', |
| 93 | + '/GR-', |
| 94 | + '/TP', |
| 95 | + ] |
| 96 | + cfg.linkflags += [ |
| 97 | + '/MACHINE:X86', |
| 98 | + '/SUBSYSTEM:WINDOWS', |
| 99 | + 'kernel32.lib', |
| 100 | + 'user32.lib', |
| 101 | + 'gdi32.lib', |
| 102 | + 'winspool.lib', |
| 103 | + 'comdlg32.lib', |
| 104 | + 'advapi32.lib', |
| 105 | + 'shell32.lib', |
| 106 | + 'ole32.lib', |
| 107 | + 'oleaut32.lib', |
| 108 | + 'uuid.lib', |
| 109 | + 'odbc32.lib', |
| 110 | + 'odbccp32.lib', |
| 111 | + ] |
| 112 | + |
| 113 | + # Optimization |
| 114 | + if builder.options.opt == '1': |
| 115 | + cfg.defines += ['NDEBUG'] |
| 116 | + if cxx.behavior == 'gcc': |
| 117 | + cfg.cflags += ['-O3'] |
| 118 | + elif cxx.behavior == 'msvc': |
| 119 | + cfg.cflags += ['/Ox'] |
| 120 | + cfg.linkflags += ['/OPT:ICF', '/OPT:REF'] |
| 121 | + |
| 122 | + # Debugging |
| 123 | + if builder.options.debug == '1': |
| 124 | + cfg.defines += ['DEBUG', '_DEBUG'] |
| 125 | + if cxx.behavior == 'msvc': |
| 126 | + cfg.cflags += ['/Od', '/RTC1'] |
| 127 | + |
| 128 | + # This needs to be after our optimization flags which could otherwise disable it. |
| 129 | + if cxx.name == 'msvc': |
| 130 | + # Don't omit the frame pointer. |
| 131 | + cfg.cflags += ['/Oy-'] |
| 132 | + |
| 133 | + # Platform-specifics |
| 134 | + if builder.target_platform == 'linux': |
| 135 | + if cxx.name == 'gcc': |
| 136 | + cfg.linkflags += ['-static-libgcc'] |
| 137 | + elif cxx.name == 'clang': |
| 138 | + cfg.linkflags += ['-lgcc_eh'] |
| 139 | + cfg.linkflags += ['-lpthread', '-lrt'] |
| 140 | + elif builder.target_platform == 'mac': |
| 141 | + cfg.linkflags += [ |
| 142 | + '-mmacosx-version-min=10.5', |
| 143 | + ] |
| 144 | + elif builder.target_platform == 'windows': |
| 145 | + cfg.defines += ['WIN32', '_WINDOWS'] |
| 146 | + |
| 147 | + cfg.defines += ['KE_THREADSAFE'] |
| 148 | + |
| 149 | + if builder.options.amtl: |
| 150 | + amtl_path = Normalize(builder.options.amtl) |
| 151 | + if not os.path.isdir(amtl_path): |
| 152 | + raise Exception('Could not find AMTL at: {0}'.format(amtl_path)) |
| 153 | + cfg.cxxincludes += [os.path.join(amtl_path, 'include')] |
| 154 | + cfg.cxxincludes += [ |
| 155 | + os.path.join(builder.sourcePath, 'include'), |
| 156 | + ] |
| 157 | + |
| 158 | +KE = KEConfig() |
| 159 | + |
| 160 | +builder.RunScript('static_lib.ambuild', { 'KE': KE }) |
| 161 | + |
0 commit comments