[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: building templates
From: |
Martin Kleinschmidt |
Subject: |
Re: building templates |
Date: |
Thu, 10 Apr 2003 11:40:11 +0200 |
User-agent: |
Mutt/1.4i |
On Mit, 09 Apr 2003, Paul D. Smith wrote:
>%% Martin Kleinschmidt <address@hidden> writes:
>
> mk> I have files xaaa.F, xbbb.F, which contain C preprocessor
> mk> directives. From each of these files, i want to generate
> mk> different objects by passing different variables to the C
> mk> preprocessor. e.g. I want to generate zaaa.o and daaa.o from
> mk> xaaa.F, and zbbb.o and dbbb.o from xbbb.F There will be multiple
> mk> x???.F files but from each x???.F I will need to generate at most
> mk> 4 (probably only 2) different objects.
>
> mk> I thought of doing something like
>
> mk> z%.f: x%.F
> mk> $(CC) -E -P $(ZWHICH) $< -o $@
>
> mk> but that would break all other z*.o (which do not depend on an x???.F)
> mk> Okay - I could place my templates in a separate directory, but
> mk> a) I don't want that and
> mk> b) I want to learn something about makefiles :-)
>
> mk> I tried:
>
> mk> ZOBJS = zaaa.o zbbb.o
> mk> $(foreach object, $(ZOBJS), $(eval \
> mk> $(object): $(patsubst z%.o, x%.F, $(object)) \
> mk> $(CC) $(PREFLAG) $(ZWHICH) $< -o $@))
>
>No, this won't work. You don't have any newlines here first of all, so
>the whole output will appear on one line. Replace "eval" with "warning"
>to see what make sees:
>
>$(foreach object, $(ZOBJS), $(warning \
>$(object): $(patsubst z%.o, x%.F, $(object)) \
> $(CC) $(PREFLAG) $(ZWHICH) $< -o $@))
>
>(the $(warning ...) function is handy for this).
Uh. Ok. But adding an escaped semicolon helps:
$(foreach object, $(ZOBJS), $(warning \
$(object): $(patsubst z%.o, x%.F, $(object))\;\
$(CC) -E -P $(ZWHICH) $$< -o $$@))
yields:
Makefile:74: zaaa.o: xaaa.F; cc -E -P -DMY_Z $< -o $@
which for me looks like what I want
(except for the incomplete build rule)
BUT: Replacing warning bey eval:
make: *** No rule to make target `zaaa.o', needed by `program'. Stop.
>Anyway, eval is very much overkill for this: you just need static
>pattern rules. Try:
I was hoping, someone would say this :-)
> ZOBJS = zaaa.o zbbb.o
>
> $(patsubst %.o,%.f,$(ZOBJS)) : %.f : %.F
> $(CC) -E -P $(ZWHICH) $< -o $@
I don't understand this.
That's TWO ":" in one line?
And it lacks the prefix change from z* to x*
What I am using now is:
$(ZOBJS) : $(patsubst z%.o, x%.F, $(ZOBJS))
$(CC) -E -P $(ZWHICH) $(patsubst z%.o, x%.F, $@) -o $(patsubst %.o,
%.f, $@)
$(FC) $(FFLAGS) -c $(patsubst %.o, %.f, $@) -o $@
It works, but has one drawback:
each of the objects in $(ZOBJS) now depends on all source files.
That's okay for the moment but I would like a way to change it.
I tried to add the dependence:
$(foreach dummy, $(ZOBJS), $(dummy): $(patsubst z%.o, x%.F, $(dummy)))
Result:
Makefile:96: *** multiple target patterns. Stop.
wrapping a $(warning ) around it makes clear why:
Makefile:96: zaaa.o: xaaa.F zbbb.o: xbbb.F
Any ideas?
...martin