-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·70 lines (55 loc) · 1.68 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
import os
import os.path
import sys
sources = ["Move.cpp","Piece.cpp","Board.cpp","Game.cpp"]
output = "shatranj"
include_path = "./"
print_only = False
def NeedToCompile(sourcefile,objectfile):
# check if object file exists
if(os.path.isfile(objectfile)):
# check its time signature
sourcetime = os.path.getmtime(sourcefile)
objecttime = os.path.getmtime(objectfile)
# leave a tolerance of 10 seconds to avoid any inaccurate time reporting
if(sourcetime < (objecttime - 10)):
return False
return True
def Execute(command):
if(print_only):
print(command)
else:
print(command)
os.system(command)
def GetObjectName(sourcename,windows_build):
object_extension = ".o"
if(windows_build): object_extension = ".obj"
objectname = sourcename[0:sourcename.rfind('.')] + object_extension
return objectname
def CompileSource(sourcefile,windows_build):
compiler = "g++"
if(windows_build): compiler = "mpicxx"
if(NeedToCompile(sourcefile,GetObjectName(sourcefile,windows_build))):
compile_string = compiler + " -I" + include_path + " -c " + sourcefile
Execute(compile_string)
return True
return False
def CompileSources(windows_build):
for source in sources:
CompileSource(source,windows_build)
def Compile(windows_build):
CompileSources(windows_build)
def Link(windows_build):
compiler = "g++"
if(windows_build): compiler = "mpicxx"
link_command = compiler + " "
for source in sources:
link_command = link_command + GetObjectName(source,windows_build) + " "
link_command = link_command + "-o " + output
Execute(link_command)
windows_build = False
if(len(sys.argv) > 1):
if(sys.argv[1] == "-w"):
windows_build = True
Compile(windows_build)
Link(windows_build)