22from pythonforandroid .toolchain import shprint , current_directory , info
33from pythonforandroid .patching import (is_darwin , is_api_gt ,
44 check_all , is_api_lt , is_ndk )
5+ from pythonforandroid .util import ensure_dir
56from os .path import exists , join , realpath
7+ from os import environ
68import sh
79
810
@@ -13,6 +15,82 @@ class Python3Recipe(TargetPythonRecipe):
1315
1416 depends = ['hostpython3' ]
1517 conflicts = ['python3crystax' , 'python2' ]
16- opt_depends = ['openssl' , 'sqlite3' ]
18+ # opt_depends = ['openssl', 'sqlite3']
19+
20+ def build_arch (self , arch ):
21+ recipe_build_dir = self .get_build_dir (arch .arch )
22+
23+ # Create a subdirectory to actually perform the build
24+ build_dir = join (recipe_build_dir , 'android-build' )
25+ ensure_dir (build_dir )
26+
27+ # TODO: Get these dynamically, like bpo-30386 does
28+ sys_prefix = '/usr/local'
29+ sys_exec_prefix = '/usr/local'
30+
31+ # Skipping "Ensure that nl_langinfo is broken" from the original bpo-30386
32+
33+ with current_directory (build_dir ):
34+ env = environ .copy ()
35+
36+
37+ # TODO: Get this information from p4a's arch system
38+ android_host = 'arm-linux-androideabi'
39+ android_build = sh .Command (join (recipe_build_dir , 'config.guess' ))().stdout .strip ().decode ('utf-8' )
40+ platform_dir = join (self .ctx .ndk_dir , 'platforms' , 'android-19' , 'arch-arm' )
41+ toolchain = '{android_host}-4.9' .format (android_host = android_host )
42+ toolchain = join (self .ctx .ndk_dir , 'toolchains' , toolchain , 'prebuilt' , 'linux-x86_64' )
43+ CC = '{clang} -target {target} -gcc-toolchain {toolchain}' .format (
44+ clang = join (self .ctx .ndk_dir , 'toolchains' , 'llvm' , 'prebuilt' , 'linux-x86_64' , 'bin' , 'clang' ),
45+ target = 'armv7-none-linux-androideabi' ,
46+ toolchain = toolchain )
47+
48+ AR = join (toolchain , 'bin' , android_host ) + '-ar'
49+ LD = join (toolchain , 'bin' , android_host ) + '-ld'
50+ RANLIB = join (toolchain , 'bin' , android_host ) + '-ranlib'
51+ READELF = join (toolchain , 'bin' , android_host ) + '-readelf'
52+ STRIP = join (toolchain , 'bin' , android_host ) + '-strip --strip-debug --strip-unneeded'
53+
54+ env ['CC' ] = CC
55+ env ['AR' ] = AR
56+ env ['LD' ] = LD
57+ env ['RANLIB' ] = RANLIB
58+ env ['READELF' ] = READELF
59+ env ['STRIP' ] = STRIP
60+
61+ ndk_flags = '--sysroot={ndk_sysroot} -D__ANDROID_API__=19 -isystem {ndk_android_host}' .format (
62+ ndk_sysroot = join (self .ctx .ndk_dir , 'sysroot' ),
63+ ndk_android_host = join (self .ctx .ndk_dir , 'sysroot' , 'usr' , 'include' , android_host ))
64+ sysroot = join (self .ctx .ndk_dir , 'platforms' , 'android-19' , 'arch-arm' )
65+ env ['CFLAGS' ] = env .get ('CFLAGS' , '' ) + ' ' + ndk_flags
66+ env ['CPPFLAGS' ] = env .get ('CPPFLAGS' , '' ) + ' ' + ndk_flags
67+ env ['LDFLAGS' ] = env .get ('LDFLAGS' , '' ) + ' --sysroot={} -march=armv7-a -Wl,--fix-cortex-a8' .format (sysroot )
68+
69+ print ('CPPflags' , env ['CPPFLAGS' ])
70+ print ('LDFLAGS' , env ['LDFLAGS' ])
71+
72+ print ('LD is' , env ['LD' ])
73+
74+ shprint (sh .Command (join (recipe_build_dir , 'configure' )),
75+ * (' ' .join (('--host={android_host}' ,
76+ '--build={android_build}' ,
77+ '--enable-shared' ,
78+ '--disable-ipv6' ,
79+ 'ac_cv_file__dev_ptmx=yes' ,
80+ 'ac_cv_file__dev_ptc=no' ,
81+ '--without-ensurepip' ,
82+ 'ac_cv_little_endian_double=yes' ,
83+ '--prefix={prefix}' ,
84+ '--exec-prefix={exec_prefix}' )).format (
85+ android_host = android_host ,
86+ android_build = android_build ,
87+ prefix = sys_prefix ,
88+ exec_prefix = sys_exec_prefix )).split (' ' ), _env = env )
89+
90+ # if not exists('config.status'):
91+
92+
93+ # shprint(sh.make, '-C', build_dir)
94+
1795
1896recipe = Python3Recipe ()
0 commit comments