public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>
Subject: Re: [PATCH 5/5] kbuild: external module build doc
Date: Mon, 14 Jun 2004 22:48:09 +0200	[thread overview]
Message-ID: <20040614204809.GF15243@mars.ravnborg.org> (raw)
In-Reply-To: <20040614204029.GA15243@mars.ravnborg.org>

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/06/14 22:21:46+02:00 sam@mars.ravnborg.org 
#   kbuild: Add external module documentation
#   
#   Add first version of a document describing how to build external modules.
#   This is not yet finished, but includes information that is nice to have
#   documented in the kernel even in a less complete form.
#   
#   Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
# 
# Documentation/kbuild/extmodules.txt
#   2004/06/14 22:21:32+02:00 sam@mars.ravnborg.org +168 -0
# 
# Documentation/kbuild/extmodules.txt
#   2004/06/14 22:21:32+02:00 sam@mars.ravnborg.org +0 -0
#   BitKeeper file /home/sam/bk/kbuild/Documentation/kbuild/extmodules.txt
# 
# Documentation/kbuild/00-INDEX
#   2004/06/14 22:21:32+02:00 sam@mars.ravnborg.org +2 -0
#   Added extmodules.txt
# 
diff -Nru a/Documentation/kbuild/00-INDEX b/Documentation/kbuild/00-INDEX
--- a/Documentation/kbuild/00-INDEX	2004-06-14 22:25:21 +02:00
+++ b/Documentation/kbuild/00-INDEX	2004-06-14 22:25:21 +02:00
@@ -6,3 +6,5 @@
 	- developer information for linux kernel makefiles
 modules.txt
 	- how to build modules and to install them
+extmodules.txt
+	- specific information about external modules
diff -Nru a/Documentation/kbuild/extmodules.txt b/Documentation/kbuild/extmodules.txt
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/Documentation/kbuild/extmodules.txt	2004-06-14 22:25:21 +02:00
@@ -0,0 +1,168 @@
+Building external modules
+=========================
+kbuild offers functionality to build external modules, with the
+prerequisite that there is a pre-built kernel avialable with full source.
+A subset of the targets available when building the kernel is available
+when building an external module.
+
+
+Building the module
+-------------------
+The command looks like his:
+
+	make -C <path to kernel src> M=`pwd`
+
+For the above command to succeed the kernel must have been built with
+modules enabled.
+
+To install the modules just being built:
+
+	make -C <path to kernel src> M=`pwd` modules_install
+
+More complex examples later, the above should get you going in most cases.
+
+
+Available targets
+- - - - - - - - - 
+$KDIR refer to path to kernel src
+
+make -C $KDIR M=`pwd`
+	Will build the module(s) located in current directory. All output
+	files will be located in the same directory as the module source.
+	No attemps are made to update the kernel source, and it is
+	expected that a successfully make has been executed
+	for the kernel.
+
+make -C $KDIR M=`pwd` modules
+	Same as if no target was specified. See description above.
+
+make -C $KDIR M=$PWD modules_install
+	Install the external module(s)
+
+make -C $KDIR M=$PWD clean
+	Remove all generated files in for the module - not the kernel
+
+make -C $KDIR M=`pwd` help
+	help will list the available target when building external
+	modules.
+
+Available options:
+- - - - - - - - - 
+$KDIR refer to path to kernel src
+
+make -C $KDIR
+	Used to specify where to find the kernel source.
+	'$KDIR' represent the directory where the kernel source is.
+	Make will actually change directory to the specified directory
+	when executed but change back when finished.
+
+make -C $KDIR M=`pwd`
+	M= is used to tell kbuild that an external module is being built.
+	The option given to M= is the directory where the external
+	module is located.
+	When an external module is being built only a subset of the
+	usual targets are avialable.
+
+make -C $KDIR SUBDIRS=`pwd`
+	Same as M=. The SUBDIRS= syntax is kept for backwards compatibility.
+
+
+A more advanced example
+- - - - - - - - - - - -
+This example shows a setup where a distribution has wisely decided
+to separate kernel source and output files:
+
+Kernel src:
+/usr/src/linux-<kernel-version>/
+
+Output from a kernel compile, including .config:
+/lib/modules/linux-<kernel-version>/build/
+
+External module to be compiled:
+/home/user/module/src/
+
+To compile the module located in the directory above use the
+following command:
+
+	cd /home/user/module/src
+	make -C /usr/src/linux-<kernel-version> \
+	O=/lib/modules/linux-<kernel-version>/build \
+	M=`pwd`
+
+Then to install the module use the following command:
+
+	make -C /usr/src/linux-<kernel-version> \
+		O=/lib/modules/linux-<kernel-version>/build \
+		M='pwd` modules_install
+
+The above are rather long commands, and the following chapter
+lists a few tricks to make it all easier.
+
+Tricks to make it easy
+---------------------
+TODO: .... This need to be rewritten......
+
+A make line with several parameters becomes tiresome and errorprone
+and what follows here is a little trick to make it possible to build
+a module only using a single 'make' command.
+
+Create a makefile named 'Makefile' with the following content:
+---> Makefile:
+
+all:
+	$(MAKE) -C /home/sam/src/kernel/v2.6 M=`pwd` \
+			$(filter-out all,$(MAKECMDGOALS))
+
+obj-m := module.o
+---> End of Makefile
+
+When make is invoked it will see the all: rule, and simply call make again with the right parameters.
+
+If a driver is being developed that is targeted for inclusion in the main kernel, an idea is to seperate out the all: rule to a Makefile nemed makefile (lower capital m) like this:
+
+---> makefile
+all:
+	$(MAKE) -f Makefile -C /home/sam/src/kernel/v2.6 \
+	        M=$(PWD) $(MAKECMDGOALS)
+
+---> End of makefile
+
+The kbuild makefile will include only a single statement:
+---> Makefile:
+
+obj-m := module.o
+
+---> End of Makefile
+When executing make, it looks for a file named makefile, before a
+file named Makefile. Therefor make will pick up the file named with lower capital 'm'.
+
+
+Prepare the kernel for building external modules
+------------------------------------------------
+When building external modules the kernel is expected to be prepared.
+This includes the precense of certain binaries, the kernel configuration
+and the symlink to include/asm.
+To do this a convinient target is made:
+
+	make modules_prepare
+
+For a typical distribution this would look like the follwoing:
+
+	make modules_prepare O=/lib/modules/linux-<kernel version>/build
+
+
+TODO: Fill out the following chapters
+
+Module versioning
+-----------------
+
+Include files targeted towards kernel include/...
+-------------------------------------------------
+
+Local include files
+-------------------
+
+Binary only .o files
+--------------------
+Use _shipped.
+

  parent reply	other threads:[~2004-06-14 20:40 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-14 20:40 [PATCH 0/5] kbuild Sam Ravnborg
2004-06-14 20:44 ` [PATCH 1/5] kbuild: default kernel image Sam Ravnborg
2004-06-14 21:05   ` Russell King
2004-06-15  4:40     ` Sam Ravnborg
2004-06-15  8:38       ` Russell King
2004-06-15  8:59         ` Christoph Hellwig
2004-06-15 21:07           ` Sam Ravnborg
2004-06-15 21:17             ` Russell King
2004-06-16 15:34             ` Tom Rini
2004-06-15 15:38         ` Tom Rini
2004-06-15 15:53           ` Russell King
2004-06-14 20:45 ` [PATCH 2/5] kbuild: move rpm to scripts/package Sam Ravnborg
2004-06-14 20:46 ` [PATCH 3/5] kbuild: add deb-pkg target Sam Ravnborg
2004-06-14 20:58   ` Wichert Akkerman
2004-06-14 21:22     ` Sam Ravnborg
2004-06-14 20:46 ` [PATCH 4/5] kbuild: make clean improved Sam Ravnborg
2004-06-14 20:50   ` Russell King
2004-06-14 21:19     ` Sam Ravnborg
2004-06-14 21:38       ` Tom Rini
2004-06-15  4:36         ` Sam Ravnborg
2004-06-15 18:50     ` V13
2004-06-14 20:48 ` Sam Ravnborg [this message]
2004-06-15 12:13   ` [PATCH 5/5] kbuild: external module build doc Horst von Brand
2004-06-15 20:09     ` Sam Ravnborg
2004-06-15 19:21   ` Jari Ruusu
2004-06-15 19:55     ` Sam Ravnborg
2004-06-15 23:00       ` Martin Schlemmer
2004-06-16 17:32       ` Jari Ruusu
2004-06-14 20:59 ` [PATCH 0/5] kbuild Sam Ravnborg
2004-06-14 23:56 ` Jeff Garzik
2004-06-15 15:41 ` Tom Rini
2004-06-15 17:49   ` Sam Ravnborg
2004-06-15 17:54     ` Tom Rini
2004-06-15 19:01       ` Sam Ravnborg
2004-06-15 19:27         ` Tom Rini
2004-06-15 21:02           ` Sam Ravnborg
2004-06-15 21:24             ` Tom Rini
2004-06-15 18:09     ` Russell King
2004-06-15 19:14       ` Sam Ravnborg
2004-06-15 19:46         ` Russell King
2004-06-15 20:12           ` Sam Ravnborg
2004-06-15 20:55           ` Sam Ravnborg
2004-06-15 20:59             ` Tom Rini
2004-06-15 21:24               ` Sam Ravnborg
2004-06-15 21:06             ` Russell King
2004-06-16 19:49               ` Sam Ravnborg
2004-06-16 20:08                 ` Tom Rini
2004-06-16 20:54                   ` Sam Ravnborg
2004-06-16 20:49                     ` Tom Rini
2004-06-17  6:56                     ` Jan-Benedict Glaw
2004-06-18 20:58                       ` Sam Ravnborg
     [not found] <sam@ravnborg.org>
2004-09-05 20:12 ` kbuild: Simplify vmlinux generation Sam Ravnborg
2004-09-05 20:19   ` Sam Ravnborg
2004-09-06 18:41   ` Horst von Brand
2004-09-06 19:00     ` Sam Ravnborg
2004-09-06 19:12     ` Sam Ravnborg
2014-06-11 19:25 ` [PATCH v2] x86,vdso: Fix vdso_install Andy Lutomirski
2014-06-11 19:45   ` Sam Ravnborg
2014-06-12 13:19   ` Josh Boyer
2014-06-12 15:28     ` [PATCH v3] " Andy Lutomirski
2014-06-12 17:01       ` Josh Boyer
2014-06-13 17:24         ` H. Peter Anvin
2014-06-13 17:28           ` Andy Lutomirski
2014-06-13 18:19       ` [tip:x86/vdso] x86/vdso: " tip-bot for Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040614204809.GF15243@mars.ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox