-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpremake5.lua
130 lines (114 loc) · 3.81 KB
/
premake5.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
workspace "kobalt"
configurations { "debug", "release", "debug-vg" }
include "extern/abl/abl.lua"
if os.host() == "windows" then
defines { "WINDOWS=1", "_CRT_SECURE_NO_WARNINGS", "_CRT_NONSTDC_NO_WARNINGS" }
else
defines { "UNIX=1", "_POSIX_C_SOURCE=200809L" }
end
filter { "configurations:release", "toolset:clang or gcc" }
buildoptions { "-Wall -Wextra" }
cdialect "C99"
filter { "configurations:debug", "toolset:clang or gcc" }
buildoptions { "-pedantic" }
if os.host() == "linux" then
filter { "configurations:debug", "toolset:clang" }
buildoptions { "-funwind-tables", "-fasynchronous-unwind-tables", "-fno-omit-frame-pointer", "-fno-optimize-sibling-calls" }
linkoptions { "-fsanitize=address,leak,undefined", "-Wl,--export-dynamic" }
defines { "DEBUG_SAN=1" }
filter { "configurations:debug or debug-vg", "toolset:clang or gcc" }
buildoptions { "-ggdb3" }
end
filter "configurations:debug or debug-vg"
defines { "DEBUG=1" }
filter "configurations:release"
defines { "DEBUG=0" }
optimize "On"
project "kl"
kind "StaticLib"
language "C"
includedirs { "include", "extern/abl/include" }
files { "include/**.h", "lib/**.h", "lib/**.c" }
project "kobalt"
kind "ConsoleApp"
language "C"
includedirs { "include", "extern/linenoise", "extern/sha-2", "extern/basenc", "extern/abl/include" }
files { "src/kobalt/**.h", "src/kobalt/**.c", "extern/linenoise/*.c", "extern/sha-2/*.c", "extern/basenc/*.c" }
links { "kl", "abl" }
newoption {
trigger = "prefix",
value = "/usr/local",
description = "Install prefix",
default = "/usr/local",
}
function install_action (prefix)
if os.host() == "windows" then
exe = "kobalt.exe"
else
exe = "kobalt"
end
bindir = prefix .. "/bin/"
libdir = prefix .. "/lib/"
os.mkdir(bindir)
os.mkdir(libdir)
assert(os.copyfile("bin/release/" .. exe, bindir .. exe))
if os.host() == "windows" then
assert(os.copyfile("bin/release/kl.lib", libdir .. "kl.lib"))
else
assert(os.copyfile("bin/release/libkl.a", libdir .. "libkl.a"))
end
end
newaction {
trigger = "install",
description = "Install kobalt on unix",
execute = function ()
install_action(_OPTIONS["prefix"])
end
}
function os.capture(cmd)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
newaction {
trigger = "release",
description = "Create release archive",
execute = function ()
if os.host() == "macosx" then
slug = "kobalt-macos"
else
slug = "kobalt-" .. os.host()
end
reldir = "tmp/" .. slug
install_action(reldir)
os.mkdir("dist")
os.chdir(reldir)
if os.host() == "windows" then
tarcmd = "tar.exe -a -c -f ../../dist/" .. slug .. ".zip " .. "bin lib"
else
tarcmd = "tar czvf ../../dist/" .. slug .. ".tar.gz " .. "bin lib"
end
print(tarcmd)
os.execute(tarcmd)
end
}
newaction {
trigger = "gen-compile-flags",
description = "Generate compile_flags.txt for clangd",
execute = function ()
flags = io.open("compile_flags.txt", "w")
flags:write("-Wall\n")
flags:write("-Wextra\n")
flags:write("-Iextern/linenoise\n")
flags:write("-Iextern/levenshtein\n")
flags:write("-Iextern/sha-2\n")
flags:write("-Iextern/base85\n")
flags:write("-Iextern/basenc\n")
flags:write("-Iinclude\n")
flags:close()
end
}