【发布时间】:2014-04-11 01:49:12
【问题描述】:
我有一个像这样的makefile:
file1 = "path/to/some/file"
header="col1;col2;col3"
$(file1):
some steps to create the file
call_perl_script:$(file1)
${perl} script.pl in=header
标头当前是硬编码的,它也在生成的 file1 中。我需要从 file1 中获取标题。不知怎的,我改变了它像
file1 = "path/to/some/file"
$(file1):
some steps to create the file
$(eval header="$(shell $(sed) -n "/^col1;col2;col3/Ip" $(file1))")
call_perl_script:$(file1)
${perl} script.pl in=$(header)
它工作正常,但想知道它是否是使用目标特定变量的正确方法。在与 eval 一起使用之前,标头不会传递其值。 此外,如果我在 call_perl_script 目标中打印 $(header),它会正确打印,但如果我使用“if”条件检查变量是否为空并设置默认值,那么它就不起作用。它在“if”块中设置 header 的值,而不考虑“sed”输出中 header 中的值。
call_perl_script:$(file1)
${echo} $(header)
ifeq "$(header)" ""
$(eval header="col1;col2;col3")
endif
${perl} script.pl in=$(header)
【问题讨论】: