Repository: conan-io/conan-center-index

Issue:
[package] Error building OpenSSL for Android
While building OpenSSL for android on macOS I've seen the following issue when building for arm:

`openssl/conanfile.py` modifies `Makefile.org` with a string replace `AR=arm-linux-androideabi-ar` this replace is somehow triggered two times resulting in `AR=arm-linux-androideabi-arm-linux-androideabi-ar`.

I think the problem always triggers when using an `arm-` prefix as this also matches searching for `AR=ar`

My conanfile.txt:
```
[requires]
OpenSSL/1.0.2s@conan/stable
Poco/1.9.3@pocoproject/stable

[generators]
cmake
```

My profile:
```
ndk_root=$HOME/Library/Android/sdk/ndk-bundle
standalone_toolchain=$HOME/Development/toolchains/android-16-arm/
target_host=arm-linux-androideabi
cc_compiler=clang
cxx_compiler=clang++

[settings]
compiler=clang
compiler.version=8
compiler.libcxx=libc++
os=Android
os.api_level=16
arch=armv7
build_type=Release

[env]
CONAN_CMAKE_TOOLCHAIN_FILE=$ndk_root/build/cmake/android.toolchain.cmake
CONAN_CMAKE_FIND_ROOT_PATH=$standalone_toolchain/sysroot
PATH=[$standalone_toolchain/bin]
CHOST=$target_host
AR=\$target_host-ar
AS=$target_host-as
RANLIB=$target_host-ranlib
CC=$target_host-$cc_compiler
CXX=$target_host-$cxx_compiler
LD=$target_host-ld
STRIP=$target_host-strip
CFLAGS= -fPIE -fPIC -I$standalone_toolchain/include/c++/4.9.x
CXXFLAGS= -fPIE -fPIC -I$standalone_toolchain/include/c++/4.9.x
LDFLAGS= -pie

```


Discussion:
The openssl recipe version here in the conan-center-index is NOT

`OpenSSL/1.0.2s@conan/stable`

please change it to `openssl/1.0.2s` and try again
I've changed the requires to :
```
[requires]
poco/1.9.3
```

Results in the same issue if I do not use `AR=\` instead of `AR`

Resolving patch:
diff --git a/recipes/openssl/ALL/conanfile.py b/recipes/openssl/ALL/conanfile.py
--- a/recipes/openssl/ALL/conanfile.py
+++ b/recipes/openssl/ALL/conanfile.py
@@ -1,5 +1,6 @@
 import os
 import fnmatch
+import platform
 from functools import total_ordering
 from conans.errors import ConanInvalidConfiguration, ConanException
 from conans import ConanFile, AutoToolsBuildEnvironment, tools
@@ -300,22 +301,25 @@ def _tool(self, env_name, apple_name):
     def _patch_makefile_org(self):
         # https://wiki.openssl.org/index.php/Compilation_and_Installation#Modifying_Build_Settings
         # its often easier to modify Configure and Makefile.org rather than trying to add targets to the configure scripts
+        def adjust_path(path):
+            return path.replace("\\", "/") if tools.os_info.is_windows else path
+
         makefile_org = os.path.join(self._source_subfolder, "Makefile.org")
         env_build = self._get_env_build()
         with tools.environment_append(env_build.vars):
             cc = os.environ.get("CC", "cc")
-            tools.replace_in_file(makefile_org, "CC= cc", "CC= %s %s" % (cc, os.environ["CFLAGS"]))
+            tools.replace_in_file(makefile_org, "CC= cc\n", "CC= %s %s\n" % (adjust_path(cc), os.environ["CFLAGS"]))
             if "AR" in os.environ:
-                tools.replace_in_file(makefile_org, "AR=ar", "AR=%s" % os.environ["AR"])
+                tools.replace_in_file(makefile_org, "AR=ar $(ARFLAGS) r\n", "AR=%s $(ARFLAGS) r\n" % adjust_path(os.environ["AR"]))
             if "RANLIB" in os.environ:
-                tools.replace_in_file(makefile_org, "RANLIB= ranlib", "RANLIB= %s" % os.environ["RANLIB"])
+                tools.replace_in_file(makefile_org, "RANLIB= ranlib\n", "RANLIB= %s\n" % adjust_path(os.environ["RANLIB"]))
             rc = os.environ.get("WINDRES", os.environ.get("RC"))
             if rc:
-                tools.replace_in_file(makefile_org, "RC= windres", "RC= %s" % rc)
+                tools.replace_in_file(makefile_org, "RC= windres\n", "RC= %s\n" % adjust_path(rc))
             if "NM" in os.environ:
-                tools.replace_in_file(makefile_org, "NM= nm", "NM= %s" % os.environ["NM"])
+                tools.replace_in_file(makefile_org, "NM= nm\n", "NM= %s\n" % adjust_path(os.environ["NM"]))
             if "AS" in os.environ:
-                tools.replace_in_file(makefile_org, "AS=$(CC) -c", "AS=%s" % os.environ["AS"])
+                tools.replace_in_file(makefile_org, "AS=$(CC) -c\n", "AS=%s\n" % adjust_path(os.environ["AS"]))
 
     def _get_env_build(self):
         if not self._env_build:
@@ -364,7 +368,7 @@ def _configure_args(self):
                 lib_path = "%s/%s.lib" % (zlib_info.lib_paths[0], zlib_info.libs[0])
             else:
                 lib_path = zlib_info.lib_paths[0]  # Just path, linux will find the right file
-            if self.settings.os == "Windows":
+            if tools.os_info.is_windows:
                 # clang-cl doesn't like backslashes in #define CFLAGS (builldinf.h -> cversion.c)
                 include_path = include_path.replace('\\', '/')
                 lib_path = lib_path.replace('\\', '/')
@@ -518,9 +522,28 @@ def build(self):
                     self._patch_makefile_org()
                 self._make()
 
+    @staticmethod
+    def detected_os():
+        if tools.OSInfo().is_macos:
+            return "Macos"
+        if tools.OSInfo().is_windows:
+            return "Windows"
+        return platform.system()
+
+    @property
+    def _cross_building(self):
+        if tools.cross_building(self.settings):
+            if self.settings.os == self.detected_os():
+                if self.settings.arch == "x86" and tools.detected_architecture() == "x86_64":
+                    return False
+            return True
+        return False
+
     @property
     def _win_bash(self):
-        return tools.os_info.is_windows and (self._is_mingw or tools.cross_building(self.settings))
+        return tools.os_info.is_windows and \
+               not self._use_nmake and \
+               (self._is_mingw or self._cross_building(self.settings))
 
     @property
     def _make_program(self):


Test patch: