From 2bb461f433da1a121dafc96a95363618795bd7fb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Mar 2022 13:43:24 +0200 Subject: Handle absolute POSIX paths in MinGW GCC search paths --- libbuild2/cc/gcc.cxx | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/libbuild2/cc/gcc.cxx b/libbuild2/cc/gcc.cxx index 3376c16..2c844b6 100644 --- a/libbuild2/cc/gcc.cxx +++ b/libbuild2/cc/gcc.cxx @@ -59,6 +59,25 @@ namespace build2 } } +#ifdef _WIN32 + // Some misconfigured MinGW GCC builds add absolute POSIX directories to + // their built-in search paths (e.g., /mingw/{include,lib}) which GCC then + // interprets as absolute paths relative to the current drive (so the set + // of built-in search paths starts depending on where we run things from). + // + // While that's definitely misguided, life is short and we don't want to + // waste it explaining this in long mailing list threads and telling + // people to complain to whomever built their GCC. So we will just + // recreate the behavior in a way that's consistent with GCC and let + // people discover this on their own. + // + static inline void + add_current_drive (string& s) + { + s.insert (0, work.string (), 0, 2); // Add e.g., `c:`. + } +#endif + // Extract system header search paths from GCC (gcc/g++) or compatible // (Clang, Intel) using the `-v -E