-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathAMBuildScript
More file actions
215 lines (176 loc) · 6.14 KB
/
AMBuildScript
File metadata and controls
215 lines (176 loc) · 6.14 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
# vim: set ts=2 sw=2 tw=99 noet ft=python:
import os, sys, shutil
def ResolveEnvPath(env, folder=None):
if env in os.environ:
path = os.environ[env]
if os.path.isdir(path):
return path
return None
if folder:
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 Normalize(path):
return os.path.abspath(os.path.normpath(path))
class AcceleratorConfig(object):
def __init__(self):
self.mms_root = None
self.sm_root = None
self.extension = None
self.libz = None
self.libbreakpad_client = None
self.libbreakpad = None
self.libdisasm = None
self.targets = []
self.target_archs = set()
self.breakpad_config = dict()
self.breakpad_patch = None
if builder.options.targets:
target_archs = builder.options.targets.split(',')
else:
target_archs = ['x86', 'x86_64']
for arch in target_archs:
try:
cxx = builder.DetectCxx(target_arch = arch)
self.target_archs.add(cxx.target.arch)
except Exception as e:
if builder.options.targets:
raise
print('Skipping target {}: {}'.format(arch, e))
continue
self.targets.append(cxx)
if not self.targets:
raise Exception('No suitable C/C++ compiler was found.')
@property
def tag(self):
if builder.options.debug == '1':
return 'Debug'
return 'Release'
def retrieve_sm(self):
if builder.options.sm_path:
self.sm_root = builder.options.sm_path
else:
self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod')
if not self.sm_root or not os.path.isdir(self.sm_root):
raise Exception('Could not find a source copy of SourceMod')
self.sm_root = Normalize(self.sm_root)
def use_auto_versioning(self):
return not builder.options.disable_auto_versioning
def configure_cxx(self, cxx):
if cxx.like('gcc'):
self.configure_gcc(cxx)
elif cxx.family == '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 cxx.target.platform == 'linux':
self.configure_linux(cxx)
elif cxx.target.platform == 'windows':
self.configure_windows(cxx)
if self.use_auto_versioning():
cxx.defines += ['GIT_ACTION_BUILD']
def configure_gcc(self, cxx):
cxx.cflags += [
'-fPIC',
'-pipe',
'-fno-strict-aliasing',
'-fvisibility=hidden',
'-fvisibility-inlines-hidden',
'-Wall',
'-Werror',
'-msse'
]
cxx.cxxflags += [
'-std=c++17',
'-fno-threadsafe-statics',
'-Wno-non-virtual-dtor',
'-Wno-overloaded-virtual',
'-Wno-implicit-exception-spec-mismatch'
]
cxx.postlink += ['-pthread', '-Wl,-z,noexecstack']
if builder.options.opt == '1':
cxx.cflags += ['-O3']
return
def configure_msvc(self, cxx):
cxx.cxxflags += [
'/EHsc',
'/std:c++17'
]
return
def configure_linux(self, cxx):
cxx.defines += ['_LINUX', 'POSIX', '_GLIBCXX_USE_CXX11_ABI=0']
return
def configure_windows(self, cxx):
cxx.defines += ['_WINDOWS']
if cxx.target.arch == 'x86':
cxx.defines += ['WIN32']
elif cxx.target.arch == 'x86_64':
cxx.defines += ['WIN64']
return
def configure(self):
self.retrieve_sm()
for cxx in self.targets:
self.configure_cxx(cxx)
def configure_extension(self, compiler, context):
compiler.cxxincludes += [
os.path.join(context.currentSourcePath),
os.path.join(self.sm_root, 'public'),
os.path.join(self.sm_root, 'public', 'extensions'),
os.path.join(self.sm_root, 'public', 'amtl', 'amtl'),
os.path.join(self.sm_root, 'public', 'amtl'),
os.path.join(self.sm_root, 'sourcepawn', 'include')
]
def link_libz(self, compiler, context):
for task in self.libz:
if task.target.arch == compiler.target.arch:
compiler.postlink += [os.path.join(context.buildPath, task.binary.path)]
compiler.linkdeps += [task.binary]
return
raise Exception('No suitable build of libz was found.')
def link_libbreakpad_client(self, compiler, context):
for task in self.libbreakpad_client:
if task.target.arch == compiler.target.arch:
compiler.postlink += [os.path.join(context.buildPath, task.binary.path)]
compiler.linkdeps += [task.binary]
return
raise Exception('No suitable build of libbreakpad_client was found.')
def link_libbreakpad(self, compiler, context):
for task in self.libbreakpad:
if task.target.arch == compiler.target.arch:
compiler.postlink += [os.path.join(context.buildPath, task.binary.path)]
compiler.linkdeps += [task.binary]
return
raise Exception('No suitable build of libbreakpad was found.')
def link_libdisasm(self, compiler, context):
for task in self.libdisasm:
if task.target.arch == compiler.target.arch:
compiler.postlink += [os.path.join(context.buildPath, task.binary.path)]
compiler.linkdeps += [task.binary]
return
raise Exception('No suitable build of libdisasm was found.')
def ConfigureLibrary(self, project, compiler, context):
binary = project.Configure(compiler, project.name, '{0} - {1}'.format(self.tag, compiler.target.arch))
binary.compiler.cxxincludes += [
os.path.join(context.currentSourcePath)
]
return binary
def ConfigureExtension(self, project, compiler, context):
binary = self.ConfigureLibrary(project, compiler, context)
self.configure_extension(binary.compiler, context)
return binary
Accelerator = AcceleratorConfig()
Accelerator.configure()
builder.Build(['third_party/Patch', 'third_party/Configure', 'third_party/AMBuilder'], { 'Accelerator': Accelerator })
BuildScripts = ['extension/AMBuilder', 'buildbot/PackageScript']
builder.Build(BuildScripts, { 'Accelerator': Accelerator })