The Linux kernel documentation page for building external modules (https://www.kernel.org/doc/Documentation/kbuild/modules.txt) says this:
=== 2. How to Build External Modules
To build external modules, you must have a prebuilt kernel available that contains the configuration and header files used in the build. Also, the kernel must have been built with modules enabled. If you are using a distribution kernel, there will be a package for the kernel you are running provided by your distribution.
An alternative is to use the "make" target "modules_prepare." This will make sure the kernel contains the information required. The target exists solely as a simple way to prepare a kernel source tree for building external modules.
My questions are the following:
To build external modules, you must have a prebuilt kernel available that contains the configuration and header files used in the build
By "prebuilt kernel", does it mean the compiled binary image (generally named vmlinux/vmlinuz)? Why exactly is the binary image needed? Shouldn't the configuration files, header files and compiler be enough?
To build external modules, you must have a prebuilt kernel available that contains the configuration and header files used in the build.
If by prebuilt kernel it means the binary image, then what is the meaning of "contains the configuration and header files"? I can understand the source tree needing to "contain the configuration and header files", but in case of binary, these files are just used to generate instructions right? What is the meaning of "contain" then? By "prebuilt kernel" does it mean the entire source tree where the kernel was built?
Also, the kernel must have been built with modules enabled.
Are they referring to the "make modules" step here or is it something different?
If you are using a distribution kernel, there will be a package for the kernel you are running provided by your distribution.
I suppose they are referring to the kernel-devel package here, which provides the header and configuation files which were used in the kernel building process. Is that correct?
An alternative is to use the "make" target "modules_prepare." This will make sure the kernel contains the information required.
What is the meaning of this? Does this mean that we don't need to have a built kernel binary in order to be able to build external modules if we do a "make modules_prepare" in the source directory?