Reputation: 531
I understand there is an option to add compile-time macros/definitions to the Kconfig file that can be used in the code.
(For example, some definition of a constant, like a #define).
Upvotes: 5
Views: 9689
Reputation: 22420
The Kconfig values are passed as Makefile defines. Also, all selected Kconfig values are put in a header file and passed to the assembler and 'C' code. So, you do not do this directly in the Kconfig file, but can do it in the Makefile or source.
config MY_DEFINE
bool "Select to get some DEFINE"
default y
help
This is a config define that is sent to both make
and defined in a config.h header.
ifeq ($(CONFIG_MY_DEFINE),y)
KBUILD_CFLAGS += -DTHE_REAL_DEAL=1 # THE_REAL_DEAL now '1' in C files.
endif
#ifdef CONFIG_MY_DEFINE
#define THE_REAL_DEAL 1
#endif
So, the Kconfig section defines the user interface information. The .config
is makefile syntax, which is output by menuconfig, etc. This is sourced when you type make
. Ie, all the stuff selected by menuconfig or another tool is available in Makefiles. The Kconfig variable has a CONFIG_ prefix added.
You can choose either the Makefile or the Source sections to get your define. If you want to select a range, then you can pass the value of CONFIG_MY_DEFINE
to the compiler. Ie, including almost any kernel header will include config.h and the 'C' value CONFIG_MY_DEFINE
will be set to whatever the user selected in the range.
See the kbuild wiki for more, which mainly references the kernel's kbuild documentation.
Upvotes: 10