Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
makefile中的变量扩展_Makefile_Variable Expansion - Fatal编程技术网

makefile中的变量扩展

makefile中的变量扩展,makefile,variable-expansion,Makefile,Variable Expansion,Make似乎仅在激活规则后才扩展变量 make ok显示已解析的名称(即“test”) makebad声称依赖于“grep”(而不是“test”) 在检查“坏”规则的依赖项之前,如何让make展开NAME CMakeLists.txt: add_executable(test testA.c testB.c) # compiler (output input input ...) 生成文件(完整): #======================================== # Sh

Make似乎仅在激活规则后才扩展变量

make ok
显示已解析的名称(即“test”)

makebad
声称依赖于“grep”(而不是“test”)

在检查“坏”规则的依赖项之前,如何让
make
展开NAME

CMakeLists.txt

add_executable(test testA.c testB.c)  # compiler (output input input ...)
生成文件(完整):

#========================================
# Shell cannot handle parentheses:
#    *** unterminated call to function 'shell': missing ')'.  Stop.
# Have also tried putting {"(", ")", "\(", "\)"} in variables
#   ...but it just created a different problem
#
#NAME := $(shell grep "add_executable(" CMakeLists.txt | sed 's/[^(]*( *\([^ ]*\) .*/\1/')
  
#========================================
# Curious results (same with or without the colon)
#
NAME := `grep "add_executable(" CMakeLists.txt | sed 's/[^(]*( *\([^ ]*\) .*/\1/'`
    
#========================================
# As expected, displays:
#    NAME=¦test¦"
#
PHONY: ok
ok:
    @echo "NAME=¦${NAME}¦"
 
#========================================
# Dies with:
#    *** No rule to make target '`grep', needed by 'bad'.  Stop."
#
.PHONY: bad
bad: ${NAME}
    @echo "NAME=¦${NAME}¦"
NAME := `grep "add_executable(" CMakeLists.txt | sed 's/[^(]*( *\([^ ]*\) .*/\1/'`
ok:
    @echo "NAME=¦${NAME}¦"
bad: ${NAME}
    @echo "NAME=¦${NAME}¦"
生成文件(相同,但压缩):

#========================================
# Shell cannot handle parentheses:
#    *** unterminated call to function 'shell': missing ')'.  Stop.
# Have also tried putting {"(", ")", "\(", "\)"} in variables
#   ...but it just created a different problem
#
#NAME := $(shell grep "add_executable(" CMakeLists.txt | sed 's/[^(]*( *\([^ ]*\) .*/\1/')
  
#========================================
# Curious results (same with or without the colon)
#
NAME := `grep "add_executable(" CMakeLists.txt | sed 's/[^(]*( *\([^ ]*\) .*/\1/'`
    
#========================================
# As expected, displays:
#    NAME=¦test¦"
#
PHONY: ok
ok:
    @echo "NAME=¦${NAME}¦"
 
#========================================
# Dies with:
#    *** No rule to make target '`grep', needed by 'bad'.  Stop."
#
.PHONY: bad
bad: ${NAME}
    @echo "NAME=¦${NAME}¦"
NAME := `grep "add_executable(" CMakeLists.txt | sed 's/[^(]*( *\([^ ]*\) .*/\1/'`
ok:
    @echo "NAME=¦${NAME}¦"
bad: ${NAME}
    @echo "NAME=¦${NAME}¦"

使用以下命令代替反引号:


(在
shell
命令中使用大括号而不是圆括号是一个很难在
sed
命令中使用圆括号的地方,我不知道如何优雅地转义。)

这里有一个粗略的解决方案,在我(或其他人)想出一个更优雅的解决方案之前,它将一直有效:
NAME:=$(shell sed-n)/add\u/{s/add|u executable.*/;s/*/;p;}“CMakeLists.txt)
非常感谢您向我展示了如何清理
grep | sed
:)谢谢。