Skip to content

Commit 2eb5d7f

Browse files
committed
kbuild: doc: describe the -C option precisely for external module builds
Building external modules is typically done using this command: $ make -C <KERNEL_DIR> M=<EXTMOD_DIR> Here, <KERNEL_DIR> refers to the output directory where the kernel was built, not the kernel source directory. When the kernel is built in the source tree, there is no ambiguity, as the output directory and the source directory are the same. If the kernel was built in a separate build directory, <KERNEL_DIR> should be the kernel output directory. Otherwise, Kbuild cannot locate necessary build artifacts. This has been the method for building external modules against a pre-built kernel in a separate directory for over 20 years. [1] If you pass the kernel source directory to the -C option, you must also specify the kernel build directory using the O= option. This approach works as well, though it results in a slightly longer command: $ make -C <KERNEL_SOURCE_DIR> O=<KERNEL_BUILD_DIR> M=<EXTMOD_DIR> Some people mistakenly believe that O= should specify a build directory for external modules when used together with M=. This commit adds more clarification to Documentation/kbuild/kbuild.rst. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=e321b2ec2eb2993b3d0116e5163c78ad923e3c54 Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <n.schier@avm.de>
1 parent e873fb9 commit 2eb5d7f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Documentation/kbuild/kbuild.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ KBUILD_OUTPUT
134134
-------------
135135
Specify the output directory when building the kernel.
136136

137+
This variable can also be used to point to the kernel output directory when
138+
building external modules against a pre-built kernel in a separate build
139+
directory. Please note that this does NOT specify the output directory for the
140+
external modules themselves.
141+
137142
The output directory can also be specified using "O=...".
138143

139144
Setting "O=..." takes precedence over KBUILD_OUTPUT.

Documentation/kbuild/modules.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Command Syntax
4545

4646
The command to build an external module is::
4747

48-
$ make -C <path_to_kernel_src> M=$PWD
48+
$ make -C <path_to_kernel_dir> M=$PWD
4949

5050
The kbuild system knows that an external module is being built
5151
due to the "M=<dir>" option given in the command.
@@ -62,12 +62,15 @@ Command Syntax
6262
Options
6363
-------
6464

65-
($KDIR refers to the path of the kernel source directory.)
65+
($KDIR refers to the path of the kernel source directory, or the path
66+
of the kernel output directory if the kernel was built in a separate
67+
build directory.)
6668

6769
make -C $KDIR M=$PWD
6870

6971
-C $KDIR
70-
The directory where the kernel source is located.
72+
The directory that contains the kernel and relevant build
73+
artifacts used for building an external module.
7174
"make" will actually change to the specified directory
7275
when executing and will change back when finished.
7376

0 commit comments

Comments
 (0)