Repository: conan-io/conan-center-index

Issue:
[package] mpir/3.0.0: autotools fails to discover working compiler on macOS
<!-- 
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.
-->

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **mpir/3.0.0**
  * Operating System+version: **MacOS 10.15.7**
  * Compiler+version: **Apple clang version 12.0.0**
  * Conan version: **conan 1.30.1**
  * Python version: **Python 3.8.2**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=apple-clang
compiler.version=12.0
compiler.libcxx=libc++
build_type=Release
[options]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
Found when trying to reproduce https://github.com/conan-io/conan-center-index/pull/1694 with `--build missing` on macos:
`````
$ git remote add bincrafters https://github.com/bincrafters/conan-center-index.git
$ git fetch bincrafters
$ git checkout gcc
$ cd recipes/gcc/all
$ conan create . gcc/10.1.0@ --build missing
``````
Can be reproduced by it's own by just compiling `mpir` from it's folder:
````
$ cd recipes/mpir/all
$ conan create . mpir/3.0.0@ --build missing
````

Apparently apple-clang adds -Wimplicit-function-declaration + using C99 as default which makes older code to fail:
`error: implicit declaration of function 'g' is invalid in C99 [-Werror,-Wimplicit-function-declaration]`

Maybe a patch is required to add `-Wno-implicit-function-declaration` ? 

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

Console output:
```
$ conan create . mpir/3.0.0@ --build missing                                                                                                    22:02:02
Exporting package recipe
mpir/3.0.0 exports: File 'conandata.yml' found. Exporting it...
mpir/3.0.0 exports: Copied 1 '.yml' file: conandata.yml
mpir/3.0.0: A new conanfile.py version was exported
mpir/3.0.0: Folder: /Users/_/.conan/data/mpir/3.0.0/_/_/export
mpir/3.0.0: Using the exported files summary hash as the recipe revision: 74dd97889e8a272693cfe1e8dce69c65 
mpir/3.0.0: Package recipe modified in export, forcing source folder removal
mpir/3.0.0: Use the --keep-source, -k option to skip it
mpir/3.0.0: Exported revision: 74dd97889e8a272693cfe1e8dce69c65
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
os_build=Macos
[options]
[build_requires]
[env]

mpir/3.0.0 (test package): Installing package
Requirements
    mpir/3.0.0 from 'conan-center' - Cache
Packages
    mpir/3.0.0:6a83d7f783e7ee89a83cf2fe72b5f5f67538e2a6 - Build
Build requirements
    yasm/1.3.0 from 'conan-center' - Cache
Build requirements packages
    yasm/1.3.0:743cf0321be3152777da4d05247a66d1552e70a2 - Cache

Installing (downloading, building) binaries...
yasm/1.3.0: Already installed!
mpir/3.0.0: Applying build-requirement: yasm/1.3.0
mpir/3.0.0: Configuring sources in /Users/_/.conan/data/mpir/3.0.0/_/_/source
Downloading mpir-3.0.0.zip completed [7067.38k]                                          

Unzipping 26.5MB, this can take a while
Unzipping 100 %                                                       
mpir/3.0.0: Copying sources to build folder
mpir/3.0.0: Building your package in /Users/_/.conan/data/mpir/3.0.0/_/_/build/6a83d7f783e7ee89a83cf2fe72b5f5f67538e2a6
mpir/3.0.0: Generator txt created conanbuildinfo.txt
mpir/3.0.0: Calling build()
mpir/3.0.0: Calling:
 > ./configure '--disable-shared' '--enable-static' '--disable-silent-rules' '--enable-gmpcompat' '--enable-cxx' '--prefix=/Users/_/.conan/data/mpir/3.0.0/_/_/package/6a83d7f783e7ee89a83cf2fe72b5f5f67538e2a6' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libexecdir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' '--datarootdir=${prefix}/share' 
checking build system type... x86_64-apple-darwin19.6.0
checking host system type... x86_64-apple-darwin19.6.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=64
checking compiler gcc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG... no, long long reliability test 2
checking whether cc is gcc... yes
checking compiler cc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG... no, long long reliability test 2
checking ABI=32
checking compiler gcc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG... no, long long reliability test 2
checking compiler icc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG... no
checking whether cc is gcc... yes
checking compiler cc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG... no, long long reliability test 2
configure: error: could not find a working compiler, see config.log for details
mpir/3.0.0: 
mpir/3.0.0: ERROR: Package '6a83d7f783e7ee89a83cf2fe72b5f5f67538e2a6' build failed
mpir/3.0.0: WARN: Build folder /Users/_/.conan/data/mpir/3.0.0/_/_/build/6a83d7f783e7ee89a83cf2fe72b5f5f67538e2a6
ERROR: mpir/3.0.0: Error in build() method, line 75
	autotools = self._configure_autotools()
while calling '_configure_autotools', line 67
	self._autotools.configure(args=args)
	ConanException: Error 1 while executing ./configure '--disable-shared' '--enable-static' '--disable-silent-rules' '--enable-gmpcompat' '--enable-cxx' '--prefix=/Users/_/.conan/data/mpir/3.0.0/_/_/package/6a83d7f783e7ee89a83cf2fe72b5f5f67538e2a6' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libexecdir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' '--datarootdir=${prefix}/share'
```

interesting part of config.log:
``````
configure:5664: cc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG conftest.c >&5
conftest.c:1:43: warning: non-void function does not return a value [-Wreturn-type]
int k; int foo () { __builtin_alloca (k); }
                                          ^
1 warning generated.
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:5667: $? = 1
failed program was:
int k; int foo () { __builtin_alloca (k); }
Test compile: long long reliability test 1
configure:5787: cc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG conftest.c >&5
configure:5790: $? = 0
configure:5795: ./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest
configure:5798: $? = 0
Test compile: long long reliability test 2
configure:5847: cc -m64 -O3 -fPIC -I/Users/_/.conan/data/yasm/1.3.0/_/_/package/743cf0321be3152777da4d05247a66d1552e70a2/include -DNDEBUG conftest.c >&5
conftest.c:6:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
^
conftest.c:6:62: error: implicit declaration of function 'g' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
                                                             ^
conftest.c:6:75: warning: non-void function does not return a value [-Wreturn-type]
f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
                                                                          ^
conftest.c:7:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
g(){}
^
conftest.c:7:5: warning: non-void function does not return a value [-Wreturn-type]
g(){}
    ^
4 warnings and 1 error generated.
configure:5850: $? = 1
failed program was:
/* The following provokes an internal compiler error on powerpc-apple-darwin.
   Extracted from mpz/cfdiv_q_2exp.c.  Causes Apple's gcc 3.3 build 1640 and
   1666 to get an ICE with -O1 -mpowerpc64.  */

#ifdef __GNUC__
f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
g(){}
#else
int dummy;
#endif

int main () { return 0; }
configure:6195: result: no, long long reliability test 2
configure:6355: error: could not find a working compiler, see config.log for details


``````
</details>



Discussion:

Resolving patch:
diff --git a/recipes/mpir/all/conanfile.py b/recipes/mpir/all/conanfile.py
--- a/recipes/mpir/all/conanfile.py
+++ b/recipes/mpir/all/conanfile.py
@@ -103,6 +103,9 @@ def _configure_autotools(self):
             args.append("--disable-silent-rules")
             args.append("--enable-cxx" if self.options.get_safe("enable_cxx") else "--disable-cxx")
             args.append("--enable-gmpcompat" if self.options.enable_gmpcompat else "--disable-gmpcompat")
+
+            # compiler checks are written for C89 but compilers that default to C99 treat implicit functions as error
+            self._autotools.flags.append("-Wno-implicit-function-declaration")            
             self._autotools.configure(args=args)
         return self._autotools
 


Test patch:
diff --git a/recipes/mpir/all/test_package/CMakeLists.txt b/recipes/mpir/all/test_package/CMakeLists.txt
--- a/recipes/mpir/all/test_package/CMakeLists.txt
+++ b/recipes/mpir/all/test_package/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.8.12)
+cmake_minimum_required(VERSION 3.1)
 project(test_package)
 
 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)