summaryrefslogtreecommitdiffstats
path: root/Documentation/kbuild/modules.txt
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-09-24 14:24:14 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-24 14:24:14 -0700
commit6e936d3e9a45a4307e7f4a29ee9829e7a0464af1 (patch)
tree555f9d89779e6a675b38d9703f278ecf0579531c /Documentation/kbuild/modules.txt
parenta68aa1cc6f3203b8a332683ebde67a00f39eec43 (diff)
parent5cc8d246d0ebbdf827d4bb7c3de175377d244d73 (diff)
downloadop-kernel-dev-6e936d3e9a45a4307e7f4a29ee9829e7a0464af1.zip
op-kernel-dev-6e936d3e9a45a4307e7f4a29ee9829e7a0464af1.tar.gz
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild
* git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild: (28 commits) kbuild: add distclean info to 'make help' and more details for 'clean' dontdiff: add utsrelease.h kbuild: fix "mkdir -p" usage in scripts/package/mkspec kbuild: correct and clarify versioning info in Makefile kbuild: fixup Documentation/kbuild/modules.txt kbuild: Extend kbuild/defconfig tags support to exuberant ctags kbuild: fix for some typos in Documentation/makefiles.txt kbuild: clarify "make C=" build option Documentaion: update Documentation/Changes with minimum versions kbuild: update help in top level Makefile kbuild: fail kernel compilation in case of unresolved module symbols kbuild: remove debug left-over from Makefile.host kbuild: create output directory for hostprogs with O=.. build kbuild: add missing return statement in modpost.c:secref_whitelist() kbuild: preperly align SYSMAP output kbuild: make -rR is now default kbuild: make V=2 tell why a target is rebuild kbuild: modpost on vmlinux regardless of CONFIG_MODULES kbuild: ignore references from ".pci_fixup" to ".init.text" kbuild: linguistic fixes for Documentation/kbuild/makefiles.txt ...
Diffstat (limited to 'Documentation/kbuild/modules.txt')
-rw-r--r--Documentation/kbuild/modules.txt161
1 files changed, 81 insertions, 80 deletions
diff --git a/Documentation/kbuild/modules.txt b/Documentation/kbuild/modules.txt
index 61fc079..2e7702e 100644
--- a/Documentation/kbuild/modules.txt
+++ b/Documentation/kbuild/modules.txt
@@ -1,7 +1,7 @@
In this document you will find information about:
- how to build external modules
-- how to make your module use kbuild infrastructure
+- how to make your module use the kbuild infrastructure
- how kbuild will install a kernel
- how to install modules in a non-standard location
@@ -24,7 +24,7 @@ In this document you will find information about:
--- 6.1 INSTALL_MOD_PATH
--- 6.2 INSTALL_MOD_DIR
=== 7. Module versioning & Module.symvers
- --- 7.1 Symbols fron the kernel (vmlinux + modules)
+ --- 7.1 Symbols from the kernel (vmlinux + modules)
--- 7.2 Symbols and external modules
--- 7.3 Symbols from another external module
=== 8. Tips & Tricks
@@ -36,13 +36,13 @@ In this document you will find information about:
kbuild includes functionality for building modules both
within the kernel source tree and outside the kernel source tree.
-The latter is usually referred to as external modules and is used
-both during development and for modules that are not planned to be
-included in the kernel tree.
+The latter is usually referred to as external or "out-of-tree"
+modules and is used both during development and for modules that
+are not planned to be included in the kernel tree.
What is covered within this file is mainly information to authors
-of modules. The author of an external modules should supply
-a makefile that hides most of the complexity so one only has to type
+of modules. The author of an external module should supply
+a makefile that hides most of the complexity, so one only has to type
'make' to build the module. A complete example will be present in
chapter 4, "Creating a kbuild file for an external module".
@@ -63,14 +63,15 @@ when building an external module.
For the running kernel use:
make -C /lib/modules/`uname -r`/build M=`pwd`
- For the above command to succeed the kernel must have been built with
- modules enabled.
+ For the above command to succeed, the kernel must have been
+ built with modules enabled.
To install the modules that were just built:
make -C <path-to-kernel> M=`pwd` modules_install
- More complex examples later, the above should get you going.
+ More complex examples will be shown later, the above should
+ be enough to get you started.
--- 2.2 Available targets
@@ -89,13 +90,13 @@ when building an external module.
Same functionality as if no target was specified.
See description above.
- make -C $KDIR M=$PWD modules_install
+ make -C $KDIR M=`pwd` modules_install
Install the external module(s).
Installation default is in /lib/modules/<kernel-version>/extra,
but may be prefixed with INSTALL_MOD_PATH - see separate
chapter.
- make -C $KDIR M=$PWD clean
+ make -C $KDIR M=`pwd` clean
Remove all generated files for the module - the kernel
source directory is not modified.
@@ -129,29 +130,28 @@ when building an external module.
To make sure the kernel contains the information required to
build external modules the target 'modules_prepare' must be used.
- 'module_prepare' solely exists as a simple way to prepare
- a kernel for building external modules.
+ 'module_prepare' exists solely as a simple way to prepare
+ a kernel source tree for building external modules.
Note: modules_prepare will not build Module.symvers even if
- CONFIG_MODULEVERSIONING is set.
- Therefore a full kernel build needs to be executed to make
- module versioning work.
+ CONFIG_MODULEVERSIONING is set. Therefore a full kernel build
+ needs to be executed to make module versioning work.
--- 2.5 Building separate files for a module
- It is possible to build single files which is part of a module.
- This works equal for the kernel, a module and even for external
- modules.
+ It is possible to build single files which are part of a module.
+ This works equally well for the kernel, a module and even for
+ external modules.
Examples (module foo.ko, consist of bar.o, baz.o):
make -C $KDIR M=`pwd` bar.lst
make -C $KDIR M=`pwd` bar.o
make -C $KDIR M=`pwd` foo.ko
make -C $KDIR M=`pwd` /
-
+
=== 3. Example commands
This example shows the actual commands to be executed when building
an external module for the currently running kernel.
-In the example below the distribution is supposed to use the
+In the example below, the distribution is supposed to use the
facility to locate output files for a kernel compile in a different
directory than the kernel source - but the examples will also work
when the source and the output files are mixed in the same directory.
@@ -170,14 +170,14 @@ the following commands to build the module:
O=/lib/modules/`uname-r`/build \
M=`pwd`
-Then to install the module use the following command:
+Then, to install the module use the following command:
make -C /usr/src/`uname -r`/source \
O=/lib/modules/`uname-r`/build \
M=`pwd` \
modules_install
-If one looks closely you will see that this is the same commands as
+If you look closely you will see that this is the same command as
listed before - with the directories spelled out.
The above are rather long commands, and the following chapter
@@ -230,7 +230,7 @@ following files:
endif
- In example 1 the check for KERNELRELEASE is used to separate
+ In example 1, the check for KERNELRELEASE is used to separate
the two parts of the Makefile. kbuild will only see the two
assignments whereas make will see everything except the two
kbuild assignments.
@@ -255,7 +255,7 @@ following files:
echo "X" > 8123_bin_shipped
- In example 2 we are down to two fairly simple files and for simple
+ In example 2, we are down to two fairly simple files and for simple
files as used in this example the split is questionable. But some
external modules use Makefiles of several hundred lines and here it
really pays off to separate the kbuild part from the rest.
@@ -282,9 +282,9 @@ following files:
endif
- The trick here is to include the Kbuild file from Makefile so
- if an older version of kbuild picks up the Makefile the Kbuild
- file will be included.
+ The trick here is to include the Kbuild file from Makefile, so
+ if an older version of kbuild picks up the Makefile, the Kbuild
+ file will be included.
--- 4.2 Binary blobs included in a module
@@ -301,18 +301,19 @@ following files:
obj-m := 8123.o
8123-y := 8123_if.o 8123_pci.o 8123_bin.o
- In example 4 there is no distinction between the ordinary .c/.h files
+ In example 4, there is no distinction between the ordinary .c/.h files
and the binary file. But kbuild will pick up different rules to create
the .o file.
=== 5. Include files
-Include files are a necessity when a .c file uses something from another .c
-files (not strictly in the sense of .c but if good programming practice is
-used). Any module that consist of more than one .c file will have a .h file
-for one of the .c files.
-- If the .h file only describes a module internal interface then the .h file
+Include files are a necessity when a .c file uses something from other .c
+files (not strictly in the sense of C, but if good programming practice is
+used). Any module that consists of more than one .c file will have a .h file
+for one of the .c files.
+
+- If the .h file only describes a module internal interface, then the .h file
shall be placed in the same directory as the .c files.
- If the .h files describe an interface used by other parts of the kernel
located in different directories, the .h files shall be located in
@@ -323,11 +324,11 @@ under include/ such as include/scsi. Another exception is arch-specific
.h files which are located under include/asm-$(ARCH)/*.
External modules have a tendency to locate include files in a separate include/
-directory and therefore needs to deal with this in their kbuild file.
+directory and therefore need to deal with this in their kbuild file.
--- 5.1 How to include files from the kernel include dir
- When a module needs to include a file from include/linux/ then one
+ When a module needs to include a file from include/linux/, then one
just uses:
#include <linux/modules.h>
@@ -348,7 +349,7 @@ directory and therefore needs to deal with this in their kbuild file.
The trick here is to use either EXTRA_CFLAGS (take effect for all .c
files) or CFLAGS_$F.o (take effect only for a single file).
- In our example if we move 8123_if.h to a subdirectory named include/
+ In our example, if we move 8123_if.h to a subdirectory named include/
the resulting Kbuild file would look like:
--> filename: Kbuild
@@ -362,19 +363,19 @@ directory and therefore needs to deal with this in their kbuild file.
--- 5.3 External modules using several directories
- If an external module does not follow the usual kernel style but
- decide to spread files over several directories then kbuild can
- support this too.
+ If an external module does not follow the usual kernel style, but
+ decides to spread files over several directories, then kbuild can
+ handle this too.
Consider the following example:
-
+
|
+- src/complex_main.c
| +- hal/hardwareif.c
| +- hal/include/hardwareif.h
+- include/complex.h
-
- To build a single module named complex.ko we then need the following
+
+ To build a single module named complex.ko, we then need the following
kbuild file:
Kbuild:
@@ -387,12 +388,12 @@ directory and therefore needs to deal with this in their kbuild file.
kbuild knows how to handle .o files located in another directory -
- although this is NOT reccommended practice. The syntax is to specify
+ although this is NOT recommended practice. The syntax is to specify
the directory relative to the directory where the Kbuild file is
located.
- To find the .h files we have to explicitly tell kbuild where to look
- for the .h files. When kbuild executes current directory is always
+ To find the .h files, we have to explicitly tell kbuild where to look
+ for the .h files. When kbuild executes, the current directory is always
the root of the kernel tree (argument to -C) and therefore we have to
tell kbuild how to find the .h files using absolute paths.
$(src) will specify the absolute path to the directory where the
@@ -412,7 +413,7 @@ External modules are installed in the directory:
--- 6.1 INSTALL_MOD_PATH
- Above are the default directories, but as always some level of
+ Above are the default directories, but as always, some level of
customization is possible. One can prefix the path using the variable
INSTALL_MOD_PATH:
@@ -420,17 +421,17 @@ External modules are installed in the directory:
=> Install dir: /frodo/lib/modules/$(KERNELRELEASE)/kernel
INSTALL_MOD_PATH may be set as an ordinary shell variable or as in the
- example above be specified on the command line when calling make.
+ example above, can be specified on the command line when calling make.
INSTALL_MOD_PATH has effect both when installing modules included in
the kernel as well as when installing external modules.
--- 6.2 INSTALL_MOD_DIR
- When installing external modules they are default installed in a
+ When installing external modules they are by default installed to a
directory under /lib/modules/$(KERNELRELEASE)/extra, but one may wish
to locate modules for a specific functionality in a separate
- directory. For this purpose one can use INSTALL_MOD_DIR to specify an
- alternative name than 'extra'.
+ directory. For this purpose, one can use INSTALL_MOD_DIR to specify an
+ alternative name to 'extra'.
$ make INSTALL_MOD_DIR=gandalf -C KERNELDIR \
M=`pwd` modules_install
@@ -444,16 +445,16 @@ Module versioning is enabled by the CONFIG_MODVERSIONS tag.
Module versioning is used as a simple ABI consistency check. The Module
versioning creates a CRC value of the full prototype for an exported symbol and
when a module is loaded/used then the CRC values contained in the kernel are
-compared with similar values in the module. If they are not equal then the
+compared with similar values in the module. If they are not equal, then the
kernel refuses to load the module.
Module.symvers contains a list of all exported symbols from a kernel build.
--- 7.1 Symbols fron the kernel (vmlinux + modules)
- During a kernel build a file named Module.symvers will be generated.
+ During a kernel build, a file named Module.symvers will be generated.
Module.symvers contains all exported symbols from the kernel and
- compiled modules. For each symbols the corresponding CRC value
+ compiled modules. For each symbols, the corresponding CRC value
is stored too.
The syntax of the Module.symvers file is:
@@ -461,27 +462,27 @@ Module.symvers contains a list of all exported symbols from a kernel build.
Sample:
0x2d036834 scsi_remove_host drivers/scsi/scsi_mod
- For a kernel build without CONFIG_MODVERSIONING enabled the crc
+ For a kernel build without CONFIG_MODVERSIONS enabled, the crc
would read: 0x00000000
- Module.symvers serve two purposes.
- 1) It list all exported symbols both from vmlinux and all modules
- 2) It list CRC if CONFIG_MODVERSION is enabled
+ Module.symvers serves two purposes:
+ 1) It lists all exported symbols both from vmlinux and all modules
+ 2) It lists the CRC if CONFIG_MODVERSIONS is enabled
--- 7.2 Symbols and external modules
- When building an external module the build system needs access to
+ When building an external module, the build system needs access to
the symbols from the kernel to check if all external symbols are
defined. This is done in the MODPOST step and to obtain all
- symbols modpost reads Module.symvers from the kernel.
+ symbols, modpost reads Module.symvers from the kernel.
If a Module.symvers file is present in the directory where
- the external module is being build this file will be read too.
- During the MODPOST step a new Module.symvers file will be written
- containing all exported symbols that was not defined in the kernel.
-
+ the external module is being built, this file will be read too.
+ During the MODPOST step, a new Module.symvers file will be written
+ containing all exported symbols that were not defined in the kernel.
+
--- 7.3 Symbols from another external module
- Sometimes one external module uses exported symbols from another
+ Sometimes, an external module uses exported symbols from another
external module. Kbuild needs to have full knowledge on all symbols
to avoid spitting out warnings about undefined symbols.
Two solutions exist to let kbuild know all symbols of more than
@@ -490,15 +491,15 @@ Module.symvers contains a list of all exported symbols from a kernel build.
impractical in certain situations.
Use a top-level Kbuild file
- If you have two modules: 'foo', 'bar' and 'foo' needs symbols
- from 'bar' then one can use a common top-level kbuild file so
- both modules are compiled in same build.
+ If you have two modules: 'foo' and 'bar', and 'foo' needs
+ symbols from 'bar', then one can use a common top-level kbuild
+ file so both modules are compiled in same build.
Consider following directory layout:
./foo/ <= contains the foo module
./bar/ <= contains the bar module
The top-level Kbuild file would then look like:
-
+
#./Kbuild: (this file may also be named Makefile)
obj-y := foo/ bar/
@@ -509,23 +510,23 @@ Module.symvers contains a list of all exported symbols from a kernel build.
knowledge on symbols from both modules.
Use an extra Module.symvers file
- When an external module is build a Module.symvers file is
+ When an external module is built, a Module.symvers file is
generated containing all exported symbols which are not
defined in the kernel.
- To get access to symbols from module 'bar' one can copy the
+ To get access to symbols from module 'bar', one can copy the
Module.symvers file from the compilation of the 'bar' module
- to the directory where the 'foo' module is build.
- During the module build kbuild will read the Module.symvers
+ to the directory where the 'foo' module is built.
+ During the module build, kbuild will read the Module.symvers
file in the directory of the external module and when the
- build is finished a new Module.symvers file is created
+ build is finished, a new Module.symvers file is created
containing the sum of all symbols defined and not part of the
kernel.
-
+
=== 8. Tips & Tricks
--- 8.1 Testing for CONFIG_FOO_BAR
- Modules often needs to check for certain CONFIG_ options to decide if
+ Modules often need to check for certain CONFIG_ options to decide if
a specific feature shall be included in the module. When kbuild is used
this is done by referencing the CONFIG_ variable directly.
@@ -537,7 +538,7 @@ Module.symvers contains a list of all exported symbols from a kernel build.
External modules have traditionally used grep to check for specific
CONFIG_ settings directly in .config. This usage is broken.
- As introduced before external modules shall use kbuild when building
- and therefore can use the same methods as in-kernel modules when testing
- for CONFIG_ definitions.
+ As introduced before, external modules shall use kbuild when building
+ and therefore can use the same methods as in-kernel modules when
+ testing for CONFIG_ definitions.
OpenPOWER on IntegriCloud