Change a use of xargs to "$(XARGS)" $(XARGS_OPTS)
[ghc-hetmet.git] / utils / ext-core / Setup.lhs
index bdcd784..35661d4 100644 (file)
@@ -1,9 +1,8 @@
 #!/usr/bin/env runhaskell
 \begin{code}
-{-# OPTIONS -Wall #-}
+{-# OPTIONS -Wall -cpp #-}
 
 import Control.Monad
-import Data.List
 import Distribution.PackageDescription
 import Distribution.Simple
 import Distribution.Simple.LocalBuildInfo
@@ -12,13 +11,13 @@ import System.Cmd
 import System.FilePath
 import System.Exit
 import System.Directory
-import Control.Exception (try)
+import Control.Exception
 
 main :: IO ()
 main = do
-   let hooks = defaultUserHooks {
+   let hooks = simpleUserHooks {
                  buildHook = build_primitive_sources 
-                           $ buildHook defaultUserHooks
+                           $ buildHook simpleUserHooks
             }
    defaultMainWithHooks hooks
 \end{code}
@@ -28,6 +27,10 @@ Mostly snarfed from ghc-prim's Setup.hs.
 \begin{code}
 type Hook a = PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
 
+
+-- Hack: If PrimEnv.hs exists *and* genprimopcode or
+-- primops.txt doesn't exist, don't rebuild PrimEnv.hs
+
 build_primitive_sources :: Hook a -> Hook a
 build_primitive_sources f pd lbi uhs x
  = do when (compilerFlavor (compiler lbi) == GHC) $ do
@@ -37,10 +40,14 @@ build_primitive_sources f pd lbi uhs x
                                   "primops.txt"]
               primhs = joinPath ["Language", "Core", "PrimEnv.hs"]
               primhs_tmp = addExtension primhs "tmp"
-          maybeExit $ system (genprimopcode ++ " --make-ext-core-source < "
+          primEnvExists <- doesFileExist primhs
+          genprimopcodeExists <- doesFileExist genprimopcode
+          primopsExists <- doesFileExist primops
+          unless (primEnvExists && not genprimopcodeExists && not primopsExists) $ do
+             maybeExit $ system (genprimopcode ++ " --make-ext-core-source < "
                            ++ primops ++ " > " ++ primhs_tmp)
-          maybeUpdateFile primhs_tmp primhs
-          maybeExit $ system ("make -C lib/GHC_ExtCore")
+             maybeUpdateFile primhs_tmp primhs
+             maybeExit $ system ("make -C lib/GHC_ExtCore")
       f pd lbi uhs x
 
 -- Replace a file only if the new version is different from the old.
@@ -50,7 +57,12 @@ maybeUpdateFile source target = do
   r <- rawSystem "cmp" ["-s" {-quiet-}, source, target]
   case r of
     ExitSuccess   -> removeFile source
-    ExitFailure _ -> do try (removeFile target); renameFile source target
-
-
+    ExitFailure _ -> do 
+#if __GLASGOW_HASKELL__ >= 610
+      (try :: IO () -> IO (Either IOException ()))
+#else
+      try
+#endif 
+       (removeFile target)
+      renameFile source target
 \end{code}
\ No newline at end of file