make option suggestion

Frederik Eaton frederik at a5.repetae.net
Tue Nov 7 07:07:14 EST 2006


> 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?

Hi Simon,

I think it's actually not easier. In your example, I would have to
list all of the generated dependencies for 'prog' in the makefile. 
Further, if I want to compile multiple programs, all of which depended
on Source.hs, then I would have to have separate entries for each of
them. My punishment for using generated files is that 'ghc --make' no
longer infers dependencies for them, and I am forced to list each one
by hand as a dependency of the program or library I am building, for
each program. Thus if I want to build n programs, each of which uses m
generated source files, the amount of text I have to put in my
makefile scales as n*m. This may seem trivial for most projects, but
it also means that each time I add a generated source file, or a
program, I have to remember to create several Makefile entries of the
proper form, which can be cumbersome.

You say "since you already have a Makefile", but in my proposal,
'make' isn't actually necessary - a simple shell script with a 'case'
statement would do. It's just a way of getting ghc to tell us what the
dependencies of a certain compilation are. In multi-target
invocations, ghc could even set an environment variable indicating
which target is being compiled - then we could change --make-command
to be something which also records dependencies for use in a makefile. 
Lastly, my proposal is trivial to use with Cabal, by setting
GHC-Options, whereas yours would perhaps require me to switch to using
Cabal via 'make', which would probably be almost as annoying as
putting the commands to generate my source files in Setup.hs in the
first place...

There are several issues which need to be worked out - when
'--make-command' is specified, then how should ghc test for existence
of source files, how should it ask for their modification times, etc. 
I think these all have pretty simple solutions though.

Cheers,

Frederik

-- 
http://ofb.net/~frederik/


More information about the Glasgow-haskell-users mailing list