这里是获取马克图书目录的跨平台方式,该目录应完全 she。
makeFileDir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
请注意,这将为您提供Makefile目前被解释的名录<>。 如果你使用另一个人的陈述列入一份男性档案,你可能会有坏(或好!)的惊讶。
如果你利用最近对窗户(即Chocolatey s的话,就足够了。
Issues with older make for Windows
根据您在视窗上重新使用这一版本,处理回击可能会有不一致之处。 您可能需要以下一种变量。 The s case for 例如,GnuWin s ,3.81 binary。
- Make the path separator consistent. The statement below uses forward slashes only, just swap
and /
to get the opposite behavior. From my experience (with GnuWin s make), you might have to use forward slashes to use such a variable for make include
statements or to use it in VPATH
.
But you would of course need backslashes in the DOS shell, and therefore in recipes... You might need two versions of the variable, but at least the substitution makes sure that the path separator is consistent!
makeFileDir := $(subst ,/,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
- The
abspath
function of GnuWin make 3.81 is broken and doesn t handle paths with drive letters in it. Here is a workaround to handle Windows absolute paths (with drive letter) as well. You can then use it to get the directory of the Makefile (here with the path separator substitution as well).
I won t explain the details, but the workaround simply returns the argument if that s already a Windows absolute path, i.e. if there is :
in the root of the path, and uses the builtin abspath
otherwise.
define fixabspath
$(if $(findstring :,$(firstword $(subst /, ,$(subst ,/,$(1))))),$$
$(1),$
$(abspath $(1)))
makeFileDir := $(subst ,/,$(dir $(call fixabspath,$(lastword $(MAKEFILE_LIST)))))
- There might be sources I m omitting here and I m sorry for that. It s been a long time ago.
- In the
fixabspath
definition, $
are just here to split the line for readability.
- The
MAKEFILE_LIST
variable contains a list of the Makefiles being interpreted, the last one being the current one. See the corresponding manual page.
- If I remember correctly, this also works with macOS native make.