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?

Asked By: Tar

||

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_target and 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 .*.cmd files. As it tries to decide whether to rebuild L_TARGET, it will find FORCE in 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 some_name.o.

For more information, see section 4.5 of the document I linked earlier (What is new in Linux-2.5/2.6’s kbuild?).

Answered By: John WH Smith

A more recent description of .cmd files from Linux kernel documentation: link. Search for .cmd there.

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".

Answered By: Pavel Shishpor
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.