[英]Running echo with flags in a Makefile under WSL
I am trying to run a Makefile
from under WSL that contains the following lines:我正在尝试从 WSL 下运行包含以下行的Makefile
:
debug: create_soft_links
@mkdir -p Debug64
@echo -e 'all: bld' > Debug64/Makefile
@echo >> Debug64/Makefile
@echo -e '%.o: ../../%.c' >> Debug64/Makefile
@echo -e '\tgcc -g $$(CFLAGS) $$(INCLUDE) $$< -o $$@' >> Debug64/Makefile
Problem is that the resulting Debug64/Makefile
file looks like this:问题是生成的Debug64/Makefile
文件如下所示:
-e all: bld
-e %.o: ../../%.c
-e gcc -O3 $(CFLAGS) $(INCLUDE) $< -o $@
A colleague just showed me on an actual Linux machine that the make
command works correctly there, and the preceding -e
flag is not printed in the generated Debug64/Makefile
.一位同事刚刚在一台实际的 Linux 机器上向我展示了make
命令在那里正常工作,并且前面的-e
标志没有打印在生成的Debug64/Makefile
。 What am I doing wrong?我究竟做错了什么?
Use instead of echo
the printf(1) command.使用printf(1)命令代替echo
。 So your last line would be所以你的最后一行是
@printf "\tgcc -g %s %s $$< -o $$@\n" $$(CFLAGS) $$(INCLUDE)
BTW, if you generate your build automation script, consider switching to ninja .顺便说一句,如果您生成构建自动化脚本,请考虑切换到ninja 。 You might use Guile or Python or GNU awk as such a generator.您可以使用Guile或Python或GNU awk作为此类生成器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.