forked from cornell-cup/cs-r2bot2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
40 lines (32 loc) · 1.24 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
import glob, os, platform, subprocess
from os import path
CC = "g++"
CFLAGS = ["-std=c++11"]
SRC_FOLDER = "R2Bot/src" # Source files
INCLUDE_FOLDER = "R2Bot/include" # Header files
OBJ_FOLDER = "obj" # Object code
BIN_FOLDER = "bin" # Compiled executable libraries and binaries
BINARY_NAME = "R2Bot." + ("exe" if platform.system() is "Windows" else "x")
if __name__ == "__main__":
# Folders
if not path.isdir(OBJ_FOLDER):
os.mkdir(OBJ_FOLDER)
if not path.isdir(BIN_FOLDER):
os.mkdir(BIN_FOLDER)
# Find all source files
sources = glob.glob("{src}/*.cpp".format(src=SRC_FOLDER))
# Compile each to objects
# TODO Parallelize with multiprocessing
# TODO Don't recompile unchanged files
objects = []
for s in sources:
o = path.join(OBJ_FOLDER, path.basename(s)[:-4] + ".o")
objects.append(o)
args = [CC] + CFLAGS + ["-c"] + ["-I", INCLUDE_FOLDER] + [s] + ["-o", o]
print("Executing {}".format(args))
subprocess.check_output(args)
# Build the binary
args = [CC] + CFLAGS + ["-I", INCLUDE_FOLDER] + objects \
+ ["-o", BIN_FOLDER + "/" + BINARY_NAME]
print("Executing {}".format(args))
subprocess.check_output(args)