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
|
--
-- gcc.lua
-- Provides GCC-specific configuration strings.
-- Copyright (c) 2002-2008 Jason Perkins and the Premake project
--
--
-- I don't know if this is the right breakdown or API to individual compilers
-- yet so treat it all as experimental. I won't know until I get the change
-- to implement a few different compilers across different toolset actions.
--
premake.tools.gcc = { }
premake.tools.gcc.cflags =
{
ExtraWarnings = "-Wall",
FatalWarning = "-Werror",
NoFramePointer = "-fomit-frame-pointer",
Optimize = "-O2",
OptimizeSize = "-Os",
OptimizeSpeed = "-O3",
Symbols = "-g",
}
premake.tools.gcc.cxxflags =
{
NoExceptions = "--no-exceptions",
NoRTTI = "--no-rtti",
}
function premake.tools.gcc.make_defines(cfg)
return table.implode(cfg.defines, '-D "', '"', ' ')
end
function premake.tools.gcc.make_includes(cfg)
return table.implode(cfg.incdirs, '-I "', '"', ' ')
end
function premake.tools.gcc.make_cppflags(cfg)
-- if $(ARCH) contains multiple targets, then disable the incompatible automatic
-- dependency generation. This allows building universal binaries on MacOSX, sorta.
return "$(if $(word 2, $(ARCH)), , -MMD)"
end
function premake.tools.gcc.make_cflags(cfg)
local flags = table.translate(cfg.flags, premake.tools.gcc.cflags)
if (cfg.kind == "SharedLib" and not os.is("windows")) then
table.insert(flags, "-fPIC")
end
return table.concat(flags, " ")
end
function premake.tools.gcc.make_cxxflags(cfg)
local flags = table.translate(cfg.flags, premake.tools.gcc.cxxflags)
return table.concat(flags, " ")
end
function premake.tools.gcc.make_ldflags(cfg)
local flags = { }
if (cfg.kind == "SharedLib") then
if (not os.is("macosx")) then
table.insert(flags, "-shared")
end
-- create import library for DLLs under Windows
if (os.is("windows") and not table.contains(cfg.flags, "NoImportLib")) then
table.insert(flags, '-Wl,--out-implib="' .. premake.project.gettargetfile(cfg, "implib", "StaticLib", "linux") .. '"')
end
end
if (os.is("windows") and cfg.kind == "WindowedExe") then
table.insert(flags, "-mwindows")
end
-- OS X has a bug, see http://lists.apple.com/archives/Darwin-dev/2006/Sep/msg00084.html
if (not table.contains(cfg.flags, "Symbols")) then
if (os.is("macosx")) then
table.insert(flags, "-Wl,-x")
else
table.insert(flags, "-s")
end
end
if (os.is("macosx") and table.contains(flags, "Dylib")) then
table.insert(flags, "-dynamiclib -flat_namespace")
end
-- need to split path from libraries to avoid runtime errors (see bug #1729227)
local dirs = { }
local names = { }
for _, link in ipairs(premake.project.getlibraries(cfg, cfg.links)) do
local dir = path.getdirectory(link)
local name = path.getbasename(link)
if (dir ~= "" and not table.contains(cfg.libdirs, dir) and not table.contains(dirs, dir)) then
table.insert(dirs, dir)
end
table.insert(names, name)
end
return table.concat(flags, " ") .. table.implode(cfg.libdirs, ' -L "', '"').. table.implode(dirs, ' -L "', '"') .. table.implode(names, ' -l "', '"')
end
function premake.tools.gcc.make_file_rule(file)
if (path.iscfile(file)) then
return "$(CC) $(CFLAGS) -o $@ -c $<"
else
return "$(CXX) $(CXXFLAGS) -o $@ -c $<"
end
end
|