'How to build multiple linux kernel module with multiple source files in a single Makefile?

I am trying to build a set of Linux kernel modules with multiple source files:

obj-m += mst_pciconf.o mst_pci.o
mst-objs += nnt_device.o nnt_dma.o nnt_pci_conf_access.o \
            nnt_pci_conf_access_no_vsec.o nnt_memory_access.o \
            nnt_ioctl.o mst_pciconf_bc.o mst_pci_bc.o

The kernel modules will be mst_pciconf and mst_pci. Seems 'mst-objs' is not the correct type.

Thanks all.



Solution 1:[1]

You should specify "-y" or "-m" (not "-obj") for every of your modules. Example from net/wireless:

obj-$(CONFIG_CFG80211) += cfg80211.o
cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o ap.o trace.o ocb.o
cfg80211-y += pmsr.o
cfg80211-$(CONFIG_OF) += of.o
cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o

where every $(CONFIG_XXX) expands to n/m/y from .config

So, in your case it would be something like that:

mst_pciconf-y += nnt_device.o nnt_dma.o nnt_pci_conf_access.o \
            nnt_pci_conf_access_no_vsec.o nnt_memory_access.o \
            nnt_ioctl.o mst_pciconf_bc.o mst_pci_bc.o
mst_pci-y += ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daft Soft