How to pass flag from makefile to preprocesor when building external kernel module

Tomek The Messenger tomekthemessenger at gmail.com
Fri Aug 21 04:39:28 EDT 2020


OK, problem solved. The issue was that preprocesor directive in c: #elseif
doesn't work. I don't know why but I replaced this with #ifdef ... #endif
and #ifdef ... #endif instead of using #elseif in the middle and
everything works.

On Fri, Aug 21, 2020 at 10:01 AM Tomek The Messenger <
tomekthemessenger at gmail.com> wrote:

> Hi
> I have problem with passing flag from makefile to .c file.
> During building external kernel module my macro isn't seen by compiler. I
> used plenty of ways.
>
> First way:
> ccflags-y += -DMY_FLAG
> $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
> Second:
> $(MAKE) -C $(KERNEL_SRC) M=$(SRC) CFLAGS_my-kernel-module.o="-DMY_FLAG"
> Third:
> $(MAKE) -C $(KERNEL_SRC) M=$(SRC) CFLAGS="-DMY_FLAG"
> Forth:
>  $(MAKE) -C $(KERNEL_SRC) M=$(SRC) ccflags-y="-DMY_FLAG"
>
> In general I use bitbake to build external kernel modules.  And I wonder
> if bitbake doesn't introduce issue as some of above solution really should
> work. And additionally I had to use absolute paths in headers because
> relative didn't work so -I append also doesn't work:
> SRC := $(shell pwd)
> ccflags-y := -I$(SRC)
>
> BR
> Tomek
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20200821/47422e45/attachment.html>


More information about the Kernelnewbies mailing list