[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multiple pattern-specific variable assignments
From: |
Adrian Ashley |
Subject: |
Re: Multiple pattern-specific variable assignments |
Date: |
Tue, 28 May 2002 15:15:43 +0100 |
Paul,
> aa> Can anyone suggest a way to accomplish multiple
> aa> pattern-specific variable assignments? This
> aa> fragment illustrates what I'm trying to do.
>
> aa> foo-%.o : CFLAGS += -DVARIANT=FOO
> aa> bar-%.o : CFLAGS += -DVARIANT=BAR
>
> aa> %-gcc.o : CFLAGS += -DGCC
> aa> %-other.o : CFLAGS += -DOTHERCC
>
> You could put one of these into a different variable, like:
>
> %-gcc.o : CCTYPE = -DGCC
> %-other.o : CCTYPE = -DOTHERCC
>
> Then:
>
> %-gcc.o: %.c
> $(CC_GCC) $(CCTYPE) $(CFLAGS) -o $@ -c $<
>
> %-other.o: %.c
> $(CC_OTHER) $(CCTYPE) $(CFLAGS) -o $@ -c $<
Tried that:
$ cat Makefile
CC_GCC=gcc
CC_OTHER=another-cc
CFLAGS = -DBASIC
foo-%.o : CFLAGS += -DVARIANT=FOO
bar-%.o : CFLAGS += -DVARIANT=BAR
%-gcc.o : CCTYPE = -DGCC
%-other.o : CCTYPE = -DOTHERCC
%-gcc.o: %.c
$(CC_GCC) $(CCTYPE) $(CFLAGS) -o $@ -c $<
%-other.o: %.c
$(CC_OTHER) $(CCTYPE) $(CFLAGS) -o $@ -c $<
$ make foo-gcc.o
gcc -DBASIC -DVARIANT=FOO -o foo-gcc.o -c foo.c
It's still stopping as soon as it's matched "foo-%.o". If I reorder the
patterns:
$ cat Makefile
[...]
%-gcc.o : CCTYPE = -DGCC
%-other.o : CCTYPE = -DOTHERCC
foo-%.o : CFLAGS += -DVARIANT=FOO
bar-%.o : CFLAGS += -DVARIANT=BAR
[...]
then it matches "%-gcc.o" instead:
$ make foo-gcc.o
gcc -DGCC -DBASIC -o foo-gcc.o -c foo.c
I hesitate to call this a bug, as the documentation does say that pattern
rule matching proceeds until the first match and then stops. But perhaps
there's a case for arguing that if the effect is only to set target- or
pattern-specific variables, then all patterns which match should do so
cumulatively (perhaps excepting terminal ones?)
Or is there a Cunning Trick?
Thanks,
--
Adrian Ashley
address@hidden