summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main/SysTools.lhs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 00311597d8..4a51b313e2 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -582,10 +582,22 @@ copyWithHeader dflags purpose maybe_header from to = do
hout <- openBinaryFile to WriteMode
hin <- openBinaryFile from ReadMode
ls <- hGetContents hin -- inefficient, but it'll do for now. ToDo: speed up
- maybe (return ()) (hPutStr hout) maybe_header
+ maybe (return ()) (header hout) maybe_header
hPutStr hout ls
hClose hout
hClose hin
+ where
+#if __GLASGOW_HASKELL__ >= 702
+ -- write the header string in UTF-8. The header is something like
+ -- {-# LINE "foo.hs" #-}
+ -- and we want to make sure a Unicode filename isn't mangled.
+ header h str = do
+ hSetEncoding h utf8
+ hPutStr h str
+ hSetBinaryMode h True
+#else
+ header h str = hPutStr h str
+#endif
-- | read the contents of the named section in an ELF object as a
-- String.