Makefile 如何将目录添加到GNU Make的搜索路径?
我有一个makefile,看起来像这样:Makefile 如何将目录添加到GNU Make的搜索路径?,makefile,gnu-make,Makefile,Gnu Make,我有一个makefile,看起来像这样: include anotherFile.mk all: someStuff include yetAnotherFile.mk export SOME_VAR = 93 OTHER_PROJECT_PATH := other ifeq (,$(filter $(OTHER_PROJECT_PATH), $(.INCLUDE_DIRS))) # this is the mechanism to add the include dir in a
include anotherFile.mk
all:
someStuff
include yetAnotherFile.mk
export SOME_VAR = 93
OTHER_PROJECT_PATH := other
ifeq (,$(filter $(OTHER_PROJECT_PATH), $(.INCLUDE_DIRS)))
# this is the mechanism to add the include dir in a recursive make
$(or $(firstword $(MAKECMDGOALS)),all):
$(MAKE) -I$(OTHER_PROJECT_PATH) $(MAKECMDGOALS)
# add empty targets for additional goals if needed
ifneq (,$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):
endif
else
# this is where the real makefile starts
all more:
echo $@: $< $^
include a.mak
endif
文件另一个文件.mk
如下所示:
include anotherFile.mk
all:
someStuff
include yetAnotherFile.mk
export SOME_VAR = 93
OTHER_PROJECT_PATH := other
ifeq (,$(filter $(OTHER_PROJECT_PATH), $(.INCLUDE_DIRS)))
# this is the mechanism to add the include dir in a recursive make
$(or $(firstword $(MAKECMDGOALS)),all):
$(MAKE) -I$(OTHER_PROJECT_PATH) $(MAKECMDGOALS)
# add empty targets for additional goals if needed
ifneq (,$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):
endif
else
# this is where the real makefile starts
all more:
echo $@: $< $^
include a.mak
endif
问题是anotherFile.mk
和yetAnotherFile.mk
与我的Makefile位于不同的目录中。因此,我的makefile不能仅更改为:
include $(OTHER_PROJECT_PATH)/anotherFile.mk
all:
someStuff
这种方法的问题是,anotherFile.mk
中的include语句将失败,因为它将在当前目录中搜索
我发现的部分解决方案是将--include dir=$OTHER\u PROJECT\u PATH
标志传递给make的调用,但这对用户来说有点不友好
所以我的问题是:在执行
include
时,我是否可以在我的makefile中添加一些东西,以添加到进行搜索的目录中?类似于MAKE\u INCLUDE\u DIRS+=$(其他项目路径)
令人惊讶的是,这个问题似乎没有一个好的答案。强制执行.INCLUDE\u DIR
没有帮助,而且似乎没有任何方法可以通过调用make
——INCLUDE DIR=$OTHER\u PROJECT\u PATH
然而,可以在makefile中放置适当的递归make调用,但是为了使它在所有合理的情况下都能工作,它很快变得太复杂,不值得这样做。总之,它要求:
- 检查
其他项目路径是否在
中的顶级条件。INCLUDE\u DIR
- 配方递归调用make的相应目标
- 如果有多个指挥目标,则可能有其他目标
- 包含在条件文件的
部分中的real make文件else
include anotherFile.mk
all:
someStuff
include yetAnotherFile.mk
export SOME_VAR = 93
OTHER_PROJECT_PATH := other
ifeq (,$(filter $(OTHER_PROJECT_PATH), $(.INCLUDE_DIRS)))
# this is the mechanism to add the include dir in a recursive make
$(or $(firstword $(MAKECMDGOALS)),all):
$(MAKE) -I$(OTHER_PROJECT_PATH) $(MAKECMDGOALS)
# add empty targets for additional goals if needed
ifneq (,$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):
endif
else
# this is where the real makefile starts
all more:
echo $@: $< $^
include a.mak
endif
OTHER\u项目路径:=OTHER
ifeq(,$(过滤器$(其他项目路径),$(包含目录)))
#这是在递归make中添加include dir的机制
$(或$(firstword$(MAKECMDGOALS)),全部:
$(MAKE)-I$(其他项目路径)$(MAKECMDGOALS)
#如果需要,为其他目标添加空目标
ifneq(,$(单词列表2,$(单词$(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(单词表2,$(单词$(MAKECMDGOALS)),$(MAKECMDGOALS)):
恩迪夫
其他的
#这就是真正的makefile开始的地方
更重要的是:
echo$@:$<$^
包括a.mak
恩迪夫
令人惊讶的是,这个问题似乎没有一个好的答案。强制执行.INCLUDE\u DIR
没有帮助,而且似乎没有任何方法可以通过调用make
——INCLUDE DIR=$OTHER\u PROJECT\u PATH
然而,可以在makefile中放置适当的递归make调用,但是为了使它在所有合理的情况下都能工作,它很快变得太复杂,不值得这样做。总之,它要求:
- 检查
其他项目路径是否在
中的顶级条件。INCLUDE\u DIR
- 配方递归调用make的相应目标
- 如果有多个指挥目标,则可能有其他目标
- 包含在条件文件的
部分中的real make文件else
include anotherFile.mk
all:
someStuff
include yetAnotherFile.mk
export SOME_VAR = 93
OTHER_PROJECT_PATH := other
ifeq (,$(filter $(OTHER_PROJECT_PATH), $(.INCLUDE_DIRS)))
# this is the mechanism to add the include dir in a recursive make
$(or $(firstword $(MAKECMDGOALS)),all):
$(MAKE) -I$(OTHER_PROJECT_PATH) $(MAKECMDGOALS)
# add empty targets for additional goals if needed
ifneq (,$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)):
endif
else
# this is where the real makefile starts
all more:
echo $@: $< $^
include a.mak
endif
OTHER\u项目路径:=OTHER
ifeq(,$(过滤器$(其他项目路径),$(包含目录)))
#这是在递归make中添加include dir的机制
$(或$(firstword$(MAKECMDGOALS)),全部:
$(MAKE)-I$(其他项目路径)$(MAKECMDGOALS)
#如果需要,为其他目标添加空目标
ifneq(,$(单词列表2,$(单词$(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(单词表2,$(单词$(MAKECMDGOALS)),$(MAKECMDGOALS)):
恩迪夫
其他的
#这就是真正的makefile开始的地方
更重要的是:
echo$@:$<$^
包括a.mak
恩迪夫
从makefile看来仍然不可能,但是如果您有一个设置环境变量的脚本,您可以使用Makefagas(例如,在Linux上导出Makefagas=I/your/path或在Windows上设置)从makefile看来仍然不可能,但是如果您有一个设置环境变量的脚本,您可以使用MAKEFLAGS(例如,在Linux上导出MAKEFLAGS=I/your/path或entlich,或在Windows上设置)