diff options
author | Julien Dessaux | 2010-07-03 21:26:00 +0200 |
---|---|---|
committer | Julien Dessaux | 2010-07-03 22:40:17 +0200 |
commit | 11c2c16835b3e8368be77ccc5b7ddf949021eccd (patch) | |
tree | 7733132ee370335156219ff6eb4f0ef2dbd1c8ff /HsbotMaster/Main.hs | |
parent | Wrote most of the resume code for the core and the irc plugin. (diff) | |
download | hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.tar.gz hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.tar.bz2 hsbot-11c2c16835b3e8368be77ccc5b7ddf949021eccd.zip |
Moved files around as a preliminary for architectural changes.
Diffstat (limited to 'HsbotMaster/Main.hs')
-rw-r--r-- | HsbotMaster/Main.hs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/HsbotMaster/Main.hs b/HsbotMaster/Main.hs new file mode 100644 index 0000000..5e528ca --- /dev/null +++ b/HsbotMaster/Main.hs @@ -0,0 +1,58 @@ +module Main (main) where + +import Control.Monad (when) +import Prelude hiding (catch) +import System.Directory +import System.Environment +import System.Exit +import System.FilePath +import System.Info +import System.IO +import System.Posix.Process (executeFile) +import System.Process + +-- | Dynamic launching function +main :: IO () +main = do + args <- getArgs + case args of + [] -> buildLaunch + ["--help"] -> usage + _ -> fail "unrecognized flags" + +usage :: IO () +usage = do + self <- getProgName + putStr . unlines $ + concat ["Usage: ", self, " [OPTION]"] : + "Options:" : + " --help : Print this message" : + [] + +buildLaunch :: IO () +buildLaunch = do + _ <- recompile + dir <- getAppUserDataDirectory "hsbot" + args <- getArgs + _ <- executeFile (dir ++ "/hsbot-" ++ arch ++ "-" ++ os) False args Nothing + return () + +recompile :: IO (Bool) +recompile = do + dir <- getAppUserDataDirectory "hsbot" + let binn = "hsbot-"++arch++"-"++os + base = dir </> "hsbot" + err = base ++ ".errors" + src = base ++ ".hs" + errorHandle <- openFile err WriteMode + exitCode <- waitForProcess =<< runProcess "ghc" ["--make", "hsbot.hs", "-fforce-recomp", "-XScopedTypeVariables", "-o", binn] (Just dir) + Nothing Nothing Nothing (Just errorHandle) + hClose errorHandle + when (exitCode /= ExitSuccess) $ do + ghcErr <- readFile err + let msg = unlines $ + ["Error detected while loading hsbot configuration file: " ++ src] + ++ lines ghcErr ++ ["","Please check the file for errors."] + hPutStrLn stderr msg + return (exitCode == ExitSuccess) + |