gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
makefiel info输出莫一行
- User
makefiel info输出莫一行
- Assistant
Makefile info命令用于在Makefile中输出一行信息,可以用于调试或显示执行过程中的一些提示信息。
示例:
codeinfo This is a message from Makefile.输出:
codeThis is a message from Makefile. - User
??
- Assistant
抱歉,我犯了一个错误。在Makefile中,要输出一行信息,需要使用
$(info ...)的形式。示例:
code$(info This is a message from Makefile.)输出:
codeThis is a message from Makefile. - User
输出代码的行号
- Assistant
要输出代码的行号,在Makefile中可以使用
$(info ...)结合$(MAKEFILE_LIST)和$(shell)函数来实现。可以使用以下示例代码:makefiledefine newline endef define show_lineno @echo $(subst $(newline),,$(strip \ $(1): ; @echo Line $$(shell \ awk '/ifeq \(.*$(strip $(1))/{ print NR }' $(MAKEFILE_LIST))))) endef .PHONY: show-lineno show-lineno: $(call show_lineno,show-lineno) .PHONY: all all: $(call show_lineno,all) .PHONY: clean clean: $(call show_lineno,clean)在这个示例中,定义了一个名为
show_lineno的函数,该函数使用$(subst ...)函数去除行尾的换行符,然后使用$(strip ...)函数去除额外空格。接下来,使用$(shell ...)函数运行一个awk命令,该命令在Makefile中查找目标的行号,并输出。可以尝试运行
make show-lineno命令,在输出中将显示每个目标所在的行号。