Request for help: how do teach module building about kernel options?

Warner Losh imp at bsdimp.com
Sun Jan 1 01:52:47 UTC 2012


On Dec 31, 2011, at 4:39 PM, Adrian Chadd wrote:

> Hi,
> 
> I need a bit of a hand with this.
> 
> I'd like to be able to make the wlan and ath modules aware of kernel
> configuration options.
> 
> For example, a kernel configuration with IEEE80211_SUPPORT_TDMA won't
> build a wlan module that'll run successfully, as wlan/Makefile doesn't
> know to suck in ieee80211_tdma.c . I could just wrap the whole file up
> in an #ifdef, but I'd like to try and instead only build / link that
> object in if it's needed.
> 
> Similarly, the ath module currently builds everything, regardless of
> what options are currently enabled in the kernel configuration file.
> So it'll always build ar5210, ar5211, ar5212, ar5416, ar9001, ar9002
> support, along with ath_rate_sample. Instead, I'd like to be able to
> specify which HAL objects to link in, much like how you can do this
> with "device ath_rfX" for the RF backends and "device ath_arX" for the
> chipset support. For the integrated SoC stuff, it'd be nice to only
> build a HAL which supports the relevant hardware, rather than having
> to suck it _all_ in.
> 
> So, what kinds of evil ways can people dream up to achieve this? :)

Build the kernel modules with the kernel and the kernel options will be picked up.

However, that only works for the opt_xxx.h files.  There's not an (easy) way to selectively include for modules with our current module system.

The easy way to "work around" this is to always include the _tdma file, and have a big ifdef around it.

The 'harder' way would be to have a Makefile variable that will set all the options in opt_foo.h as Makefile variables so you could .if based on them.  However, making that automated starts to get messy, due to the order of inclusion.

Working off the cuff, I'd propose the following API:

KERNOPTS=foo baz
SRC_FOO = foo.c
SRC_BAZ = baz.c
SRC= a.c b.c d.c

And have the magic needed to conditionally add SRC_FOO and SRC_BAZ to SRC in bsd.kern.mk.

Warner



More information about the freebsd-arch mailing list