Makefile 基本目标及其依赖
Makefile base target and its dependent
我的 make 结构如下:
base :
build.sh base.output
//# if base.output is newer than sub-base.output by 1 minute then build the below -- How do i do this ?
sub-base :
build.sh sub-base.output
基本上,如果基础 folder/target 发生变化,所有依赖 folders/targets 都需要构建。
我正在考虑编写一个 shell 脚本来检查时间戳,但是 makefile 提供了更好的方法来做到这一点?
这就是生成文件的作用。这就是他们的目的。
只需使用以下内容作为您的 makefile。
base.output:
build.sh base.output
sub-base.output: base.output
build.sh sub-base.output
然后 运行宁 make base.output
将 运行 那个食谱和 make sub-base.output
将 运行 build.sh sub-base.output
但仅当 sub-base.output
比 base.output
.
大
您还应该在其目标行中列出 base.output
的任何先决条件,以便 make 正确处理它。
或者,如果没有,则需要使用 force target。
FORCE: ;
base.output: FORCE
build.sh base.output
强制 make 构建 base.output
,即使它已经存在。
如果您想保持说 make base
或 make sub-base
的能力,那么您也需要 phony targets。
.PHONY: base sub-base
base: base.output
sub-base: sub-base.output
我的 make 结构如下:
base :
build.sh base.output
//# if base.output is newer than sub-base.output by 1 minute then build the below -- How do i do this ?
sub-base :
build.sh sub-base.output
基本上,如果基础 folder/target 发生变化,所有依赖 folders/targets 都需要构建。
我正在考虑编写一个 shell 脚本来检查时间戳,但是 makefile 提供了更好的方法来做到这一点?
这就是生成文件的作用。这就是他们的目的。
只需使用以下内容作为您的 makefile。
base.output:
build.sh base.output
sub-base.output: base.output
build.sh sub-base.output
然后 运行宁 make base.output
将 运行 那个食谱和 make sub-base.output
将 运行 build.sh sub-base.output
但仅当 sub-base.output
比 base.output
.
您还应该在其目标行中列出 base.output
的任何先决条件,以便 make 正确处理它。
或者,如果没有,则需要使用 force target。
FORCE: ;
base.output: FORCE
build.sh base.output
强制 make 构建 base.output
,即使它已经存在。
如果您想保持说 make base
或 make sub-base
的能力,那么您也需要 phony targets。
.PHONY: base sub-base
base: base.output
sub-base: sub-base.output