[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Makefile - how to filter out x.c files that do not have correspondin
From: |
Paul D. Smith |
Subject: |
Re: Makefile - how to filter out x.c files that do not have corresponding x.h in a rule that has %.h as prerequisite |
Date: |
13 Jan 2006 14:18:19 -0500 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
%% hzmonte@hotmail.com writes:
h> I found out there is a thread "optional prerequisite" in
h> help-make@gnu.org on Aug 31, 2005 that says it cannot be done.
h> I ended up doing this:
h> $(NO_H_OBJ) =prog3.o prog4.o
h> $(NO_H_OBJ): %.o %.c
h> $(CC) -c $< -o $@
h> $(filter-out $(NO_H_OBJ), $(OBJ)): %.o: %.c %.h
h> $(CC) -c $< -o $@
h> Still, is there a better way?
It's much easier to leave the %.h off the pattern, and add the header as
a prerequisite to those targets that DO have it. If you put the %.h in
the pattern then there's no way around it: every single target that
matches the pattern will have to have a .h file; that's what that _means_.
Why not do something like this:
%.o : %.c
$(CC) -c $< -o $@
foo.o: foo.h
bar.o: bar.h
baz.o: baz.h
etc. If you want it to be a little more automatic you could do
something like this:
%.o : %.c
$(CC) -c $< -o $@
__have_h := $(basename $(wildcard $(patsubst %.o,%.h,$(OBJ))))
$(foreach B,$(__have_h),$(eval $B.o: $B.h))
Note this only works in newer versions of GNU make.
--
-------------------------------------------------------------------------------
Paul D. Smith <psmith@gnu.org> 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