3 years, 3 months ago
How do I find the original target in a makefile?
My makefile can be invoked by any one of many top level makefiles. Some of the top level makefiles use a default target of 'lib', or 'releaselib', or 'debuglib'. When my makefile is invoked, I just know that 'lib' is a prerequisite of something, but I would like to be able to figure out the top-level target of the dependency tree.
Separate topics with commas, or by pressing return. Use the delete or backspace key to edit or remove existing topics.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$1 Answer
Are you looking for your lower level makefile to behave differently depending on what the top-level target was? If so, I think you'd have to have the top-level make files export the target name into an environment variable and have your makefile read that (and check $(MAKELEVEL), too, if you're using gnumake).
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$
I should have said that answer assumes you are calling make with $(MAKE) or something. It doesn't help if your top-level make file is getting the lower-level one through an include.