Using phony targets as target aliases

We have a (very convoluted) build system that I'm presently trying to clean up and simplify a little. It is centered on a Perl script that sets up all kinds of interdependent environment variables and then starts make . What target make is invoked on depends on the arguments passed to the Perl script, some other environment variables and the current moon phase.

The thing that is bugging me is that our makefile contains way too many phony targets, which leads to targets constantly being rebuilt even though there is no need, which is a huge time waster. Targets (directly or indirectly) depend on a ton of phony targets, and since a phony target is always considered "out of date", lots of stuff is unnecessarily updated.

The reason why there are so many phony targets is that our makefile is never called directly but always through the Perl script I mentioned before, and by having phony targets, the Perl script doesn't have to know the exact path names of a particular target that the user wants to update.

My intention is to have no target depend on any phony targets any more. I want to convert all phony targets into concrete, non-phony ones so that each target's tree of dependencies contains only non-phony targets. Then, to make individual targets easily accessible in the Perl script, I'm going to add a new phony target for each of these that does nothing except mention the concrete target as its sole dependency and just print out an echo in its build recipe.

I'm not overly well-versed in make , so I'd like to ask if this will work as intended or if there will be unintended consequences.


This will work as intended (and is the right way to do it), provided that you first create all the concrete targets, having them depending on other concrete targets, and then abstract the names away using phony targets with concrete ones as prerequisites. In other words, the concrete targets should stand up by themselves and not depend on phonies.

By the way, you can also leave the recipe empty if you want to (no need for a "dummy" echo ).

链接地址: http://www.djcxy.com/p/64126.html

上一篇: 如何通过预制产生假目标?

下一篇: 使用假目标作为目标别名