This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.lua
325 lines (280 loc) · 7.26 KB
/
common.lua
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
-- http://industriousone.com/scripting-reference --
-- https://bitbucket.org/premake/premake-dev/wiki --
dofile("settings.lua")
function checkdir(dir)
if not os.isdir(dir) then
error("Directory does not exist: "..dir)
end
end
function dbg_hook(name)
local f=_G[name]
_G[name] = function(a,...)
if type(a)=="string" then
--print(name,"",a,...)
else
--print(name,"",unpack(a))
end
return f(a,...)
end
end
dbg_hook "links"
dbg_hook "targetdir"
dbg_hook "location"
dbg_hook "libdirs"
dbg_hook "configuration"
dbg_hook "flags"
dbg_hook "solution"
dbg_hook "defines"
dbg_hook "includedirs"
dbg_hook "linkoptions"
dbg_hook "project"
dbg_hook "files"
dbg_hook "targetname"
local function fixdir(dir,nocheck)
dir = path.getabsolute(dir)
if not nocheck then
checkdir(dir)
end
return dir
end
--Relative paths
GARRYSMOD_INCLUDES_PATH = fixdir "gmod-module-base/include"
BACKWARDS_HEADERS = fixdir "backwards_headers"
HOOKING = fixdir "hooking"
SIGSCANNING = fixdir "sigscanning"
LUA51 = fixdir "lua51"
LUAJIT = fixdir "luajit"
SOURCE_SDK = fixdir (SOURCE_SDK)
SRCDS_DIR = fixdir (SRCDS_DIR)
STEAMWORKS_SDK = fixdir (STEAMWORKS_SDK)
PROJECT_FOLDER = os.get() .. "/" .. _ACTION
SOURCE_SDK_INCLUDES={
SOURCE_SDK.."/public",
SOURCE_SDK.."/public/engine",
SOURCE_SDK.."/common",
SOURCE_SDK.."/public/vstdlib",
SOURCE_SDK.."/public/steam",
SOURCE_SDK.."/public/tier0",
SOURCE_SDK.."/public/tier1",
SOURCE_SDK.."/tier1",
SOURCE_SDK.."/public/game/server",
SOURCE_SDK.."/game/shared",
SOURCE_SDK.."/game/server",
SOURCE_SDK.."/game/client",
}
function SOURCE_SDK_LINKS()
local cfg = configuration()
configuration "windows"
links{"tier0","tier1","tier2","tier3","mathlib","steam_api","vstdlib"}
configuration "linux"
linkoptions { -- :(
SOURCE_SDK.."/lib/public/linux32/tier1.a",
SOURCE_SDK.."/lib/public/linux32/tier2.a",
SOURCE_SDK.."/lib/public/linux32/tier3.a",
SOURCE_SDK.."/lib/public/linux32/mathlib.a",
}
links {"tier0_srv","vstdlib_srv","steam_api"}
configuration(cfg.terms)
end
local include_helpers = {
source_sdk={
func = function(_)
libdirs{
SOURCE_SDK.."/lib/public/linux32",
SOURCE_SDK.."/lib/linux32",
SOURCE_SDK.."/lib/public"
}
includedirs(SOURCE_SDK_INCLUDES)
end,
},
gmod_sdk={
func = function(_)
includedirs{GARRYSMOD_INCLUDES_PATH}
end,
},
backwards_headers={
func = function(_)
includedirs{BACKWARDS_HEADERS}
libdirs{BACKWARDS_HEADERS}
end,
},
hooking={
func = function(_,i)
includedirs{HOOKING}
if i then
files{HOOKING..'/hde.cpp'}
end
end,
},
sigscanning={
func = function(_,i)
includedirs{SIGSCANNING}
if i then
files{SIGSCANNING..'/symbolfinder.cpp'}
configuration "windows"
files{SIGSCANNING..'/sigscan.cpp'}
configuration "linux"
files{SIGSCANNING..'/memutils.cpp'}
end
end,
},
steamworks={
func = function(_,i)
includedirs{STEAMWORKS_SDK..'/public'}
includedirs{STEAMWORKS_SDK..'/public/steam'}
if i then
libdirs {
STEAMWORKS_SDK..'/redistributable_bin',
STEAMWORKS_SDK..'/redistributable_bin/linux32'
}
end
end,
},
lua51={ -- gmod lua 5.1 compat
func = function(_,i)
includedirs{LUA51..'/src'}
libdirs{LUA51} -- lua_shared
if i then
configuration "windows"
links {"lua_shared"}
configuration "linux"
-- massive hack, but it works just the way I wanted it to
linkoptions {"-Wl,-rpath='$$ORIGIN'"}
linkoptions {"garrysmod/bin/lua_shared_srv.so"}
prelinkcommands {"mkdir -p garrysmod/bin && ln -s -f "..SRCDS_DIR.."/garrysmod/bin/lua_shared_srv.so garrysmod/bin/lua_shared_srv.so "}
end
end,
},
luajit={ -- luajit
func = function(_,i)
includedirs{LUAJIT..'/src'}
libdirs{LUAJIT..'/src'}
if i then
configuration "windows"
libdirs{LUAJIT..'/src'}
links_static "lua51"
configuration "linux"
libdirs{LUAJIT..'/src'}
links_static "luajit"
end
end,
},
}
function INCLUDES(what)
local t = include_helpers[what]
if not t then error("Not found: "..what) end
local included = t.included
print("Including "..what,included and "REINCLUDE!?!?" or "")
t:func(included)
t.included = true
--Should we ?
--configuration {}
end
function IsIncluded(what)
local t = include_helpers[what]
if not t then error("Not found: "..what) end
local included = t.included
return included or false
end
local runtime_required
function RequireRuntime()
runtime_required = true
end
function SOLUTION(name)
_SOLUTION_NAME=name
solution (name)
language ("C++")
location (PROJECT_FOLDER)
targetdir "Release"
if platforms then
platforms { "x32" }
end
if optimize and DEBUG~=true then
optimize"On"
else
optimize"Off"
end
-- debug symbols are always built in, DEBUG just makes them not be stripped
flags {"NoPCH","Symbols"}
if vectorextensions then
vectorextensions "SSE2"
else
flags {"EnableSSE2","EnableSSE"}
end
if not runtime_required then
flags {"StaticRuntime"}
end
configurations
{
"Release"
}
end
local defaultlibs_required
function RequireDefaultlibs()
defaultlibs_required = true
end
function WINDOWS()
configuration ("windows")
defines {"COMPILER_MSVC32","WIN32","_WIN32","_WINDOWS"}
defines {'SERVER_BIN="server.dll"'}
if not defaultlibs_required then
linkoptions { "/nodefaultlib:\"libcmt\"", "/nodefaultlib:\"libcmtd\"" }
end
end
function LINUX()
configuration ("linux")
defines {'SERVER_BIN="server_srv.so"'}
defines {'LUA_SHARED="lua_shared_srv.so"'}
defines {'LUA_SHARED_CLIENT="lua_shared.so"'}
defines {"COMPILER_GCC","POSIX","_POSIX","LINUX","_LINUX","GNUC","NO_MALLOC_OVERRIDE"}
if not FUCKSYMS then
linkoptions {"-Wl,-z,defs"}
end
libdirs {SRCDS_DIR..'/bin'}
links {"rt","dl"}
end
function PROJECT()
project(_SOLUTION_NAME)
targetname(_SOLUTION_NAME)
kind ("SharedLib")
defines {
"GMMODULE",
--"NO_HOOK_MALLOC",
--LINUX? "NO_MALLOC_OVERRIDE",
--"SOURCE_SDK=1",
--"CLIENT_DLL",
"VERSION_SAFE_STEAM_API_INTERFACES",
"VECTOR",
--"NO_STRING_T", -- breaks cbase.h for example
--"NO_SDK",
"_CRT_NONSTDC_NO_DEPRECATE",
"_CRT_SECURE_NO_DEPRECATE",
"RAD_TELEMETRY_DISABLED",
"PROTECTED_THINGS_ENABLE",
--"strncpy=use_Q_strncpy_instead",
--"_snprintf=use_Q_snprintf_instead",
--"fopen=dont_use_fopen",
}
if DEBUG ~= true then
defines "NDEBUG"
else
defines "DEBUG"
end
files {"src/*.cpp"}
targetprefix "gmsv_"
if IsIncluded"backwards_headers" then
files {BACKWARDS_HEADERS.."/*.cpp"}
end
configuration "windows"
targetsuffix "_win32"
configuration "linux"
targetsuffix "_linux"
targetextension ".dll"
if DEBUG~=true then
postbuildcommands { "strip --keep-file-symbols --strip-debug -p %{cfg.linktarget.relpath}" }
end
project(_SOLUTION_NAME)
end
function links_static(what)
linkoptions{"-Wl,-Bstatic,-l"..what..",-Bdynamic"}
end