What are the `some_name.o.cmd` files?
What are the
some_name.o.cmd files that I see in Linux’s kernel code? are they auto-generated?
From Kernel configuration and building in Linux 2.5 (the section I’m quoting deals with changes brought in 2.5/2.6 kernels) :
Compiling built-in objects and modules in a single pass, recognizing changed command line arguments […]
The major performance issue for the kernel build are the invocations of make (most of the time is of course normally spent compiling / linking, but this cost is independent of the build system used). make has to read the local Make- file, the general rules and all the dependencies and figure out the work to be done from there. An obvious way to optimize the performance of the build system is thus to avoid unnecessary invocations. […]
A more flexible scheme to handle changing command lines within GNU make was created. The actual use is pretty simple, instead of writing the command directly into the command part of the rule, it is instead assigned to the variable
cmd_link_l_targetand the build system takes care of executing the command as necessary, keeping track of changes to the command line itself. The implementation works as follows. After executing the command, the macro
if_changed, records the command line into the file
.<target>.cmd. As make is invoked again during a rebuild, it will include those
.*.cmdfiles. As it tries to decide whether to rebuild
L_TARGET, it will find
FORCEin the prerequisites, which actually forces it to always rerun the command part of the rule.
Basically, this is kernel compilation optimisation. These files are used to prevent
make from working too much when unnecessary. As you can read above, a
some_name.o.cmd file would be there to keep tracks of what’s been done already/needs to be done when it comes to the compilation of
For more information, see section 4.5 of the document I linked earlier (What is new in Linux-2.5/2.6’s kbuild?).
A more recent description of .cmd files from Linux kernel documentation: link. Search for
The documentation explains that it is not only an optimization: "The target should be rebuilt also when the command line has changed since the last invocation. This is not supported by Make itself, so Kbuild achieves this by a kind of meta-programming".