#!/usr/bin/env runghc import Distribution.Simple import qualified Control.Exception as Ex import System.Directory import Control.Monad import System.Info import System.Exit import List b = "infinity" api = ["API.hi","API.o"] -- needed for plugins to load main = defaultMainWithHooks $ defaultUserHooks { postBuild = copyInfinity, postClean = cleanInfinity } copyInfinity _ _ _ _ = do copyFile ("dist/build/infinity/"++b) b mapM_ (\x -> copyFile ("dist/build/infinity/infinity-tmp/"++x) x) api return ExitSuccess cleanInfinity _ _ _ _ = do Ex.catch (removeFile b >> -- we don't care too much if there's no removeDirectory "dist") -- infinity binary in the topmost dir, or (\_ -> return ()) -- a dist/ dir clean "." clean "Plugins" return ExitSuccess where clean s = do c <- getDirectoryContents s forM_ c $ \f -> do if (".o" `isSuffixOf` f || ".hi" `isSuffixOf` f || "~" `isSuffixOf` f) then removeFile $ s++"/"++f else return ()