2022-01-23 13:43:50 +01:00
|
|
|
import Distribution.Simple
|
|
|
|
import System.Process
|
|
|
|
import System.Environment
|
|
|
|
import System.Directory
|
|
|
|
|
2022-01-23 13:58:15 +01:00
|
|
|
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
|
2022-01-23 13:43:50 +01:00
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
(a:_) <- getArgs
|
|
|
|
if a == "build"
|
|
|
|
then do
|
2022-01-23 13:58:15 +01:00
|
|
|
b <- doesDirectoryExist target
|
|
|
|
if not b
|
|
|
|
then regenerateGrammar
|
|
|
|
else do
|
|
|
|
sourceDate <- getModificationTime source
|
|
|
|
targetDate <- getModificationTime target
|
|
|
|
if sourceDate >= targetDate
|
|
|
|
then regenerateGrammar
|
|
|
|
else pure ()
|
2022-01-23 13:43:50 +01:00
|
|
|
else pure ()
|
|
|
|
defaultMain
|