使用sed

时间:2016-11-08 04:48:40

标签: sed makefile

我正在尝试使用sed更改Makefile变量。我写了一个小的Makefile来说明我想要做的事情。 CINCS变量最终将附加到CFLAGS变量。 CSINCS变量应该保存所有包含文件的路径,前面没有“-I”。

SHELL = /bin/sh

SRCS = /usr/local/src/jpeg/jpeg-9b
CINCS = -I/usr/local/src/jpeg/jpeg-9b
CSINCS = $(CINCS) | sed -e "s/-I//g"

check:
@echo 1. $(SRCS)
find $(SRCS) -name "*.c" -print > cscope.files
@echo 2. $(CSINCS)
find '$(CSINCS) -name" "*.h' -print >> cscope.files
cscope -k -b
cat cscope.files | xargs ctags -u

我正在尝试删除所有包含路径前面的“-I”。执行官:

$ make -f test check
1. /usr/local/src/jpeg/jpeg-9b
find /usr/local/src/jpeg/jpeg-9b -name "*.c" -print > cscope.files
2. /usr/local/src/jpeg/jpeg-9b
find '-I/usr/local/src/jpeg/jpeg-9b | sed -e "s/-I//g" -name" "*.h'   -print >> cscope.files
find: unknown predicate `-I/usr/local/src/jpeg/jpeg-9b | sed -e "s/-I//g" -name" "*.h'
test:8: recipe for target 'check' failed
make: *** [check] Error 1

位置“2”CSINCS变量看起来正确。但是有一个“查找命令”的扩展。这就是问题所在。

我知道我可以在cscope命令中使用CINCS变量:

cscope -I $(CINCS)

但我也希望将cscope.files用于ctags文件。我可以生成一个单独的CSINCS变量,并始终保持CINCS和CSINCS同步。只是好奇发生了什么。

1 个答案:

答案 0 :(得分:3)

你没有告诉make将CSINCS的值作为shell脚本执行,你需要像

这样的东西
CSINCS := $(shell echo $(CINCS) | sed -e "s/-I//g")

或者如果您最近制作4.0或更多

CSINCS != echo $(CINCS) | sed -e "s/-I//g"

虽然对于这个简单的东西,你不需要使用sed或shell

CSINCS := $(subst -I,,$(CINCS))
相关问题