Contributed by Jörg Wunsch <joerg@FreeBSD.org>
Note: You should be familiar with the section about kernel configuration before reading here.
The use of kernel options is basically described in the kernel configuration section. There's also an explanation of ``historic'' and ``new-style'' options. The ultimate goal is to eventually turn all the supported options in the kernel into new-style ones, so for people who correctly did a make depend in their kernel compile directory after running config(8), the build process will automatically pick up modified options, and only recompile those files where it is necessary. Wiping out the old compile directory on each run of config(8) as it is still done now can then be eliminated again.
Basically, a kernel option is nothing else than the definition of a C preprocessor macro for the kernel compilation process. To make the build truly optional, the corresponding part of the kernel source (or kernel .h file) must be written with the option concept in mind, i.e. the default must have been made overridable by the config option. This is usually done with something like:
#ifndef THIS_OPTION #define THIS_OPTION (some_default_value) #endif /* THIS_OPTION */
This way, an administrator mentioning another value for the option in his config file will take the default out of effect, and replace it with his new value. Clearly, the new value will be substituted into the source code during the preprocessor run, so it must be a valid C expression in whatever context the default value would have been used.
It is also possible to create value-less options that simply enable or disable a particular piece of code by embracing it in
#ifdef THAT_OPTION [your code here] #endif
Simply mentioning THAT_OPTION in the config file (with or without any value) will then turn on the corresponding piece of code.
People familiar with the C language will immediately recognize that everything could be counted as a ``config option'' where there is at least a single #ifdef referencing it... However, it's unlikely that many people would put
in their config file, and then wonder why the kernel compilation falls over. :-)
Clearly, using arbitrary names for the options makes it very hard to track their usage throughout the kernel source tree. That is the rationale behind the new-style option scheme, where each option goes into a separate .h file in the kernel compile directory, which is by convention named opt_foo.h. This way, the usual Makefile dependencies could be applied, and make can determine what needs to be recompiled once an option has been changed.
The old-style option mechanism still has one advantage for local options or maybe experimental options that have a short anticipated lifetime: since it is easy to add a new #ifdef to the kernel source, this has already made it a kernel config option. In this case, the administrator using such an option is responsible himself for knowing about its implications (and maybe manually forcing the recompilation of parts of his kernel). Once the transition of all supported options has been done, config(8) will warn whenever an unsupported option appears in the config file, but it will nevertheless include it into the kernel Makefile.