Use sed to make stage-specific ghc-inplace.c's
authorIan Lynagh <igloo@earth.li>
Fri, 14 Sep 2007 23:34:46 +0000 (23:34 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 14 Sep 2007 23:34:46 +0000 (23:34 +0000)
When trying to do it with -D we were having trouble getting the double
quotes through in all Windows configurations.

compiler/Makefile
compiler/ghc-inplace.c

index 6e94fb2..4797814 100644 (file)
@@ -737,6 +737,7 @@ SRC_LD_OPTS += -no-link-chk
 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
 # a real binary here rather than a shell script.
 
+INPLACE_SRC  = $(odir)/ghc-inplace.c
 INPLACE_PROG = $(odir)/ghc-inplace$(_way)$(exeext)
 EXCLUDED_C_SRCS += ghc-inplace.c
 
@@ -746,8 +747,11 @@ ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
 INPLACE_EXTRA_FLAGS = -optc-DWINDOWS
 endif
 
-$(INPLACE_PROG): ghc-inplace.c
-       $(HC) -cpp -optc-DGHC_PATH=$(DQ)$(GHC_PATH)$(DQ) -optc-DTOP_ABS=$(DQ)$(FPTOOLS_TOP_ABS)$(DQ) $(INPLACE_EXTRA_FLAGS) $< -o $@
+$(INPLACE_SRC): ghc-inplace.c
+       $(SED) -e "s@GHC_PATH@$(GHC_PATH)@g" -e "s@TOP_ABS@$(FPTOOLS_TOP_ABS)@g" < $< > $@
+
+$(INPLACE_PROG): $(INPLACE_SRC)
+       $(HC) -cpp $(INPLACE_EXTRA_FLAGS) $< -o $@
 
 all :: $(INPLACE_PROG)
 
index 2e345bc..d7599ea 100644 (file)
@@ -31,8 +31,8 @@ int main(int argc, char **argv) {
         fprintf(stderr, "Malloc failed\n");
         exit(1);
     }
-    args[0] = GHC_PATH;
-    args[1] = "-B" TOP_ABS;
+    args[0] = "GHC_PATH"; /* Gets replaced by sed */
+    args[1] = "-BTOP_ABS"; /* Gets replaced by sed */
     args[2] = "-fhardwire-lib-paths";
     if ((argc >= 2) && (strcmp(argv[1], "-v") == 0)) {
         printf("Using %s %s %s\n", args[0], args[1], args[2]);
@@ -40,7 +40,10 @@ int main(int argc, char **argv) {
     }
     memcpy(args + 3, argv + 1, sizeof(char *) * (argc - 1));
     args[argc+2] = NULL;
-    return run(argv[0], GHC_PATH, argc + 2, args);
+    return run(argv[0],
+               "GHC_PATH", /* Gets replaced by sed */
+               argc + 2,
+               args);
 }
 
 #ifndef WINDOWS