Skip to content

Commit

Permalink
Move pieces around so the Makefile run is in Start, not System.Make
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell committed May 30, 2013
1 parent dd74553 commit b135af3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 33 deletions.
28 changes: 1 addition & 27 deletions Development/Make/Main.hs → Development/Make/All.hs
@@ -1,6 +1,6 @@
{-# LANGUAGE RecordWildCards, PatternGuards, CPP #-}

module Development.Make.Main(main) where
module Development.Make.All(runMakefile) where

import System.Environment
import Development.Shake
Expand All @@ -17,32 +17,6 @@ import Control.Monad
import System.Cmd
import System.Exit
import Control.Monad.Trans.State.Strict
import System.Console.GetOpt


main :: IO ()
main = do
args <- getArgs
withArgs ("--no-time":args) $
shakeArgsWith shakeOptions flags $ \opts targets -> do
makefile <- case reverse [x | UseMakefile x <- opts] of
x:_ -> return x
_ -> findMakefile
fmap Just $ runMakefile makefile targets


data Flag = UseMakefile FilePath

flags = [Option "f" ["file","makefile"] (ReqArg (Right . UseMakefile) "FILE") "Read FILE as a makefile."]


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
error "Could not find either `makefile' or `Makefile'"


runMakefile :: FilePath -> [String] -> IO (Rules ())
Expand Down
2 changes: 1 addition & 1 deletion Examples/Test/Makefile.hs
Expand Up @@ -3,7 +3,7 @@ module Examples.Test.Makefile(main) where

import Development.Shake(action, liftIO)
import Development.Shake.FilePath
import qualified Development.Make.Main as Makefile
import qualified Start as Makefile
import System.Environment
import System.Directory
import Examples.Util
Expand Down
2 changes: 1 addition & 1 deletion Main.hs
@@ -1,4 +1,4 @@

module Main(main) where

import Development.Make.Main(main)
import Start
33 changes: 33 additions & 0 deletions Start.hs
@@ -0,0 +1,33 @@

module Start(main) where

import Development.Make.All
import System.Environment
import Development.Shake
import qualified System.Directory as IO
import System.Console.GetOpt


main :: IO ()
main = do
args <- getArgs
withArgs ("--no-time":args) $
shakeArgsWith shakeOptions flags $ \opts targets -> do
makefile <- case reverse [x | UseMakefile x <- opts] of
x:_ -> return x
_ -> findMakefile
fmap Just $ runMakefile makefile targets


data Flag = UseMakefile FilePath

flags = [Option "f" ["file","makefile"] (ReqArg (Right . UseMakefile) "FILE") "Read FILE as a makefile."]


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
error "Could not find either `makefile' or `Makefile'"
4 changes: 2 additions & 2 deletions Test.hs
Expand Up @@ -33,7 +33,7 @@ import qualified Examples.Test.Progress as Progress
import qualified Examples.Test.Random as Random
import qualified Examples.Test.Resources as Resources

import qualified Development.Make.Main as Make
import qualified Start as Start


fakes = ["clean" * clean, "test" * test, "make" * makefile]
Expand Down Expand Up @@ -76,7 +76,7 @@ main = do
makefile :: IO () -> IO ()
makefile _ = do
args <- getArgs
withArgs (drop 1 args) Make.main
withArgs (drop 1 args) Start.main


clean :: IO () -> IO ()
Expand Down
6 changes: 4 additions & 2 deletions shake.cabal
Expand Up @@ -151,11 +151,12 @@ executable shake
build-depends: unix >= 2.5.1

other-modules:
Development.Make.All
Development.Make.Env
Development.Make.Main
Development.Make.Parse
Development.Make.Rules
Development.Make.Type
Start


executable shake-test
Expand Down Expand Up @@ -186,8 +187,8 @@ executable shake-test
build-depends: unix >= 2.5.1

other-modules:
Development.Make.All
Development.Make.Env
Development.Make.Main
Development.Make.Parse
Development.Make.Rules
Development.Make.Type
Expand All @@ -214,3 +215,4 @@ executable shake-test
Examples.Test.Progress
Examples.Test.Random
Examples.Test.Resources
Start

0 comments on commit b135af3

Please sign in to comment.