All of lore.kernel.org
 help / color / mirror / Atom feed
* Building separate files for a kernel module
@ 2018-04-04 21:29 Martin Galvan
  2018-04-05  5:26 ` valdis.kletnieks at vt.edu
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Galvan @ 2018-04-04 21:29 UTC (permalink / raw)
  To: kernelnewbies

Hi all,

I'm trying to build a kernel module by statically linking object files
with a library. My source tree looks like this:

source/
??? bar/
|   ??? bar1.c
|   ??? bar2.c
??? foo.c

The relevant parts of my Makefile look like this:

mydriver-y := foo.o bar.a
obj-m += mydriver.o
bar-objs := bar/bar1.o bar/bar2.o

# This builds foo.o
mydriver:
    $(MAKE) -C $(kernel-src-dir) M=$(CURDIR) modules

$(bar-objs): %.o: %.c
    $(MAKE) -C $(kernel-src-dir) M=$(CURDIR) $@

bar.a: $(bar-objs)
    ar rcs $@ $^

Here, the rule for $(bar-objs) should use the kbuild machinery to
build bar1.o and bar2.o, as stated in Documentation/kbuld/modules.txt:

--- 2.4 Building Separate Files

It is possible to build single files that are part of a module.
This works equally well for the kernel, a module, and even for
external modules.

Example (The module foo.ko, consist of bar.o and baz.o):
make -C $KDIR M=$PWD bar.lst
make -C $KDIR M=$PWD baz.o
make -C $KDIR M=$PWD foo.ko
make -C $KDIR M=$PWD /

However, when I try to build bar.a, I get the following:

make -C /lib/modules/$(uname -r)/build M=/home/martin/source/bar/bar1.o
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-38-generic'
scripts/Makefile.build:44: /home/martin/source/bar/Makefile: No such
file or directory
make[2]: *** No rule to make target '/home/martin/source/bar/Makefile'.  Stop.

It's like kbuild expects me to have a Makefile on the 'bar' subdir as
well. Am I doing something wrong?

PS: Yes, I'm aware I could just add $(bar-objs) to mydriver-y and
avoid building bar.a, but I really need to have those files as a
separate library. Building them with a separate Makefile (i.e. without
the kbuild machinery) isn't desirable either because I want to use the
full array of flags and such that kbuild adds when invoking gcc.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building separate files for a kernel module
  2018-04-04 21:29 Building separate files for a kernel module Martin Galvan
@ 2018-04-05  5:26 ` valdis.kletnieks at vt.edu
  2018-04-05 14:49   ` Martin Galvan
  0 siblings, 1 reply; 7+ messages in thread
From: valdis.kletnieks at vt.edu @ 2018-04-05  5:26 UTC (permalink / raw)
  To: kernelnewbies

On Wed, 04 Apr 2018 18:29:21 -0300, Martin Galvan said:

> PS: Yes, I'm aware I could just add $(bar-objs) to mydriver-y and
> avoid building bar.a, but I really need to have those files as a
> separate library.

What's driving the requirement for a separate library?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building separate files for a kernel module
  2018-04-05  5:26 ` valdis.kletnieks at vt.edu
@ 2018-04-05 14:49   ` Martin Galvan
  2018-04-05 15:02     ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Galvan @ 2018-04-05 14:49 UTC (permalink / raw)
  To: kernelnewbies

2018-04-05 2:26 GMT-03:00  <valdis.kletnieks@vt.edu>:
> On Wed, 04 Apr 2018 18:29:21 -0300, Martin Galvan said:
>
>> PS: Yes, I'm aware I could just add $(bar-objs) to mydriver-y and
>> avoid building bar.a, but I really need to have those files as a
>> separate library.
>
> What's driving the requirement for a separate library?

I want my module to be DKMS-enabled, but since the 'bar' binaries
don't use anything Linux-specific I don't want to distribute the
sources for it. It's similar to the "_shipped" binary blobs the
documentation mentions, except in this case I want to use the kbuild
machinery to build it.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building separate files for a kernel module
  2018-04-05 14:49   ` Martin Galvan
@ 2018-04-05 15:02     ` Greg KH
  2018-04-09 17:19       ` Martin Galvan
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2018-04-05 15:02 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Apr 05, 2018 at 11:49:36AM -0300, Martin Galvan wrote:
> 2018-04-05 2:26 GMT-03:00  <valdis.kletnieks@vt.edu>:
> > On Wed, 04 Apr 2018 18:29:21 -0300, Martin Galvan said:
> >
> >> PS: Yes, I'm aware I could just add $(bar-objs) to mydriver-y and
> >> avoid building bar.a, but I really need to have those files as a
> >> separate library.
> >
> > What's driving the requirement for a separate library?
> 
> I want my module to be DKMS-enabled, but since the 'bar' binaries
> don't use anything Linux-specific I don't want to distribute the
> sources for it.

Hahaha, good luck, please discuss this with a lawyer as to the
legalities involved.  You are on your own here.

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building separate files for a kernel module
  2018-04-05 15:02     ` Greg KH
@ 2018-04-09 17:19       ` Martin Galvan
  2018-04-18 15:57         ` Daniel.
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Galvan @ 2018-04-09 17:19 UTC (permalink / raw)
  To: kernelnewbies

2018-04-05 12:02 GMT-03:00 Greg KH <greg@kroah.com>:
> On Thu, Apr 05, 2018 at 11:49:36AM -0300, Martin Galvan wrote:
>> I want my module to be DKMS-enabled, but since the 'bar' binaries
>> don't use anything Linux-specific I don't want to distribute the
>> sources for it.
>
> Hahaha, good luck, please discuss this with a lawyer as to the
> legalities involved.  You are on your own here.

You're right, and I apologize if this practice is frowned upon. I just
assumed it wasn't since the kbuild docs mention ways for having binary
blobs included with kernel modules.

Thanks for the answer.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building separate files for a kernel module
  2018-04-09 17:19       ` Martin Galvan
@ 2018-04-18 15:57         ` Daniel.
  2018-04-18 15:57           ` Daniel.
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel. @ 2018-04-18 15:57 UTC (permalink / raw)
  To: kernelnewbies

AFAIK if foo is GPL, you can't link bar to it except if it's GPL to. Doing
so would be license breaking. If foo is not GPL, you are tainting your
kernel and would be hard to get help with a tainted kernel.

2018-04-09 14:19 GMT-03:00 Martin Galvan <omgalvan.86@gmail.com>:

> 2018-04-05 12:02 GMT-03:00 Greg KH <greg@kroah.com>:
> > On Thu, Apr 05, 2018 at 11:49:36AM -0300, Martin Galvan wrote:
> >> I want my module to be DKMS-enabled, but since the 'bar' binaries
> >> don't use anything Linux-specific I don't want to distribute the
> >> sources for it.
> >
> > Hahaha, good luck, please discuss this with a lawyer as to the
> > legalities involved.  You are on your own here.
>
> You're right, and I apologize if this practice is frowned upon. I just
> assumed it wasn't since the kbuild docs mention ways for having binary
> blobs included with kernel modules.
>
> Thanks for the answer.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
?If you're going to try, go all the way. Otherwise, don't even start. ..."
  Charles Bukowski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20180418/6bde1b7c/attachment-0001.html>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Building separate files for a kernel module
  2018-04-18 15:57         ` Daniel.
@ 2018-04-18 15:57           ` Daniel.
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel. @ 2018-04-18 15:57 UTC (permalink / raw)
  To: kernelnewbies

except if it's GPL too*

2018-04-18 12:57 GMT-03:00 Daniel. <danielhilst@gmail.com>:

> AFAIK if foo is GPL, you can't link bar to it except if it's GPL to. Doing
> so would be license breaking. If foo is not GPL, you are tainting your
> kernel and would be hard to get help with a tainted kernel.
>
> 2018-04-09 14:19 GMT-03:00 Martin Galvan <omgalvan.86@gmail.com>:
>
>> 2018-04-05 12:02 GMT-03:00 Greg KH <greg@kroah.com>:
>> > On Thu, Apr 05, 2018 at 11:49:36AM -0300, Martin Galvan wrote:
>> >> I want my module to be DKMS-enabled, but since the 'bar' binaries
>> >> don't use anything Linux-specific I don't want to distribute the
>> >> sources for it.
>> >
>> > Hahaha, good luck, please discuss this with a lawyer as to the
>> > legalities involved.  You are on your own here.
>>
>> You're right, and I apologize if this practice is frowned upon. I just
>> assumed it wasn't since the kbuild docs mention ways for having binary
>> blobs included with kernel modules.
>>
>> Thanks for the answer.
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>
>
>
> --
> ?If you're going to try, go all the way. Otherwise, don't even start. ..."
>   Charles Bukowski
>



-- 
?If you're going to try, go all the way. Otherwise, don't even start. ..."
  Charles Bukowski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20180418/029a1dba/attachment.html>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-04-18 15:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04 21:29 Building separate files for a kernel module Martin Galvan
2018-04-05  5:26 ` valdis.kletnieks at vt.edu
2018-04-05 14:49   ` Martin Galvan
2018-04-05 15:02     ` Greg KH
2018-04-09 17:19       ` Martin Galvan
2018-04-18 15:57         ` Daniel.
2018-04-18 15:57           ` Daniel.

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.