diff --git a/Setup.hs b/Setup.hs index e7795b5..a7e9cb1 100644 --- a/Setup.hs +++ b/Setup.hs @@ -3,16 +3,31 @@ import System.Process import System.Environment import System.Directory -libdir :: String -libdir = "src" +target :: String +target = "src/Hm" + +source :: String +source = "hm.cf" + +regenerateGrammar :: IO () +regenerateGrammar = do + callProcess "bnfc" ["-d", "--text-token", "--functor", source] + removePathForcibly target + renameDirectory "Hm" target main :: IO () main = do (a:_) <- getArgs if a == "build" then do - callProcess "bnfc" ["-d", "--text-token", "--functor", "hm.cf"] - removePathForcibly (libdir <> "/Hm") - renameDirectory "Hm" (libdir <> "/Hm") + b <- doesDirectoryExist target + if not b + then regenerateGrammar + else do + sourceDate <- getModificationTime source + targetDate <- getModificationTime target + if sourceDate >= targetDate + then regenerateGrammar + else pure () else pure () defaultMain diff --git a/hm.cabal b/hm.cabal index 31c42a5..dc39041 100644 --- a/hm.cabal +++ b/hm.cabal @@ -18,6 +18,7 @@ custom-setup , Cabal >= 2.4 , process >= 1 , directory >= 1 + , time >= 1 library ghc-options: -Werror=incomplete-patterns -Wall -fno-warn-name-shadowing