[PATCH] Find mingw-builds include directory

Yaron Keren yaron.keren at gmail.com
Sun Oct 6 10:50:26 PDT 2013


I agree it's not very nice. The trouble is there is no registry or
environment entry set by the MingW installation to indicate where it is, so
you just search for it. It may be on the PATH or may not, depending if the
user set it.

While it is not complete efficient, my thinking was to make the directory
search future-proof in handling directory structure and version changes. I
did check the directory structure of mingw-builds installation
and i686-w64-mingw32 should be found quite fast, in the 9th iteration or
so.  It's not deep.
I can get rid of the iteration by assuming more about the directory
structure, hopefully it will not break in the future.

While at it, the existing code (below) includes many possible hardcoded
version paths (which actually does not work with all current and future
versions) and later prunes the non-existing ones:

  case llvm::Triple::MinGW32:
    // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
    AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
    // mingw.org C++ include paths
    AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2");
//MSYS
#if defined(_WIN32)
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
    AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
#endif

...
      // mingw-w64 crt include paths
      // <sysroot>/i686-w64-mingw32/include
      SmallString<128> P = StringRef(HSOpts.ResourceDir);
      llvm::sys::path::append(P, "../../../i686-w64-mingw32/include");
      AddPath(P.str(), System, false);

      // <sysroot>/x86_64-w64-mingw32/include
      P.resize(HSOpts.ResourceDir.size());
      llvm::sys::path::append(P, "../../../x86_64-w64-mingw32/include");
      AddPath(P.str(), System, false);

      // mingw.org crt include paths
      // <sysroot>/include
      P.resize(HSOpts.ResourceDir.size());
      llvm::sys::path::append(P, "../../../include");
      AddPath(P.str(), System, false);
      AddPath("/mingw/include", System, false);
#if defined(_WIN32)
      AddPath("c:/mingw/include", System, false);
#endif

Why MingW include path should depend on HSOpts.ResourceDir at all? clang
may be a devleopment version running not in C:\program files\ at all and we
still want clang to locate MingW correctly.

The #if defined(_WIN32) especiialy odd since MingW is a Windows-only target
so why is it needed?

If it makes sense, I can rewrite the whole MingW include logic (including
the mingw-builds patch) replacing all the code with something more generic
and version-proof. It will still need some hardcoded paths to support the
different MingW distributions but not hard-coded version numbers or
clang-relative directories as above.

What do you think?

Yaron





2013/10/6 Anton Korobeynikov <anton at korobeynikov.info>

> What if it's installed in some other directory? Is there a way to find
> the installation directory precisely?
>
> Iterating over all the subdirs of some dir during each run of clang
> looks pretty gross.
>
> On Sun, Oct 6, 2013 at 7:20 PM, Yaron Keren <yaron.keren at gmail.com> wrote:
> > mingw-builds is installed by default in c:\Program Files
> > (x86)\mingw-builds\...
> >
> > This patch locates its include directory.
> >
> > Yaron
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>
>
>
> --
> With best regards, Anton Korobeynikov
> Faculty of Mathematics and Mechanics, Saint Petersburg State University
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131006/e8ed302e/attachment.html>


More information about the cfe-commits mailing list