makefile包含库目录
I experience this problem:
我遇到这个问题:
I have a file common.mk that includes release.mk which in the same directory. common.mk is included by the top-level Makefile. common.mk and release.mk are shared by multiple projects and the top-level Makefile may stay in different directories with {common,release}.mk.
我有一个文件common.mk,其中包含同一目录中的release.mk。 common.mk包含在顶层Makefile中 。 common.mk和release.mk由多个项目共享,并且顶层Makefile与{common,release} .mk可能位于不同的目录中。
Now, include
in make use the pwd
as base directory. So, simply include release.mk
does not work if the top-level Makefile is not in the same directory as releas.mk
.
现在, include
在利用pwd
作为基本目录。 因此,如果顶级Makefile与releas.mk
不在同一目录中,则只需include release.mk
就releas.mk
。
For example, in a directory structure like
例如,在目录结构中
Makefile
common.mk
release.mk
it is find. But for
找到了。 但对于
Makefile
external/common.mk
external/release.mk
The same include release.mk
in commin.mk will reports that release.mk does not exists.
commin.mk中的相同include release.mk
将报告release.mk不存在。
In bash, we can use $(dirname $0)
to get the current script’s directory. How to achieve the similar thing in Makefile so that I can use include $(self_dir)/release.mk
?
在bash中,我们可以使用$(dirname $0)
来获取当前脚本的目录。 如何在Makefile中实现类似的功能,以便可以使用include $(self_dir)/release.mk
?
The key is to find the “current” makefile’s directory:
关键是找到“当前” makefile的目录:
SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
SELF_DIR
will contain the directory of the makefile which contains this piece of code. So you can include
the release.mk by:
SELF_DIR
将包含包含此代码段的makefile目录。 因此,您可以通过以下方式include
release.mk:
include $(SELF_DIR)/release.mk
This will not reply on which directory the top-level Makefile stay in anymore.
这将不再答复顶级Makefile保留在哪个目录上。
翻译自: https://www.systutorials.com/how-to-get-a-makefiles-directory-for-including-other-makefiles/
makefile包含库目录