summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2009-10-29 11:58:31 +0000
committerIan Lynagh <igloo@earth.li>2009-10-29 11:58:31 +0000
commit80aea54a820cd718d47ff43b6988d2ea3ed615ae (patch)
tree3dbeed20648dac2ccda2c9f553a8a1d4db6b3413 /driver
parentb7078f351d72f77b0a2b5d1fdf6e050ea0bfef61 (diff)
downloadhaskell-80aea54a820cd718d47ff43b6988d2ea3ed615ae.tar.gz
Improvements to the gcc wrapper
Add some comments and better error reporting
Diffstat (limited to 'driver')
-rw-r--r--driver/gcc/gcc.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/driver/gcc/gcc.c b/driver/gcc/gcc.c
index cd8a511074..c086f748e5 100644
--- a/driver/gcc/gcc.c
+++ b/driver/gcc/gcc.c
@@ -1,12 +1,24 @@
+/* gcc on mingw is hardcoded to use /mingw (which is c:/mingw) to
+ find various files. If this is a different version of mingw to the
+ one that we have in the GHC tree then things can go wrong. We
+ therefore need to add various -B flags to the gcc commandline,
+ so that it uses our in-tree mingw. Hence this wrapper. */
+
#include "getLocation.h"
+#include <errno.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
+
+static void die(const char *fmt, ...) {
+ va_list argp;
-static void die(char *msg) {
- fprintf(stderr, "%s", msg);
+ va_start(argp, fmt);
+ vfprintf(stderr, fmt, argp);
+ va_end(argp);
exit(1);
}
@@ -16,23 +28,24 @@ static char *mkString(const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
- i = vsnprintf(p, 0, fmt, argp);
+ i = vsnprintf(NULL, 0, fmt, argp);
va_end(argp);
if (i < 0) {
- die("snprintf failed\n");
+ die("snprintf 0 failed: errno %d: %s\n", errno, strerror(errno));
}
p = malloc(i + 1);
if (p == NULL) {
- die("malloc failed\n");
+ die("malloc failed: errno %d: %s\n", errno, strerror(errno));
}
va_start(argp, fmt);
j = vsnprintf(p, i + 1, fmt, argp);
va_end(argp);
if (i < 0) {
- die("snprintf failed\n");
+ die("snprintf with %d failed: errno %d: %s\n",
+ i + 1, errno, strerror(errno));
}
return p;
@@ -45,7 +58,7 @@ char *quote(char *str) {
quotedStr = malloc(2 * strlen(str) + 2 + 1);
if (quotedStr == NULL) {
- die("malloc failed\n");
+ die("malloc failed: errno %d: %s\n", errno, strerror(errno));
}
p = quotedStr;
*p++ = '"';
@@ -89,7 +102,7 @@ int main(int argc, char** argv) {
// execv(exePath, argv);
ret = spawnv(_P_WAIT, exePath, (const char* const*)newArgv);
if (errno) {
- die("Spawn failed\n");
+ die("spawnv failed: errno %d: %s\n", errno, strerror(errno));
}
exit(ret);
}