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. */
16 void die(const char *fmt, ...) {
20 vfprintf(stderr, fmt, argp);
25 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 run(char *exePath, int numArgs1, char **args1, int numArgs2, char **args2) {
82 newArgv = malloc(sizeof(char *) * (1 + numArgs1 + numArgs2 + 1));
83 if (newArgv == NULL) {
84 die("malloc failed: errno %d: %s\n", errno, strerror(errno));
87 *p++ = quote(exePath);
88 for (i = 0; i < numArgs1; i++) {
89 *p++ = quote(args1[i]);
91 for (i = 0; i < numArgs2; i++) {
92 *p++ = quote(args2[i]);
95 ret = spawnv(_P_WAIT, exePath, (const char* const*)newArgv);
97 die("spawnv failed: errno %d: %s\n", errno, strerror(errno));