2 #include "getLocation.h"
8 static void die(char *msg) {
9 fprintf(stderr, "%s", msg);
13 static char *mkString(const char *fmt, ...) {
19 i = vsnprintf(p, 0, fmt, argp);
23 die("snprintf failed\n");
28 die("malloc failed\n");
32 j = vsnprintf(p, i + 1, fmt, argp);
35 die("snprintf failed\n");
41 char *quote(char *str) {
46 quotedStr = malloc(2 * strlen(str) + 2 + 1);
47 if (quotedStr == NULL) {
48 die("malloc failed\n");
64 int main(int argc, char** argv) {
72 binDir = getExecutablePath();
73 exePath = mkString("%s/realgcc.exe", binDir);
75 /* Without these -B args, gcc will still work. However, if you
76 have a mingw installation in c:/mingw then it will use files
77 from that in preference to the in-tree files. */
79 newArgv = malloc(sizeof(char *) * (argc + 4 + 1));
80 newArgv[0] = quote(exePath);
81 newArgv[1] = quote(mkString("-B%s", binDir));
82 newArgv[2] = quote(mkString("-B%s/../lib", binDir));
83 newArgv[3] = quote(mkString("-B%s/../lib/gcc/mingw32/3.4.5", binDir));
84 newArgv[4] = quote(mkString("-B%s/../libexec/gcc/mingw32/3.4.5", binDir));
85 for (i = 1; i < argc; i++) {
86 newArgv[4 + i] = quote(argv[i]);
88 newArgv[4 + argc] = NULL;
89 // execv(exePath, argv);
90 ret = spawnv(_P_WAIT, exePath, (const char* const*)newArgv);
92 die("Spawn failed\n");