1
- import os
1
+ import re
2
+ from pythonforandroid .logger import info
2
3
from pythonforandroid .recipe import CompiledComponentsPythonRecipe
3
4
4
5
@@ -9,19 +10,24 @@ class GeventRecipe(CompiledComponentsPythonRecipe):
9
10
patches = ["gevent.patch" ]
10
11
11
12
def get_recipe_env (self , arch = None , with_flags_in_cc = True ):
13
+ """
14
+ - Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
15
+ - Moves all -l<lib> from LDFLAGS to LIBS environment.
16
+ - Fixes linker name (use cross compiler) and flags (appends LIBS)
17
+ """
12
18
env = super (GeventRecipe , self ).get_recipe_env (arch , with_flags_in_cc )
13
- # sets linker to use the correct gcc (cross compiler)
14
- env ['LDSHARED' ] = env ['CC' ] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
15
19
# CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS
16
- env ['CPPFLAGS' ] = env ['CFLAGS' ] + ' -I{}/sources/python/3.5/include/python/' .format (self .ctx .ndk_dir )
17
- env ['CFLAGS' ] = ''
20
+ regex = re .compile ('\s*-[DI][\S]+' )
21
+ env ['CPPFLAGS' ] = '' .join (re .findall (regex , env ['CFLAGS' ])).strip ()
22
+ env ['CFLAGS' ] = re .sub (regex , '' , env ['CFLAGS' ])
23
+ info ('Moved "{}" from CFLAGS to CPPFLAGS.' .format (env ['CPPFLAGS' ]))
18
24
# LDFLAGS may only be used to specify linker flags, for libraries use LIBS
19
- env [ 'LDFLAGS' ] = env [ 'LDFLAGS' ]. replace ( '-lm' , '' ). replace ( '-lcrystax' , ' ' )
20
- env ['LDFLAGS ' ] + = ' -L{}' . format ( os . path . join (self . ctx . bootstrap . build_dir , 'libs' , arch . arch ) )
21
- env ['LIBS ' ] = ' -lm'
22
- if self . ctx . ndk == 'crystax' :
23
- env [ 'LIBS' ] += ' -lcrystax -lpython{}m' . format ( self . ctx . python_recipe . version [ 0 : 3 ])
24
- env ['LDSHARED' ] += env ['LIBS' ]
25
+ regex = re . compile ( '\s*-l[\w\.]+ ' )
26
+ env ['LIBS ' ] = '' . join (re . findall ( regex , env [ 'LDFLAGS' ])). strip ( )
27
+ env ['LDFLAGS ' ] = re . sub ( regex , '' , env [ 'LDFLAGS' ])
28
+ info ( 'Moved "{}" from LDFLAGS to LIBS.' . format ( env [ 'LIBS' ]))
29
+ # linker to use the correct gcc (cross compiler) plus additional libs
30
+ env ['LDSHARED' ] = '{} -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions {}' . format ( env ['CC' ], env [ ' LIBS' ])
25
31
return env
26
32
27
33
0 commit comments