-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·130 lines (102 loc) · 3.01 KB
/
build.py
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
#!/usr/bin/python3
import os, sys, shutil, platform, time
import cembed
OUTPUT = "bin/juno"
EMBED_DIR = "src/embed"
TEMPSRC_DIR = ".tempsrc"
COMPILER = "gcc"
INCLUDE = [ TEMPSRC_DIR ]
SOURCE = [
"src/*.c",
"src/lib/sera/*.c",
"src/lib/vec/*.c",
"src/lib/stb_vorbis.c"
]
FLAGS = [ "-Wall", "-Wextra", "--std=gnu99", "-fno-strict-aliasing" ]
LINK = [ "m" ]
DEFINE = [ ]
EXTRA = ""
if platform.system() == "Windows":
OUTPUT += ".exe"
LINK += [ "mingw32", "luajit-5.1", "SDLmain", "SDL", "dxguid", "winmm" ]
FLAGS += [ "-mwindows" ]
if platform.system() == "Linux":
LINK += [ "luajit-5.1", "SDLmain", "SDL" ]
if platform.system() == "Darwin":
LINK += [ "luajit-5.1" ]
FLAGS += [ "-pagezero_size 10000", "-image_base 100000000" ]
FLAGS += [ os.popen("sdl-config --cflags").read().strip() ]
EXTRA += os.popen("sdl-config --libs").read().strip()
DEFINE += [ "SR_MODE_ARGB" ]
def fmt(fmt, dic):
for k in dic:
fmt = fmt.replace("{" + k + "}", str(dic[k]))
return fmt
def clearup():
if os.path.exists(TEMPSRC_DIR):
shutil.rmtree(TEMPSRC_DIR)
def main():
global FLAGS, SOURCE, LINK
print("initing...")
starttime = time.time()
# Handle args
build = "debug" if "debug" in sys.argv else "release"
verbose = "verbose" in sys.argv
# Handle build type
if build == "debug":
FLAGS += [ "-g" ]
else:
if "small" in sys.argv:
FLAGS += [ "-Os" ]
else:
FLAGS += [ "-O3" ]
# Handle "nojit" option -- compile with normal embedded Lua instead
if "nojit" in sys.argv:
LINK = [x for x in LINK if "lua" not in x]
SOURCE += ["src/lib/lua51/*.c"]
# Handle "static" option -- link dependencies statically
if "static" in sys.argv:
FLAGS += ["-static"]
print("building (" + build + ")...")
# Make sure there arn't any temp files left over from a previous build
clearup()
# Create directories
os.makedirs(TEMPSRC_DIR)
outdir = os.path.dirname(OUTPUT)
if not os.path.exists(outdir):
os.makedirs(outdir)
# Create embedded-file header files
for filename in os.listdir(EMBED_DIR):
fullname = EMBED_DIR + "/" + filename
res = cembed.process(fullname)
open(TEMPSRC_DIR + "/" + cembed.safename(fullname) + ".h", "w").write(res)
# Build
cmd = fmt(
"{compiler} -o {output} {flags} {source} {include} {link} {define} " +
"{extra}",
{
"compiler" : COMPILER,
"output" : OUTPUT,
"source" : " ".join(SOURCE),
"include" : " ".join(["-I" + x for x in INCLUDE]),
"link" : " ".join(["-l" + x for x in LINK]),
"define" : " ".join(["-D" + x for x in DEFINE]),
"flags" : " ".join(FLAGS),
"extra" : EXTRA,
})
if verbose:
print(cmd)
print("compiling...")
res = os.system(cmd)
if build == "release":
print("stripping...")
os.system("strip %s" % OUTPUT)
print("clearing up...")
clearup()
if res == 0:
print("done (%.2fs)" % (time.time() - starttime))
else:
print("done with errors")
sys.exit(res)
if __name__ == "__main__":
main()