make option suggestion

Simon Marlow simonmarhaskell at
Tue Nov 7 05:54:27 EST 2006

Frederik Eaton wrote:
> Hello,
> I have a proposal for ghc. I think that it should take a new option,
> say "--make-command". This will specify a command to be run whenever a
> source file is read in by ghc. The command will be passed an argument,
> which is the name of the source file. The idea is that the command can
> be used to create auto-generated "source" files when ghc needs them.
> The purpose of this would be the following. Suppose I have a source
> file, say Source.hs, which is generated from some template, say
> If I edit, and compile my program with 'ghc
> --make', then the copy of Source.hs which ghc uses will be out of
> date. That's because ghc doesn't know about the fact that Source.hs is
> generated from If I use ghc, then I'll have to remember
> to manually generate a new version of Source.hs every time I modify
> But under the present proposal, I would simply write a Makefile with
> the rules for generating Source.hs, and then pass --make-command=make
> to ghc. For instance, my Makefile might say:
> Source.hs:
>     $(TAC) < $< > $@
> Then every time I run ghc, and Source.hs is out of date, an up-to-date
> version of Source.hs will be generated automatically - because ghc
> will call 'make Source.hs' before reading it in.
> Does this sound like a good idea?

Since you already have a Makefile, why not add this to it:

SRCS = Source.hs ...
prog: $(SRCS)
	ghc --make $(SRCS) -o prog

and then just say 'make' to build your program?  Surely that's easier than 
typing 'ghc --make-command=make ...'?  Maybe I'm missing something?


More information about the Glasgow-haskell-users mailing list