1 #!/usr/bin/env runhaskell
3 > import Distribution
.Simple
4 > import System
.FilePath
5 > import System
.Directory
8 > import System
.Time
(ClockTime)
9 > import System
.Process
12 > heads
= unfoldr step
. Just
14 > step Nothing
= Nothing
15 > step
(Just
[]) = Just
([], Nothing
)
16 > step
(Just
(x
:xs
)) = Just
(x
, Just xs
)
18 > preludeSrcDir
= "prelude"
19 > preludePath
= "gen/Kaos/Prelude.hs"
20 > preludeDir
= fst $ splitFileName preludePath
21 > preludeDirs
= reverse $ map combine
$ heads
$ splitPath preludeDir
23 > hooks
= defaultUserHooks
{ preBuild
= checkPrelude
, cleanHook
= cleanPreludeHook
, runTests
= testhook
}
24 > main
= defaultMainWithHooks hooks
26 > cleanPreludeHook pd lbi uh cf
= do
28 > cleanHook defaultUserHooks pd lbi uh cf
30 > checkPreludeDirs
= createDirectoryIfMissing
True preludeDir
33 > removeDirectoryRecursive
"gen"
35 > loadPreludeSource
:: IO ([(String, String)], ClockTime)
36 > loadPreludeSource
= do
37 > entries
<- liftM sort $ getDirectoryContents preludeSrcDir
38 > l
<- mapM (scanEnt
. ((preludeSrcDir
++ "/")++)) entries
39 > let (strs
, modTimes
) = unzip $ concat l
40 > return $ (strs
, maximum modTimes
)
43 > |
not (".k" `
isSuffixOf` e
)
47 > contents
<- readFile e
48 > modTime
<- getModificationTime e
49 > return [((e
, contents
), modTime
)]
51 > checkPrelude args buildflags
= do
53 > (preludeSrc
, preludeModTime
) <- loadPreludeSource
54 > pe
<- doesFileExist preludePath
55 > when (not pe
) $ genPrelude preludeSrc
56 > lastGen
<- getModificationTime preludePath
57 > when (preludeModTime
>= lastGen
) $ genPrelude preludeSrc
58 > preBuild defaultUserHooks args buildflags
61 > writeFile preludePath
$ unlines [
62 > "module Kaos.Prelude (preludeStr) where",
63 > "preludeStr :: [(String, String)]",
64 > "preludeStr = " ++ show src
67 > testhook args _ _ _
= do
68 > ph
<- runProcess
"perl" ("runtests.pl":args
) Nothing Nothing Nothing Nothing Nothing
69 > exitCode
<- waitForProcess ph
71 > ExitSuccess
-> return ()
72 > _
-> exitWith exitCode