Repository: kivy/python-for-android

Issue:
Fix/clean-up LDSHARED 
`LDSHARED` doesn't seem to be set in `PythonRecipe` leading to failing compilation in some scenarios.
The compilation may be failing because p4a would then pick up the system linker rather than the cross-compiler one.
For this reasons some recipes added that change in their `get_recipe_env()` method, like below:
```python
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
```
As in last master commit 0dc7664 we have at least 17 of them:
```
$ grep -r "env\['LDSHARED'\] = env\['CC'\]" pythonforandroid/recipes/ | wc -l
17
```
 
In his PR JonasT tries to address it via `pythonforandroid/archs.py`, see https://github.com/kivy/python-for-android/pull/1357/files#diff-569e13021e33ced8b54385f55b49cbe6R115
This probably requires investigation to know where is the proper place to put it and then the pull request fixing it should also clean recipes overriding it in their `get_recipe_env()` method.


Discussion:
By the way, similar issue: ```env['CFLAGS'] += ' -I{}/sources/python/{}/include/python/'.format(self.ctx.ndk_dir, self.ctx.python_recipe.version[0:3])```

Your greenlet recipe pull request does that, mine does, I've seen yet another do it - maybe this should be handled centrally as well? I am pretty sure it could go in the same place in `archs.py`.
I added a pull request here: https://github.com/kivy/python-for-android/pull/1361 (still WIP, I'm building my app with it right now to see if things blow up)
Even though https://github.com/kivy/python-for-android/pull/1361 is now merged, we still need to clean existing recipes to remove redundant `env['LDSHARED']` override before closing the issue.
I think it would be great to also verify everything is going OK at unit test level e.g. checking all recipes `get_recipe_env()` behaviour.

Resolving patch:
diff --git a/pythonforandroid/recipes/pycryptodome/__init__.py b/pythonforandroid/recipes/pycryptodome/__init__.py
--- a/pythonforandroid/recipes/pycryptodome/__init__.py
+++ b/pythonforandroid/recipes/pycryptodome/__init__.py
@@ -6,11 +6,5 @@ class PycryptodomeRecipe(PythonRecipe):
     url = 'https://github.com/Legrandin/pycryptodome/archive/v{version}.tar.gz'
     depends = ['setuptools', 'cffi']
 
-    def get_recipe_env(self, arch=None, with_flags_in_cc=True):
-        env = super(PycryptodomeRecipe, self).get_recipe_env(arch, with_flags_in_cc)
-        # sets linker to use the correct gcc (cross compiler)
-        env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
-        return env
-
 
 recipe = PycryptodomeRecipe()
diff --git a/pythonforandroid/recipes/secp256k1/__init__.py b/pythonforandroid/recipes/secp256k1/__init__.py
--- a/pythonforandroid/recipes/secp256k1/__init__.py
+++ b/pythonforandroid/recipes/secp256k1/__init__.py
@@ -1,10 +1,11 @@
 import os
-from pythonforandroid.recipe import PythonRecipe
+from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe
 
 
-class Secp256k1Recipe(PythonRecipe):
+class Secp256k1Recipe(CppCompiledComponentsPythonRecipe):
 
-    url = 'https://github.com/ludbb/secp256k1-py/archive/master.zip'
+    version = '0.13.2.4'
+    url = 'https://github.com/ludbb/secp256k1-py/archive/{version}.tar.gz'
 
     call_hostpython_via_targetpython = False
 
@@ -17,29 +18,12 @@ class Secp256k1Recipe(PythonRecipe):
         "cross_compile.patch", "drop_setup_requires.patch",
         "pkg-config.patch", "find_lib.patch", "no-download.patch"]
 
-    def get_recipe_env(self, arch=None, with_flags_in_cc=True):
-        env = super(Secp256k1Recipe, self).get_recipe_env(arch, with_flags_in_cc)
-        # sets linker to use the correct gcc (cross compiler)
-        env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
+    def get_recipe_env(self, arch=None):
+        env = super(Secp256k1Recipe, self).get_recipe_env(arch)
         libsecp256k1 = self.get_recipe('libsecp256k1', self.ctx)
         libsecp256k1_dir = libsecp256k1.get_build_dir(arch.arch)
-        env['LDFLAGS'] += ' -L{}'.format(libsecp256k1_dir)
-        env['CFLAGS'] = ' -I' + os.path.join(libsecp256k1_dir, 'include')
-        # only keeps major.minor (discards patch)
-        python_version = self.ctx.python_recipe.version[0:3]
-        # required additional library and path for Crystax
-        if self.ctx.ndk == 'crystax':
-            ndk_dir_python = os.path.join(self.ctx.ndk_dir, 'sources/python/', python_version)
-            env['LDFLAGS'] += ' -L{}'.format(os.path.join(ndk_dir_python, 'libs', arch.arch))
-            env['LDFLAGS'] += ' -lpython{}m'.format(python_version)
-            # until `pythonforandroid/archs.py` gets merged upstream:
-            # https://github.com/kivy/python-for-android/pull/1250/files#diff-569e13021e33ced8b54385f55b49cbe6
-            env['CFLAGS'] += ' -I{}/include/python/'.format(ndk_dir_python)
-        else:
-            env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
-            env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python{}'.format(python_version)
-            env['LDFLAGS'] += " -lpython{}".format(python_version)
-        env['LDFLAGS'] += " -lsecp256k1"
+        env['CFLAGS'] += ' -I' + os.path.join(libsecp256k1_dir, 'include')
+        env['LDFLAGS'] += ' -L{} -lsecp256k1'.format(libsecp256k1_dir)
         return env
 
 


Test patch: