From dc03e317b40d640e6501be0fce3e32bc29699fbb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 Feb 2015 12:20:03 -0400 Subject: Propellor now builds itself without needing the Makefile. --- src/Propellor/Bootstrap.hs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Propellor/Bootstrap.hs (limited to 'src/Propellor/Bootstrap.hs') diff --git a/src/Propellor/Bootstrap.hs b/src/Propellor/Bootstrap.hs new file mode 100644 index 00000000..7ad4bb1f --- /dev/null +++ b/src/Propellor/Bootstrap.hs @@ -0,0 +1,42 @@ +module Propellor.Bootstrap ( + buildPropellor +) where + +import Propellor +import Utility.SafeCommand + +import System.Posix.Files + +buildPropellor :: IO () +buildPropellor = unlessM (actionMessage "Propellor build" build) $ + errorMessage "Propellor build failed!" + +-- Build propellor using cabal, and symlink propellor to where cabal +-- leaves the built binary. +-- +-- For speed, only runs cabal configure when it's not been run before. +-- If the build fails cabal may need to have configure re-run. +build :: IO Bool +build = catchBoolIO $ do + make "dist/setup-config" ["propellor.cabal"] $ + cabal ["configure"] + unlessM (cabal ["build"]) $ do + void $ cabal ["configure"] + unlessM (cabal ["build"]) $ + error "cabal build failed" + nukeFile "propellor" + createSymbolicLink "dist/build/propellor-config/propellor-config" "propellor" + return True + +make :: FilePath -> [FilePath] -> IO Bool -> IO () +make dest srcs builder = do + dt <- getmtime dest + st <- mapM getmtime srcs + when (dt == Nothing || any (> dt) st) $ + unlessM builder $ + error $ "failed to make " ++ dest + where + getmtime = catchMaybeIO . getModificationTime + +cabal :: [String] -> IO Bool +cabal = boolSystem "cabal" . map Param -- cgit v1.3-2-g0d8e