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

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jun 30 19:12:13 AEST 1999


On 30-Jun-1999, Warwick Harvey <wharvey at cs.monash.edu.au> wrote:
> Is it documented anywhere that having a Mercury module name end in "_init"
> is a bad idea?  :-)

Ouch :-(

No.

> Estimated hours taken: 2
> 
> Specifying GRADEFLAGS and C2INITFLAGS on a per-program basis didn't work
> properly for `_init.c' 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.c' "suffix" (we assume such a string will only be
> 	at the end of a file name) from the `$@' automatic variable used in
> 	the per-target definitions of GRADEFLAGS and C2INITFLAGS.

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

	maybe-base-GRADEFLAGS- = $(GRADEFLAGS-$(subst _init,,$*)

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.

>  TARGET_C2INITFLAGS = \
> -  $(maybe-target-C2INITFLAGS-$(findstring undefined,$(origin C2INITFLAGS-$@)))
> -maybe-target-C2INITFLAGS- = $(C2INITFLAGS-$@)
> +  $(maybe-target-C2INITFLAGS-$(findstring undefined,\
> +		$(origin C2INITFLAGS-$(subst _init.c,,$@))))
> +maybe-target-C2INITFLAGS- = $(C2INITFLAGS-$(subst _init.c,,$@))
>  maybe-target-C2INITFLAGS-undefined =

Likewise here you should use $(patsubst ...) or $(@:_init.c=) rather than
$(subst ...).

-- 
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 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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