如何使用 makefile 函数中的 if 语句?
how to use if statement from a makefile function?
我正在从 .config 文件中读取配置,如果配置已启用,我想执行一些操作。我编写了以下函数,但它抛出错误消息“/bin/sh:1:语法错误:”)“意外(预期"then")”
define parse_configs
while read -r file; do \
config=$$(echo $$file | grep -Po '(?<=(CONFIG_)).*(?==)'); \
val=$$(echo $$file | grep -Po '(?<=(=)).*'); \
$$(if $(findstring y, $$val), echo "do Ops", echo "No ops"); \
done < .config;
endef
问题出在if语句,函数的其他部分没问题。请让我知道代码中的错误。谢谢
声明有什么问题:
$$(if $(findstring y, $$val), echo "do Ops", echo "No ops");
其实就是一个GNU Make if-function,
调用 GNU Make findstring-function,
您在 shell 语句的中间写了它,并要求 ($$
) 它被 shell 扩展,但它对 shell 没有意义。
它也可能是 Javascript。将其替换为适当的 shell if 语句,例如
while read -r file; do \
config=$$(echo $$file | grep -Po '(?<=(CONFIG_)).*(?==)'); \
val=$$(echo $$file | grep -Po '(?<=(=)).*'); \
if [ -z $${val##*"y"*} ]; then echo "do Ops"; else echo "No ops"; fi; \
done < .config;
我正在从 .config 文件中读取配置,如果配置已启用,我想执行一些操作。我编写了以下函数,但它抛出错误消息“/bin/sh:1:语法错误:”)“意外(预期"then")”
define parse_configs
while read -r file; do \
config=$$(echo $$file | grep -Po '(?<=(CONFIG_)).*(?==)'); \
val=$$(echo $$file | grep -Po '(?<=(=)).*'); \
$$(if $(findstring y, $$val), echo "do Ops", echo "No ops"); \
done < .config;
endef
问题出在if语句,函数的其他部分没问题。请让我知道代码中的错误。谢谢
声明有什么问题:
$$(if $(findstring y, $$val), echo "do Ops", echo "No ops");
其实就是一个GNU Make if-function,
调用 GNU Make findstring-function,
您在 shell 语句的中间写了它,并要求 ($$
) 它被 shell 扩展,但它对 shell 没有意义。
它也可能是 Javascript。将其替换为适当的 shell if 语句,例如
while read -r file; do \
config=$$(echo $$file | grep -Po '(?<=(CONFIG_)).*(?==)'); \
val=$$(echo $$file | grep -Po '(?<=(=)).*'); \
if [ -z $${val##*"y"*} ]; then echo "do Ops"; else echo "No ops"; fi; \
done < .config;