具有两个具有相同名称的目标的Makefile [英] Makefile with two targets with the same name
问题描述
我有一个包含include语句的makefile.我无法控制包含的makefile的内容.不过,我希望能够在某些"(不是全部)目标之前添加一些预处理步骤.考虑以下示例:
I have a makefile containing an include statement. I have no control over the content of the included makefile. Still, I want to be able to add some pre-processing steps before "some" (not all) of the targets. Consider the following example:
install:
@echo "install target"
include othermakefile.mk
othermakefile.mk 也包含 install 目标.如果我运行此脚本,make会发出警告,并忽略第一个 install 目标.
othermakefile.mk contains install target as well. If I run this script, make gives a warning and ignores the first install target.
推荐答案
没有什么比这容易的了:
Nothing easier:
install: pre_install
.PHONY: pre_install
pre_install:
do preinstallation things
include othermakefile.mk
如果要在install
或其任何先决条件之前运行pre_install
,这是一种方法.这很粗糙而且很丑陋,但是确实可以做到:
If you want to run pre_install
before install
or any of its preqs, here is a way. It's crude and ugly, but it does the job:
install: pre_install
$(MAKE) -f othermakefile.mk $@
.PHONY: pre_install
pre_install:
do preinstallation things
请注意,这不一定会重建install
的所有前提条件,因此其中某些前提条件可能保持其旧状态并且不能反映pre_install
的影响.如果这还不够好,并且您想要在所有其他先决条件之前先pre_install
,则可以添加一个选项标志:
Note that this will not necessarily rebuild all prerequisites of install
, so some of them may remain in their old states and not reflect the effects of pre_install
. If that's not good enough, and you want pre_install
before all of the other prerequisites, you can add an option flag:
install: pre_install
$(MAKE) --always-make -f othermakefile.mk $@
现在,Make将假定所有目标都已过时,并从头开始重建(在pre_install
之后).
Now Make will assume that all targets are out of date, and rebuild from the ground up (after pre_install
).
这篇关于具有两个具有相同名称的目标的Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!