make option suggestion

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 Source.hs.in. If I edit Source.hs.in, 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 Source.hs.in. If I use ghc, then I'll have to remember to manually generate a new version of Source.hs every time I modify Source.hs.in. 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: Source.hs.in $(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? Frederik -- http://ofb.net/~frederik/

I think this kind of build system feature ought to go into Cabal so it can be used more widely and without people needing Makefiles. I admit that we're not there yet with how easy it is to generate source files. Duncan On Mon, 2006-11-06 at 21:12 +0000, 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 Source.hs.in. If I edit Source.hs.in, 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 Source.hs.in. If I use ghc, then I'll have to remember to manually generate a new version of Source.hs every time I modify Source.hs.in.
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: Source.hs.in $(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?
Frederik

Hi
Just for completeness, I came up with a proposal that would solve all
this, but in a very non-cabal style way.
Taking an example of happy, every generated file (File.hs) would have
as its first line:
{-# ORIGIN happy sourcefile.y -options -to -happy #-}
Then you just modify all haskell generating tools to output this
(easy) and suddenly the whole problem of preprocessors goes away.
I realise its not the "cabal" style way of doing it - since the
information gets put in the generated files etc - but it is pretty
simple.
You can also add to the file Happy.y:
{-# GENERATE happy sourcefile.y -options -to -happy #-}
To complete the other side of the generation.
Thanks
Neil
On 11/6/06, Duncan Coutts
I think this kind of build system feature ought to go into Cabal so it can be used more widely and without people needing Makefiles.
I admit that we're not there yet with how easy it is to generate source files.
Duncan
On Mon, 2006-11-06 at 21:12 +0000, 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 Source.hs.in. If I edit Source.hs.in, 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 Source.hs.in. If I use ghc, then I'll have to remember to manually generate a new version of Source.hs every time I modify Source.hs.in.
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: Source.hs.in $(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?
Frederik
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

I would definitely like something like this. like {-# PREPROCESS drift-ghc #-} to specify the file should be preprocced by drift-ghc. John -- John Meacham - ⑆repetae.net⑆john⑈

John Meacham wrote:
I would definitely like something like this. like
{-# PREPROCESS drift-ghc #-}
to specify the file should be preprocced by drift-ghc.
I worry that putting details of the build procedure into the source file will lead to problems. Often build parameters need to be configurable, eg. do I use happy's -g option or not? It depends what Haskell compiler you're using. Build systems are usually well suited to doing configurable things. Also, we don't really want pathnames leaking into source files. So we're left with just specifying the kind of preprocessor to use, as in the example above. It's certainly more general than the existing scheme of looking at the file extension, but I wonder whether it's worth it. Cheers, Simon

The {-# ORIGIN ... #-} keyword sounds like a nice solution, but wouldn't it require creating each generated file initially by hand, so that the compilers know that it exists? I'd rather have a build system where I can delete all of the generated files before distributing my code, and still have compilation work. Maybe I'm not understanding. Cheers, Frederik On Mon, Nov 06, 2006 at 09:37:18PM +0000, Neil Mitchell wrote:
Hi
Just for completeness, I came up with a proposal that would solve all this, but in a very non-cabal style way.
Taking an example of happy, every generated file (File.hs) would have as its first line:
{-# ORIGIN happy sourcefile.y -options -to -happy #-}
Then you just modify all haskell generating tools to output this (easy) and suddenly the whole problem of preprocessors goes away.
I realise its not the "cabal" style way of doing it - since the information gets put in the generated files etc - but it is pretty simple.
You can also add to the file Happy.y: {-# GENERATE happy sourcefile.y -options -to -happy #-}
To complete the other side of the generation.
Thanks
Neil
On 11/6/06, Duncan Coutts
wrote: I think this kind of build system feature ought to go into Cabal so it can be used more widely and without people needing Makefiles.
I admit that we're not there yet with how easy it is to generate source files.
Duncan
On Mon, 2006-11-06 at 21:12 +0000, 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 Source.hs.in. If I edit Source.hs.in, 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 Source.hs.in. If I use ghc, then I'll have to remember to manually generate a new version of Source.hs every time I modify Source.hs.in.
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: Source.hs.in $(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?
Frederik
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

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 Source.hs.in. If I edit Source.hs.in, 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 Source.hs.in. If I use ghc, then I'll have to remember to manually generate a new version of Source.hs every time I modify Source.hs.in.
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: Source.hs.in $(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? Cheers, Simon

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/
participants (5)
-
Duncan Coutts
-
Frederik Eaton
-
John Meacham
-
Neil Mitchell
-
Simon Marlow