diff options
author | Joey Hess <joey@kitenet.net> | 2010-11-18 13:30:42 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-11-18 13:30:42 -0400 |
commit | 54513c69baffa40f2fcce42eb8651fdd98e05277 (patch) | |
tree | f3934b369e7b5b259b88abeee228381fb2bcd6e0 /configure.hs | |
parent | 5c7d1b027916ce3fc207329f926041d2bcad3bcd (diff) |
Add configure step to build process.
* configure: Check to see if cp -a can be used.
* configure: Check to see if cp --reflink=auto can be used.
Diffstat (limited to 'configure.hs')
-rw-r--r-- | configure.hs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/configure.hs b/configure.hs new file mode 100644 index 000000000..fa07be3ab --- /dev/null +++ b/configure.hs @@ -0,0 +1,78 @@ +{- Checks system configuration and generates SysConfig.hs. + -} + +import System.IO +import System.Cmd +import System.Exit +import System.Directory + +type Test = IO Bool +data TestDesc = TestDesc String String Test +data Config = Config String Bool + +tests :: [TestDesc] +tests = [ + TestDesc "cp -a" "cp_a" cp_a + , TestDesc "cp --reflink" "cp_reflink" cp_reflink + ] + +tmpDir :: String +tmpDir = "tmp" + +testFile :: String +testFile = tmpDir ++ "/testfile" + +quiet :: String -> String +quiet s = s ++ " 2>/dev/null" + +cp_a :: Test +cp_a = testCmd $ quiet $ "cp -a " ++ testFile ++ " " ++ testFile ++ ".new" + +cp_reflink :: Test +cp_reflink = testCmd $ quiet $ "cp --reflink=auto " ++ testFile ++ " " ++ testFile ++ ".new" + +testCmd :: String -> Test +testCmd c = do + ret <- system c + return $ ret == ExitSuccess + +testStart :: String -> IO () +testStart s = do + putStr $ " checking " ++ s ++ "..." + hFlush stdout + +testEnd :: Bool -> IO () +testEnd r = putStrLn $ " " ++ (show r) + +writeSysConfig :: [Config] -> IO () +writeSysConfig config = do + writeFile "SysConfig.hs" $ unlines $ header ++ vars config ++ footer + where + header = [ + "{- Automatically generated by configure. -}" + , "module SysConfig where" + ] + footer = [] + vars [] = [] + vars (c:cs) = showvar c ++ vars cs + showvar (Config name val) = [ + name ++ " :: Bool" + , name ++ " = " ++ show val + ] + +runTests :: [TestDesc] -> IO [Config] +runTests [] = return [] +runTests ((TestDesc tname key t):ts) = do + testStart tname + val <- t + testEnd val + rest <- runTests ts + return $ (Config key val):rest + +main :: IO () +main = do + createDirectoryIfMissing True tmpDir + writeFile testFile "test file contents" + config <- runTests tests + removeDirectoryRecursive tmpDir + writeSysConfig config |