Repository: conan-io/conan-center-index

Issue:
[package] gmp/6.1.2: can't be built with mingw
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **gmp/6.1.2**
  * Operating System+version: **Windows 10 1903**
  * Compiler+version: **GCC 8**
  * Conan version: **conan 1.19.1**
  * Python version: **Python 3.7.3**

### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=8
compiler.exception=seh
compiler.libcxx=libstdc++11
compiler.threads=posix
build_type=Release
[options]
[build_requires]
*: mingw_installer/1.0@conan/stable, msys2_installer/latest@bincrafters/stable
[env]
```

### Steps to reproduce (Include if Applicable)
conanfile.txt
```
[requires]
gmp/6.1.2@bincrafters/stable

[generators]
txt
```

Running from Git bash
```
conan install --profile mingw -o gmp:disable_assembly=False -o gmp:enable_cxx=False -o gmp:fPIC=True -o gmp:run_checks=True -o gmp:shared=True --build gmp ../build_gmp
```

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
gmp/6.1.2@bincrafters/stable: Copying sources to build folder
gmp/6.1.2@bincrafters/stable: Building your package in C:\.conan\data\gmp\6.1.2\bincrafters\stable\build\92709a555eae5613e66076e2183cc3e52e0cd0e5
gmp/6.1.2@bincrafters/stable: Generator txt created conanbuildinfo.txt
gmp/6.1.2@bincrafters/stable: Calling build()
gmp/6.1.2@bincrafters/stable: WARN: Error running `configure --help`: Error 1 while executing source_subfolder/configure --help
gmp/6.1.2@bincrafters/stable: Calling:
 > source_subfolder/configure --enable-shared --disable-static --prefix=C:/.conan/data/gmp/6.1.2/bincrafters/stable/package/92709a555eae5613e66076e2183cc3e52e0cd0e5
'source_subfolder' is not recognized as an internal or external command,
operable program or batch file.
gmp/6.1.2@bincrafters/stable:
gmp/6.1.2@bincrafters/stable: ERROR: Package '92709a555eae5613e66076e2183cc3e52e0cd0e5' build failed
gmp/6.1.2@bincrafters/stable: WARN: Build folder C:\.conan\data\gmp\6.1.2\bincrafters\stable\build\92709a555eae5613e66076e2183cc3e52e0cd0e5
ERROR: gmp/6.1.2@bincrafters/stable: Error in build() method, line 66
        autotools = self._configure_autotools()
while calling '_configure_autotools', line 62
        self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder)
        ConanException: Error 1 while executing source_subfolder/configure --enable-shared --disable-static --prefix=C:/.conan/data/gmp/6.1.2/bincrafters/stable/package/92709a555eae5613e66076e2183cc3e52e0cd0e5
```
</details>

Replacing
```self._autotools = AutoToolsBuildEnvironment(self)```
with
```self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)```
allows to go further.

<details><summary>Click to expand log</summary>

```
gmp/6.1.2@bincrafters/stable: checking if the .align directive accepts an 0x90 fill in .text... yes
gmp/6.1.2@bincrafters/stable: checking size of void *... 8
gmp/6.1.2@bincrafters/stable: checking size of unsigned short... 2
gmp/6.1.2@bincrafters/stable: checking size of unsigned... 4
gmp/6.1.2@bincrafters/stable: checking size of unsigned long... 4
gmp/6.1.2@bincrafters/stable: checking size of mp_limb_t... 0
gmp/6.1.2@bincrafters/stable: configure: error: Oops, mp_limb_t doesn't seem to work
gmp/6.1.2@bincrafters/stable:
gmp/6.1.2@bincrafters/stable: ERROR: Package '92709a555eae5613e66076e2183cc3e52e0cd0e5' build failed
gmp/6.1.2@bincrafters/stable: WARN: Build folder C:\.conan\data\gmp\6.1.2\bincrafters\stable\build\92709a555eae5613e66076e2183cc3e52e0cd0e5
ERROR: gmp/6.1.2@bincrafters/stable: Error in build() method, line 66
        autotools = self._configure_autotools()
while calling '_configure_autotools', line 62
        self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder)
        ConanException: Error 1 while executing /c/.conan/data/gmp/6.1.2/bincrafters/stable/build/92709a555eae5613e66076e2183cc3e52e0cd0e5/source_subfolder/configure --enable-shared --disable-static --prefix=C:/.conan/data/gmp/6.1.2/bincrafters/stable/package/92709a555eae5613e66076e2183cc3e52e0cd0e5
```
</details>

Next I've tried adding 
```with tools.chdir(self._source_subfolder):```
to build and package steps for autotools. And removed ```configure_dir=self._source_subfolder``` from ```self._autotools.configure```

This has allowed me to build gmp but I'm not sure that it is the right way.



Discussion:
This way I get 2 files: .lib and .dll which are completely the same. So I had to also create import library manually.
@Nekto89 Are you using the version from this repo or the bincrafters version?
I can reproduce with the CCI version.

`config.log` shows the following lines:
```
configure:27494: checking size of mp_limb_t
configure:27499: /c/users/maarten/.conan/data/mingw_installer/1.0/conan/stable/package/649c186bbe7e6cd995c27c9e2e8ee09fe6c43e00/bin/gcc.exe -o conftest.exe -m64 -O3 -s -I/c/users/maarten/.conan/data/mingw_installer/1.0/conan/stable/package/649c186bbe7e6cd995c27c9e2e8ee09fe6c43e00/include -DNDEBUG -D_GLIBCXX_USE_CXX11_ABI=0 -m64 -L/c/users/maarten/.conan/data/mingw_installer/1.0/conan/stable/package/649c186bbe7e6cd995c27c9e2e8ee09fe6c43e00/lib conftest.c  >&5
conftest.c:85:10: fatal error: /c/users/maarten/.conan/data/gmp/6.1.2/_/_/build/ff67b0370bc595303e654a991b6c55e6be0b3e32/source_subfolder/gmp-h.in: No such file or directory
 #include "/c/users/maarten/.conan/data/gmp/6.1.2/_/_/build/ff67b0370bc595303e654a991b6c55e6be0b3e32/source_subfolder/gmp-h.in"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
configure:27499: $? = 1
configure: program exited with status 1
```
This path is a win_bash path (I'm using `msys2/20161025`) and mingw apparently cannot cope with it.
(I'm using `mingw_installer/1.0@conan/stable`)

Resolving patch:
diff --git a/recipes/gmp/all/conanfile.py b/recipes/gmp/all/conanfile.py
--- a/recipes/gmp/all/conanfile.py
+++ b/recipes/gmp/all/conanfile.py
@@ -37,9 +37,9 @@ def source(self):
 
     def _configure_autotools(self):
         if not self._autotools:
-            self._autotools = AutoToolsBuildEnvironment(self)
+            self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
             if self.settings.os == "Macos":
-                configure_file = os.path.join(self._source_subfolder, "configure")
+                configure_file = "configure"
                 tools.replace_in_file(configure_file, r"-install_name \$rpath/", "-install_name ")
                 configure_stats = os.stat(configure_file)
                 os.chmod(configure_file, configure_stats.st_mode | stat.S_IEXEC)
@@ -52,12 +52,13 @@ def _configure_autotools(self):
                 configure_args.extend(["--disable-shared", "--enable-static"])
             if self.options.enable_cxx:
                 configure_args.append('--enable-cxx')
-            self._autotools.configure(args=configure_args, configure_dir=self._source_subfolder)
+            self._autotools.configure(args=configure_args)
         return self._autotools
 
     def build(self):
-        autotools = self._configure_autotools()
-        autotools.make()
+        with tools.chdir(self._source_subfolder):
+            autotools = self._configure_autotools()
+            autotools.make()
         # INFO: According to the gmp readme file, make check should not be omitted, but it causes timeouts on the CI server.
         if self.options.run_checks:
             autotools.make(args=['check'])
@@ -65,8 +66,9 @@ def build(self):
     def package(self):
         self.copy("COPYINGv2", dst="licenses", src=self._source_subfolder)
         self.copy("COPYING.LESSERv3", dst="licenses", src=self._source_subfolder)
-        autotools = self._configure_autotools()
-        autotools.install()
+        with tools.chdir(self._source_subfolder):
+            autotools = self._configure_autotools()
+            autotools.install()
         tools.rmdir(os.path.join(self.package_folder, "share"))
         # remove la files
         for la_name in ['libgmp.la', 'libgmpxx.la']:


Test patch: