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.