forked from TurkeyMan/premake-emscripten
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemscripten_emcc.lua
296 lines (232 loc) · 6.39 KB
/
emscripten_emcc.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
--
-- emscripten_vstudio.lua
-- Emscripten integration for vstudio.
-- Copyright (c) 2012-2015 Manu Evans and the Premake project
--
local p = premake
local emscripten = premake.modules.emscripten
emscripten.emcc = {}
premake.tools.emcc = emscripten.emcc
local emcc = emscripten.emcc
local clang = premake.tools.clang
local config = premake.config
-- Patch Clang toolset architecture specific options.
clang.shared.architecture[p.WASM32] = clang.shared.architecture[p.X86]
clang.shared.architecture[p.WASM64] = clang.shared.architecture[p.X86_64]
clang.ldflags[p.WASM32] = clang.ldflags[p.X86]
clang.ldflags[p.WASM64] = clang.ldflags[p.X86_64]
--
-- Build a list of flags for the C preprocessor corresponding to the
-- settings in a particular project configuration.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C preprocessor flags.
--
function emcc.getcppflags(cfg)
-- Just pass through to Clang for now
local flags = clang.getcppflags(cfg)
return flags
end
--
-- Build a list of C compiler flags corresponding to the settings in
-- a particular project configuration. These flags are exclusive
-- of the C++ compiler flags, there is no overlap.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C compiler flags.
--
function emcc.getcflags(cfg)
-- Just pass through to Clang for now
local flags = clang.getcflags(cfg)
return flags
end
--
-- Build a list of C++ compiler flags corresponding to the settings
-- in a particular project configuration. These flags are exclusive
-- of the C compiler flags, there is no overlap.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of C++ compiler flags.
--
function emcc.getcxxflags(cfg)
-- Just pass through to Clang for now
local flags = clang.getcxxflags(cfg)
return flags
end
--
-- Returns a list of defined preprocessor symbols, decorated for
-- the compiler command line.
--
-- @param defines
-- An array of preprocessor symbols to define; as an array of
-- string values.
-- @return
-- An array of symbols with the appropriate flag decorations.
--
function emcc.getdefines(defines)
-- Just pass through to Clang for now
local flags = clang.getdefines(defines)
return flags
end
function emcc.getundefines(undefines)
-- Just pass through to Clang for now
local flags = clang.getundefines(undefines)
return flags
end
--
-- Returns a list of forced include files, decorated for the compiler
-- command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of force include files with the appropriate flags.
--
function emcc.getforceincludes(cfg)
-- Just pass through to Clang for now
local flags = clang.getforceincludes(cfg)
return flags
end
--
-- Returns a list of include file search directories, decorated for
-- the compiler command line.
--
-- @param cfg
-- The project configuration.
-- @param dirs
-- An array of include file search directories; as an array of
-- string values.
-- @return
-- An array of symbols with the appropriate flag decorations.
--
function emcc.getincludedirs(cfg, dirs)
-- Just pass through to Clang for now
local flags = clang.getincludedirs(cfg, dirs)
return flags
end
emcc.getrunpathdirs = clang.getrunpathdirs
--
-- Build a list of linker flags corresponding to the settings in
-- a particular project configuration.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of linker flags.
--
emcc.ldflags = {
flags = {
NoClosureCompiler = "", -- TODO...
NoMinifyJavaScript = "",
IgnoreDynamicLinking = "",
},
kind = {
HTMLPage = function(cfg)
-- ???
end,
SharedLib = function(cfg)
local r = { iif(cfg.system == premake.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 == premake.WINDOWS then return "-mwindows" end
end,
},
linkeroptimize = { -- TODO...
Off = "",
Simple = "",
On = "",
Unsafe = ""
},
typedarrays = {
None = "",
Parallel = "",
Shared = ""
}
}
function emcc.getldflags(cfg)
local flags = config.mapFlags(cfg, emcc.ldflags)
return flags
end
--
-- Build a list of additional library directories for a particular
-- project configuration, decorated for the tool command line.
--
-- @param cfg
-- The project configuration.
-- @return
-- An array of decorated additional library directories.
--
function emcc.getLibraryDirectories(cfg)
-- Just pass through to Clang for now
local flags = clang.getLibraryDirectories(cfg)
return flags
end
--
-- Build a list of libraries to be linked for a particular project
-- configuration, decorated for the linker command line.
--
-- @param cfg
-- The project configuration.
-- @param systemOnly
-- Boolean flag indicating whether to link only system libraries,
-- or system libraries and sibling projects as well.
-- @return
-- A list of libraries to link, decorated for the linker.
--
function emcc.getlinks(cfg, systemOnly)
-- Just pass through to Clang for now
local flags = clang.getlinks(cfg, systemOnly)
return flags
end
--
-- Return a list of makefile-specific configuration rules. This will
-- be going away when I get a chance to overhaul these adapters.
--
-- @param cfg
-- The project configuration.
-- @return
-- A list of additional makefile rules.
--
function emcc.getmakesettings(cfg)
-- Just pass through to Clang for now
local flags = clang.getmakesettings(cfg)
return flags
end
--
-- Retrieves the executable command name for a tool, based on the
-- provided configuration and the operating environment. I will
-- be moving these into global configuration blocks when I get
-- the chance.
--
-- @param cfg
-- The configuration to query.
-- @param tool
-- The tool to fetch, one of "cc" for the C compiler, "cxx" for
-- the C++ 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.
--
emcc.tools = {
cc = "emcc",
cxx = "em++",
ar = "emar"
}
function emcc.gettoolname(cfg, tool)
if _ACTION == "gmake" or _ACTION == "gmake2" then
if cfg.emccpath ~= nil then
return path.join(cfg.emccpath, emcc.tools[tool])
end
end
return emcc.tools[tool]
end