This repository was archived by the owner on Mar 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinstall_3rdparty
executable file
·368 lines (295 loc) · 10.5 KB
/
install_3rdparty
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/usr/bin/env python
import os, sys, subprocess, inspect, shutil, glob
TERM_RESET = '\033[0m'
TERM_GREY = '\033[90m'
TERM_RED = '\033[31m'
TERM_GREEN = '\033[32m'
TERM_YELLOW = '\033[33m'
TERM_BLUE = '\033[34m'
TERM_WHITE = '\033[37m'
TERM_BOLDYELLOW = '\033[1m\033[33m'
TERM_BOLDBLUE = '\033[1m\033[34m'
TERM_BOLDMAGENTA = '\033[1m\033[35m'
TERM_BOLDRED = '\033[1m\033[31m'
TERM_BOLDWHITE = '\033[1m\033[37m'
TERM_BOLDGREEN = '\033[1m\033[32m'
ROOTDIR = os.path.abspath(os.path.dirname(inspect.getframeinfo(inspect.currentframe())[0]))
LIBDIR = ''
INCLUDEDIR = ''
PREFIX = ROOTDIR
def log(msg, color = TERM_RESET):
if sys.platform == 'linux' or sys.platform == 'darwin':
sys.stdout.write(color + msg + TERM_RESET)
else:
sys.stdout.write(msg)
sys.stdout.flush()
def search_package(name):
libs = []
ver = ''
if sys.platform == 'linux':
try:
subprocess.check_output(['pkg-config', '--exists', name], universal_newlines=True)
sver = subprocess.check_output(['pkg-config', '--modversion', name],
universal_newlines=True)
slibs = subprocess.check_output(['pkg-config', '--libs', name], universal_newlines=True)
except subprocess.CalledProcessError:
return (False, ver, libs)
else:
ver = sver.split('\n')[0]
libs_raw = slibs.split('\n')[0].split(' ')
for lib in libs_raw:
if len(lib) > 0:
libs.append(lib.split('-l')[0])
return (True, ver, libs)
else:
return (False, ver, libs)
def install_lua():
luadir = os.path.join(ROOTDIR, '3rdparty', 'tmp', 'lua')
libfile = os.path.join(LIBDIR, 'liblua.so')
if os.path.isfile(libfile):
return True
url = 'https://github.com/LuaDist/lua/archive/master.zip'
log('downloading lua source from "https://github.com/LuaDist/lua"...\n', TERM_GREY)
log('')
os.makedirs(luadir, exist_ok=True)
os.chdir(luadir)
if os.system('wget -N {0}'.format(url)) != 0:
os.chdir(ROOTDIR)
return False
if os.system('unzip -o master.zip') != 0:
os.chdir(ROOTDIR)
return False
os.chdir('lua-master')
if os.system('cmake .') != 0:
os.chdir(ROOTDIR)
return False
if os.system('make') != 0:
os.chdir(ROOTDIR)
return False
# copy important files
shutil.copyfile('liblua.so', libfile)
# headers
includes = os.path.join(INCLUDEDIR, 'lua')
headers = ['src/lua.h', 'src/lauxlib.h', 'src/lua.hpp', 'src/lualib.h']
os.makedirs(includes, exist_ok=True)
for header in headers:
shutil.copyfile(header, os.path.join(includes, os.path.basename(header)))
os.chdir(ROOTDIR)
return True
def check_lua():
log('looking for lua...', TERM_GREEN)
(r, ver, libs) = search_package('lua')
if not r:
log('\t\tnot found\n', TERM_YELLOW)
return False
sver = ver.split('.')
if int(sver[0]) < 5 or int(sver[1]) < 2:
log('\t\told version: {0}\n'.format(ver), TERM_YELLOW)
return False
log('\t\tfound: {0}\n'.format(ver), TERM_GREEN)
return True
def install_assimp():
if os.path.isfile(os.path.join(LIBDIR, 'libassimp.so')):
return True
url = 'https://github.com/assimp/assimp/archive/master.zip'
log('downloading assimp source from "https://github.com/assimp/assimp"...\n', TERM_GREY)
assimpdir = os.path.join(ROOTDIR, '3rdparty', 'tmp', 'assimp')
os.makedirs(assimpdir, exist_ok=True)
os.chdir(assimpdir)
if os.system('wget -N {0}'.format(url)) != 0:
os.chdir(ROOTDIR)
return False
if os.system('unzip -o master.zip') != 0:
os.chdir(ROOTDIR)
return False
os.chdir('assimp-master')
if os.system('cmake -DENABLE_BOOST_WORKAROUND=ON . ') != 0:
os.chdir(ROOTDIR)
return False
if os.system('make') != 0:
os.chdir(ROOTDIR)
return False
# copy important files
# libs
libs = glob.glob('lib/libassimp.so*')
for lib in libs:
shutil.copyfile(lib, os.path.join(LIBDIR, os.path.basename(lib)))
# headers
includes = os.path.join(INCLUDEDIR, 'assimp')
headers = glob.glob('include/assimp/*')
os.makedirs(includes, exist_ok=True)
for header in headers:
if os.path.isfile(header):
shutil.copyfile(header, os.path.join(includes, os.path.basename(header)))
os.makedirs(os.path.join(includes, 'Compiler'), exist_ok=True)
headers = glob.glob('include/assimp/Compiler/*')
for header in headers:
shutil.copyfile(header, os.path.join(includes, 'Compiler', os.path.basename(header)))
os.chdir(ROOTDIR)
return True
def check_assimp():
log('looking for assimp...', TERM_GREEN)
(r, ver, libs) = search_package('assimp')
if not r:
log('\t\tnot found\n', TERM_YELLOW)
return False
sver = ver.split('.')
if int(sver[0]) < 3:
log('\t\told version: {0}\n'.format(ver), TERM_YELLOW)
return False
log('\t\tfound: {0}\n'.format(ver), TERM_GREEN)
return True
def install_glfw():
if os.path.isfile(os.path.join(LIBDIR, 'libglfw.so')):
return True
url = 'https://github.com/glfw/glfw/archive/master.zip'
log('downloading glfw source from "https://github.com/glfw/glfw"...\n', TERM_GREY)
glfwdir = os.path.join(ROOTDIR, '3rdparty', 'tmp', 'glfw')
os.makedirs(glfwdir, exist_ok=True)
os.chdir(glfwdir)
if os.system('wget -N {0}'.format(url)) != 0:
os.chdir(ROOTDIR)
return False
if os.system('unzip -o master.zip') != 0:
os.chdir(ROOTDIR)
return False
os.chdir('glfw-master')
if os.system('cmake . -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=%s' % PREFIX) != 0:
os.chdir(ROOTDIR)
return False
if os.system('make install') != 0:
os.chdir(ROOTDIR)
return False
os.chdir(ROOTDIR)
return True
def check_glfw():
log('looking for glfw...', TERM_GREEN)
(r, ver, libs) = search_package('glfw')
if not r:
log('\t\tnot found\n', TERM_YELLOW)
return False
sver = ver.split('.')
if int(sver[0]) < 3:
log('\t\told version: {0}\n'.format(ver), TERM_YELLOW)
return False
log('\t\tfound: {0}\n'.format(ver), TERM_GREEN)
return True
def check_glew():
log('looking for glew...', TERM_GREEN)
(r, ver, libs) = search_package('glew')
if not r:
log('\t\tnot found\n', TERM_YELLOW)
return False
sver = ver.split('.')
if int(sver[0]) < 1 or int(sver[1]) < 10:
log('\t\told version: {0}\n'.format(ver), TERM_YELLOW)
return False
log('\t\tfound: {0}\n'.format(ver), TERM_GREEN)
return True
def install_glew():
if os.path.isfile(os.path.join(LIBDIR, 'libGLEW.so')):
return True
url = 'https://sourceforge.net/projects/glew/files/glew/1.10.0/glew-1.10.0.zip/download'
log('downloading glew source from "https://sourceforge.net/projects/glew"...\n', TERM_GREY)
glewdir = os.path.join(ROOTDIR, '3rdparty', 'tmp', 'glew')
os.makedirs(glewdir, exist_ok=True)
os.chdir(glewdir)
if os.system('wget -N {0}'.format(url)) != 0:
os.chdir(ROOTDIR)
return False
if os.system('unzip -o download') != 0:
os.chdir(ROOTDIR)
return False
dirs = glob.glob('*')
for d in dirs:
if os.path.isdir(d):
os.chdir(d)
break
if os.system('make') != 0:
os.chdir(ROOTDIR)
return False
# copy important files
# libs
libs = glob.glob('lib/libGLEW.so*')
for lib in libs:
shutil.copyfile(lib, os.path.join(LIBDIR, os.path.basename(lib)))
# headers
includes = os.path.join(INCLUDEDIR, 'GL')
headers = glob.glob('include/GL/*.h')
os.makedirs(includes, exist_ok=True)
for header in headers:
shutil.copyfile(header, os.path.join(includes, os.path.basename(header)))
os.chdir(ROOTDIR)
return True
def install_efsw():
log('looking for efsw...', TERM_GREEN)
if os.path.isfile(os.path.join(LIBDIR, 'libefsw.so')):
log('\t\tfound\n', TERM_GREEN)
return True
log('\t\tnot found\n', TERM_YELLOW)
url = 'https://bitbucket.org/sepul/efsw/get/5de4baca1a60.zip'
log('downloading efsw source from "https://bitbucket.org/sepul/efsw"...\n', TERM_GREY)
efswdir = os.path.join(ROOTDIR, '3rdparty', 'tmp', 'efsw')
os.makedirs(efswdir, exist_ok=True)
os.chdir(efswdir)
if os.system('wget -N {0}'.format(url)) != 0:
os.chdir(ROOTDIR)
return False
if os.system('unzip -o ' + os.path.basename(url)) != 0:
os.chdir(ROOTDIR)
return False
name = os.path.splitext(os.path.basename(url))[0]
dirname = 'sepul-efsw-' + name
os.chdir(dirname)
if os.system('waf configure build install') != 0:
os.chdir(ROOTDIR)
return False
# copy important files
# libs
libs = glob.glob('lib/libefsw.so*')
for lib in libs:
shutil.copyfile(lib, os.path.join(LIBDIR, os.path.basename(lib)))
# headers
includes = os.path.join(INCLUDEDIR, 'efsw')
headers = glob.glob('include/efsw/*.h*')
os.makedirs(includes, exist_ok=True)
for header in headers:
shutil.copyfile(header, os.path.join(includes, os.path.basename(header)))
os.chdir(ROOTDIR)
return True
def main():
global LIBDIR, INCLUDEDIR, PREFIX
for arg in sys.argv:
if '--prefix' in arg:
prefix_value = arg.split('=')[-1]
if os.path.isdir(prefix_value):
PREFIX = prefix_value
LIBDIR = os.path.join(PREFIX, 'lib')
INCLUDEDIR = os.path.join(PREFIX, 'include')
log('library install path: ' + LIBDIR + '\n', TERM_GREEN)
log('include install path: ' + INCLUDEDIR + '\n', TERM_GREEN)
os.makedirs(INCLUDEDIR, exist_ok=True)
os.makedirs(LIBDIR, exist_ok=True)
if not check_lua():
if not install_lua():
log('error: could not install lua\n', TERM_RED)
return False
if not check_assimp():
if not install_assimp():
log('error: could not install assimp\n', TERM_RED)
return False
if not check_glfw():
if not install_glfw():
log('error: could not install glfw\n', TERM_RED)
return False
if not check_glew():
if not install_glew():
log('error: could not install glew\n', TERM_RED)
return False
if not install_efsw():
log('error: could not install efsw\n', TERM_RED)
return False
log('ok, ready for build.\n')
r = main()
if r: sys.exit(0)
else: sys.exit(-1)