Lines Matching +full:target +full:- +full:module

5 This document describes how to build an out-of-tree kernel module.
13 both in-tree and out-of-tree is provided. The method for building
15 out-of-tree.
18 in building out-of-tree (or "external") modules. The author of an
19 external module should supply a makefile that hides most of the
20 complexity, so one only has to type "make" to build the module. This is
22 section `Creating a Kbuild File for an External Module`_.
34 An alternative is to use the "make" target "modules_prepare." This will
35 make sure the kernel contains the information required. The target
39 NOTE: "modules_prepare" will not build Module.symvers even if
41 executed to make module versioning work.
44 --------------
46 The command to build an external module is::
48 $ make -C <path_to_kernel_dir> M=$PWD
50 The kbuild system knows that an external module is being built
55 $ make -C /lib/modules/`uname -r`/build M=$PWD
57 Then to install the module(s) just built, add the target
60 $ make -C /lib/modules/`uname -r`/build M=$PWD modules_install
62 Starting from Linux 6.13, you can use the -f option instead of -C. This
64 module will be output to the directory where you invoke make.
66 $ make -f /lib/modules/`uname -r`/build/Makefile M=$PWD
69 -------
78 make -C $KDIR M=$PWD [MO=$BUILD_DIR]
80 -C $KDIR
82 artifacts used for building an external module.
87 Informs kbuild that an external module is being built.
89 directory where the external module (kbuild file) is
93 Specifies a separate output directory for the external module.
96 -------
98 When building an external module, only a subset of the "make"
101 make -C $KDIR M=$PWD [target]
103 The default will build the module(s) located in the current
104 directory, so a target does not need to be specified. All
111 The default target for external modules. It has the
112 same functionality as if no target was specified. See
116 Install the external module(s). The default location is
119 `Module Installation`_).
122 Remove all generated files in the module directory only.
128 -----------------------
130 It is possible to build single files that are part of a module.
131 This works equally well for the kernel, a module, and even for
134 Example (The module foo.ko, consist of bar.o and baz.o)::
136 make -C $KDIR M=$PWD bar.lst
137 make -C $KDIR M=$PWD baz.o
138 make -C $KDIR M=$PWD foo.ko
139 make -C $KDIR M=$PWD ./
142 Creating a Kbuild File for an External Module
145 In the last section we saw the command to build a module for the
146 running kernel. The module is not actually built, however, because a
148 the module(s) being built, along with the list of requisite source
151 obj-m := <module_name>.o
154 and, after linking, will result in the kernel module <module_name>.ko.
156 When the module is built from multiple sources, an additional line is
159 <module_name>-y := <src1>.o <src2>.o ...
165 module 8123.ko, which is built from the following files::
172 ---------------
174 An external module always includes a wrapper makefile that
175 supports building the module using "make" with no arguments.
176 This target is not used by kbuild; it is only for convenience.
183 --> filename: Makefile
186 obj-m := 8123.o
187 8123-y := 8123_if.o 8123_pci.o
191 KDIR ?= /lib/modules/`uname -r`/build
194 $(MAKE) -C $(KDIR) M=$$PWD
204 initiated by the parameterized "make" in the default target.
207 ---------------------------------
215 --> filename: Kbuild
216 obj-m := 8123.o
217 8123-y := 8123_if.o 8123_pci.o
219 --> filename: Makefile
220 KDIR ?= /lib/modules/`uname -r`/build
223 $(MAKE) -C $(KDIR) M=$$PWD
230 Linux 6.13 and later support another way. The external module Makefile
235 --> filename: Kbuild
236 obj-m := 8123.o
237 8123-y := 8123_if.o 8123_pci.o
239 --> filename: Makefile
240 KDIR ?= /lib/modules/$(shell uname -r)/build
246 -------------------------
252 obj-m := foo.o bar.o
253 foo-y := <foo_srcs>
254 bar-y := <bar_srcs>
266 module, then the file is placed in the same directory as the
279 ---------------
284 #include <linux/module.h>
290 -------------------
295 directory, use either ccflags-y or CFLAGS_<filename>.o.
301 --> filename: Kbuild
302 obj-m := 8123.o
304 ccflags-y := -I $(src)/include
305 8123-y := 8123_if.o 8123_pci.o
308 ----------------------
323 To build the module complex.ko, we then need the following
326 --> filename: Kbuild
327 obj-m := complex.o
328 complex-y := src/complex_main.o
329 complex-y += src/hal/hardwareif.o
331 ccflags-y := -I$(src)/include
332 ccflags-y += -I$(src)/src/hal/include
341 root of the kernel tree (the argument to "-C") and therefore an
347 Module Installation
360 ----------------
371 calling "make." This has effect when installing both in-tree
372 and out-of-tree modules.
375 ---------------
383 $ make INSTALL_MOD_DIR=gandalf -C $KDIR \
388 Module Versioning
391 Module versioning is enabled by the CONFIG_MODVERSIONS tag, and is used
393 for an exported symbol is created. When a module is loaded/used, the
395 the module; if they are not equal, the kernel refuses to load the
396 module.
398 Module.symvers contains a list of all exported symbols from a kernel
402 -------------------------------------------
404 During a kernel build, a file named Module.symvers will be
405 generated. Module.symvers contains all exported symbols from
409 The syntax of the Module.symvers file is::
411 <CRC> <Symbol> <Module> <Export Type> <Namespace>
413 0xe1cc2a05 usb_stor_suspend drivers/usb/storage/usb-storage EXPORT_SYMBOL_GPL USB_STORAGE
421 Module.symvers serves two purposes:
427 ---------------------------
437 CRC stored in the __versions section of the importing module. This
443 section as a series of concatenated, null-terminated strings. CRCs for
447 ----------------------------
449 When building an external module, the build system needs access
452 the symbols by reading Module.symvers from the kernel source
453 tree. During the MODPOST step, a new Module.symvers file will be
454 written containing all exported symbols from that external module.
456 Symbols From Another External Module
457 ------------------------------------
459 Sometimes, an external module uses exported symbols from
460 another external module. Kbuild needs to have full knowledge of
464 NOTE: The method with a top-level kbuild file is recommended
467 Use a top-level kbuild file
470 common top-level kbuild file so both modules are
477 The top-level kbuild file would then look like::
480 obj-m := foo/ bar/
484 $ make -C $KDIR M=$PWD
487 full knowledge of symbols from either module.
490 If it is impractical to add a top-level kbuild file,
501 --------------------------
504 decide if a specific feature is included in the module. In
509 obj-$(CONFIG_EXT2_FS) += ext2.o
511 ext2-y := balloc.o bitmap.o dir.o
512 ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o