result.tar

result.txt



import Development.Shake

import Development.Shake.FilePath



main = shake shakeOptions $ do

want ["result.tar"]

"*.tar" *> \out -> do

contents <- readFileLines $ replaceExtension out "txt"

need contents

system' "tar" $ ["-cf",out] ++ contents



FilePath

main

shake

shakeOptions

shake

want

*>

want

result.tar

*.tar

.tar

result.tar

readFileLines

result.txt

.tar

.txt

contents

result.tar

need

contents

tar

result.txt

result.txt

result.tar

ghc --make

cabal

At the Haskell Implementors Workshop 2010 I described a Haskell build system named Shake ( video here ), hoping an implementation would be available "soon". Better late than never, I am delighted to announce that Shake is now available on Hackage . This version is a from scratch reimplementation, based on an improved underlying theory, all completed in my spare time. Several users have already experimented with this version, so it is reasonably robust.As a simple example of a Shake build system, let us build the filefrom the files listed byWe start by importing the modules defining both Shake and routines for manipulatingvalues. We defineto callwith the default. As the second argument to, we provide a set of rules. There are two common forms of rules,to specify target files, andto define a rule which builds a file pattern. We useto require that after the build completes the fileshould be ready.Therule describes how to build files with the extension, including. Weon, after changing theextension to. We read each line into the variable-- being a list of the files that should go into. Next, we depend () all the files in. If any of these files change, the rule will be repeated. Finally we call theprogram. If eitherchanges, or any of the files listed bychange, thenwill be rebuilt.If you are interested in writing a build system using Shake, I suggest you read the documentation . One thing noted in the documentation is that iforis capable of building your project, use that instead. Custom build systems are necessary for many complex projects, but many projects are not complex.As an example of how to do this task in Make, see this StackOverflow question . I'll cover the differences and similarities with other build tools in a forthcoming blog post.