bug#75939: bug in compile wrapper when using MSVC from Msys2

Kirill Makurin <[email protected]> Wed, 29 Jan 2025 23:09:40 +0000
Newsgroups gmane.comp.sysutils.automake.bugs
Message-ID <MWHPR0601MB365868DCBE24A84067FF8060B1EE2@MWHPR0601MB3658.namprd06.prod.outlook.com>
Hi,

I would like to report one quite annoying issue related to Automake's `compile` wrapper when it is used with `cl.exe` to compile some C++ files from Msys2.

I was building some GNU packages with MSVC's `cl.exe`, and compilation of some C++ source files was failing with `cl.exe` reporting non-sensual filenames like `H:E:/Msys2/{builddir}/somefile.cxx`.

Apparently, the issue is double conversion of a unix-style filename by Msys2's shell. In example above, Msys2 is installed to `E:/Msys2` and builddir is `/h/{builddir}`.

As I figured out later, it was happening because `compile` was converting `/h/{builddir}/somefile.cxx` to `H:/{builddir}/somefile.cxx` and passing it as `-TpH:/{builddir}/somefile.cxx` to `cl.exe`. However, Msys2 was interpreting `/{builddir}/somefile.cxx` as a unix-style path and converted it again, resulting in `-TpH:E:/Msys2/{builddir}/somefile.cxx`.

One way to work around this issue is :

```
export MSYS2_ARG_CONV_EXCL='-Tp'
```

However, this must be set by the user, which is inconvenient. I wonder if anything can be done in the `compile` wrapper to fix this.

I am using latest versions of MSVC tools and `cl.exe` allows to pass argument to `-Tp` as a separate argument and this seems to work correctly. However, I don't know whether older versions of `cl.exe` allow it.

- Kirill Makurin