1+ import os , sys
2+
3+ class cythonizer ():
4+ def __init__ (self ,
5+ android_ndk = os .environ ["ANDROIDNDK" ],
6+ android_api = os .environ ["ANDROIDAPI" ],
7+ python_for_android = os .path .join (os .path .split (os .path .realpath (__file__ ))[0 ])
8+ ):
9+ self .android_ndk = android_ndk
10+ self .android_api = android_api
11+ self .py_for_a = python_for_android
12+
13+ for path in [self .android_ndk , self .py_for_a ]:
14+ if not os .path .isdir (path ):
15+ print "!! Haven't found path:" , repr (path )
16+ sys .exit ()
17+
18+ self .gcc = "%s/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc" % (self .android_ndk )
19+ self .sysroot = "%s/platforms/android-%s/arch-arm" % (self .android_ndk , self .android_api )
20+ self .a_incl = "-I%s/platforms/android-%s/arch-arm/usr/include" % (self .android_ndk , self .android_api )
21+ self .p_incl = "-I%s/build/python-install/include/python2.7" % (self .py_for_a )
22+ self .libs = "-L%s/build/libs" % (self .py_for_a )
23+ self .p_libs = "-L%s/build/python-install/lib" % (self .py_for_a )
24+ self .a_libs = "-L%s/platforms/android-%s/arch-arm/usr/lib" % (self .android_ndk , self .android_api )
25+
26+ def make_o (self , c_file , o_file ):
27+ command = """%s -mandroid -fomit-frame-pointer -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC --sysroot %s %s %s -c database.c -o database.o""" % (self .gcc ,
28+ self .sysroot ,
29+ self .a_incl ,
30+ self .p_incl )
31+ print command
32+
33+ def make_so (self , o_file , so_file = None ):
34+ if so_file == None :
35+ so_file = os .path .splitext (os .path .realpath (o_file ))[0 ]+ ".so"
36+ command = """%s -shared -O3 -mandroid -fomit-frame-pointer --sysroot %s -lm -lGLESv2 -lpython2.7 %s %s %s %s -o %s """ % (self .gcc ,
37+ self .sysroot ,
38+ self .libs ,
39+ self .p_libs ,
40+ self .a_libs ,
41+ o_file ,
42+ so_file )
43+ print command
44+ def make (self , py_pyx ):
45+ for root , dirs , files in os .walk (directory ):
46+ for file in files :
47+ if file .endswith ('.py' ) or file .endswith ('.pyx' ):
48+ print file
49+ self .make_o (py_pyx )
50+ self .make_so (py_pyx )
51+
52+ if __name__ == "__main__" :
53+ c = cythonizer ()
54+ c .make ("test.py" )
0 commit comments