-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmake.py
More file actions
101 lines (88 loc) · 2.8 KB
/
make.py
File metadata and controls
101 lines (88 loc) · 2.8 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
import subprocess
import sys
import os
gen_name = "catlab"
compile_defines_c = {
'num' : 0,
'definevariables' : [],
'definevalues' : [],
}
compile_profile_c = {
'compiler' : 'mpicc',
'compile_option' : ['-I.','-I/home/yyli/include','-Wall'],
'link_option' : [],
'require' : ['toms_lite','cephes_lite'],
}
compile_objects_c = [
'catlab_specfunc',
'catlab_matrix',
'catlab_eig',
]
generate_lib = {
'cmd' : 'ar',
'opt' : 'rv',
'ranlib' : 'ranlib',
}
def docompile(objects,profile,defines):
cwdir = os.getcwd()
for lib in profile['require']:
libdir = cwdir+'/'+lib
runcmd = 'python '+libdir+'/make.py'
print(runcmd)
subprocess.call(runcmd, cwd = libdir,shell=True)
cc = profile['compiler']
opt = ''
for option in profile['compile_option']:
opt = opt + ' ' + option
variables = defines['definevariables']
defvalues = defines['definevalues']
dopt = ''
for itr in range(defines['num']):
dopt = dopt + ' -D'+variables[itr]+'='+defvalues[itr]
for obj in objects:
runcmd = cc+' '+obj+'.c'+' -c'+opt+dopt
print (runcmd)
subprocess.call(runcmd,shell=True)
def genlib(libname,objects,genlib,profile):
libfilename = 'lib'+libname+'.a'
runcmd = genlib['cmd']+' '+genlib['opt']+' '+libfilename+' '
for obj in objects:
runcmd += obj+'.o '
print (runcmd)
subprocess.call(runcmd,shell=True)
runcmd = genlib['ranlib']+' '+libfilename
print (runcmd)
subprocess.call(runcmd,shell=True)
# if there are required libraries, we need to combine them into one lib
if (profile['require']!=[]):
for lib in profile['require']:
thislibruncmd = 'ar x lib'+lib+'.a '
print(thislibruncmd)
subprocess.call(thislibruncmd,shell=True)
runcmd = 'ar x '+libfilename
print(runcmd)
subprocess.call(runcmd,shell=True)
runcmd = 'ar rv '+libfilename+' *.o'
print(runcmd)
subprocess.call(runcmd,shell=True)
runcmd = 'ranlib '+libfilename
print(runcmd)
subprocess.call(runcmd,shell=True)
runcmd = 'mv '+libfilename+' ../'
subprocess.call(runcmd,shell=True)
def dolink(output,objects,profile):
cc = profile['compiler']
opt = ''
for option in profile['link_option']:
opt = opt + ' ' + option
objs = ''
for obj in objects:
objs = objs+' '+obj+'.o'
runcmd = cc+objs+opt+' -o '+output
print (runcmd)
subprocess.call(runcmd,shell=True)
if __name__ == '__main__':
docompile(compile_objects_c,compile_profile_c,compile_defines_c)
genlib(gen_name,compile_objects_c,generate_lib,compile_profile_c)
subprocess.call('rm *.o',shell=True)
subprocess.call('rm *.a',shell=True)