This is an attempt to make GHC build reproducible. The name of .c files may end
up in the resulting binary (in the debug section), but not the directory.

Since the temporary directory already contains the process id, there is no need
to put it into the filename as well.

Index: ghc-7.8.4/compiler/main/SysTools.lhs
===================================================================
--- ghc-7.8.4.orig/compiler/main/SysTools.lhs	2014-12-19 16:35:34.000000000 +0100
+++ ghc-7.8.4/compiler/main/SysTools.lhs	2015-06-07 16:20:31.875021456 +0200
@@ -58,6 +58,7 @@
 import Util
 import DynFlags
 import Exception
+import Fingerprint
 
 import Data.IORef
 import Control.Monad
@@ -1011,8 +1012,7 @@
 newTempName :: DynFlags -> Suffix -> IO FilePath
 newTempName dflags extn
   = do d <- getTempDir dflags
-       x <- getProcessID
-       findTempName (d </> "ghc" ++ show x ++ "_")
+       findTempName (d </> "ghc_")
   where
     findTempName :: FilePath -> IO FilePath
     findTempName prefix
@@ -1031,8 +1031,8 @@
     mapping <- readIORef dir_ref
     case Map.lookup tmp_dir mapping of
         Nothing -> do
-            pid <- getProcessID
-            let prefix = tmp_dir </> "ghc" ++ show pid ++ "_"
+            pid <- getStableProcessID
+            let prefix = tmp_dir </> "ghc" ++ pid ++ "_"
             mask_ $ mkTempDir prefix
         Just dir -> return dir
   where
@@ -1347,6 +1347,14 @@
 getProcessID = System.Posix.Internals.c_getpid >>= return . fromIntegral
 #endif
 
+-- Debian-specific hack to get reproducible output, by not using the "random"
+-- pid, but rather something determinisic
+getStableProcessID :: IO String
+getStableProcessID = do
+    args <- getArgs
+    return $ take 4 $ show $ fingerprintString $ unwords args
+
+
 -- Divvy up text stream into lines, taking platform dependent
 -- line termination into account.
 linesPlatform :: String -> [String]
