我在make文件的顶部定义了以下代码,它读取文件的内容并正确地将文本解析为变量:
VER_VAR:=$(shell cat output/target/version.txt)
FILENAME_BIN=$(word 1, $(VER_VAR)).$(word 2, $(VER_VAR)).$(word 3, $(VER_VAR)).bin
FILENAME_JFFS2=$(word 1, $(VER_VAR)).$(word 2, $(VER_VAR)).$(word 3, $(VER_VAR)).jffs2
读取的文件格式:
str1 str2 1.1.0_nightlybuild (1389:1497M@trunk)
但是我想将此代码移动到这样的函数中:
define EXAMPLE
VER_VAR:=$(shell cat output/target/version.txt)
FILENAME_BIN=$(word 1, $(VER_VAR)).$(word 2, $(VER_VAR)).$(word 3, $(VER_VAR)).bin
FILENAME_JFFS2=$(word 1, $(VER_VAR)).$(word 2, $(VER_VAR)).$(word 3, $(VER_VAR)).jffs2
endef
这会导致错误:
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `VER_VAR:=str1 str2 1.1.0_nightlybuild (1389:1497M@trunk)'
make: *** [/home/buildmaster/svn_main/buildroot/output/images/rootfs.ext2] Error 1
几个问题。为什么这会导致函数中的错误而不是文件的顶部。我该如何解决?我试过报价等,这只会导致更多的错误。
例如,如果我尝试:
VER_VAR:="$(shell cat output/target/version.txt)"
我明白了:
VER_VAR:="str1 str2 1.1.0_nightlybuild (1389:1497M@trunk)"
/bin/bash: VER_VAR:=str1 str2 1.1.0_nightlybuild (1389:1497M@trunk): command not found
调用示例:
# Alter the post-gen hooks, depending on what options are selected
ifneq ($(BR2_TARGET_ROOTFS_EXT2_BOOTIMAGE),)
ROOTFS_EXT2_POST_GEN_HOOKS += EXAMPLE
endif