检查Makefile中路径的有效性

时间:2016-06-16 17:15:39

标签: makefile

我的系统中所有机器都有/workarea/myjob目录。但是,某些作业是分布式的,因此用户需要使用/net/<hostname>/workarea/myjob

cd到其运行目录

如果用户尝试在路径中没有/net/<hostname>的情况下进行构建,则作业最终会失败。

我想在开始构建之前检查pwd是否在Makefile中返回/net/<hostname>/workarea形式的路径。

这样做的好方法是什么?

1 个答案:

答案 0 :(得分:4)

GNU make当前目录位于${CURDIR}变量中。测试看起来像:

hostname := $(shell hostname)
ifeq ($(findstring /net/${hostname}/workarea, ${CURDIR}),)
$(error "Wrong current directory: ${CURDIR}")
endif