-
-
Notifications
You must be signed in to change notification settings - Fork 618
/
gdc.lua
327 lines (277 loc) · 7.1 KB
/
gdc.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
326
327
--
-- d/tools/gdc.lua
-- Provides GDC-specific configuration strings.
-- Copyright (c) 2013-2015 Andrew Gough, Manu Evans, and the Premake project
--
local p = premake
p.tools.gdc = { }
local gdc = p.tools.gdc
local project = p.project
local config = p.config
local d = p.modules.d
--
-- Set default tools
--
gdc.dc = "gdc"
--
-- Returns list of D compiler flags for a configuration.
--
gdc.dflags = {
architecture = {
x86 = "-m32",
x86_64 = "-m64",
},
flags = {
Documentation = "-fdoc",
FatalWarnings = "-Werror",
GenerateHeader = "-fintfc",
GenerateJSON = "-fX",
-- Release = "-frelease",
RetainPaths = "-op",
SymbolsLikeC = "-fdebug-c",
UnitTest = "-funittest",
Verbose = "-fd-verbose",
-- THESE ARE THE DMD ARGS...
-- ProfileGC = "-profile=gc",
-- StackFrame = "-gs",
-- StackStomp = "-gx",
-- AllInstantiate = "-allinst",
-- BetterC = "-betterC",
-- Main = "-main",
-- PerformSyntaxCheckOnly = "-o-",
ShowTLS = "-fd-vtls",
-- ShowGC = "-vgc",
-- IgnorePragma = "-ignore",
ShowDependencies = "-fdeps",
},
boundscheck = {
Off = "-fno-bounds-check",
-- On = "-boundscheck=on",
-- SafeOnly = "-boundscheck=safeonly",
},
deprecatedfeatures = {
Allow = "-fdeprecated",
-- Warn = "-dw",
-- Error = "-de",
},
floatingpoint = {
Fast = "-ffast-math",
Strict = "-ffloat-store",
},
optimize = {
Off = "-O0",
On = "-O2 -finline-functions",
Debug = "-Og",
Full = "-O3 -finline-functions",
Size = "-Os -finline-functions",
Speed = "-O3 -finline-functions",
},
pic = {
On = "-fPIC",
},
vectorextensions = {
AVX = "-mavx",
SSE = "-msse",
SSE2 = "-msse2",
},
warnings = {
-- Default = "-w", -- TODO: check this...
High = "-Wall",
Extra = "-Wall -Wextra",
},
symbols = {
On = "-g",
FastLink = "-g",
Full = "-g -gf",
}
}
function gdc.getdflags(cfg)
local flags = config.mapFlags(cfg, gdc.dflags)
if config.isDebugBuild(cfg) then
table.insert(flags, "-fdebug")
else
table.insert(flags, "-frelease")
end
if cfg.flags.Documentation then
if cfg.docname then
table.insert(flags, "-fdoc-file=" .. p.quoted(cfg.docname))
end
if cfg.docdir then
table.insert(flags, "-fdoc-dir=" .. p.quoted(cfg.docdir))
end
end
if cfg.flags.GenerateHeader then
if cfg.headername then
table.insert(flags, "-fintfc-file=" .. p.quoted(cfg.headername))
end
if cfg.headerdir then
table.insert(flags, "-fintfc-dir=" .. p.quoted(cfg.headerdir))
end
end
return flags
end
--
-- Decorate versions for the DMD command line.
--
function gdc.getversions(versions, level)
local result = {}
for _, version in ipairs(versions) do
table.insert(result, '-fversion=' .. version)
end
if level then
table.insert(result, '-fversion=' .. level)
end
return result
end
--
-- Decorate debug constants for the DMD command line.
--
function gdc.getdebug(constants, level)
local result = {}
for _, constant in ipairs(constants) do
table.insert(result, '-fdebug=' .. constant)
end
if level then
table.insert(result, '-fdebug=' .. level)
end
return result
end
--
-- Decorate import file search paths for the DMD command line.
--
function gdc.getimportdirs(cfg, dirs)
local result = {}
for _, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir)
table.insert(result, '-I' .. p.quoted(dir))
end
return result
end
--
-- Decorate import file search paths for the DMD command line.
--
function gdc.getstringimportdirs(cfg, dirs)
local result = {}
for _, dir in ipairs(dirs) do
dir = project.getrelative(cfg.project, dir)
table.insert(result, '-J' .. p.quoted(dir))
end
return result
end
--
-- Returns the target name specific to compiler
--
function gdc.gettarget(name)
return "-o " .. name
end
--
-- Return a list of LDFLAGS for a specific configuration.
--
gdc.ldflags = {
architecture = {
x86 = { "-m32" },
x86_64 = { "-m64" },
},
kind = {
SharedLib = function(cfg)
local r = { iif(cfg.system == p.MACOSX, "-dynamiclib", "-shared") }
if cfg.system == "windows" and not cfg.flags.NoImportLib then
table.insert(r, '-Wl,--out-implib="' .. cfg.linktarget.relpath .. '"')
end
return r
end,
WindowedApp = function(cfg)
if cfg.system == p.WINDOWS then return "-mwindows" end
end,
},
}
function gdc.getldflags(cfg)
local flags = config.mapFlags(cfg, gdc.ldflags)
return flags
end
--
-- Return a list of decorated additional libraries directories.
--
gdc.libraryDirectories = {
architecture = {
x86 = "-L/usr/lib",
x86_64 = "-L/usr/lib64",
}
}
function gdc.getLibraryDirectories(cfg)
local flags = config.mapFlags(cfg, gdc.libraryDirectories)
-- Scan the list of linked libraries. If any are referenced with
-- paths, add those to the list of library search paths
for _, dir in ipairs(config.getlinks(cfg, "system", "directory")) do
table.insert(flags, '-Wl,-L' .. project.getrelative(cfg.project, dir))
end
return flags
end
--
-- Return the list of libraries to link, decorated with flags as needed.
--
function gdc.getlinks(cfg, systemonly)
local result = {}
local links
if not systemonly then
links = config.getlinks(cfg, "siblings", "object")
for _, link in ipairs(links) do
-- skip external project references, since I have no way
-- to know the actual output target path
if not link.project.external then
if link.kind == p.STATICLIB then
-- Don't use "-l" flag when linking static libraries; instead use
-- path/libname.a to avoid linking a shared library of the same
-- name if one is present
table.insert(result, "-Wl," .. project.getrelative(cfg.project, link.linktarget.abspath))
else
table.insert(result, "-Wl,-l" .. link.linktarget.basename)
end
end
end
end
-- The "-l" flag is fine for system libraries
links = config.getlinks(cfg, "system", "fullpath")
for _, link in ipairs(links) do
if path.isframework(link) then
table.insert(result, "-framework " .. path.getbasename(link))
elseif path.isobjectfile(link) then
table.insert(result, "-Wl," .. link)
else
table.insert(result, "-Wl,-l" .. path.getbasename(link))
end
end
return result
end
--
-- Returns makefile-specific configuration rules.
--
gdc.makesettings = {
}
function gdc.getmakesettings(cfg)
local settings = config.mapFlags(cfg, gdc.makesettings)
return table.concat(settings)
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "dc" for the D compiler, or "ar" for the static linker.
-- @return
-- The executable command name for a tool, or nil if the system's
-- default value should be used.
--
gdc.tools = {
ps3 = {
dc = "ppu-lv2-gdc",
ar = "ppu-lv2-ar",
},
}
function gdc.gettoolname(cfg, tool)
local names = gdc.tools[cfg.architecture] or gdc.tools[cfg.system] or {}
local name = names[tool]
return name or gdc[tool]
end