TL;博士:
这在 MacOS (catalina) 的 Makefile 中不起作用:
grab_setup_rule != cat $(all_makefiles_except_current) | grep -h -E '.+-setup:.*##' | awk '{ print $1 }'
但是在命令行上执行时,用$(all_makefiles_except_current)
正确的路径替换,它可以工作。
深入解释
嘿,
我在 Makefile 中有以下代码:
BASEPATH = ..
repos = project1 project2
possible_includes = $(foreach repo,$(repos), $(BASEPATH)/$(repo)/Makefile)
-include $(possible_includes)
all_makefiles_except_current := $(wordlist 2,$(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
grab_setup_rule != cat $(all_makefiles_except_current) | grep -h -E '.+-setup:.*##' | awk '{ print $1 }'
这样做是包含repos
变量中指定的所有 Makefile,获取所有包含文件的列表,设置在 中all_makefiles_except_current
,然后尝试从以 .结尾的 Makefile 中获取所有目标-setup
。
这是包含的 Makefile 中的示例:
projectName-targetX: ### desc
code
projectName-setup: ## desc
code
<.. more targets ..>
这是一个自我记录的 makefile。
如果我运行 shell 命令:
cat ../project1/Makefile | grep -h -E '.+-setup:.*##' | awk '{ print $1 }'
注意:在 windows 和 linux 上,grep 正则表达式必须没有单引号,例如:grep -h -E .+-setup:.*##
在命令行IT WORKS上,我得到了我想要的目标,这将在 Windows (msys2)、Linux (ubuntu) 和 MacOS (catalina) 上运行。
但在 Makefile 中,MacOS 中的grab_setup_rule
始终为空。似乎它没有得到正确处理。
我grab_setup_rule
在 MacOS 上做错了什么?