-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
executable file
·190 lines (169 loc) · 4.93 KB
/
make.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
# -------------------------------------------------------------------
# Helper script to manage compiling and running OpenEngine.
# For usage information run ./make.py help
# -------------------------------------------------------------------
# Copyright (C) 2007 OpenEngine.dk (See AUTHORS)
#
# This program is free software; It is covered by the GNU General
# Public License version 2 or any later version.
# See the GNU General Public License for more details (see LICENSE).
#--------------------------------------------------------------------
import string, sys, subprocess, os, os.path as path
# import the helpers from oelib.py
from oelib import printCommands, error, execute, system, ExecError, cores
build_dir = path.join(os.getcwd(), "build")
deps_dir = path.join(os.getcwd(), "deps-build")
def commands():
return ((build, "all"),
(test, "test"),
(testv, "testv"),
(rebuild, "rebuild"),
(clean, "clean"),
(targets, "targets"),
(doc, "doc"),
(etags, "etags"),
(help, "help"),
(deps, "deps"),
(cleandeps, "deps-clean"),
(make, None))
def build():
"""
all (default) -- set up the build system and compile the source
"""
make("all")
def rebuild():
"""
rebuild -- remove the build system and rebuild from source
"""
clean(False)
build()
def clean(delroot=True):
"""
clean -- delete all build files
"""
if not path.isdir(build_dir):
return
for root, dirs, files in os.walk(build_dir, topdown=False):
for name in files:
os.remove(path.join(root, name))
for name in dirs:
os.rmdir(path.join(root, name))
if delroot:
os.rmdir(build_dir)
def targets():
"""
targets -- list of make targets
"""
make("help")
def doc():
"""
doc -- build the doxygen documentation (requires doxygen)
"""
make("doc")
def test():
"""
test -- run all tests added to the build system
"""
make("test")
def testv():
"""
testv -- verbosely run all tests (better error output)
"""
make('test ARGS="-V"')
def etags():
"""
etags -- generate build/TAGS file for emacs (*nix only)
"""
prepare()
execute("find src extensions projects \
\\( -name *.h -o -name *.cpp \\) \
-not -path */_darcs/* \
| xargs etags -o %s/TAGS"
% (build_dir))
def help():
"""
help -- this message
"""
print("Small script to help compiling and running OpenEngine.")
print("Some useful targets are:")
printCommands(commands())
def deps():
"""
deps -- compile dependency libraries
"""
prepare()
owd = os.getcwd()
os.chdir(deps_dir)
if not path.isfile(path.join(deps_dir, "Makefile")):
if system("win"):
execute("cmake -DDEPS=true -G \"MinGW Makefiles\" ../")
else:
execute("cmake -DDEPS=true -G \"Unix Makefiles\" ../")
sys_exec_make("all")
sys_exec_make("install")
os.chdir(owd)
def cleandeps():
"""
cleandeps -- remove compiled dependency libraries
"""
if not path.isdir(deps_dir):
return
for root, dirs, files in os.walk(deps_dir, topdown=False):
for name in files:
os.remove(path.join(root, name))
for name in dirs:
os.rmdir(path.join(root, name))
os.rmdir(deps_dir)
def make(target):
"""
<other> -- forwarded to make in the build directory
"""
prepare()
owd = os.getcwd()
os.chdir(build_dir)
if not path.isfile(path.join(build_dir, "Makefile")):
sys_exec_cmake()
sys_exec_make(target)
os.chdir(owd)
def prepare():
if not path.isdir(build_dir):
os.mkdir(build_dir)
if not path.isdir(deps_dir):
os.mkdir(deps_dir)
def sys_exec_cmake():
if system("win"):
execute("cmake -G \"MinGW Makefiles\" ../")
else:
execute("cmake ../")
def sys_exec_make(target):
if system("win"):
execute("mingw32-make --jobs %s" % (target))
else:
execute("make --jobs %d %s" % (cores()+1, target))
def main():
# check run location
if not path.isfile(path.join(os.getcwd(), "make.py")):
print("You must run make.py from the OpenEngine root directory.")
# if no command is given run default
if len(sys.argv) < 2:
build()
sys.exit(0)
# get command
cmd = sys.argv[1]
fn = None
for f,c in commands():
if cmd == c: fn = f
if fn: fn()
elif len(sys.argv) == 2:
make(sys.argv[1])
else:
print("Invalid command.")
print("Possible commands are:")
printCommands(commands())
sys.exit(1)
if __name__ == '__main__':
try: main()
except ExecError as e:
print(e)
sys.exit(1)