I came across a Linux kernel build system (Kbuild, kernel ≥2.6.28) with a directory structure and build system for a larger project. Our project contains an external Linux kernel module, and our directory structure looks like this (simplified, obviously):
checkout/src/common/*.c source files (common to Linux and other platforms)
checkout/src/linux-driver/*.c source files (for the Linux kernel driver)
checkout/build/linux/Kbuild Kbuild
tmp/linux-2.6.xx/ where the Linux kernel is unpacked and configured
output/linux-arm-debug/ where object files must end up
The build process should not change anything under checkout, and creating a module should not change anything in tmp/linux-2.6.xx. All output files must end under output/linux-arm-debug(or any other architecture and debugging option was selected during build).
I read kbuild/modules.txtand started writing my file Kbuild:
MOD_OUTPUT_DIR = ../../../output/linux-$(ARCH)-$(DEBUG)
obj-m += $(MOD_OUTPUT_DIR)/foo_mod.o
$(MOD_OUTPUT_DIR)/our_module-objs := $(MOD_OUTPUT_DIR)/foo_common.o $(MOD_OUTPUT_DIR)/foo_linux.o
, Kbuild . , , foo_common.o …/checkout/src/common/foo_common.c foo_linux.o …/checkout/src/linux-driver/foo_linux.c?