Repository: conan-io/conan-center-index

Issue:
[package] mingw-w64/8.0.2: failed to create symbolic link
<!-- 
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.
-->

Trying to install mingw-w64/8.0.2 on linux fails with
```
ln: failed to create symbolic link '/home/conan/.conan/data/mingw-w64/8.0.2/_/_/package/4cfe33ba23f3b0106f09220780349c6834f3da6e/mingw': File exists
```

Although the symbolic link is created in `package_info` https://github.com/conan-io/conan-center-index/blob/90da06e2efe561a27ac8b43aa637ce6028bae929/recipes/mingw-w64/linux/conanfile.py#L310-L313
it exists on the binary package and so when the package is installed conan fails to recreate it.

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **mingw-w64/8.0.2**
  * Operating System+version: **Linux Ubuntu 18.04**
  * Docker image: **conanio/gcc5:1.43.0**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=5
os=Linux
os_build=Linux
[options]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
docker run --rm -it conanio/gcc5:1.43.0 conan install mingw-w64/8.0.2@


### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
Auto detecting your dev setup to initialize the default profile (/home/conan/.conan/profiles/default)
CC and CXX: /usr/bin/gcc, /usr/bin/g++ 
Found gcc 5.4
gcc>=5, using the major as version

************************* WARNING: GCC OLD ABI COMPATIBILITY ***********************
 
Conan detected a GCC version > 5 but has adjusted the 'compiler.libcxx' setting to
'libstdc++' for backwards compatibility.
Your compiler is likely using the new CXX11 ABI by default (libstdc++11).

If you want Conan to use the new ABI for the default profile, run:

    $ conan profile update settings.compiler.libcxx=libstdc++11 default

Or edit '/home/conan/.conan/profiles/default' and set compiler.libcxx=libstdc++11

************************************************************************************



Default settings
        os=Linux
        os_build=Linux
        arch=x86_64
        arch_build=x86_64
        compiler=gcc
        compiler.version=5
        compiler.libcxx=libstdc++
        build_type=Release
*** You can change them in /home/conan/.conan/profiles/default ***
*** Or override with -s compiler='other' -s ...s***


WARN: Remotes registry file missing, creating default one in /home/conan/.conan/remotes.json
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++
compiler.version=5
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

mingw-w64/8.0.2: Not found in local cache, looking in remotes...
mingw-w64/8.0.2: Trying with 'conancenter'...
Downloading conanmanifest.txt completed [0.10k]                                          
Downloading conanfile.py completed [17.74k]                                              
Downloading conan_export.tgz completed [0.57k]                                           
Decompressing conan_export.tgz completed [0.00k]                                         
mingw-w64/8.0.2: Downloaded recipe revision 0
Installing package: mingw-w64/8.0.2
Requirements
    mingw-w64/8.0.2 from 'conancenter' - Downloaded
Packages
    mingw-w64/8.0.2:4cfe33ba23f3b0106f09220780349c6834f3da6e - Download

Installing (downloading, building) binaries...
mingw-w64/8.0.2: Retrieving package 4cfe33ba23f3b0106f09220780349c6834f3da6e from remote 'conancenter' 
Downloading conanmanifest.txt completed [335.86k]                                        
Downloading conaninfo.txt completed [0.30k]                                              
Downloading conan_package.tgz completed [118882.32k]                                     
Decompressing conan_package.tgz completed [0.00k]                                        
mingw-w64/8.0.2: Package installed 4cfe33ba23f3b0106f09220780349c6834f3da6e
mingw-w64/8.0.2: Downloaded package revision 0
mingw-w64/8.0.2: Appending PATH env var with : /home/conan/.conan/data/mingw-w64/8.0.2/_/_/package/4cfe33ba23f3b0106f09220780349c6834f3da6e/bin
ln: failed to create symbolic link '/home/conan/.conan/data/mingw-w64/8.0.2/_/_/package/4cfe33ba23f3b0106f09220780349c6834f3da6e/mingw': File exists
ERROR: mingw-w64/8.0.2: Error in package_info() method, line 313
        os.path.join(self.package_folder, 'mingw')))
        ConanException: Error 1 while executing ln -s /home/conan/.conan/data/mingw-w64/8.0.2/_/_/package/4cfe33ba23f3b0106f09220780349c6834f3da6e/x86_64-w64-mingw32 /home/conan/.conan/data/mingw-w64/8.0.2/_/_/package/4cfe33ba23f3b0106f09220780349c6834f3da6e/mingw```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/mingw-w64/linux/conanfile.py b/recipes/mingw-w64/linux/conanfile.py
--- a/recipes/mingw-w64/linux/conanfile.py
+++ b/recipes/mingw-w64/linux/conanfile.py
@@ -35,6 +35,9 @@ def validate(self):
                 raise ConanInvalidConfiguration("gcc version {} is not in the list of valid versions: {}"
                                                 .format(str(self.options.gcc), valid_gcc))
 
+    def build_requirements(self):
+        self.build_requires("m4/1.4.19")
+
     def _download_source(self):
         arch_data = self.conan_data["sources"][self.version]
 
@@ -257,16 +260,17 @@ def build(self):
 
     def package(self):
         self.copy("COPYING", src=os.path.join(self.build_folder, "sources", "mingw-w64"), dst="licenses")
-        tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
-        tools.remove_files_by_mask(os.path.join(self.package_folder, "x86_64-w64-mingw32", "lib"), "*.la")
-        tools.remove_files_by_mask(os.path.join(self.package_folder, "x86_64-w64-mingw32", "lib32"), "*.la")
-        tools.remove_files_by_mask(os.path.join(self.package_folder, "bin", "gcc", "x86_64-w64-mingw32", "10.3.0"), "*.la")
+        tools.remove_files_by_mask(self.package_folder, "*.la")
         tools.rmdir(os.path.join(self.package_folder, "share", "man"))
         tools.rmdir(os.path.join(self.package_folder, "share", "doc"))
         tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
-        # Remove symlinks, we need to create them in the package_info step
+        # replace with relative symlinks so they'll resolve correctly on consumer's machine
         os.unlink(os.path.join(self.package_folder, 'mingw'))
         os.unlink(os.path.join(self.package_folder, self._target_tag, 'lib64'))
+        self.run("ln -s {} {}".format(os.path.join(os.curdir, self._target_tag),
+                                        os.path.join(self.package_folder, 'mingw')))
+        self.run("ln -s {} {}".format(os.path.join(os.curdir, 'lib'),
+                                        os.path.join(self.package_folder, self._target_tag, 'lib64')))
 
     def package_info(self):
         if getattr(self, "settings_target", None):
@@ -307,10 +311,4 @@ def package_info(self):
         self.env_info.STRIP = prefix + "strip"
         self.env_info.GCOV = prefix + "gcov"
         self.env_info.RC = prefix + "windres"
-        # Symlinks cannot be created in package step, otherwise the link target is wrong.
-        if not os.path.exists(os.path.join(self.package_folder, 'mingw')):
-            self.run("ln -s {} {}".format(os.path.join(self.package_folder, self._target_tag),
-                                            os.path.join(self.package_folder, 'mingw')))
-        if not os.path.exists(os.path.join(self.package_folder, self._target_tag, 'lib64')):
-            self.run("ln -s {} {}".format(os.path.join(self.package_folder, self._target_tag, 'lib'),
-                                            os.path.join(self.package_folder, self._target_tag, 'lib64')))
+        self.env_info.DLLTOOL = prefix + "dlltool"


Test patch: