0

I have some source code which I want to use for both a kernel module and in a user-space program. I'd like to only maintain a single copy of that code within my source tree. I was thinking of putting the shared source files in a shared folder (outside of the kernel tree), have kbuild build these files from the external directory, and produce .o files inside of the module's directory. Is there a good way to include source files from an external directory using kbuild?

My target directory would look something like this:

+ linux
| + drivers
|   + foo
|     + Makefile
|     + foomain.c
|     + foomain.o
|     + shared.o
+ shared
| + shared.c
+ bar
  + Makefile
  + barmain.c
  + barmain.o
  + shared.o

While it's possible to copy shared.c into the foo directory as part of the build process, it seems like an ugly solution, and I'm wondering if there's a better way.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
John
  • 3,400
  • 3
  • 31
  • 47

1 Answers1

0

I think it's possible.

Create a Makefile under shared directory, which can support to build the shared.o for kernel module foo and shared.o for user space application bar.

That means to create two different build targets in the Makefile, the two targets can have the same name but need to use macro such as KERNEL_BUILD to different them.

tian_yufeng
  • 1,780
  • 10
  • 8