forked from TF2-DMB/hl2sdk-tf2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AMBuildScript
162 lines (133 loc) · 4 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
# vim: set ts=2 sw=2 tw=99 noet ft=python:
import os, sys, shutil
from ambuild2 import util
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 SDKConfig(object):
def __init__(self):
self.libs = []
self.targets = []
self.target_archs = set()
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 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']
if cxx.target.arch == 'x86_64':
cxx.defines += ['X64BITS', 'PLATFORM_64BITS']
cxx.defines += ['RAD_TELEMETRY_DISABLED']
# Platform-specifics
if cxx.target.platform == 'linux':
self.configure_linux(cxx)
elif cxx.target.platform == 'windows':
self.configure_windows(cxx)
def configure_gcc(self, cxx):
cxx.cflags += [
'-Wall',
'-Werror',
'-Wno-overloaded-virtual',
'-Wno-unused-function',
'-msse',
'-fPIC'
]
cxx.defines += [
'COMPILER_GCC'
]
cxx.cxxflags += [
'-std=c++17'
]
if builder.options.opt == '1':
cxx.cflags += ['-O3']
return
def configure_msvc(self, cxx):
cxx.defines += ['COMPILER_MSVC']
if cxx.target.arch == 'x86':
cxx.defines += ['COMPILER_MSVC32']
elif cxx.target.arch == 'x86_64':
cxx.defines += ['COMPILER_MSVC64']
cxx.cxxflags += [
'/std:c++17',
'/WX'
]
if builder.options.opt == '1':
cxx.cflags += ['/Ox', '/Zo']
cxx.linkflags += ['/OPT:ICF', '/OPT:REF']
return
def configure_linux(self, cxx):
cxx.defines += ['_LINUX', 'LINUX', 'POSIX', 'GNUC']
# Set of defines required by the HL2SDK
cxx.defines += [
'_finite=finite',
'strnicmp=strncasecmp', '_vsnprintf=vsnprintf',
'_alloca=alloca',
'NO_MALLOC_OVERRIDE'
]
return
def configure_windows(self, cxx):
cxx.defines += ['_WINDOWS', 'WINDOWS', 'COMPILER_MSVC']
if cxx.target.arch == 'x86':
cxx.defines += ['WIN32']
elif cxx.target.arch == 'x86_64':
cxx.defines += ['WIN64']
return
def configure(self):
for cxx in self.targets:
self.configure_cxx(cxx)
def ConfigureLibrary(self, project, compiler, context, prefix = ''):
name = prefix + project.name
if compiler.target.platform == 'linux' and compiler.target.arch == 'x86':
name += '_i486'
binary = project.Configure(compiler, name, '{0} - {1}'.format(self.tag, compiler.target.arch))
binary.compiler.cxxincludes += [
os.path.join(context.currentSourcePath)
]
return binary
HL2SDK = SDKConfig()
HL2SDK.configure()
BuildScripts = ['mathlib/AMBuilder', 'tier1/AMBuilder', 'PackageScript']
# Turn off the 'lib' prefix for all platform, we will add it if we need to
util.StaticLibPrefix = ''
builder.Build(BuildScripts, { 'HL2SDK': HL2SDK })