made build script python3 copatible
This commit is contained in:
91
build.py
91
build.py
@@ -1,27 +1,27 @@
|
|||||||
#!/usr/bin/python2.7
|
#!/usr/bin/python
|
||||||
import os, sys, shutil, re, textwrap
|
import os, sys, shutil, re, textwrap
|
||||||
|
|
||||||
COMPILER = "i586-pc-msdosdjgpp-gcc"
|
COMPILER = "i586-pc-msdosdjgpp-gcc"
|
||||||
SRC_DIR = "src"
|
SRC_DIR = "src"
|
||||||
BIN_DIR = "bin"
|
BIN_DIR = "bin"
|
||||||
BIN_NAME = "love.exe"
|
BIN_NAME = "love.exe"
|
||||||
EMBED_DIR = "src/embed"
|
EMBED_DIR = "src/embed"
|
||||||
TEMPSRC_DIR = ".tempsrc"
|
TEMPSRC_DIR = ".tempsrc"
|
||||||
|
|
||||||
CFLAGS = [ "-O2", "-Wall", "-s", "-Wno-misleading-indentation" ]
|
CFLAGS = ["-O2", "-Wall", "-s", "-Wno-misleading-indentation"]
|
||||||
DLIBS = [ "m" ]
|
DLIBS = ["m"]
|
||||||
DEFINES = [ "DMT_ABORT_NULL", "LUA_COMPAT_ALL" ]
|
DEFINES = ["DMT_ABORT_NULL", "LUA_COMPAT_ALL"]
|
||||||
INCLUDES = [ "src", TEMPSRC_DIR ]
|
INCLUDES = ["src", TEMPSRC_DIR]
|
||||||
|
|
||||||
|
|
||||||
def fmt(fmt, var):
|
def fmt(fmt, var):
|
||||||
for k in var:
|
for k in var:
|
||||||
fmt = fmt.replace("{%s}" % str(k), var[k])
|
fmt = fmt.replace("{%s}" % str(k), var[k])
|
||||||
return fmt
|
return fmt
|
||||||
|
|
||||||
|
|
||||||
def listdir(path):
|
def listdir(path):
|
||||||
return [os.path.join(dp, f) for dp, dn, fn in os.walk(path) for f in fn]
|
return [os.path.join(dp, f) for dp, dn, fn in os.walk(path) for f in fn]
|
||||||
|
|
||||||
|
|
||||||
def make_c_include(name, data):
|
def make_c_include(name, data):
|
||||||
@@ -34,46 +34,47 @@ def make_c_include(name, data):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
os.chdir(sys.path[0])
|
os.chdir(sys.path[0])
|
||||||
|
|
||||||
if not os.path.exists(BIN_DIR):
|
if not os.path.exists(BIN_DIR):
|
||||||
os.makedirs(BIN_DIR)
|
os.makedirs(BIN_DIR)
|
||||||
|
|
||||||
if not os.path.exists(TEMPSRC_DIR):
|
if not os.path.exists(TEMPSRC_DIR):
|
||||||
os.makedirs(TEMPSRC_DIR)
|
os.makedirs(TEMPSRC_DIR)
|
||||||
|
|
||||||
embedded_files = listdir(EMBED_DIR)
|
embedded_files = listdir(EMBED_DIR)
|
||||||
|
|
||||||
for filename in embedded_files:
|
for filename in embedded_files:
|
||||||
name = os.path.basename(filename)
|
name = os.path.basename(filename)
|
||||||
name, text = make_c_include(name, open(filename).read())
|
name, text = make_c_include(name, open(filename).read())
|
||||||
open("%s/%s.h" % (TEMPSRC_DIR, name), "wb").write(text)
|
open("%s/%s.h" % (TEMPSRC_DIR, name), "wb").write(text)
|
||||||
|
|
||||||
cfiles = filter(lambda x:x.endswith((".c", ".C")), listdir(SRC_DIR))
|
cfiles = filter(lambda x: x.endswith((".c", ".C")), listdir(SRC_DIR))
|
||||||
|
|
||||||
cmd = fmt(
|
cmd = fmt(
|
||||||
"{compiler} {flags} {defines} {includes} -o {outfile} {srcfiles} {libs} {argv}",
|
"{compiler} {flags} {defines} {includes} -o {outfile} {srcfiles} {libs} {argv}",
|
||||||
{
|
{
|
||||||
"compiler" : COMPILER,
|
"compiler": COMPILER,
|
||||||
"flags" : " ".join(CFLAGS),
|
"flags": " ".join(CFLAGS),
|
||||||
"defines" : " ".join(map(lambda x: "-D " + x, DEFINES)),
|
"defines": " ".join(map(lambda x: "-D " + x, DEFINES)),
|
||||||
"includes" : " ".join(map(lambda x: "-I " + x, INCLUDES)),
|
"includes": " ".join(map(lambda x: "-I " + x, INCLUDES)),
|
||||||
"outfile" : BIN_DIR + "/" + BIN_NAME,
|
"outfile": BIN_DIR + "/" + BIN_NAME,
|
||||||
"srcfiles" : " ".join(cfiles),
|
"srcfiles": " ".join(cfiles),
|
||||||
"libs" : " ".join(map(lambda x: "-l" + x, DLIBS)),
|
"libs": " ".join(map(lambda x: "-l" + x, DLIBS)),
|
||||||
"argv" : " ".join(sys.argv[1:])
|
"argv": " ".join(sys.argv[1:]),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
print "compiling..."
|
print("compiling...")
|
||||||
res = os.system(cmd)
|
print(" {}".format(cmd))
|
||||||
|
res = os.system(cmd)
|
||||||
|
|
||||||
print "deleting temporary files..."
|
print("deleting temporary files...")
|
||||||
if os.path.exists(TEMPSRC_DIR):
|
if os.path.exists(TEMPSRC_DIR):
|
||||||
shutil.rmtree(TEMPSRC_DIR)
|
shutil.rmtree(TEMPSRC_DIR)
|
||||||
|
|
||||||
print "done" + (" with errors" if res else "")
|
|
||||||
|
|
||||||
|
print("done" + (" with errors" if res else ""))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user