help-make
[Top][All Lists]
Advanced

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

Re: Merging rules


From: Sébastien Hinderer
Subject: Re: Merging rules
Date: Thu, 14 Jun 2018 13:51:08 +0200

OK here is my real example, I think it's just simpler to show the
fragments as they are -- sorry I dind't do it earlier.

After a bunch of refactorings, I reached a point where the frament in
question looks like this:

%.$(O): %.c
        $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<

%.$(DBGO): OC_CPPFLAGS += $(OC_DEBUG_CPPFLAGS)
%.d.$(O): %.c
        $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<

%.i.$(O): OC_CPPFLAGS += $(OC_INSTR_CPPFLAGS)
%.i.$(O): %.c
        $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<

%.pic.$(O): OC_CFLAGS += $(SHAREDLIB_CFLAGS)
%.pic.$(O): %.c
        $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<

As you can see, the recipe is the same for all these rules.

Now I am wondering whether there would be a way to rewrite this fragment
without having to repeat the command.

I tried:

%.$(O) %.d.$(O) %.i.$(O) %.pic.$(O): %.c
        $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $<

%.d.$(O): OC_CPPFLAGS += $(OC_DEBUG_CPPFLAGS)

%.i.$(O): OC_CPPFLAGS += $(OC_INSTR_CPPFLAGS)

%.pic.$(O): OC_CFLAGS += $(SHAREDLIB_CFLAGS)

But that does not work: when make tries to build the target that
requires the .d.o files, it fails to do so because the expected files
have not been built.

My interpretation of why this happens is that the rule has been invoked
once, to build the regular .o files, and then make believes that this
single invocation has built all the targets, which is actually not the
case.

Any help warmly appreciated, sorry if the question is naïve!

Best wishes,

Sébastien.



reply via email to

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