# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / Documentation / kbuild / modules.txt
1 For now this is a raw copy from the old Documentation/kbuild/modules.txt,
2 which was removed in 2.6.0-test5.
3 The information herein is correct but not complete.
4
5 Installing modules in a non-standard location
6 ---------------------------------------------
7 When the modules needs to be installed under another directory
8 the INSTALL_MOD_PATH can be used to prefix "/lib/modules" as seen
9 in the following example:
10
11 make INSTALL_MOD_PATH=/frodo modules_install
12
13 This will install the modules in the directory /frodo/lib/modules.
14 /frodo can be a NFS mounted filesystem on another machine, allowing
15 out-of-the-box support for installation on remote machines.
16
17
18 Compiling modules outside the official kernel
19 ---------------------------------------------
20
21 Often modules are developed outside the official kernel.  To keep up
22 with changes in the build system the most portable way to compile a
23 module outside the kernel is to use the kernel build system,
24 kbuild. Use the following command-line:
25
26 make -C path/to/kernel/src M=$PWD modules
27
28 This requires that a makefile exits made in accordance to
29 Documentation/kbuild/makefiles.txt. Read that file for more details on
30 the build system.
31
32 The following is a short summary of how to write your Makefile to get
33 you up and running fast. Assuming your module will be called
34 yourmodule.ko, your code should be in yourmodule.c and your Makefile
35 should include
36
37 obj-m := yourmodule.o
38
39 If the code for your module is in multiple files that need to be
40 linked, you need to tell the build system which files to compile. In
41 the case of multiple files, none of these files can be named
42 yourmodule.c because doing so would cause a problem with the linking
43 step. Assuming your code exists in file1.c, file2.c, and file3.c and
44 you want to build yourmodule.ko from them, your Makefile should
45 include
46
47 obj-m := yourmodule.o
48 yourmodule-objs := file1.o file2.o file3.o
49
50 Now for a final example to put it all together. Assuming the
51 KERNEL_SOURCE environment variable is set to the directory where you
52 compiled the kernel, a simple Makefile that builds yourmodule.ko as
53 described above would look like
54
55 # Tells the build system to build yourmodule.ko.
56 obj-m := yourmodule.o
57
58 # Tells the build system to build these object files and link them as
59 # yourmodule.o, before building yourmodule.ko. This line can be left
60 # out if all the code for your module is in one file, yourmodule.c. If
61 # you are using multiple files, none of these files can be named
62 # yourmodule.c.
63 yourmodule-objs := file1.o file2.o file3.o
64
65 # Invokes the kernel build system to come back to the current
66 # directory and build yourmodule.ko.
67 default:
68         make -C ${KERNEL_SOURCE} M=`pwd` modules