Safe Haskell | None |
---|---|
Language | Haskell2010 |
A module for useful utility functions for Shake build systems.
- parseMakefile :: String -> [(FilePath, [FilePath])]
- needMakefileDependencies :: FilePath -> Action ()
- neededMakefileDependencies :: FilePath -> Action ()
- shakeArgsAccumulate :: ShakeOptions -> [OptDescr (Either String (a -> a))] -> a -> (a -> [String] -> IO (Maybe (Rules ()))) -> IO ()
Documentation
parseMakefile :: String -> [(FilePath, [FilePath])] Source
Given the text of a Makefile, extract the list of targets and dependencies. Assumes a
small subset of Makefile syntax, mostly that generated by gcc -MM
.
parseMakefile "a: b c\nd : e" == [("a",["b","c"]),("d",["e"])]
needMakefileDependencies :: FilePath -> Action () Source
Depend on the dependencies listed in a Makefile. Does not depend on the Makefile itself.
needMakefileDependencies file = need . concatMap snd . parseMakefile =<< liftIO (readFile file)
neededMakefileDependencies :: FilePath -> Action () Source
Depend on the dependencies listed in a Makefile. Does not depend on the Makefile itself. Use this function to indicate that you have already used the files in question.
neededMakefileDependencies file = needed . concatMap snd . parseMakefile =<< liftIO (readFile file)
shakeArgsAccumulate :: ShakeOptions -> [OptDescr (Either String (a -> a))] -> a -> (a -> [String] -> IO (Maybe (Rules ()))) -> IO () Source
Like shakeArgsWith
, but instead of accumulating a list of flags, apply functions to a default value.
Usually used to populate a record structure. As an example of a build system that can use either gcc
or distcc
for compiling:
import System.Console.GetOpt data Flags = Flags {distCC :: Bool} deriving Eq flags = [Option "" ["distcc"] (NoArg $ Right $ \x -> x{distCC=True}) "Run distributed."] main =shakeArgsAccumulate
shakeOptions
flags (Flags False) $ \flags targets -> return $ Just $ do if null targets thenwant
["result.exe"] elsewant
targets let compiler = if distCC flags then "distcc" else "gcc" "*.o"*>
\out -> doneed
...cmd
compiler ... ...
Now you can pass --distcc
to use the distcc
compiler.