-
Notifications
You must be signed in to change notification settings - Fork 5
/
genie.lua
256 lines (208 loc) · 5.59 KB
/
genie.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
local function add_flags(flags)
buildoptions(flags)
linkoptions(flags)
end
local function declare_project(name)
project(name)
language "C"
includedirs { "include", "deps" }
flags {
"ExtraWarnings",
"FatalWarnings"
}
configuration "linux"
buildoptions {
"-Wno-missing-field-initializers"
}
files { "src/"..name.."/**" }
end
local function declare_library(name)
declare_project(name)
language "C"
targetname("lip-"..name)
configuration "*Dynamic"
kind "SharedLib"
configuration "*Static"
kind "StaticLib"
configuration "linux"
buildoptions { "-pedantic" }
configuration {"linux", "*Dynamic"}
buildoptions { "-fvisibility=hidden" }
configuration "Debug*"
if _OPTIONS['with-coverage'] then
add_flags { "--coverage" }
end
configuration {}
defines { "LIP_" .. name:upper() .. "_BUILDING" }
files { "include/lip/"..name..".h", }
end
local function declare_app(name)
declare_project(name)
kind "ConsoleApp"
end
-- Override generator to use $ORIGIN as rpath
local ninja = premake.ninja
function ninja.cpp.linker(prj, cfg, objfiles, tool)
local all_ldflags = ninja.list(table.join(tool.getlibdirflags(cfg), tool.getldflags(cfg), cfg.linkoptions))
local lddeps = ninja.list(premake.getlinks(cfg, "siblings", "fullpath"))
local libs
local flags = {}
local has_so = false
for _, value in ipairs(premake.getlinks(cfg, "siblings", "fullpath")) do
if path.getextension(value) == ".so" then
table.insert(flags, "-l:" .. path.getbasename(value) .. ".so")
has_so = true
else
table.insert(flags, value)
end
end
libs = ninja.list(flags) .. " " .. ninja.list(tool.getlinkflags(cfg))
if has_so then
all_ldflags = all_ldflags .. " -Wl,-rpath='$$ORIGIN'"
end
local function writevars()
_p(1, "all_ldflags = " .. all_ldflags)
_p(1, "libs = " .. libs)
_p(1, "all_outputfiles = " .. table.concat(objfiles, " "))
end
if cfg.kind == "StaticLib" then
local ar_flags = ninja.list(tool.getarchiveflags(cfg, cfg, false))
_p("# link static lib")
_p("build " .. cfg:getoutputfilename() .. ": ar " .. table.concat(objfiles, " ") .. " | " .. lddeps)
_p(1, "flags = " .. ninja.list(tool.getarchiveflags(cfg, cfg, false)))
_p(1, "all_outputfiles = " .. table.concat(objfiles, " "))
elseif cfg.kind == "SharedLib" then
local output = cfg:getoutputfilename()
_p("# link shared lib")
_p("build " .. output .. ": link " .. table.concat(objfiles, " ") .. " | " .. lddeps)
writevars()
elseif (cfg.kind == "ConsoleApp") or (cfg.kind == "WindowedApp") then
_p("# link executable")
_p("build " .. cfg:getoutputfilename() .. ": link " .. table.concat(objfiles, " ") .. " | " .. lddeps)
writevars()
else
p.error("ninja action doesn't support this kind of target " .. cfg.kind)
end
end
newaction {
trigger = "gen-config.h",
description = "Generate config.h",
execute = function()
local version = os.outputof("git describe --tags"):gsub("%s+", "")
os.mkdir("include/lip/gen")
local file = io.open("include/lip/gen/config.h", "w")
file:write("#define LIP_VERSION \""..version.."\"\n")
file:close()
end
}
solution "lip"
location "build"
configurations { "ReleaseStatic", "DebugStatic", "ReleaseDynamic", "DebugDynamic" }
platforms { "native", "universal", "arm" }
debugdir "."
targetdir "bin"
startproject "repl"
newoption {
trigger = "with-config.h",
description = "Generate config.h"
}
if _OPTIONS["with-config.h"] then
prebuildcommands {
_PREMAKE_COMMAND .. " gen-config.h"
}
defines { "LIP_HAVE_CONFIG_H" }
end
flags {
"StaticRuntime",
"Symbols",
"NoEditAndContinue",
"NoNativeWChar",
"NoManifest"
}
defines { "_CRT_SECURE_NO_WARNINGS" }
configuration "linux"
newoption {
trigger = "with-coverage",
description = "Compile with coverage"
}
newoption {
trigger = "with-asan",
description = "Compile with AddressSanitizer"
}
newoption {
trigger = "with-ubsan",
description = "Compile with UndefinedBehaviorSanitizer"
}
newoption {
trigger = "with-lto",
description = "Compile with Link-time Optimization"
}
newoption {
trigger = "with-clang",
description = "Compile with Clang"
}
newoption {
trigger = "with-gprof",
description = "Compile for gprof"
}
add_flags { "-pthread" }
configuration "Release*"
flags { "OptimizeSpeed" }
configuration "*Dynamic"
defines { "LIP_DYNAMIC=1" }
configuration { "Release*", "linux" }
if _OPTIONS["with-lto"] then
add_flags { add_flags("-flto") }
end
configuration "linux"
if _OPTIONS["with-asan"] then
add_flags { "-fsanitize=address", "-fPIC" }
end
if _OPTIONS["with-ubsan"] then
add_flags {
"-fsanitize=undefined",
"-fno-sanitize-recover=undefined"
}
end
if _OPTIONS["with-gprof"] then
add_flags { "-pg" }
end
if _OPTIONS["with-clang"] then
premake.gcc.cc = "clang"
premake.gcc.cxx = "clang++"
premake.gcc.llvm = true
end
declare_library "core"
files { "include/lip/core/*.h" }
declare_library "std"
links { "core" }
declare_library "dbg"
links { "core", "cmp" }
configuration "linux"
buildoptions { "-Wno-unused-function" }
linkoptions { "-Wl,--exclude-libs=ALL" }
declare_app "repl"
targetname "lip"
links { "core", "std", "dbg", "linenoise" }
configuration { "linux", "*Static" }
links { "cmp" }
declare_app "compiler"
targetname "lipc"
links { "core", "std" }
project "cmp"
language "C"
kind "StaticLib"
files {
"deps/cmp/cmp.h",
"deps/cmp/cmp.c",
}
project "linenoise"
language "C"
kind "StaticLib"
files {
"deps/linenoise/**.h",
"deps/linenoise/**.c"
}
excludes {
"deps/linenoise/exaple.c"
}