运行 在 WSL 下的 Makefile 中使用标志回显

Running echo with flags in a Makefile under WSL

我正在尝试从包含以下行的 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

问题是生成的 Debug64/Makefile 文件如下所示:

-e all: bld

-e %.o: ../../%.c
-e      gcc -O3 $(CFLAGS) $(INCLUDE) $< -o $@

一位同事刚刚在一台实际的 Linux 机器上向我展示了 make 命令在那里正常工作,并且前面的 -e 标志没有打印在生成的 Debug64/Makefile.我做错了什么?

使用 printf(1) 命令代替 echo。所以你的最后一行是

@printf "\tgcc -g %s %s $$< -o $$@\n" $$(CFLAGS) $$(INCLUDE)

顺便说一句,如果您将 build automation script, consider switching to ninja. You might use Guile or Python or GNU awk 生成为这样的生成器。