%% [EMAIL PROTECTED] writes:
h> I found out there is a thread "optional prerequisite" in
h> [email protected] 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 <[EMAIL PROTECTED]> 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
_______________________________________________
help-gnu-utils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gnu-utils