forked from rcbotCheeseh/rcbot2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAMBuildScript
More file actions
338 lines (290 loc) · 9.52 KB
/
AMBuildScript
File metadata and controls
338 lines (290 loc) · 9.52 KB
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
proj_c_flags = [
'-Wall',
'-Wno-non-virtual-dtor',
'-Wno-overloaded-virtual',
'-Werror',
]
proj_c_flags_opt = [
'-O3',
'-funroll-loops',
'-pipe',
]
proj_c_flags_dbg = [
'-g',
'-ggdb3',
]
import os, sys
SdkHelpers = builder.Eval('hl2sdk-manifests/SdkHelpers.ambuild', {
'Project': 'rcbot'
})
def ResolveEnvPath(env, folder):
if env in os.environ:
path = os.environ[env]
if os.path.isdir(path):
return path
else:
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 SetArchFlags(compiler, arch, platform):
if compiler.behavior == 'gcc':
if arch == 'x86':
compiler.cflags += ['-m32']
compiler.linkflags += ['-m32']
if platform == 'mac':
compiler.linkflags += ['-arch', 'i386']
elif arch == 'x64':
compiler.cflags += ['-m64', '-fPIC']
compiler.linkflags += ['-m64']
if platform == 'mac':
compiler.linkflags += ['-arch', 'x86_64']
elif compiler.like('msvc'):
if arch == 'x86':
compiler.linkflags += ['/MACHINE:X86']
elif arch == 'x64':
compiler.linkflags += ['/MACHINE:X64']
def AppendArchSuffix(binary, name, arch):
if arch == 'x64':
binary.localFolder = name + '.x64'
class MMSConfig(object):
def __init__(self):
self.sdks = {}
self.sdk_targets = []
self.binaries = []
self.generated_headers = None
self.archs = ['x86']
self.mms_root = builder.options.mms_path
self.sm_path = builder.options.sm_path or None
self.cxx_list = []
self.platform = None
def detectProductVersion(self):
builder.AddConfigureFile('product.version')
# For OS X dylib versioning
import re
with open(os.path.join(builder.sourcePath, 'product.version'), 'r') as fp:
productContents = fp.read()
m = re.match(r'(\d+)\.(\d+)\.(\d+).*', productContents)
if m == None:
self.productVersion = '1.0.0'
else:
major, minor, release = m.groups()
self.productVersion = '{0}.{1}.{2}'.format(major, minor, release)
def findSdkPath(self, sdk_name):
dir_name = 'hl2sdk-{}'.format(sdk_name)
if builder.options.hl2sdk_root:
sdk_path = os.path.join(builder.options.hl2sdk_root, dir_name)
if os.path.exists(sdk_path):
return sdk_path
return ResolveEnvPath('HL2SDK{}'.format(sdk_name.upper()), dir_name)
def shouldIncludeSdk(self, sdk):
# Filter out Source2 SDKs
return not sdk.get('source2', False)
def detectSDKs(self):
sdk_list = builder.options.sdks.split(',')
if sdk_list[0] == '':
sdk_list = []
# Detect compilers for each arch
for arch in self.archs:
try:
cxx = builder.DetectCxx(target_arch = arch)
self.cxx_list.append(cxx)
if self.platform is None:
self.platform = cxx.target.platform
except Exception as e:
print('Skipping target {}: {}'.format(arch, e))
continue
if not self.cxx_list:
raise Exception('No suitable C/C++ compiler was found.')
# Set up SDK manifest callbacks
SdkHelpers.find_sdk_path = self.findSdkPath
SdkHelpers.sdk_filter = self.shouldIncludeSdk
SdkHelpers.findSdks(builder, self.cxx_list, sdk_list)
self.sdks = SdkHelpers.sdks
self.sdk_targets = SdkHelpers.sdk_targets
if not self.sdk_targets and len(sdk_list):
raise Exception('No buildable SDKs were found, nothing to build.')
if not builder.options.mms_path:
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
else:
self.mms_root = os.path.abspath(os.path.join(builder.sourcePath, builder.options.mms_path))
if not self.mms_root:
raise Exception('Metamod:Source path is missing. Supply a --mms_path flag')
def configure(self):
if not set(self.archs).issubset(['x86', 'x64']):
raise Exception('Unknown target architecture: {0}'.format(self.archs))
if not self.cxx_list:
return
cxx = self.cxx_list[0]
if cxx.like('msvc') and len(self.archs) > 1:
raise Exception('Building multiple archs with MSVC is not currently supported')
if cxx.behavior == 'gcc':
cxx.defines += [
'stricmp=strcasecmp',
'_stricmp=strcasecmp',
'_snprintf=snprintf',
'_vsnprintf=vsnprintf',
'_alloca=alloca',
'GNUC'
]
cxx.cflags += proj_c_flags
cxx.cflags += [
'-fPIC',
'-fno-exceptions',
'-fno-rtti',
'-msse',
'-fno-strict-aliasing',
]
if (cxx.version >= 'gcc-4.0') or cxx.family == 'clang':
cxx.cflags += [
'-fvisibility=hidden',
'-fvisibility-inlines-hidden',
'-std=c++11',
'-w',
'-D__linux',
]
if (cxx.version >= 'gcc-4.7' or cxx.version >= 'clang-3.0' or cxx.version >= 'apple-clang-5.1'):
cxx.cflags += [
'-Wno-delete-non-virtual-dtor',
'-Wno-unused-private-field',
'-Wno-deprecated-register',
]
if cxx.family == 'clang':
if cxx.version >= 'clang-3.9' or cxx.version >= 'apple-clang-10.0':
cxx.cxxflags += ['-Wno-expansion-to-defined']
elif cxx.like('msvc'):
if builder.options.debug == '1':
cxx.cflags += ['/MTd']
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
else:
cxx.cflags += ['/MT']
cxx.defines += [
'_CRT_SECURE_NO_DEPRECATE',
'_CRT_SECURE_NO_WARNINGS',
'_CRT_NONSTDC_NO_DEPRECATE',
'_ITERATOR_DEBUG_LEVEL=0',
'WIN32',
'_WINDOWS'
]
cxx.cflags += [
'/W3',
]
cxx.cxxflags += [
'/EHsc',
'/GR-',
'/TP',
]
cxx.linkflags += [
'/MACHINE:X86',
]
# Optimization
if builder.options.opt == '1':
if cxx.behavior == 'gcc':
cxx.cflags += proj_c_flags_opt
elif cxx.behavior == 'msvc':
cxx.cflags += ['/Ox', '/Zo']
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
# Debugging
if builder.options.debug == '1':
cxx.defines += ['_DEBUG']
if cxx.behavior == 'gcc':
cxx.cflags += proj_c_flags_dbg
cxx.linkflags += ['-rdynamic']
elif cxx.behavior == 'msvc':
cxx.cflags += ['/MTd']
cxx.linkflags += ['/NODEFAULTLIB:libcmt']
# This needs to be after our optimization flags which could otherwise disable it.
if cxx.family == 'msvc':
cxx.cflags += ['/Oy-']
# Platform-specifics
if self.platform == 'linux':
cxx.defines += [
'POSIX',
'_LINUX',
]
cxx.linkflags += ['-shared']
if cxx.family == 'gcc':
cxx.linkflags += ['-static-libgcc']
# catch link errors at compile time
cxx.linkflags += [ '-Wl,-no-undefined' ]
elif self.platform == 'mac':
cxx.defines += [
'POSIX',
'OSX',
'_OSX',
]
cxx.cflags += ['-mmacosx-version-min=10.9']
cxx.linkflags += [
'-dynamiclib',
'-lc++',
'-mmacosx-version-min=10.9',
]
elif self.platform == 'windows':
pass
cxx.includes += [
os.path.join(builder.buildPath, 'includes')
]
def AddVersioning(self, binary, arch):
if self.platform == 'windows':
pass
elif self.platform == 'mac' and binary.type == 'library':
binary.compiler.postlink += [
'-compatibility_version', '1.0.0',
'-current_version', self.productVersion
]
binary.compiler.sourcedeps += MMS.generated_headers
return binary
def LibraryBuilder(self, compiler, name, arch):
binary = compiler.Library(name)
AppendArchSuffix(binary, name, arch)
self.AddVersioning(binary, arch)
return binary
def Library(self, context, name, cxx, arch):
compiler = cxx.clone()
SetArchFlags(compiler, arch, self.platform)
return self.LibraryBuilder(compiler, name, arch)
def HL2Library(self, context, name, sdk, cxx, arch):
compiler = cxx.clone()
SetArchFlags(compiler, arch, self.platform)
compiler.cxxincludes += [
os.path.join(context.currentSourcePath),
]
# Generate SE_* defines for all known SDKs (used for SOURCE_ENGINE checks)
for other_sdk in SdkHelpers.sdk_manifests:
compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])]
# MMS include paths
if sdk['name'] in ['episode1', 'darkm']:
compiler.cxxincludes.append(os.path.join(self.mms_root, 'core-legacy'))
compiler.cxxincludes.append(os.path.join(self.mms_root, 'core-legacy', 'sourcehook'))
else:
compiler.cxxincludes.append(os.path.join(self.mms_root, 'core'))
compiler.cxxincludes.append(os.path.join(self.mms_root, 'core', 'sourcehook'))
binary = self.LibraryBuilder(compiler, name, arch)
# Let SdkHelpers configure all SDK-specific includes, defines, and libraries
SdkHelpers.configureCxx(context, binary, sdk)
# SDK manifests omit some include paths that the SDK headers need.
if sdk['name'] not in ['episode1', 'darkm']:
binary.compiler.cxxincludes += [os.path.join(sdk['path'], 'game', 'server')]
return binary
MMS = MMSConfig()
MMS.detectProductVersion()
MMS.detectSDKs()
MMS.configure()
MMS.generated_headers = builder.Build('versioning/AMBuildScript', { 'MMS': MMS })
BuildScripts = [
'AMBuilder',
'loader/AMBuilder'
] # add sub-modules here
if getattr(builder.options, 'enable_tests', False):
BuildScripts += [] # add tests here
import os
if builder.backend == 'amb2':
BuildScripts += [
'PackageScript',
]
builder.Build(BuildScripts, { 'MMS': MMS })