LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to "subclass" a suffix rule in a makefile? (https://www.linuxquestions.org/questions/programming-9/how-to-subclass-a-suffix-rule-in-a-makefile-945372/)

RileyTheWiley 05-16-2012 03:24 PM

How to "subclass" a suffix rule in a makefile?
 
Make noob here.

I have some code that looks a little like this:

foo : foo.o

foo.o : foo.cpp

In other words it relies on (default) suffix rules to build. I wish to execute some code (setting a variable) when the rule is evaluated, then fire the default rule. So my first cut looks like this:

foo : foo.o
@echo Linking!

foo.o : foo.cpp
@echo Compiling!


But of course when I run it, the printed line replaces the default rule. I want to do this:

foo : foo.o
@echo Linking!
run_default_rule

foo.o : foo.cpp
@echo Compiling!
run_default_rule

But don't know how. How do I get at that "higher" rule? I realize I can run make -p to get info, and then just paste it into my makefile .. but I am looking for something more elegant.

RDeW

pan64 05-17-2012 07:51 AM

the default rule is used when there is no other rule.
you can change the default rule to contain the echo line also, and there can be other tricks...


All times are GMT -5. The time now is 11:04 PM.