我找到了一种工具,至少可以帮助回答我的问题的一部分,所以我将其发布以供我自己和其他人参考:
可以通过$(warning <some string>)
调用“调试”Makefile。
所以在我的例子中,我这样使用它:
all: $(warning All before exe call) $(EXECUTABLE)
$(warning All warning after call)
%.o : %.c
$(warning before pattern)
$(CC) -o $@ -c $<
$(warning after pattern)
$(EXECUTABLE): $(warning before obj) $(OBJS)
$(warning after obj)
$(CC) -o $@ $<
得到的输出显示了我的流程:
mike@mike-VirtualBox:~/C$ make
Makefile:6: All before exe call // started at all
Makefile:14: before obj // Jumped to EXECUTABLE label
Makefile:10: before pattern // Jumped to pattern matching
Makefile:10: after pattern
gcc -o a.o -c a.c
Makefile:15: after obj // back to EXECUTABLE label
Makefile:15: after build // back to build command
gcc -o hello a.o
Makefile:7: All warning after call
使用它我发现我可以这样做:
$(EXECUTABLE): $(warning before obj) $(OBJS)
但不是:
$(EXECUTABLE):
$(warning before obj)
$(OBJS)
这是有道理的,因为空白在 Makefile 中很重要