我在应用程序的特定目录中有几个Makefile,如下所示:
/project1/apps/app_typeA/Makefile
/project1/apps/app_typeB/Makefile
/project1/apps/app_typeC/Makefile
每个Makefile在上一级路径中都包含一个.inc文件:
/project1/apps/app_rules.inc
在app_rules.inc中,我设置了构建时放置二进制文件的目标位置。我希望所有的二进制文件都在它们各自的app_type
路径中:
/project1/bin/app_typeA/
我尝试这样使用 $(CURDIR)
,:
OUTPUT_PATH = /project1/bin/$(CURDIR)
但是,我将二进制文件隐藏在整个路径名中,如下所示:(注意冗余)
/project1/bin/projects/users/bob/project1/apps/app_typeA
我可以做什么来获得执行的“当前目录”,这样我就可以知道app_typeX
,以便将二进制文件放在它们各自的类型文件夹中?
发布于 2013-08-09 06:11:50
shell函数。
您可以使用shell
函数:current_dir = $(shell pwd)
。如果不需要绝对路径:current_dir = $(notdir $(shell pwd))
,也可以将shell
与notdir
结合使用。
更新。
给定的解决方案仅在您从Makefile的当前目录运行make
时有效。
正如@Flimm所说:
请注意,这将返回当前工作目录,而不是Makefile的父目录。
例如,如果运行cd /; make -f /home/username/project/Makefile
,则current_dir
变量将为/
,而不是/home/username/project/
。
下面的代码将适用于从任何目录调用的Makefiles:
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
发布于 2014-04-27 22:37:04
取自here;
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
显示为;
$ cd /home/user/
$ make -f test/Makefile
/home/user/test
$ cd test; make Makefile
/home/user/test
希望这能有所帮助
发布于 2015-03-16 15:45:12
THIS_DIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
https://stackoverflow.com/questions/18136918
复制相似问题