summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/genie/src/tools/gcc.lua
blob: 44b2edb2a0f307889d5945b207169562ed5df1b6 (plain) (blame)
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
--
-- gcc.lua
-- Provides GCC-specific configuration strings.
-- Copyright (c) 2002-2011 Jason Perkins and the Premake project
--


	premake.gcc = { }


--
-- Set default tools
--

	premake.gcc.cc     = "gcc"
	premake.gcc.cxx    = "g++"
	premake.gcc.ar     = "ar"
	premake.gcc.rc     = "windres"
	premake.gcc.llvm   = false


--
-- Translation of Premake flags into GCC flags
--

	local cflags =
	{
		EnableSSE        = "-msse",
		EnableSSE2       = "-msse2",
		EnableAVX        = "-mavx",
		EnableAVX2       = "-mavx2",
		PedanticWarnings = "-Wall -Wextra -pedantic",
		ExtraWarnings    = "-Wall -Wextra",
		FatalWarnings    = "-Werror",
		FloatFast        = "-ffast-math",
		FloatStrict      = "-ffloat-store",
		NoFramePointer   = "-fomit-frame-pointer",
		Optimize         = "-O2",
		OptimizeSize     = "-Os",
		OptimizeSpeed    = "-O3",
		Symbols          = "-g",
	}

	local cxxflags =
	{
		Cpp11        = "-std=c++11",
		Cpp14        = "-std=c++14",
		Cpp17        = "-std=c++17",
		CppLatest    = "-std=c++2a",
		NoExceptions = "-fno-exceptions",
		NoRTTI       = "-fno-rtti",
		UnsignedChar = "-funsigned-char",
	}

	local objcflags =
	{
		ObjcARC = "-fobjc-arc",
	}

--
-- Map platforms to flags
--

	premake.gcc.platforms =
	{
		Native = {
			cppflags = "-MMD -MP",
		},
		x32 = {
			cppflags = "-MMD -MP",
			flags    = "-m32",
		},
		x64 = {
			cppflags = "-MMD -MP",
			flags    = "-m64",
		},
		Universal = {
			ar       = "libtool",
			cppflags = "-MMD -MP",
			flags    = "-arch i386 -arch x86_64 -arch ppc -arch ppc64",
		},
		Universal32 = {
			ar       = "libtool",
			cppflags = "-MMD -MP",
			flags    = "-arch i386 -arch ppc",
		},
		Universal64 = {
			ar       = "libtool",
			cppflags = "-MMD -MP",
			flags    = "-arch x86_64 -arch ppc64",
		},
		PS3 = {
			cc         = "ppu-lv2-g++",
			cxx        = "ppu-lv2-g++",
			ar         = "ppu-lv2-ar",
			cppflags   = "-MMD -MP",
		},
		WiiDev = {
			cppflags    = "-MMD -MP -I$(LIBOGC_INC) $(MACHDEP)",
			ldflags		= "-L$(LIBOGC_LIB) $(MACHDEP)",
			cfgsettings = [[
  ifeq ($(strip $(DEVKITPPC)),)
    $(error "DEVKITPPC environment variable is not set")'
  endif
  include $(DEVKITPPC)/wii_rules']],
		},
		Orbis = {
			cc         = "orbis-clang",
			cxx        = "orbis-clang++",
			ar         = "orbis-ar",
			cppflags   = "-MMD -MP",
		},
		Emscripten = {
			cc         = "$(EMSCRIPTEN)/emcc",
			cxx        = "$(EMSCRIPTEN)/em++",
			ar         = "$(EMSCRIPTEN)/emar",
			cppflags   = "-MMD -MP",
		}
	}

	local platforms = premake.gcc.platforms


--
-- Returns a list of compiler flags, based on the supplied configuration.
--

	function premake.gcc.getcppflags(cfg)
		local flags = { }
		table.insert(flags, platforms[cfg.platform].cppflags)

		-- We want the -MP flag for dependency generation (creates phony rules
		-- for headers, prevents make errors if file is later deleted)
		if flags[1]:startswith("-MMD") then
			table.insert(flags, "-MP")
		end

		return flags
	end


	function premake.gcc.getcflags(cfg)
		local result = table.translate(cfg.flags, cflags)
		table.insert(result, platforms[cfg.platform].flags)
		if cfg.system ~= "windows" and cfg.kind == "SharedLib" then
			table.insert(result, "-fPIC")
		end
		return result
	end


	function premake.gcc.getcxxflags(cfg)
		local result = table.translate(cfg.flags, cxxflags)
		return result
	end


	function premake.gcc.getobjcflags(cfg)
		return table.translate(cfg.flags, objcflags)
	end


--
-- Returns a list of linker flags, based on the supplied configuration.
--

	function premake.gcc.getldflags(cfg)
		local result = { }

		-- OS X has a bug, see http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html
		if not cfg.flags.Symbols then
			if cfg.system == "macosx" then
-- Issue#80
-- https://github.com/bkaradzic/genie/issues/80#issuecomment-100664007
--				table.insert(result, "-Wl,-x")
			else
				table.insert(result, "-s")
			end
		end

		if cfg.kind == "Bundle" then
			table.insert(result, "-bundle")
		end

		if cfg.kind == "SharedLib" then
			if cfg.system == "macosx" then
				table.insert(result, "-dynamiclib")
			else
				table.insert(result, "-shared")
			end

			if cfg.system == "windows" and not cfg.flags.NoImportLib then
				table.insert(result, '-Wl,--out-implib="' .. cfg.linktarget.fullpath .. '"')
			end
		end

		if cfg.kind == "WindowedApp" and cfg.system == "windows" then
			table.insert(result, "-mwindows")
		end

		local platform = platforms[cfg.platform]
		table.insert(result, platform.flags)
		table.insert(result, platform.ldflags)

		return result
	end


--
-- Return a list of library search paths. Technically part of LDFLAGS but need to
-- be separated because of the way Visual Studio calls GCC for the PS3. See bug
-- #1729227 for background on why library paths must be split.
--

	function premake.gcc.getlibdirflags(cfg)
		local result = { }
		for _, value in ipairs(premake.getlinks(cfg, "all", "directory")) do
			table.insert(result, '-L\"' .. value .. '\"')
		end
		return result
	end

--
-- Given a path, return true if it's considered a real path
-- to a library file, false otherwise.
--  p: path
--
	function premake.gcc.islibfile(p)
		if path.getextension(p) == ".a" then
			return true
		end
		return false
	end

--
-- Returns a list of project-relative paths to external library files.
-- This function examines the linker flags and returns any that seem to be
-- a real path to a library file (e.g. "path/to/a/library.a", but not "GL").
-- Useful for adding to targets to trigger a relink when an external static
-- library gets updated.
--  cfg: configuration
--
	function premake.gcc.getlibfiles(cfg)
		local result = {}
		for _, value in ipairs(premake.getlinks(cfg, "system", "fullpath")) do
			if premake.gcc.islibfile(value) then
				table.insert(result, _MAKE.esc(value))
			end
		end
		return result
	end

--
-- This is poorly named: returns a list of linker flags for external
-- (i.e. system, or non-sibling) libraries. See bug #1729227 for
-- background on why the path must be split.
--

	function premake.gcc.getlinkflags(cfg)
		local result = {}
		for _, value in ipairs(premake.getlinks(cfg, "system", "fullpath")) do
			if premake.gcc.islibfile(value) then
				value = path.rebase(value, cfg.project.location, cfg.location)
				table.insert(result, _MAKE.esc(value))
			elseif path.getextension(value) == ".framework" then
				table.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value)))
			else
				table.insert(result, '-l' .. _MAKE.esc(path.getname(value)))
			end
		end
		return result
	end

--
-- Get the arguments for whole-archive linking.
--

	function premake.gcc.wholearchive(lib)
		if premake.gcc.llvm then
			return {"-force_load", lib}
		else
			return {"-Wl,--whole-archive", lib, "-Wl,--no-whole-archive"}
		end
	end

--
-- Get flags for passing to AR before the target is appended to the commandline
--  prj: project
--  cfg: configuration
--  ndx: true if the final step of a split archive
--

	function premake.gcc.getarchiveflags(prj, cfg, ndx)
		local result = {}
		if cfg.platform:startswith("Universal") then
				if prj.options.ArchiveSplit then
					error("gcc tool 'Universal*' platforms do not support split archives")
				end
				table.insert(result, '-o')
		else
			if (not prj.options.ArchiveSplit) then
				if premake.gcc.llvm then
					table.insert(result, 'rcs')
				else
					table.insert(result, '-rcs')
				end
			else
				if premake.gcc.llvm then
					if (not ndx) then
						table.insert(result, 'qc')
					else
						table.insert(result, 'cs')
					end
				else
					if (not ndx) then
						table.insert(result, '-qc')
					else
						table.insert(result, '-cs')
					end
				end
			end
		end
		return result
	end


--
-- Decorate defines for the GCC command line.
--

	function premake.gcc.getdefines(defines)
		local result = { }
		for _,def in ipairs(defines) do
			table.insert(result, "-D" .. def)
		end
		return result
	end

--
-- Decorate include file search paths for the GCC command line.
--

	function premake.gcc.getincludedirs(includedirs)
		local result = { }
		for _,dir in ipairs(includedirs) do
			table.insert(result, "-I\"" .. dir .. "\"")
		end
		return result
	end

--
-- Decorate user include file search paths for the GCC command line.
--

	function premake.gcc.getquoteincludedirs(includedirs)
		local result = { }
		for _,dir in ipairs(includedirs) do
			table.insert(result, "-iquote \"" .. dir .. "\"")
		end
		return result
	end

--
-- Decorate system include file search paths for the GCC command line.
--

	function premake.gcc.getsystemincludedirs(includedirs)
		local result = { }
		for _,dir in ipairs(includedirs) do
			table.insert(result, "-isystem \"" .. dir .. "\"")
		end
		return result
	end

--
-- Return platform specific project and configuration level
-- makesettings blocks.
--

	function premake.gcc.getcfgsettings(cfg)
		return platforms[cfg.platform].cfgsettings
	end