From 54513c69baffa40f2fcce42eb8651fdd98e05277 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 18 Nov 2010 13:30:42 -0400 Subject: [PATCH] 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. --- .gitignore | 2 ++ Makefile | 8 +++-- configure.hs | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 3 ++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 configure.hs diff --git a/.gitignore b/.gitignore index 6956c49dd2..a4cac10f43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ build/* test +configure +SysConfig.hs git-annex git-annex.1 doc/.ikiwiki diff --git a/Makefile b/Makefile index 77e7a5edb8..685044146f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,11 @@ all: git-annex docs ghcmake=ghc -Wall -odir build -hidir build -O2 --make -git-annex: +SysConfig.hs: + $(ghcmake) configure + ./configure + +git-annex: SysConfig.hs $(ghcmake) git-annex install: @@ -29,7 +33,7 @@ docs: --disable-plugin=smiley clean: - rm -rf build git-annex git-annex.1 test + rm -rf build git-annex git-annex.1 test configure SysConfig.hs rm -rf doc/.ikiwiki html .PHONY: git-annex test install diff --git a/configure.hs b/configure.hs new file mode 100644 index 0000000000..fa07be3ab5 --- /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 diff --git a/debian/changelog b/debian/changelog index 2a8871c30e..e6549c1f08 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,9 @@ git-annex (0.08) UNRELEASED; urgency=low * Fix `git annex add ../foo` (when ran in a subdir of the repo). + * 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. -- Joey Hess Wed, 17 Nov 2010 13:54:49 -0400