update to mingw gcc 4.5.2
[ghc-hetmet.git] / driver / gcc / gcc.c
1
2 /* gcc on mingw is hardcoded to use /mingw (which is c:/mingw) to
3    find various files. If this is a different version of mingw to the
4    one that we have in the GHC tree then things can go wrong. We
5    therefore need to add various -B flags to the gcc commandline,
6    so that it uses our in-tree mingw. Hence this wrapper. */
7
8 #include "cwrapper.h"
9 #include "getLocation.h"
10
11 #include <stdio.h>
12 #include <stdlib.h>
13
14 int main(int argc, char** argv) {
15     char *binDir;
16     char *exePath;
17     char *preArgv[4];
18     char *oldPath;
19     char *newPath;
20     int n;
21
22     binDir = getExecutablePath();
23     exePath = mkString("%s/realgcc.exe", binDir);
24
25     /* We need programs like
26            inplace/mingw/libexec/gcc/mingw32/4.5.0/cc1.exe
27        to be able to find the DLLs in inplace/mingw/bin, so we need to
28        add it to $PATH */
29     oldPath = getenv("PATH");
30     if (!oldPath) {
31         die("Couldn't read PATH\n");
32     }
33     n = snprintf(NULL, 0, "PATH=%s;%s", binDir, oldPath);
34     n++;
35     newPath = malloc(n);
36     if (!newPath) {
37         die("Couldn't allocate space for PATH\n");
38     }
39     snprintf(newPath, n, "PATH=%s;%s", binDir, oldPath);
40     n = putenv(newPath);
41     if (n) {
42         die("putenv failed\n");
43     }
44
45     /* Without these -B args, gcc will still work. However, if you
46        have a mingw installation in c:/mingw then it will use files
47        from that in preference to the in-tree files. */
48     preArgv[0] = mkString("-B%s", binDir);
49     preArgv[1] = mkString("-B%s/../lib", binDir);
50     preArgv[2] = mkString("-B%s/../lib/gcc/mingw32/4.5.2", binDir);
51     preArgv[3] = mkString("-B%s/../libexec/gcc/mingw32/4.5.2", binDir);
52
53     run(exePath, 4, preArgv, argc - 1, argv + 1);
54 }
55