* Re: [kbuild-devel] kbuild support to build one module with multiple separate components?
[not found] <20040702234735.63710.qmail@web40003.mail.yahoo.com>
@ 2004-07-14 21:19 ` Sam Ravnborg
2004-07-14 21:40 ` Song Wang
0 siblings, 1 reply; 3+ messages in thread
From: Sam Ravnborg @ 2004-07-14 21:19 UTC (permalink / raw)
To: Song Wang; +Cc: kbuild-devel, linux-kernel
On Fri, Jul 02, 2004 at 04:47:35PM -0700, Song Wang wrote:
> Hi, Folks
>
> I'm puzzled by the kbuild system in 2.6 kernel.
> I want to write a kernel module, which consists of
> several components. The module is produced by
> linking these components. These components are located
> in separate subdirectories (for example A, B,C).
> Each component is generated also by linking
> multiple files. (For example, a_1.c, a_2.c for
> building A.o, b_1.c, b_2.c for building B.o, then A.o
> and B.o
> should be linked to produce mymodule.o)
>
> I know if I put all the files in a single directory
> The makefile of the module looks like
>
> obj-$(CONFIG_MYMODULE) += mymodule.o
> mymodule-objs := a_1.o a_2.o b_1.o b_2.o c_1.o c_2.o
>
> It should work. But it is really messy, especially
> there are a lot of files or each component requires
> different EXTRA_CFLAGS. However, if I write
> separate Makefiles for each component in their own
> subdirectory, the Makefile of component A looks like
>
> obj-y := A.o (or obj-$(CONFIG_MYMODULE) += A.o)
> A-objs := a_1.o a_2.o
>
> This is wrong, because kbuild will treat A as
> independent module. All I want is to treat
> A as component of the only module mymodule.o. It
> should be linked to mymodule.o
>
> Any idea on how to write a kbuild Makefile to
> support such kind of single module produced
> by linking multiple components and each component
> is located in separate directory? Thanks.
Hi Song (added lkml to cc:).
You just need to have one common module usign all the sub-modules.
So having each sub-module in directory M/sub-a M/sub-b etc.
you need a makefile in M/ that looks like:
M/Makefile:
obj-m += sub-a/
obj-m += sub-b/
obj-m += mainmodule.o
In each sub-directory you need a separate Makefile like:
M/sub-a/Makefile
obj-m += a_sub_module.o
Then all symbols used by the mainmodule needs to be properly
exported in each sub-module.
Hope this clarifies it.
Sam
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [kbuild-devel] kbuild support to build one module with multiple separate components?
2004-07-14 21:19 ` [kbuild-devel] kbuild support to build one module with multiple separate components? Sam Ravnborg
@ 2004-07-14 21:40 ` Song Wang
2004-07-19 17:29 ` sam
0 siblings, 1 reply; 3+ messages in thread
From: Song Wang @ 2004-07-14 21:40 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: kbuild-devel, linux-kernel
Hi, Sam
Thanks for the reply.
However, in the way you indicate, the
mainmodule and each submodule will be built
as separate kernel modules. You will get
mainmodule.ko, a_sub_module.ko, b_sub_module.ko etc.
This is not what I tried to get. I tried to
build a single kernel module, which means that
mainmodule.o, a_sub_module.o, b_sub_module.o
should be linked together to produce the single
module.
This will be convenient, for instance, for
distribution because you need only to distribute one
kernel module instead of a long list of modules.
-Song
--- Sam Ravnborg <sam@ravnborg.org> wrote:
> On Fri, Jul 02, 2004 at 04:47:35PM -0700, Song Wang
> wrote:
> > Hi, Folks
> >
> > I'm puzzled by the kbuild system in 2.6 kernel.
> > I want to write a kernel module, which consists of
> > several components. The module is produced by
> > linking these components. These components are
> located
> > in separate subdirectories (for example A, B,C).
> > Each component is generated also by linking
> > multiple files. (For example, a_1.c, a_2.c for
> > building A.o, b_1.c, b_2.c for building B.o, then
> A.o
> > and B.o
> > should be linked to produce mymodule.o)
> >
> > I know if I put all the files in a single
> directory
> > The makefile of the module looks like
> >
> > obj-$(CONFIG_MYMODULE) += mymodule.o
> > mymodule-objs := a_1.o a_2.o b_1.o b_2.o c_1.o
> c_2.o
> >
> > It should work. But it is really messy, especially
> > there are a lot of files or each component
> requires
> > different EXTRA_CFLAGS. However, if I write
> > separate Makefiles for each component in their own
> > subdirectory, the Makefile of component A looks
> like
> >
> > obj-y := A.o (or obj-$(CONFIG_MYMODULE) += A.o)
> > A-objs := a_1.o a_2.o
> >
> > This is wrong, because kbuild will treat A as
> > independent module. All I want is to treat
> > A as component of the only module mymodule.o. It
> > should be linked to mymodule.o
> >
> > Any idea on how to write a kbuild Makefile to
> > support such kind of single module produced
> > by linking multiple components and each component
> > is located in separate directory? Thanks.
>
>
> Hi Song (added lkml to cc:).
>
> You just need to have one common module usign all
> the sub-modules.
>
> So having each sub-module in directory M/sub-a
> M/sub-b etc.
> you need a makefile in M/ that looks like:
> M/Makefile:
> obj-m += sub-a/
> obj-m += sub-b/
> obj-m += mainmodule.o
>
> In each sub-directory you need a separate Makefile
> like:
> M/sub-a/Makefile
> obj-m += a_sub_module.o
>
> Then all symbols used by the mainmodule needs to be
> properly
> exported in each sub-module.
>
> Hope this clarifies it.
>
> Sam
>
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [kbuild-devel] kbuild support to build one module with multiple separate components?
2004-07-14 21:40 ` Song Wang
@ 2004-07-19 17:29 ` sam
0 siblings, 0 replies; 3+ messages in thread
From: sam @ 2004-07-19 17:29 UTC (permalink / raw)
To: Song Wang; +Cc: Sam Ravnborg, kbuild-devel, linux-kernel
On Wed, Jul 14, 2004 at 02:40:44PM -0700, Song Wang wrote:
> Hi, Sam
>
> Thanks for the reply.
>
> However, in the way you indicate, the
> mainmodule and each submodule will be built
> as separate kernel modules. You will get
> mainmodule.ko, a_sub_module.ko, b_sub_module.ko etc.
>
> This is not what I tried to get. I tried to
> build a single kernel module, which means that
> mainmodule.o, a_sub_module.o, b_sub_module.o
> should be linked together to produce the single
> module.
OK.
This is even simpler:
Makefile:
EXTRA_CFLAGS := -I $(obj)/include
module-y := file.o dir/file.o
obj-m := module.o
And then code your C files as usual.
Assumig you have a directory named include.
Include header files like this:
#include "header.h"
So you end up having:
module/file.c
module/Makefile
module/dir/file.c
module/include/header.h
And you use:
make -C kernelsrcdir M=$PWD
to compile your module.
If this does not solve your issue please say so.
Sam
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-07-19 15:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20040702234735.63710.qmail@web40003.mail.yahoo.com>
2004-07-14 21:19 ` [kbuild-devel] kbuild support to build one module with multiple separate components? Sam Ravnborg
2004-07-14 21:40 ` Song Wang
2004-07-19 17:29 ` sam
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®