File: Start.hs

package info (click to toggle)
haskell-shake 0.13.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 888 kB
  • ctags: 127
  • sloc: haskell: 6,388; makefile: 35; ansic: 25; sh: 2
file content (49 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

module Start(main) where

import Development.Make.All
import Development.Ninja.All
import System.Environment
import Development.Shake
import Development.Shake.FilePath
import General.Timing
import Data.Maybe
import qualified System.Directory as IO
import System.Console.GetOpt


main :: IO ()
main = do
    resetTimings
    args <- getArgs
    withArgs ("--no-time":args) $
        shakeArgsWith shakeOptions{shakeCreationCheck=False} flags $ \opts targets -> do
            let tool = listToMaybe [x | Tool x <- opts]
            makefile <- case reverse [x | UseMakefile x <- opts] of
                x:_ -> return x
                _ -> findMakefile
            if takeExtension makefile == ".ninja" then
                runNinja makefile targets tool
             else if isJust tool then
                error "--tool flag is not supported without a .ninja Makefile"
             else
                fmap Just $ runMakefile makefile targets


data Flag = UseMakefile FilePath
          | Tool String

flags = [Option "f" ["file","makefile"] (ReqArg (Right . UseMakefile) "FILE") "Read FILE as a makefile."
        ,Option "t" ["tool"] (ReqArg (Right . Tool) "TOOL") "Ninja-compatible tools."
        ]


findMakefile :: IO FilePath
findMakefile = do
    b <- IO.doesFileExist "makefile"
    if b then return "makefile" else do
        b <- IO.doesFileExist "Makefile"
        if b then return "Makefile" else do
            b <- IO.doesFileExist "build.ninja"
            if b then return "build.ninja" else
                error "Could not find `makefile', `Makefile' or `build.ninja'"