Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amigalemming opened this issue Jan 29, 2024 · 0 comments

Comments

@amigalemming
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant