makefile包含库目录_如何获取包含其他Makefile的Makefile目录

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.mkreleas.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保留在哪个目录上。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自: https://www.systutorials.com/how-to-get-a-makefiles-directory-for-including-other-makefiles/

makefile包含库目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值