Repository navigation
Expand file tree
/
Copy pathbuild_native.py
More file actions
executable file
·312 lines (256 loc) · 10.1 KB
/
Copy pathbuild_native.py
File metadata and controls
executable file
·312 lines (256 loc) · 10.1 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env python
import subprocess
import sys
import getopt
import os
import glob
import logging
import distutils.dir_util
import shutil
from sys import platform as _platform
from os import listdir
from os.path import isfile, isdir, join
verbose = False
overwrite = False
has_built_osx = False
windows = False
osx = False
linux = False
# OS X globals
is_ready_for_osx_build = False
did_build_for_osx_successfully = False
def check_osx():
print ""
print "OS X Pre-build check-----------------------------------------"
check_xcodeproj()
check_xcode_tools()
check_has_built_for_osx()
global is_ready_for_osx_build
if has_xcodeProj and has_xcodeTools:
is_ready_for_osx_build = True
print "STATUS: Ready to build libSampleLibrary.dylib for OS X"
else:
is_ready_for_osx_build = False
if not is_ready_for_osx_build:
print "STATUS: NOT ready for OSX build. Please address the following:"
if not has_xcodeProj:
print " ---ERROR: Script in wrong location or xcodeproj missing----------------"
print " This script must be placed in the SampleLibrary project folder. This folder"
print " should contain the SampleLibrary.xcodeproj file that is used in "
print " the command line build. If this script is in the SampleLibrary folder,"
print " and you are getting this error message, then you are likely missing"
print " the XCode project. "
if not has_xcodeTools:
print " ---ERROR: XCode Command Line Tools Missing-----------------------------"
print " Building the native binary requires xcodebuild. This utility"
print " is included with Apple's XCode Command Line Tools. As of XCode 4.3,"
print " Command Line Tools are optional. To install Command Line tools, open"
print " XCode > Preferences > Downloads Tab > Components > Command Line Tools."
print " Download and install. Be sure to close/restart your terminal session"
print " before running this command again."
return
def check_xcodeproj():
sys.stdout.write(" Checking for xcodeproj ")
global has_xcodeProj
if os.path.exists("SampleLibrary.xcodeproj"):
sys.stdout.write("...Found\n")
has_xcodeProj = True
else:
sys.stdout.write("...SampleLibrary.xcodeproj NOT FOUND\n")
has_xcodeProj = False
def check_xcode_tools():
sys.stdout.write(" Checking for XCode command line tools ")
global has_xcodeTools
if which("xcodebuild") is None:
sys.stdout.write("...xcodebuild NOT FOUND\n")
has_xcodeTools = False
else:
sys.stdout.write("...Found\n")
has_xcodeTools = True
def check_has_built_for_osx():
sys.stdout.write(" Checking for existing builds ")
global has_built_osx
if os.path.exists("build/Debug/libSampleLibrary.dylib"):
if os.path.exists("build/Release/libSampleLibrary.dylib"):
sys.stdout.write("...Found\n")
has_built_osx = True
else:
sys.stdout.write("...Not Found\n")
has_built_osx = False
def create_build_folders_for_osx():
if not os.path.exists("build"):
os.mkdir("build")
#check to make sure the folder was created successfully
if not os.path.exists("build"):
print "ERROR: Unable to create build folders. Please make sure you have admin privileges and try again."
sys.exit()
if not os.path.exists("build/Debug"):
os.mkdir("build/Debug")
#check to make sure the folder was created successfully
if not os.path.exists("build/Debug"):
print "ERROR: Unable to create build folders. Please make sure you have admin privileges and try again."
sys.exit()
def build_for_osx():
print ""
print "OSX Build-------------------------------------------------------"
print "Making dynamic libSampleLibrary.dylib for OSX..."
sys.stdout.write(" Compiling Debug version ")
if verbose:
subprocess.call(
["xcodeBuild", "-project", "SampleLibrary.xcodeproj", "-target", "SampleLibrary", "-configuration", "Debug",
"clean", "build"])
else:
devnull = open(os.devnull, 'w')
subprocess.call(
["xcodeBuild", "-project", "SampleLibrary.xcodeproj", "-target", "SampleLibrary", "-configuration", "Debug",
"clean", "build"], stdout=devnull, stderr=devnull)
if os.path.exists("build/Debug/libSampleLibrary.dylib"):
sys.stdout.write("...Done\n")
else:
sys.stdout.write("...FAILED\n")
sys.exit()
sys.stdout.write(" Compiling Release version ")
if verbose:
subprocess.call(
["xcodeBuild", "-project", "SampleLibrary.xcodeproj", "-target", "SampleLibrary", "-configuration",
"Release", "clean", "build"])
else:
devnull = open(os.devnull, 'w')
subprocess.call(
["xcodeBuild", "-project", "SampleLibrary.xcodeproj", "-target", "SampleLibrary", "-configuration",
"Release", "clean", "build"], stdout=devnull, stderr=devnull)
if os.path.exists("build/Release/libSampleLibrary.dylib"):
sys.stdout.write("...Done\n")
else:
sys.stdout.write("...FAILED\n")
sys.exit()
sys.stdout.write("...Done\n")
global did_build_for_osx_successfully
did_build_for_osx_successfully = True
def write_osx_finished_message():
print "STATUS: OS X Build Complete. Libraries are in build/Debug"
def which(program):
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def usage():
print ""
print("build_native.py - script for building native openNURBS library")
print "usage: ./build_native.py -p [argument] --check --help --verbose"
print ""
print " option: arguments: description:"
print " --------------- ---------- ---------------------------------------"
print " -p --platform all build libSampleLibrary for all platforms"
if osx:
print " osx build libopennurbs.dylib for OS X"
print " -c --check all pre-requisites check for all platforms"
if osx:
print " osx pre-requisites check for OS X"
print " -h --help display this screen"
print " -v --verbose show verbose build messages"
print " -o --overwrite overwrite existing builds"
print ""
print "Examples:"
if osx:
print "./build_native.py -p all (build for all platforms)"
print "./build_native.py -p osx -v (build OS X with verbose messages)"
print "./build_native.py -c osx (check pre-requisites for OS X)"
print "./build_native.py -p osx -o (build for OS X overwriting existing)"
print ""
print "NOTE: Builds are stored in the build/Debug/ folder."
print ""
return
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hvoc:p:", ["help", "verbose", "overwrite", "check=", "platform="])
except getopt.GetoptError as err:
# print help information and exit:
usage()
sys.exit(2)
platform = None
check = None
#check os
global linux
global osx
global windows
if _platform == "linux" or _platform == "linux2":
linux = True
elif _platform == "darwin":
osx = True
elif _platform == "win32" or _platform == "cygwin":
windows = True
for o, a in opts:
if o == "-v" or o == "--verbose":
global verbose
verbose = True
elif o == "-o" or o == "--overwrite":
global overwrite
overwrite = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-p", "--platform"):
platform = a
elif o in ("-c", "--check"):
check = a
else:
assert False, "unhandled option"
#user has not entered any arguments...
if platform is None and check is None:
usage()
sys.exit()
#check prerequisites
if check == "all":
if osx:
check_osx()
elif check == "osx":
if osx:
check_osx()
else:
print ("ERROR: Targeting OS X requires running this script on Mac OS X 10.9.2 +")
#platform compiles
if platform == "all":
if osx:
check_osx()
if osx:
if overwrite or not has_built_osx:
create_build_folders_for_osx()
elif has_built_osx and not overwrite:
print ("STATUS: Existing OS X build found. NOT BUILDING. (Use -o argument to overwrite existing.)")
if osx:
if overwrite and is_ready_for_osx_build:
build_for_osx()
elif not has_built_osx and is_ready_for_osx_build:
build_for_osx()
if osx:
if did_build_for_osx_successfully:
write_osx_finished_message()
elif platform == "osx":
if osx:
check_osx()
else:
print ("ERROR: Targeting iOS or OS X requires running this script on Mac OS X 10.9.2 +")
sys.exit()
if has_built_osx and not overwrite:
print ("STATUS: Existing build found. NOT BUILDING. Use -o argument to overwrite the existing builds")
sys.exit()
if overwrite or not has_built_osx:
create_build_folders_for_osx()
if is_ready_for_osx_build:
build_for_osx()
else:
sys.exit()
if did_build_for_osx_successfully:
write_osx_finished_message()
if __name__ == "__main__":
main()