help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to have an "optional" prerequisite in a static pattern rule


From: Boris Kolpackov
Subject: Re: how to have an "optional" prerequisite in a static pattern rule
Date: Sat, 14 Jan 2006 11:37:43 +0000 (UTC)
User-agent: nn/6.6.5+RFC1522

"Ming Kin Lai" <address@hidden> writes:

> Suppose I have prog1.c prog2.c prog3.c prog4.c prog1.h prog2.h
> In my Makefile I have these:
>
> $(OBJ)= prog1.o prog2.o prog3.o prog4.o
> $(OBJ): %.o: %.c %.h
>      $(CC) -c $< -o $@
>
> I do not want to explicitly write a separate rule for prog3 and prog4:
>
> ...
>
> That would be too awkward.  Is there a better way?

If you don't mind using features from 3.81beta4 then you can do it like
this:

.SECONDEXPANSION:

$(OBJ): %.o: %.c $$(if $$(wildcard %.h),%.h)
        $(CC) -c $< -o $@

hth,
-boris





reply via email to

[Prev in Thread] Current Thread [Next in Thread]