Compile multiple modules with a single makefile

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Fri Apr 26 15:48:17 EDT 2013


On Fri, 26 Apr 2013 11:11:09 -0700, Henrique Rodrigues said:

> I have the one .c source file that I want to create multiple kernel modules
> out of it by setting macros using the makefile.

Generally considered ugly by the mainstream kernel.

> The idea is that if -DMODULE1 is set, I'll build module1.ko and if
> -DMODULE2 is set, I'll build module 2.

The way this would usually be done is splitting your module into 3
parts - one common, one for device 1 and one for device 2.

Then something like this (cut-n-paste from drivers/net/wireless/hostap/Makefile:

hostap-y := hostap_80211_rx.o hostap_80211_tx.o hostap_ap.o hostap_info.o \
            hostap_ioctl.o hostap_main.o hostap_proc.o
obj-$(CONFIG_HOSTAP) += hostap.o

obj-$(CONFIG_HOSTAP_CS) += hostap_cs.o
obj-$(CONFIG_HOSTAP_PLX) += hostap_plx.o
obj-$(CONFIG_HOSTAP_PCI) += hostap_pci.o

Which will build 3 different modules (_cs, _plx, _pci) using the common C files
and 1 device-specific C file for each one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130426/80004ac2/attachment.bin 


More information about the Kernelnewbies mailing list