首页 > 解决方案 > 参见 make 命令和之后所有调用的 make 文件

问题描述

我正在尝试分解一个非常大的代码库的 make 构建系统,但是我无法看到 make 调用的每个命令,因为它调用了当前目录之外的许多目录中的各种 make 文件。我遵循了这个答案和其他各种在不使用 CMake 时执行之前的 make print 命令

尽管上述内容取得了一些进步并且很有启发性,但这不是我需要的本垒打。它提供了查看进行调用的命令的解决方案。这比伟大更好。但是,问题在于之后调用的各种 sub make 命令。我只看到打印的那些命令,没有关于正在发生的事情的附加信息。我试图别名 make 这样

alias make='make SHELL='\''/bin/bash -x'\'''

# or

alias make='make -n'

但是,上面无法用别名替换调用的 make 命令。有没有另一种方法可以剖析大型代码库构建系统?

> make
rmdir --ignore-fail-on-non-empty /somefolder* 2> /dev/null; true
cd /someotherfolder/; make cur-dir=somefolder dirs-to-build=somemorefolders/ env_variable another_variable someMakeRule # no output from this  make
make  TARGET=someTarget env_variable gdbinit source_dir someMakeRule; # no output from this  make
# ...
# output from first top makefile
# ...
make[1]: Nothing to be done for 'someMakeRule'.

标签: linuxmakefilebuildembedded-linuxlegacy-code

解决方案


--trace您可以使用选项轻松跟踪执行。考虑以下示例,其中有人想只显示干净的输出而没有任何冗长的选项:

$ cat Makefile
all: foo
        @echo Done with $@

foo: bar
        @echo Done with $@

bar:
        @$(MAKE) -f Makefile2 bar

.SILENT:

$ cat Makefile2
bar: baz
        @echo Done with $@

baz:
        @echo Done with $@

常规构建不允许检查正在发生的事情:

$ make
Done with baz
Done with bar
Done with foo
Done with all

--trace会显示正在发生的事情以及原因:

$ make --trace
Makefile:8: target 'bar' does not exist
make -f Makefile2 bar
Makefile2:5: target 'baz' does not exist
echo Done with baz
Done with baz
Makefile2:2: update target 'bar' due to: baz
echo Done with bar
Done with bar
Makefile:5: update target 'foo' due to: bar
echo Done with foo
Done with foo
Makefile:2: update target 'all' due to: foo
echo Done with all
Done with all

推荐阅读