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. */
8 #include "getLocation.h"
16 static void die(const char *fmt, ...) {
20 vfprintf(stderr, fmt, argp);
25 static char *mkString(const char *fmt, ...) {
31 i = vsnprintf(NULL, 0, fmt, argp);
35 die("snprintf 0 failed: errno %d: %s\n", errno, strerror(errno));
40 die("malloc failed: errno %d: %s\n", errno, strerror(errno));
44 j = vsnprintf(p, i + 1, fmt, argp);
47 die("snprintf with %d failed: errno %d: %s\n",
48 i + 1, errno, strerror(errno));
54 char *quote(char *str) {
59 quotedStr = malloc(2 * strlen(str) + 2 + 1);
60 if (quotedStr == NULL) {
61 die("malloc failed: errno %d: %s\n", errno, strerror(errno));
77 int main(int argc, char** argv) {
85 binDir = getExecutablePath();
86 exePath = mkString("%s/realgcc.exe", binDir);
88 /* Without these -B args, gcc will still work. However, if you
89 have a mingw installation in c:/mingw then it will use files
90 from that in preference to the in-tree files. */
92 newArgv = malloc(sizeof(char *) * (argc + 4 + 1));
93 newArgv[0] = quote(exePath);
94 newArgv[1] = quote(mkString("-B%s", binDir));
95 newArgv[2] = quote(mkString("-B%s/../lib", binDir));
96 newArgv[3] = quote(mkString("-B%s/../lib/gcc/mingw32/3.4.5", binDir));
97 newArgv[4] = quote(mkString("-B%s/../libexec/gcc/mingw32/3.4.5", binDir));
98 for (i = 1; i < argc; i++) {
99 newArgv[4 + i] = quote(argv[i]);
101 newArgv[4 + argc] = NULL;
102 // execv(exePath, argv);
103 ret = spawnv(_P_WAIT, exePath, (const char* const*)newArgv);
105 die("spawnv failed: errno %d: %s\n", errno, strerror(errno));