I want to compile my c code (in kernel) which needs to include some header files from another directory.
Instead of specifying the complete path to header files in c file, I would like to specify the include path in Makefile.
My c file gets complied when the config option CONFIG_FEATURE_X
is enabled.
I have written the following in Makefile:
obj-$(CONFIG_FEATURE_X) += my_file.o
ccflags-$(CONFIG_FEATURE_X) += -I$(obj)/../../path
When the
CONFIG_FEATURE_X
is enabled (Y) in .config using make menuconfig, it works fine.But when the
CONFIG_FEATURE_X
is enabled as module (m) in .config, this does not include the header files from the path specified and gives the file not found error.
How can I do this?
That's because
would evaluate to
According to Documentation/kbuild/makefiles.txt:
So you have defined a valid compilation flag for the built-in case.
That's because
would evaluate to
According to the current version of Documentation/kbuild/makefiles.txt, there is no such compilation flag as "ccflags-m".
So the path specification is never used for the loadable module.
Instead of the ccflags-$() flag, you could try to use CFLAGS_$@, a per-file options for $(CC).
So in your Makefile:
As noted by the @sawdust answer, it seems (according to documentation) that only
ccflags-y
variable is supported, not accflags-m
one.However, for make things work you may use a "trick":
Complete code: