[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: building templates
From: |
Paul D. Smith |
Subject: |
Re: building templates |
Date: |
Wed, 9 Apr 2003 14:32:58 -0400 |
%% 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> so what I did:
mk> writing it explicitly:
mk> ZWHICH = -DMY_Z
mk> zaaa.f: xaaa.F
mk> $(CC) -E -P $(ZWHICH) $< -o $@
mk> and subsequently applying the standard rules for %.o:%.f
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).
Anyway, eval is very much overkill for this: you just need static
pattern rules. Try:
ZOBJS = zaaa.o zbbb.o
$(patsubst %.o,%.f,$(ZOBJS)) : %.f : %.F
$(CC) -E -P $(ZWHICH) $< -o $@
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist
- building templates, Martin Kleinschmidt, 2003/04/09
- Re: building templates,
Paul D. Smith <=