0

How can you distinguish between MSYS and MSYS2 and CYGWIN, e.g via a command or a predefined environment variable?

This distinction would be needed by tools like Scons to adapt generated command lines, e.g. by issuing double backslashed c:\\path\\to\\file or backticked `cygpath -w /c/path/to/file`.

Background: I would like to use MSYS2, because of its superior package management. Scons generates the /c/path/to/file on MSYS2, but csc (Microsoft's C# compiler) only allows Windows style paths.

Roland Puntaier
  • 3,250
  • 30
  • 35
  • MSYS may _allow_ you to use a path name such as 'C:\path\to\file', but it much prefers you to use '/c/path/to/file'. The issue should be moot anyway: when you invoke any native tool, (such as Microsoft's C# compiler), from the MSYS shell, the path name '/c/path/to/file' is converted on the fly, to its native windows equivalent, (possibly with regular '/' dirname separators, which _are_ valid in native path names). I don't know if MSYS2 does likewise -- I do not use it -- but I understood that it was supposed to. – Keith Marshall Sep 08 '15 at 19:12
  • MSYS does, but MSYS2 makes problems with `csc` ( error CS1504: Source file could not be opened), probably because MSYS2 is almost Cygwin. – Roland Puntaier Sep 09 '15 at 08:30
  • 1
    MSYS2 is an independent fork of cygwin; it is not supported by MinGW.org, (who do provide MSYS), for the very reason that it seems to have completely lost sight of the original _minimalist_ intent of MSYS, so becoming, as you say, "almost cygwin", (so why bother with it, rather than just use cygwin?) – Keith Marshall Sep 09 '15 at 09:40
  • Yeah, right. I turned to it in the search of an easy command line way to install MSYS with MinGW on Windows. The name MSYS2 is misleading. Now I do ``choco install git && choco install mingw`` and copy the ``tools/mingw64`` over ``git/mingw64`` and use ``git-bash``. – Roland Puntaier Sep 09 '15 at 10:53
  • The easy command line way to install MinGW+MSYS is `mingw-get install ...`, but right now we don't have a git package to go with that. Also, if you specifically want mingw-w64 -- which is very definitely ___not___ MinGW -- then I don't think there are any mingw-get aware packages for that either. – Keith Marshall Sep 09 '15 at 11:06
  • [Waf][https://waf.io/] works on MSYS2, because it uses python's subprocess module without shell. – Roland Puntaier Dec 14 '15 at 22:38

2 Answers2

0

I don't know of any environment variable which will reliably convey this information, but the output from uname -s should tell you.

Keith Marshall
  • 1,980
  • 15
  • 19
  • cygwin: `CYGWIN_NT-6.1-WOW64`, MSYS: `MINGW64_NT-6.1`, MSYS2: `MINGW64_NT-6.1`. So it does not help to distinguish between MSYS and MSYS2. I think this is an MSYS2 issue. I'll try to forward it there. Thx. – Roland Puntaier Sep 09 '15 at 08:18
  • @RolandPuntaier: What does `uname -o` say? Is it any more useful? – Keith Marshall Sep 09 '15 at 09:44
  • ``uname -o`` is cygwin: ``Cygwin``, MSYS: ``Msys``, MSYS2: ``Msys``. I.e no better :-) – Roland Puntaier Sep 09 '15 at 10:44
  • @RolandPuntaier: "_`uname -o` ... no better_". Then this is a deficiency in MSYS2, with which I am unable to help. You'll need to file a bug report with the appropriate project. – Keith Marshall Sep 09 '15 at 11:09
0

Check the system name and version:

case "$(uname -or)" in
    1.*Msys)  system='msys'   ;;
    2.*Msys)  system='msys2'  ;;
    .*Cygwin) system='cygwin' ;;
esac