最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Makefile自定义函数调用出错:unterminated call to function `notdir’: missing `)’. Stop

makefile crifan 5109浏览 0评论

折腾:

【已解决】Makefile中实现自己的函数并调用

期间,Makefile中尝试自己写函数:

<code>define getCurrentDirAndDirName
# get current folder name
  # support call makefile from anywhere, not only from current path of makefile located
  # MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
  # CURRENT_DIR_WITH_SLASH := $(notdir $(patsubst %/,%,$(MAKEFILE_DIR))
  MAKEFILE_LIST_LASTWORD = $(lastword $(MAKEFILE_LIST))
  MAKEFILE_PATH := $(abspath $(MAKEFILE_LIST_LASTWORD))
  MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
  MAKEFILE_DIR_PATSUBST := $(patsubst %/,%,$(MAKEFILE_DIR))
  MAKEFILE_DIR_NOSLASH = $(MAKEFILE_DIR_PATSUBST)
  CURRENT_DIR_WITH_SLASH = $(MAKEFILE_DIR)
  CURRENT_DIR = $(MAKEFILE_DIR_NOSLASH)
  CURRENT_DIR_NAME := $(notdir $(MAKEFILE_DIR_PATSUBST))
  $(1) := $$(CURRENT_DIR_NAME)
  $(2) := $$(CURRENT_DIR)
endef

$(eval $(call getCurrentDirAndDirName, CURRENT_DIR_NAME, CURRENT_DIR))
echo "CURRENT_DIR_NAME="$(CURRENT_DIR_NAME)
$(info "CURRENT_DIR="${CURRENT_DIR})
</code>

结果调用出错:

<code>../Makefile_common:34: *** unterminated call to function `notdir': missing `)'.  Stop.
</code>

然后去加上echo:

<code>  MAKEFILE_LIST_LASTWORD = $(lastword $(MAKEFILE_LIST))
  echo MAKEFILE_LIST_LASTWORD=$(MAKEFILE_LIST_LASTWORD)

  MAKEFILE_PATH := $(abspath $(MAKEFILE_LIST_LASTWORD))
  echo MAKEFILE_PATH=$(MAKEFILE_PATH)

  MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
</code>

都无法打印出信息。

makefile unterminated call to function `notdir’: missing `)’.  Stop.

[ovs-discuss] Makefile.main:14: *** unterminated call to function `foreach’: missing `)’. Stop.

[转]Makefile的常见错误信息 – CSDN博客

Multiple Shell command in Makefile – Stack Overflow

makefile custom function echo not working

makefile – GNU make conditional function $(if …) inside a user-defined function always evaluates to true – Stack Overflow

gnu make – Echo command in makefile not printing – Stack Overflow

Is there a way to tell my makefile to output a custom error message if a certain an include file is not found? – Stack Overflow

cross platform – makefile custom functions – Stack Overflow

makefile – Defining custom GNU make functions – Stack Overflow

难道是自定义函数中,多加了tab,没有开头?

改为:

<code>define getCurrentDirAndDirName
# get current folder name
# support call makefile from anywhere, not only from current path of makefile located
# MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
# CURRENT_DIR_WITH_SLASH := $(notdir $(patsubst %/,%,$(MAKEFILE_DIR))
MAKEFILE_LIST_LASTWORD = $(lastword $(MAKEFILE_LIST))
echo MAKEFILE_LIST_LASTWORD=$(MAKEFILE_LIST_LASTWORD)

MAKEFILE_PATH := $(abspath $(MAKEFILE_LIST_LASTWORD))
echo MAKEFILE_PATH=$(MAKEFILE_PATH)

MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
MAKEFILE_DIR_PATSUBST := $(patsubst %/,%,$(MAKEFILE_DIR))
MAKEFILE_DIR_NOSLASH = $(MAKEFILE_DIR_PATSUBST)
CURRENT_DIR_WITH_SLASH = $(MAKEFILE_DIR)
CURRENT_DIR = $(MAKEFILE_DIR_NOSLASH)
CURRENT_DIR_NAME := $(notdir $(MAKEFILE_DIR_PATSUBST))
$(1) := $$(CURRENT_DIR_NAME)
$(2) := $$(CURRENT_DIR)
endef
</code>

结果:问题依旧。

把:

<code>$(1) := $$(CURRENT_DIR_NAME)
$(2) := $$(CURRENT_DIR)
</code>

改为:

<code>$(1) := $(CURRENT_DIR_NAME)
$(2) := $(CURRENT_DIR)
</code>

结果:

问题依旧。

makefile – Defining custom GNU make functions – Stack Overflow

11. Example Makefiles – Managing Projects with GNU Make, 3rd Edition [Book]

才注意到:

makefile – Defining custom GNU make functions – Stack Overflow

11. Example Makefiles – Managing Projects with GNU Make, 3rd Edition [Book]

define的函数中,都是 $1,而不是$(1)去访问参数的。

所以改为:

<code>CURRENT_DIR_NAME := $(notdir $(MAKEFILE_DIR_PATSUBST))
$1 := $(CURRENT_DIR_NAME)
$2 := $(CURRENT_DIR)
</code>

结果:

问题依旧。

看起来像是:notdir的问题?

makefile notdir

GNU make: File Name Functions

makefile中wildcard notdir patsubst的简单介绍 – CSDN博客

$(notdir names…)

Extracts all but the directory-part of each file name in names. If the file name contains no slash, it is left unchanged. Otherwise, everything through the last slash is removed from it.

A file name that ends with a slash becomes an empty string. This is unfortunate, because it means that the result does not always have the same number of whitespace-separated file names as the argument had; but we do not see any other valid alternative.

For example,

$(notdir src/foo.c hacks)

produces the result ‘foo.c hacks’.

暂时注释掉notdir试试:

<code>CURRENT_DIR = $(MAKEFILE_DIR_NOSLASH)
# CURRENT_DIR_NAME := $(notdir $(MAKEFILE_DIR_PATSUBST))
# $1 := $(CURRENT_DIR_NAME)
$2 := $(CURRENT_DIR)
endef
</code>

结果:问题依旧。

把34行的,define的函数开始的注释移到函数外面:

<code># get current folder name
# support call makefile from anywhere, not only from current path of makefile located
# MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
# CURRENT_DIR_WITH_SLASH := $(notdir $(patsubst %/,%,$(MAKEFILE_DIR))
define getCurrentDirAndDirName
MAKEFILE_LIST_LASTWORD = $(lastword $(MAKEFILE_LIST))
# echo MAKEFILE_LIST_LASTWORD=$(MAKEFILE_LIST_LASTWORD)
$(info "MAKEFILE_LIST_LASTWORD="${MAKEFILE_LIST_LASTWORD})

MAKEFILE_PATH := $(abspath $(MAKEFILE_LIST_LASTWORD))
echo MAKEFILE_PATH=$(MAKEFILE_PATH)

MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
MAKEFILE_DIR_PATSUBST := $(patsubst %/,%,$(MAKEFILE_DIR))
MAKEFILE_DIR_NOSLASH = $(MAKEFILE_DIR_PATSUBST)
CURRENT_DIR_WITH_SLASH = $(MAKEFILE_DIR)
CURRENT_DIR = $(MAKEFILE_DIR_NOSLASH)
# CURRENT_DIR_NAME := $(notdir $(MAKEFILE_DIR_PATSUBST))
# $1 := $(CURRENT_DIR_NAME)
$2 := $(CURRENT_DIR)
endef
</code>

结果:

可以正常运行了。。。

在此期间出现:

【已解决】Makefile中define自定义函数中打印输出没效果

【总结】

此处的:

<code>define getCurrentDirAndDirName
# get current folder name
...
endef
</code>

的Makefile中出错:

unterminated call to function `notdir’: missing `)’.  Stop

的原因是:

define的开始不能包含# xxx的注释

解决办法是:

把# xxx移动到define 自定义函数外部:

<code># get current folder name
# support call makefile from anywhere, not only from current path of makefile located
# MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
# CURRENT_DIR_WITH_SLASH := $(notdir $(patsubst %/,%,$(MAKEFILE_DIR))
define getCurrentDirAndDirName
MAKEFILE_LIST_LASTWORD = $(lastword $(MAKEFILE_LIST))
# echo MAKEFILE_LIST_LASTWORD=${MAKEFILE_LIST_LASTWORD}
# $(info "MAKEFILE_LIST_LASTWORD="${MAKEFILE_LIST_LASTWORD})
# print MAKEFILE_LIST_LASTWORD

xxx
endef
</code>

即可。

转载请注明:在路上 » 【已解决】Makefile自定义函数调用出错:unterminated call to function `notdir’: missing `)’. Stop

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.190 seconds, using 22.05MB memory