Skip to content

How to simulate make's behaviour with respect to optional dependencies? #848

@amigalemming

Description

@amigalemming

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions