[mercury-users] term_expansion (was Re: Microsoft Common Lisp?)

Fergus Henderson fjh at cs.mu.oz.au
Tue Feb 18 23:32:01 AEDT 1997

Peter Schachte wrote:
> On Mon, 17 Feb 1997, Fergus Henderson wrote:
> > Peter Schachte wrote:
> > >     2.  term_expansion doesn't require users to monkey with Makefiles
> > > 	to get their programs to work correctly.
> > 
> > I consider the requirement that files that use language extensions have
> > have different extension to be a feature, not a bug.  The different
> > extension gives maintenance programmers a clue that something funny
> > is going on here.
> Even if we agree that a source file that is going to be transformed
> should be marked in some way, putting this information in the file
> name seems like a pretty bad idea.  This information belongs *in* the
> file.
> > >     3.  term_expansion handles, though not a smoothly as one might
> > > 	like, the use of multiple languages extensions in the same
> > > 	file, while simple make rules won't.
> > Hang on, here's another idea.
> > 
> > 	PREPROCESSOR = foo | bar
> > 
> > 	%.m: %.pp
> > 		cat $< | $PREPROCESSOR > $@
> This approach winds up running all the preprocessors on all files that
> need any preprocessing.  This may be horribly inefficient, but more
> importantly it may be wrong.

Ok, how about the following technique?
It seems to address most of your concerns in points 2 & 3 above.

	GET_PREPROCESSORS = sed -n '/^%%% PREPROCESSORS = /{s///p;q;}'

	%.m: %.pp
		@echo "cat $< | `$(GET_PREPROCESSORS) $<` > $@"
		@cat $< | eval `$(GET_PREPROCESSORS) $<` > $@

The sed command searches for the first string of the form

	%%% PREPROCESSORS = blah ...

in a source file and prints out the "blah ..." part.
The "blah ..." part is then executed using `eval'.
Thus this stylized comment form becomes special syntax.
(The `@echo ...' and the `@' before the `cat ...' are just so that when
you run `mmake' you can see which preprocessors are being executed.)

With this technique, the information about which preprocessors are used
is in the source file, not the makefile, and you can use different
preprocessors in different orders for different source files.

So, would that satisfy your requirements?

The wonderful thing about the Unix makefile approach is that it is
extremely powerful and extremely flexible :->.
You can use it to implement a variety of different techniques,
depending on the requirements you need to satisfy.

Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at         |     -- the last words of T. S. Garp.

More information about the users mailing list