7
7
8
8
from mars_utils import *
9
9
10
- NDK_BUILD_CMD = "ndk-build NDK_DEBUG=0 -j 4 -B SDK=0 LIBPREFIX=mars -C "
10
+ NDK_BUILD_CMD = "ndk-build _ARCH_=%s NDK_DEBUG=0 -j 4 -B SDK=0 LIBPREFIX=mars -C "
11
+ MARS_LIBS_PATH = "mars_android_sdk"
12
+ XLOG_LIBS_PATH = "mars_xlog_sdk"
13
+
14
+
11
15
BUILD_XLOG_PATHS = ("openssl" , "comm" , "log" )
12
16
COPY_XLOG_FILES = {"../log/crypt/log_crypt.h" : "jni/log_crypt.h" ,
13
17
"../log/crypt/decode_mars_log_file.py" : "jni/decode_mars_log_file.py.rewriteme" ,
27
31
}
28
32
29
33
30
- def build_android_xlog_static_libs (_path = "mars_xlog_sdk" ):
34
+ def build_android_xlog_static_libs (_path = "mars_xlog_sdk" , _arch = "" ):
31
35
libs_save_path = _path + "/mars_libs"
32
36
src_save_path = _path + "/"
33
37
@@ -42,7 +46,7 @@ def build_android_xlog_static_libs(_path="mars_xlog_sdk"):
42
46
for i in range (0 , len (BUILD_XLOG_PATHS )):
43
47
if not os .path .exists ("../" + BUILD_XLOG_PATHS [i ] + "/jni" ):
44
48
continue
45
- if 0 != os .system (NDK_BUILD_CMD + "../" + BUILD_XLOG_PATHS [i ]):
49
+ if 0 != os .system (NDK_BUILD_CMD % ( _arch ) + "../" + BUILD_XLOG_PATHS [i ]):
46
50
return - 1
47
51
48
52
@@ -57,7 +61,7 @@ def build_android_xlog_static_libs(_path="mars_xlog_sdk"):
57
61
58
62
cpu_libs = os .path .join (libs_save_path , f )
59
63
cpu_symbols = os .path .join (cpu_libs , "symbols" )
60
- print cpu_libs , cpu_symbols
64
+ # print cpu_libs, cpu_symbols
61
65
if not os .path .exists (cpu_libs ):
62
66
os .makedirs (cpu_libs )
63
67
if not os .path .exists (cpu_symbols ):
@@ -83,9 +87,9 @@ def build_android_xlog_static_libs(_path="mars_xlog_sdk"):
83
87
print ("build succeed!" )
84
88
return 0
85
89
86
- def build_android_xlog_shared_libs (_path = "mars_xlog_sdk" ):
90
+ def build_android_xlog_shared_libs (_path = "mars_xlog_sdk" , _arch = "armeabi" ):
87
91
88
- if 0 != build_android_xlog_static_libs ("mars_xlog_sdk" ):
92
+ if 0 != build_android_xlog_static_libs (_path , _arch ):
89
93
print ("build static libs fail!!!" )
90
94
return - 1
91
95
@@ -94,22 +98,18 @@ def build_android_xlog_shared_libs(_path="mars_xlog_sdk"):
94
98
shutil .rmtree (_path + "/obj" , True )
95
99
96
100
97
- if 0 != os .system (NDK_BUILD_CMD + _path ):
101
+ if 0 != os .system (NDK_BUILD_CMD % ( _arch ) + _path ):
98
102
print ("build fail!!!" )
99
103
return - 1
100
104
101
105
print ("build succeed!" )
102
106
return 0
103
107
104
108
105
- def build_android_mars_static_libs (_path = "mars_android_sdk" , _arch = "" ):
109
+ def build_android_mars_static_libs (_path = "mars_android_sdk" , _arch = "armeabi " ):
106
110
libs_save_path = _path + "/mars_libs"
107
111
src_save_path = _path + "/"
108
112
109
- if _arch != "" :
110
- global NDK_BUILD_CMD
111
- NDK_BUILD_CMD = "ndk-build _ARCH_=" + _arch + " NDK_DEBUG=0 -j 4 -B SDK=0 LIBPREFIX=mars -C "
112
- print (NDK_BUILD_CMD )
113
113
114
114
shutil .rmtree (libs_save_path , True )
115
115
for i in range (0 , len (BUILD_MARS_PATHS )):
@@ -121,7 +121,7 @@ def build_android_mars_static_libs(_path="mars_android_sdk", _arch=""):
121
121
for i in range (0 , len (BUILD_MARS_PATHS )):
122
122
if not os .path .exists ("../" + BUILD_MARS_PATHS [i ] + "/jni" ):
123
123
continue
124
- if 0 != os .system (NDK_BUILD_CMD + "../" + BUILD_MARS_PATHS [i ]):
124
+ if 0 != os .system (NDK_BUILD_CMD % ( _arch ) + "../" + BUILD_MARS_PATHS [i ]):
125
125
return - 1
126
126
127
127
@@ -164,9 +164,9 @@ def build_android_mars_static_libs(_path="mars_android_sdk", _arch=""):
164
164
print ("build succeed!" )
165
165
return 0
166
166
167
- def build_android_mars_shared_libs (_path = "mars_android_sdk" ):
167
+ def build_android_mars_shared_libs (_path = "mars_android_sdk" , _arch = "armeabi" ):
168
168
169
- if 0 != build_android_mars_static_libs ():
169
+ if 0 != build_android_mars_static_libs (_path , _arch ):
170
170
print ("build static libs fail!!!" )
171
171
return - 1
172
172
@@ -175,33 +175,22 @@ def build_android_mars_shared_libs(_path="mars_android_sdk"):
175
175
shutil .rmtree (_path + "/obj" , True )
176
176
177
177
178
- if 0 != os .system (NDK_BUILD_CMD + _path ):
178
+ if 0 != os .system (NDK_BUILD_CMD % ( _arch ) + _path ):
179
179
print ("build fail!!!" )
180
180
return - 1
181
181
182
182
print ("build succeed!" )
183
183
return 0
184
184
185
185
def choose_android_mars_jni_arch ():
186
- platforms = ['armeabi' , 'x86' , 'mips' , 'armeabi-v7a' , 'arm64-v8a' , 'x86_64' , 'mips64' ]
187
- archnum = raw_input ("Enter the architecture which would like to build, support multi-selection which should be separated by comma(','):\n 1. armeabi.\n 2. x86.\n 3. mips.\n 4. armeabi-v7a.\n 5. arm64-v8a.\n 6. x86_64.\n 7. mips64.\n 8. exit.\n " )
188
- arr = []
189
- if "8" == archnum :
190
- arr .append ('exit' )
191
- elif len (archnum ) >= 3 :
192
- archs = archnum .split (',' )
193
- for i in range (0 , len (archs )):
194
- if (int (archs [i ]) <= 7 ):
195
- arr .append (platforms [int (archs [i ])- 1 ])
196
- i += 1
197
- elif len (archnum ) == 2 :
198
- arr .append ('err' )
199
- else :
200
- if (int (archnum ) <= 7 ):
201
- arr .append (platforms [int (archnum )- 1 ])
202
- else :
203
- arr .append ('err' )
204
- return arr
186
+ platforms = ['armeabi' , 'x86' , 'mips' , 'armeabi-v7a' , 'arm64-v8a' , 'x86_64' , 'mips64' ]
187
+ archnum = raw_input ("Enter the architecture which would like to build:\n 1. armeabi.\n 2. x86.\n 3. mips.\n 4. armeabi-v7a.\n 5. arm64-v8a.\n 6. x86_64.\n 7. mips64.\n 8. exit.\n " )
188
+
189
+ if archnum >= "1" and archnum <= str (len (platforms )):
190
+ return platforms [int (archnum )- 1 ]
191
+ else :
192
+ return None
193
+
205
194
206
195
def main ():
207
196
if not check_env ():
@@ -220,85 +209,37 @@ def main():
220
209
else :
221
210
num = raw_input ("Enter menu:\n 1. build mars static libs.\n 2. build mars shared libs.\n 3. build xlog static libs.\n 4. build xlog shared libs.\n 5. exit.\n " )
222
211
arch = choose_android_mars_jni_arch ()
212
+ if not arch :
213
+ return
223
214
224
215
if flag == 1 :
225
- if "1" == num :
226
- return build_android_mars_static_libs ()
227
- elif "2" == num :
228
- return build_android_mars_shared_libs ()
229
- elif "3" == num :
230
- return build_android_xlog_static_libs ()
231
- elif "4" == num :
232
- return build_android_xlog_shared_libs ()
233
- elif "5" == num :
234
- return 0
235
- else :
236
- pass
216
+ if "1" == num :
217
+ return build_android_mars_static_libs ()
218
+ elif "2" == num :
219
+ return build_android_mars_shared_libs ()
220
+ elif "3" == num :
221
+ return build_android_xlog_static_libs ()
222
+ elif "4" == num :
223
+ return build_android_xlog_shared_libs ()
224
+ elif "5" == num :
225
+ return 0
226
+ else :
227
+ pass
237
228
else :
238
- if "1" == num :
239
- return build_android_mars_static_libs ()
240
- elif "2" == num :
241
- if arch [0 ] == 'err' :
242
- return
243
- elif arch [0 ] == 'exit' :
244
- return
245
- else :
246
- if os .path .exists ('mars_android_sdk/so_cache' ):
247
- shutil .rmtree ('mars_android_sdk/so_cache' , True )
248
- os .mkdir ('mars_android_sdk/so_cache' )
249
- for i in range (0 , len (arch )):
250
- NDK_BUILD_CMD = "ndk-build _ARCH_=" + arch [i ] + " NDK_DEBUG=0 -j 4 -B SDK=0 LIBPREFIX=mars -C "
251
- print (NDK_BUILD_CMD )
252
- build_android_mars_shared_libs ()
253
- if i != (len (arch )- 1 ):
254
- libs_dir = 'mars_android_sdk/so_cache/' + arch [i ];
255
- symbols_dir = 'mars_android_sdk/so_cache/symbol/' + arch [i ];
256
- if not os .path .exists ('mars_android_sdk/so_cache/symbol/' ):
257
- os .mkdir ('mars_android_sdk/so_cache/symbol/' )
258
- os .mkdir (libs_dir )
259
- os .mkdir (symbols_dir )
260
- for lib in glob .glob ("mars_android_sdk/obj/local/" + arch [i ] + "/*.so" ):
261
- shutil .copy (lib , symbols_dir )
262
- for lib in glob .glob ("mars_android_sdk/libs/" + arch [i ] + "/*.so" ):
263
- shutil .copy (lib , libs_dir )
264
- for i in range (0 , len (arch )- 1 ):
265
- shutil .copytree ('mars_android_sdk/so_cache/' + arch [i ], 'mars_android_sdk/libs/' + arch [i ])
266
- shutil .copytree ('mars_android_sdk/so_cache/symbol/' + arch [i ], 'mars_android_sdk/obj/local/' + arch [i ])
267
- return
268
- elif "3" == num :
269
- return build_android_xlog_static_libs ()
270
- elif "4" == num :
271
- if arch [0 ] == 'err' :
272
- return
273
- elif arch [0 ] == 'exit' :
274
- return
275
- else :
276
- if os .path .exists ('mars_xlog_sdk/so_cache' ):
277
- shutil .rmtree ('mars_xlog_sdk/so_cache' , True )
278
- os .mkdir ('mars_xlog_sdk/so_cache' )
279
- for i in range (0 , len (arch )):
280
- NDK_BUILD_CMD = "ndk-build _ARCH_=" + arch [i ] + " NDK_DEBUG=0 -j 4 -B SDK=0 LIBPREFIX=mars -C "
281
- print (NDK_BUILD_CMD )
282
- build_android_xlog_shared_libs ()
283
- if i != (len (arch )- 1 ):
284
- libs_dir = 'mars_xlog_sdk/so_cache/' + arch [i ];
285
- symbols_dir = 'mars_xlog_sdk/so_cache/symbol/' + arch [i ];
286
- if not os .path .exists ('mars_xlog_sdk/so_cache/symbol/' ):
287
- os .mkdir ('mars_xlog_sdk/so_cache/symbol/' )
288
- os .mkdir (libs_dir )
289
- os .mkdir (symbols_dir )
290
- for lib in glob .glob ("mars_xlog_sdk/obj/local/" + arch [i ] + "/*.so" ):
291
- shutil .copy (lib , symbols_dir )
292
- for lib in glob .glob ("mars_xlog_sdk/libs/" + arch [i ] + "/*.so" ):
293
- shutil .copy (lib , libs_dir )
294
- for i in range (0 , len (arch )- 1 ):
295
- shutil .copytree ('mars_xlog_sdk/so_cache/' + arch [i ], 'mars_xlog_sdk/libs/' + arch [i ])
296
- shutil .copytree ('mars_xlog_sdk/so_cache/symbol/' + arch [i ], 'mars_xlog_sdk/obj/local/' + arch [i ])
297
- return
298
- elif "5" == num :
299
- return 0
300
- else :
301
- pass
229
+ if "1" == num :
230
+ return build_android_mars_static_libs (MARS_LIBS_PATH , arch )
231
+ elif "2" == num :
232
+ return build_android_mars_shared_libs (MARS_LIBS_PATH , arch )
233
+
234
+ elif "3" == num :
235
+ return build_android_xlog_static_libs (XLOG_LIBS_PATH , arch )
236
+ elif "4" == num :
237
+ return build_android_xlog_shared_libs (XLOG_LIBS_PATH , arch )
238
+
239
+ elif "5" == num :
240
+ return 0
241
+ else :
242
+ pass
302
243
303
244
if __name__ == "__main__" :
304
245
main ()
0 commit comments