在 makefile 中将新创建的文件设置为变量
Set newly created file as variable in makefile
我正在尝试创建一个文件并将文件的内容设置为一个变量,但该变量始终显示为空。
一个例子:
define FILE_VAR
cat /output/1.txt >> /output/2.txt
$(eval s := $(shell cat /output/2.txt))
$(eval FILENAME_BIN=$(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).bin)
$(eval FILENAME_JFFS2=$(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).jffs2)
endef
如果 2.txt
在 运行 之前存在,变量将被设置为 运行 之前的数据(不是新的重定向数据),如果 2.txt
不存在则未设置变量。看起来它正在评估当 make 是第一个时文件是什么样的 运行,这不是我想要的...
您不清楚 GNU make 做了什么,什么时候做了什么,shell,
以及何时执行配方。
$(...)
形式的 makefile 中任何地方的任何内容都由 make
计算
除非它在 shell 命令中转义为 $$(...)
。
A shell 命令,除非在 make-function $(shell ...)
的上下文中或
back-ticks 只能是配方中的命令:
target: [prerequisite...]
command
...
组成配方的命令按顺序执行,每个命令都在不同的位置
shell,执行配方。
未转义形式 $(...)
中的任何内容都不是 command-sequence 中的命令
配方的扩展,除非它是您定义的 扩展 到命令的变量或宏的扩展。
目标范围内的一行不必是命令或扩展为命令。它
也可能包含一个 $(...)
表达式,它展开为空,
并简单地指示 make
做某事,例如
$(info ...)
展开为空,并告诉 make
在标准输出上打印 ...
。
$(eval ...)
展开为零并告诉 make
计算 ...
这个食谱只有两个命令,而不是四个:
target: prereq...
$(eval TARGET=$@)
command1
$(info $(TARGET))
command2
配方范围内的任何 make-expressions、$(...)
在
make 决定 运行 配方 和 command-sequence 时的顺序
在他们都被评估之后剩下。然后
command-sequence 是 运行。例如:
生成文件
target:
echo Hello > hello.txt
$(info Begin {)
$(eval s := $(shell cat hello.txt))
$(eval WORD=$(word 1, $(s)))
$(info [$(WORD)])
$(info } End)
运行 即:
$ make
Begin {
cat: hello.txt: No such file or directory
[]
} End
echo Hello > hello.txt
观察所有 make-expressions 在 之前被计算
目标的命令是 运行.
您的 FILE_VAR
宏显然打算在配方范围内扩展,因为第一行是 shell 命令。
因此,如果剩余的行依赖于
运行ning 第一行的效果。 None 他们这样做了。其余3行
如果在 make-time.
处不存在,则在 2.txt
存在之前进行评估
我正在尝试创建一个文件并将文件的内容设置为一个变量,但该变量始终显示为空。
一个例子:
define FILE_VAR
cat /output/1.txt >> /output/2.txt
$(eval s := $(shell cat /output/2.txt))
$(eval FILENAME_BIN=$(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).bin)
$(eval FILENAME_JFFS2=$(word 1, $(s)).$(word 2, $(s)).$(word 3, $(s)).jffs2)
endef
如果 2.txt
在 运行 之前存在,变量将被设置为 运行 之前的数据(不是新的重定向数据),如果 2.txt
不存在则未设置变量。看起来它正在评估当 make 是第一个时文件是什么样的 运行,这不是我想要的...
您不清楚 GNU make 做了什么,什么时候做了什么,shell, 以及何时执行配方。
$(...)
形式的 makefile 中任何地方的任何内容都由 make
计算
除非它在 shell 命令中转义为 $$(...)
。
A shell 命令,除非在 make-function $(shell ...)
的上下文中或
back-ticks 只能是配方中的命令:
target: [prerequisite...]
command
...
组成配方的命令按顺序执行,每个命令都在不同的位置 shell,执行配方。
未转义形式 $(...)
中的任何内容都不是 command-sequence 中的命令
配方的扩展,除非它是您定义的 扩展 到命令的变量或宏的扩展。
目标范围内的一行不必是命令或扩展为命令。它
也可能包含一个 $(...)
表达式,它展开为空,
并简单地指示 make
做某事,例如
$(info ...)
展开为空,并告诉 make
在标准输出上打印 ...
。
$(eval ...)
展开为零并告诉 make
计算 ...
这个食谱只有两个命令,而不是四个:
target: prereq...
$(eval TARGET=$@)
command1
$(info $(TARGET))
command2
配方范围内的任何 make-expressions、$(...)
在
make 决定 运行 配方 和 command-sequence 时的顺序
在他们都被评估之后剩下。然后
command-sequence 是 运行。例如:
生成文件
target:
echo Hello > hello.txt
$(info Begin {)
$(eval s := $(shell cat hello.txt))
$(eval WORD=$(word 1, $(s)))
$(info [$(WORD)])
$(info } End)
运行 即:
$ make
Begin {
cat: hello.txt: No such file or directory
[]
} End
echo Hello > hello.txt
观察所有 make-expressions 在 之前被计算 目标的命令是 运行.
您的 FILE_VAR
宏显然打算在配方范围内扩展,因为第一行是 shell 命令。
因此,如果剩余的行依赖于
运行ning 第一行的效果。 None 他们这样做了。其余3行
如果在 make-time.
2.txt
存在之前进行评估