[m-dev.] For review: Simplify specification of some per-program flags

Warwick Harvey wharvey at cs.monash.edu.au
Thu Jul 1 12:56:31 AEST 1999


Fergus wrote:
> > +++ Mmake.vars.in	1999/06/30 02:10:47
> > @@ -185,10 +185,11 @@
> >  
> >  TARGET_GRADEFLAGS = \
> >    $(maybe-base-GRADEFLAGS-$(findstring undefined,$(origin GRADEFLAGS-$*))) \
> > -  $(maybe-target-GRADEFLAGS-$(findstring undefined,$(origin GRADEFLAGS-$@)))
> > +  $(maybe-target-GRADEFLAGS-$(findstring undefined,\
> > +		$(origin GRADEFLAGS-$(subst _init.c,,$@))))
> >  maybe-base-GRADEFLAGS- = $(GRADEFLAGS-$*)
> >  maybe-base-GRADEFLAGS-undefined =
> > -maybe-target-GRADEFLAGS- = $(GRADEFLAGS-$@)
> > +maybe-target-GRADEFLAGS- = $(GRADEFLAGS-$(subst _init.c,,$@))
> >  maybe-target-GRADEFLAGS-undefined =
> 
> For GRADEFLAGS, when compiling the `*_init.c' file to `*_init.o',
> the `$@' automatic variable will be `*_init.o' rather than `*_init.c',
> won't it?  So don't you need to apply the same trick to maybe-base-GRADEFLAGS
> that you applied to maybe-target-GRADEFLAGS?

Agh, yes.  I didn't test it enough.  :-(

I'd been trying to get away with not doing that one, because I thought 
"_init" as a non-final substring was way too likely, whereas "_init.c" was 
not.  However, once again you point out an obvious solution:

> Also, it would be better to use $(patsubst) rather than $(subst):
> 
> 	maybe-base-GRADEFLAGS- = $(GRADEFLAGS-$(patsubst %_init,%,$*)
> 
> This will ensure that you only match things at the end of the file name.
> 
> You can also write this more concisely as
> 
> 	maybe-base-GRADEFLAGS- = $(GRADEFLAGS-$(*:_init=)
> 
> but I leave the choice of which is more readable up to you.

The conciseness of the latter option is appealing, but for readability I'd 
have to go with the former.


Anyway, with the GRADEFLAGS stuff, if one does the substitution for both the 
`$@' and `$*' variables, one gets the grade flags repeated in the call to 
`c2init', since both match.  This is probably harmless.  However, I'm going 
to argue that whenever `$(patsubst %_init.c,%,$@)' gives you `foo', 
`$(patsubst %_init,%,$*)' will also give you `foo' (`_init.c' files are only 
ever built by implicit rules, right?), so the substitution is only necessary 
for the latter.  This avoids the repetition.

A revised diff follows.

Warwick


Estimated hours taken: 3

Specifying GRADEFLAGS and C2INITFLAGS on a per-program basis didn't work
properly for `_init.*' files.  Rather than just specifying `-foo' versions,
one had to specify `-foo_init.c' or `-foo_init' versions instead or as well.
This change corrects this.

scripts/Mmake.vars.in:
	Strip any `_init' suffix from the `$*' automatic variable used in
	the per-target definitions of GRADEFLAGS.
	Strip any `_init.c' suffix from the `$@' automatic variable used in
	the per-target definitions of C2INITFLAGS.

Index: Mmake.vars.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmake.vars.in,v
retrieving revision 1.24
diff -u -r1.24 Mmake.vars.in
--- Mmake.vars.in	1998/12/06 23:48:56	1.24
+++ Mmake.vars.in	1999/07/01 02:52:28
@@ -184,9 +184,10 @@
 # undefined variables is enabled.
 
 TARGET_GRADEFLAGS = \
-  $(maybe-base-GRADEFLAGS-$(findstring undefined,$(origin GRADEFLAGS-$*))) \
+  $(maybe-base-GRADEFLAGS-$(findstring undefined,\
+		$(origin GRADEFLAGS-$(patsubst %_init,%,$*)))) \
   $(maybe-target-GRADEFLAGS-$(findstring undefined,$(origin GRADEFLAGS-$@)))
-maybe-base-GRADEFLAGS- = $(GRADEFLAGS-$*)
+maybe-base-GRADEFLAGS- = $(GRADEFLAGS-$(patsubst %_init,%,$*))
 maybe-base-GRADEFLAGS-undefined =
 maybe-target-GRADEFLAGS- = $(GRADEFLAGS-$@)
 maybe-target-GRADEFLAGS-undefined =
@@ -197,8 +198,9 @@
 maybe-base-MCFLAGS-undefined =
 
 TARGET_C2INITFLAGS = \
-  $(maybe-target-C2INITFLAGS-$(findstring undefined,$(origin 
C2INITFLAGS-$@)))
-maybe-target-C2INITFLAGS- = $(C2INITFLAGS-$@)
+  $(maybe-target-C2INITFLAGS-$(findstring undefined,\
+		$(origin C2INITFLAGS-$(patsubst %_init.c,%,$@))))
+maybe-target-C2INITFLAGS- = $(C2INITFLAGS-$(patsubst %_init.c,%,$@))
 maybe-target-C2INITFLAGS-undefined =
 
 TARGET_MGNUCFLAGS = \


--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list