![add mingw to path add mingw to path](http://3.bp.blogspot.com/-hgwH5e98qdU/UVdUGYRbEvI/AAAAAAAAAek/CNcJXSXo9AA/s1600/img1.png)
Note that individual elements of that list are enabled and disabled via preprocessor macros, so these paths could from from any pre-processor variables, it's impossible to tell which ones. How these affect different hard-coded paths? Well, imagine that gcc is configured with -prefix=/mingw -with-sysroot=/root, /mingw is c:/foo/bar/mingw, /root is c:/foo/bar/root. The third, update_path(), branch doesn't change anything on W32, as stated above. It also doesn't work if the path does not start with the configure-time prefix (it is difficult to tell whether this is a real possibility or not). But it doesn't come into effect if add_sysroot=1 for the path. The second branch, where path rewriting is done, is what works most of the time on W32, and is the reason why gcc can be moved around and still work.
![add mingw to path add mingw to path](https://i.stack.imgur.com/8qiK1.png)
One can pass -isysroot to set sysroot at run-time, but that is only used in special cases. Note that sysroot is NULL at run-time on W32 - it's initialized by the TARGET_SYSTEM_ROOT macro, which is usually undefined even if it were to be defined, it would have to be an absolute DOSish path or an absolute *nixish path, and prepending it to anything wouldn't solve any problem all by itself. In any case, the path is added to the list of include directories after that. Replace compile-time-prefix in the path with current gcc libexec prefix (determined at runtime)Ĭall update_path() on the path (on W32 update_path() mostly replaces '\\', '/' and little else). If add_sysroot=1 AND sysroot is not NULL:Įlse if add_sysroot=0 AND path starts with a compile-time-prefix AND gcc was moved (determined at runtime):
![add mingw to path add mingw to path](https://i.stack.imgur.com/5o3Gv.png)
Gcc does the following with each hard-coded path: Whether it is good or bad also depends on the add_sysroot constant that is hard-coded for each path. "Get mangled" or "don't get mangled" does not map directly into "bad" and "good" in this case (usually mangled paths in final binaries is "bad"). At least two of them are passed via config.h instead, and they don't get mangled. Most of the standard include paths, which are hard-coded into gcc, are passed to the preprocessor via command line (there's a PREPROCESSOR_DEFINES variable in Makefile), so they get DOSified (due to MSYS path mangling) by the time they reach the code.
ADD MINGW TO PATH CODE
Most of the code that the text below refers to is in inpath.c, incpath.h, cppdefault.c and cppdefault.h. All of the following is applicable to i686 mingw-w64 gcc builds, which is compiled gcc-4.8.0 using rubenvb's personal i686->i686 (cross?)compiler, in MSys, using -prefix=/mingw -with-sysroot=/root, where /mingw contains rubenvb's pre-built toolchain, while /root is the place where gcc and its prerequisites are installed once gcc is compiled, mounts are changed - /mingw points to the place /root used to point, and /root is removed completely, so that everything can be configured with -prefix=/mingw, which is the usual convention.