Refactor gcc.c, pulling out the reusable code
[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 #include <errno.h>
11 #include <process.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <stdarg.h>
15 #include <string.h>
16
17 int main(int argc, char** argv) {
18     char *binDir;
19     char *exePath;
20     char *preArgv[4];
21
22     binDir = getExecutablePath();
23     exePath = mkString("%s/realgcc.exe", binDir);
24
25     /* Without these -B args, gcc will still work. However, if you
26        have a mingw installation in c:/mingw then it will use files
27        from that in preference to the in-tree files. */
28     preArgv[0] = mkString("-B%s", binDir);
29     preArgv[1] = mkString("-B%s/../lib", binDir);
30     preArgv[2] = mkString("-B%s/../lib/gcc/mingw32/3.4.5", binDir);
31     preArgv[3] = mkString("-B%s/../libexec/gcc/mingw32/3.4.5", binDir);
32
33     run(exePath, 4, preArgv, argc - 1, argv + 1);
34 }
35