@@ -3,12 +3,17 @@ module Main(main) where
5import Parser
5import Parser
6−import Control.Monad
6+import Control.Monad.Extra
7+import System.Process.Extra
8+import System.Directory
10+import System.IO.Extra
11+import System.FilePath
12+import System.Info.Extra
9main :: IO ()
15main :: IO ()
11− writeFile "test.h" $ unlines $ compile html
12 forM_ examples $ \(b, src) -> do
17 forM_ examples $ \(b, src) -> do
13 putStrLn ""
18 putStrLn ""
14 putStrLn src
19 putStrLn src
@@ -16,7 +21,24 @@ main = do
17 print (trail, err)
22 print (trail, err)
18 putStrLn $ rerender src res
23 putStrLn $ rerender src res
24+ writeFileChanged "test.h" $ unlines $ compile html
25+ buildRule ["test.h","test.c"] ["gen" <.> (if isWindows then "exe" else "")] $
26+ system_ "gcc test.c -o gen"
29+writeFileChanged :: FilePath -> String -> IO ()
30+writeFileChanged file new = do
31+ old <- ifM (doesFileExist file) (readFile' file) (return "")
35+buildRule :: [FilePath] -> [FilePath] -> IO () -> IO ()
36+buildRule from to act = do
37+ let modTime x = ifM (doesFileExist x) (Just <$> getModificationTime x) (return Nothing)
38+ from <- mapM modTime from
39+ to <- mapM modTime to
40+ when (any isNothing (from ++ to) || maximum from >= minimum to)
21examples :: [(Bool, String)]
43examples :: [(Bool, String)]