summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ghc/compiler/main/CodeOutput.lhs28
-rw-r--r--ghc/driver/ghc.lprl2
2 files changed, 12 insertions, 18 deletions
diff --git a/ghc/compiler/main/CodeOutput.lhs b/ghc/compiler/main/CodeOutput.lhs
index ec316beb8a..81e17608b5 100644
--- a/ghc/compiler/main/CodeOutput.lhs
+++ b/ghc/compiler/main/CodeOutput.lhs
@@ -40,10 +40,10 @@ codeOutput mod_name c_code h_code flat_abstractC ncg_uniqs
doOutput opt_ProduceS ncg_output_w >>
dumpIfSet opt_D_dump_foreign "Foreign export header file" stub_h_output_d >>
- outputHStub opt_ProduceExportHStubs stub_h_output_w >>
+ outputForeignStubs True{-.h output-} opt_ProduceExportHStubs stub_h_output_w >>
dumpIfSet opt_D_dump_foreign "Foreign export stubs" stub_c_output_d >>
- outputCStub mod_name opt_ProduceExportCStubs stub_c_output_w >>
+ outputForeignStubs False{-not .h-} opt_ProduceExportCStubs stub_c_output_w >>
dumpIfSet opt_D_dump_realC "Real C" c_output_d >>
doOutput opt_ProduceC c_output_w
@@ -81,21 +81,15 @@ codeOutput mod_name c_code h_code flat_abstractC ncg_uniqs
-- don't use doOutput for dumping the f. export stubs
-- since it is more than likely that the stubs file will
-- turn out to be empty, in which case no file should be created.
-outputCStub mod_name switch ""
- = return ()
-outputCStub mod_name switch doc_str
- = case switch of
- Nothing -> return ()
- Just fname -> writeFile fname ("#include \"Rts.h\"\n#include \"RtsAPI.h\"\n"++rest)
- where
- rest = "#include "++show (moduleString mod_name ++ "_stub.h") ++ '\n':doc_str
-
-outputHStub switch ""
- = return ()
-outputHStub switch doc_str
- = case switch of
- Nothing -> return ()
- Just fname -> writeFile fname ("#include \"Rts.h\"\n"++doc_str)
+outputForeignStubs is_header switch "" = return ()
+outputForeignStubs is_header switch doc_str =
+ case switch of
+ Nothing -> return ()
+ Just fname -> writeFile fname (include_prefix ++ doc_str)
+ where
+ include_prefix
+ | is_header = "#include \"Rts.h\"\n"
+ | otherwise = "#include \"RtsAPI.h\"\n"
doOutput switch io_action
= case switch of
diff --git a/ghc/driver/ghc.lprl b/ghc/driver/ghc.lprl
index 9886de5e05..ff08503cad 100644
--- a/ghc/driver/ghc.lprl
+++ b/ghc/driver/ghc.lprl
@@ -1462,7 +1462,7 @@ Now the Haskell compiler, C compiler, and assembler
}
if (-f $hsc_out_c_stub) {
- &run_something("cp $hsc_out_c_stub $ofile_c_stub_target", 'Copy foreign export C stubs');
+ &run_something("rm -f $ofile_c_stub_target && echo '#include \"${ofile_h_stub_target}\"' > $ofile_c_stub_target && cat $hsc_out_c_stub >> $ofile_c_stub_target", 'Copy foreign export C stubs');
local ($hsc_out_s_stub);
local ($hsc_out_o_stub);
($ofile_s_stub_target = $ofile_c_stub_target) =~ s/\.(.*)$/\.s/;