1
+ import time
2
+ from os .path import join
1
3
from functools import partial
2
4
3
5
from pythonforandroid .toolchain import Recipe , shprint , current_directory
4
6
import sh
5
7
6
8
7
9
class OpenSSLRecipe (Recipe ):
8
- version = '1.0.2h'
9
- url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
10
+ '''
11
+ The OpenSSL libraries for python-for-android. This recipe will generate the
12
+ following libraries as shared libraries (*.so):
13
+
14
+ - crypto
15
+ - ssl
16
+
17
+ The generated openssl libraries are versioned, where the version is the
18
+ recipe attribute :attr:`version` e.g.: ``libcrypto1.1.so``,
19
+ ``libssl1.1.so``...so...to link your recipe with the openssl libs,
20
+ remember to add the version at the end, e.g.:
21
+ ``-lcrypto1.1 -lssl1.1``. Or better, you could do it dynamically
22
+ using the methods: :meth:`include_flags` and :meth:`link_flags`.
23
+
24
+ .. versionchanged:: 0.6.0
25
+
26
+ - The gcc compiler has been deprecated in favour of clang and libraries
27
+ updated to version 1.1.1 (LTS - supported until 11th September 2023)
28
+ - Added two new methods to make easier to link with openssl:
29
+ :meth:`include_flags` and :meth:`link_flags`
30
+ - subclassed versioned_url
31
+ - Adapted method :meth:`select_build_arch` to API 21+
32
+
33
+ '''
34
+
35
+ version = '1.1'
36
+ '''the major minor version used to link our recipes'''
37
+
38
+ url_version = '1.1.1'
39
+ '''the version used to download our libraries'''
40
+
41
+ url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz'
42
+
43
+ @property
44
+ def versioned_url (self ):
45
+ if self .url is None :
46
+ return None
47
+ return self .url .format (url_version = self .url_version )
48
+
49
+ def include_flags (self , arch ):
50
+ '''Returns a string with the include folders'''
51
+ openssl_includes = join (self .get_build_dir (arch .arch ), 'include' )
52
+ return ' -I' + openssl_includes + \
53
+ ' -I' + join (openssl_includes , 'internal' ) + \
54
+ ' -I' + join (openssl_includes , 'openssl' )
55
+
56
+ def link_flags (self , arch ):
57
+ '''Returns a string with the right link flags to compile against the
58
+ openssl libraries'''
59
+ build_dir = self .get_build_dir (arch .arch )
60
+ return ' -L' + build_dir + \
61
+ ' -lcrypto{version} -lssl{version}' .format (version = self .version )
10
62
11
63
def should_build (self , arch ):
12
64
return not self .has_libs (arch , 'libssl' + self .version + '.so' ,
@@ -21,20 +73,20 @@ def check_symbol(self, env, sofile, symbol):
21
73
print ('{} missing symbol {}; rebuilding' .format (sofile , symbol ))
22
74
return False
23
75
24
- def get_recipe_env (self , arch = None ):
25
- env = super (OpenSSLRecipe , self ).get_recipe_env (arch )
76
+ def get_recipe_env (self , arch = None , with_flags_in_cc = True , clang = True ):
77
+ env = super (OpenSSLRecipe , self ).get_recipe_env (
78
+ arch , with_flags_in_cc = True , clang = True )
26
79
env ['OPENSSL_VERSION' ] = self .version
27
- env ['CFLAGS' ] += ' ' + env ['LDFLAGS' ]
28
- env ['CC' ] += ' ' + env ['LDFLAGS' ]
29
80
env ['MAKE' ] = 'make' # This removes the '-j5', which isn't safe
81
+ env ['ANDROID_NDK' ] = self .ctx .ndk_dir
30
82
return env
31
83
32
84
def select_build_arch (self , arch ):
33
85
aname = arch .arch
34
86
if 'arm64' in aname :
35
87
return 'linux-aarch64'
36
88
if 'v7a' in aname :
37
- return 'android-armv7 '
89
+ return 'android-arm '
38
90
if 'arm' in aname :
39
91
return 'android'
40
92
if 'x86' in aname :
@@ -48,16 +100,17 @@ def build_arch(self, arch):
48
100
# so instead we manually run perl passing in Configure
49
101
perl = sh .Command ('perl' )
50
102
buildarch = self .select_build_arch (arch )
51
- shprint (perl , 'Configure' , 'shared' , 'no-dso' , 'no-krb5' , buildarch , _env = env )
103
+ shprint (perl , 'Configure' , 'shared' , 'no-dso' , 'no-asm' , buildarch ,
104
+ '-D__ANDROID_API__={}' .format (self .ctx .ndk_api ),
105
+ _env = env )
52
106
self .apply_patch ('disable-sover.patch' , arch .arch )
53
- self .apply_patch ('rename-shared-lib.patch' , arch .arch )
54
107
55
- # check_ssl = partial(self.check_symbol, env, 'libssl' + self.version + '.so')
56
108
check_crypto = partial (self .check_symbol , env , 'libcrypto' + self .version + '.so' )
57
109
while True :
58
110
shprint (sh .make , 'build_libs' , _env = env )
59
- if all (map (check_crypto , ('SSLeay' , ' MD5_Transform' , 'MD4_Init' ))):
111
+ if all (map (check_crypto , ('MD5_Transform' , 'MD4_Init' ))):
60
112
break
113
+ time .sleep (3 )
61
114
shprint (sh .make , 'clean' , _env = env )
62
115
63
116
self .install_libs (arch , 'libssl' + self .version + '.so' ,
0 commit comments