非递归使收缩目标 [英] non-recursive make constrict targets
问题描述
基于本文,我正在尝试重做以下内容的子集我的构建系统是非递归的.实际上效果很好.默认情况下,我通过模板将makefile include
的所有相关目录的一部分包含在其中:
Based on this paper, I'm trying to rework a subset of my build system to be non-recursive. It's actually working pretty well. By default, I have part of my makefile include
all the relevant directories via a template:
DIRECTORIES = dirA dirB ... etc ...
define import_template
dir := $(1)
include $(1)/Rules.mk
include Rules.mk
endef
$(foreach DIR,$(DIRECTORIES), \
$(eval $(call import_template,$(DIR))))
那些includes
建立一个像TGT_BIN
这样的变量,就像所有文章一样,它们都可以工作.
Those includes
build up a variables like TGT_BIN
, a la the paper, that all works.
$ make # does the right thing
但是,我想为用户提供制作这些目录子集的功能.我知道我可以像这样定义DIRECTORIES
However, I want to provide the user the ability to make a subset of those directories. I know I can define DIRECTORIES
like:
DIRECTORIES ?= dirA ...
因此:
$ make DIRECTORIES="dirB dirF"
有效.但是有没有办法这样写我的makefile:
works. But is there a way to write my makefile such that:
$ make -j12 dirB dirF
会做同样的事情吗?
推荐答案
假定您要构建每个目录的目标变量(例如TGT_dirB
,TGT_dirF
等),那么您要做的就应该很简单添加:
Assuming you have per-directory variables of targets to build (e.g. TGT_dirB
, TGT_dirF
, etc.) then doing what you want should be as simple as adding:
$(eval $(DIR): $(TGT_$(DIR)))
像这样
进入foreach
循环:
$(eval $(call import_template,$(DIR)))$(eval $(DIR): $(TGT_$(DIR)))
将所有每个目录目标添加为目录目标的先决条件.
to add all the per-directory targets as pre-requisites of the directory targets.
并添加
.PHONY: $(DIRECTORIES)
在makefile中的某个位置,以确保make意识到这些对象是虚假的目标,实际上并不意味着目录本身.
somewhere in the makefile to make sure make realizes those are phony targets and don't actually mean the directories themselves.
这篇关于非递归使收缩目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!