Say, I have Haskell modules, filepath extension is .hs. Most modules are written by hand, but some are generated by a preprocessor from files with extension, say .lhs. My problem is not exactly about Literate Haskell, I only want to describe the general problem.
In a Makefile I can declare the rule:
%.hs: %.lhs
preprocess-lhs $< $@
If a .hs module is present without a .lhs, then make is happy and does not try to generate .hs. If an .lhs is present but older than .hs, make will also not try to regenerate the .hs. However, if .lhs is present and newer than .hs, then .hs is rebuild.
How can I teach shake this behavior?
In Shakefile.hs I can write:
"//*.hs" %> \dst -> do
let src = dst -<.> "lhs"
need [src]
cmd_ "preprocess-lhs" [src, dst]
However, if .hs is handwritten and no .lhs available, then shake will refuse to run.
I can write instead:
"//*.hs" %> \dst ->
let src = dst -<.> "lhs"
available <- doesFileExist src
when available $ cmd_ "preprocess-lhs" [src, dst]
Now, shake no longer complains about missing .lhs, but instead it does not rebuild .hs after editing .lhs.
That problem sounds pretty much like a FAQ, but I have not found it there.
Say, I have Haskell modules, filepath extension is
.hs. Most modules are written by hand, but some are generated by a preprocessor from files with extension, say.lhs. My problem is not exactly about Literate Haskell, I only want to describe the general problem.In a
MakefileI can declare the rule:If a
.hsmodule is present without a.lhs, thenmakeis happy and does not try to generate.hs. If an.lhsis present but older than.hs, make will also not try to regenerate the.hs. However, if.lhsis present and newer than.hs, then.hsis rebuild.How can I teach shake this behavior?
In
Shakefile.hsI can write:However, if
.hsis handwritten and no.lhsavailable, thenshakewill refuse to run.I can write instead:
Now,
shakeno longer complains about missing.lhs, but instead it does not rebuild.hsafter editing.lhs.That problem sounds pretty much like a FAQ, but I have not found it there.