我有几个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,以便将二进制文件放在各自的类型文件夹中?


当前回答

解决方案:https://sourceforge.net/p/ipt-netflow/bugs-requests-patches/53/

解决方案是:$(CURDIR)

你可以这样使用它:

CUR_DIR = $(CURDIR)

## Start :
start:
    cd $(CUR_DIR)/path_to_folder

其他回答

解决方案:https://sourceforge.net/p/ipt-netflow/bugs-requests-patches/53/

解决方案是:$(CURDIR)

你可以这样使用它:

CUR_DIR = $(CURDIR)

## Start :
start:
    cd $(CUR_DIR)/path_to_folder

用{}代替()

cur_dir=${shell pwd}
parent_dir=${shell dirname ${shell pwd}}}

从这里带走;

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

Makefile中的一行就足够了:

= $(notdir $(CURDIR))

如果您正在使用GNU make, $(CURDIR)实际上是一个内置变量。它是Makefile所在的位置,当前工作目录可能是Makefile所在的位置,但并不总是这样。

OUTPUT_PATH = /project1/bin/$(notdir $(CURDIR))

参见http://www.gnu.org/software/make/manual/make.html中的“附录A快速参考”