In shake-0.9 and below phony targets are a bit of a weak spot in Shake - you can do them, but they are a more verbose and manual than they should be. Here are a few options:
Have the install rule produce a file
As a very simple solution, just add writeFile' "install" ""
at the bottom of the install
rule. This produces a dummy file, but it will rerun every time mytarget
changes. If you want it to run every time install
is requested (like a phony would in make), just add alwaysRerun
. If you can ignore the redundant file, this is the simplest solution, until there is first-class phony support.
Use action
You can write:
main = shake shakeOptions $ do
action $ do
need ["mytarget"]
system' "ln" ["-s", "mytarget", "linkname"]
This declares an action that is run on every build. In reality you probably only want this to be run if install
is on the command line, so you can do:
main = do
args <- getArgs
shake shakeOptions $ do
when ("install" `elem` args) $ action $ do
... install code ...
Use shakeArguments
In the later versions of shake you can use the shakeArgsWith
function to write:
main = shakeArgsWith shakeOptions [] $ \_ targets ->
if "clean" `elem` targets then do
removeFiles "_make" "//*"
return Nothing
else return $ Just $ do
when ("install" `elem` targets) $ do
... install code ...
... other rules ...
want $ delete "install" targets
This gives you full control over how the targets are processed, so you can do something far more powerful than phony targets, but its more work.