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