This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
build.py
executable file
·79 lines (57 loc) · 2.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
#!/usr/bin/python2.7
import os, sys, shutil, re, textwrap
COMPILER = "i586-pc-msdosdjgpp-gcc"
SRC_DIR = "src"
BIN_DIR = "bin"
BIN_NAME = "love.exe"
EMBED_DIR = "src/embed"
TEMPSRC_DIR = ".tempsrc"
CFLAGS = [ "-O2", "-Wall", "-s", "-Wno-misleading-indentation" ]
DLIBS = [ "m" ]
DEFINES = [ "DMT_ABORT_NULL", "LUA_COMPAT_ALL" ]
INCLUDES = [ "src", TEMPSRC_DIR ]
def fmt(fmt, var):
for k in var:
fmt = fmt.replace("{%s}" % str(k), var[k])
return fmt
def listdir(path):
return [os.path.join(dp, f) for dp, dn, fn in os.walk(path) for f in fn]
def make_c_include(name, data):
name = re.sub("[^a-z0-9]", "_", name.lower())
res = "static const char " + name + "[] = {"
for c in data:
res += str(ord(c)) + ", "
res = res.rstrip(", ") + "};"
return name, textwrap.fill(res, width=79)
def main():
os.chdir(sys.path[0])
if not os.path.exists(BIN_DIR):
os.makedirs(BIN_DIR)
if not os.path.exists(TEMPSRC_DIR):
os.makedirs(TEMPSRC_DIR)
embedded_files = listdir(EMBED_DIR)
for filename in embedded_files:
name = os.path.basename(filename)
name, text = make_c_include(name, open(filename).read())
open("%s/%s.h" % (TEMPSRC_DIR, name), "wb").write(text)
cfiles = filter(lambda x:x.endswith((".c", ".C")), listdir(SRC_DIR))
cmd = fmt(
"{compiler} {flags} {defines} {includes} -o {outfile} {srcfiles} {libs} {argv}",
{
"compiler" : COMPILER,
"flags" : " ".join(CFLAGS),
"defines" : " ".join(map(lambda x: "-D " + x, DEFINES)),
"includes" : " ".join(map(lambda x: "-I " + x, INCLUDES)),
"outfile" : BIN_DIR + "/" + BIN_NAME,
"srcfiles" : " ".join(cfiles),
"libs" : " ".join(map(lambda x: "-l" + x, DLIBS)),
"argv" : " ".join(sys.argv[1:])
})
print "compiling..."
res = os.system(cmd)
print "deleting temporary files..."
if os.path.exists(TEMPSRC_DIR):
shutil.rmtree(TEMPSRC_DIR)
print "done" + (" with errors" if res else "")
if __name__ == "__main__":
main()