I have a kernel module I'd like to build with any of make
, make debug
, make test
, where the only difference between each one is a -D
option to the compiler. This is essentially the same question as Creating a debug target in Linux 2.6 driver module makefile, but that one was marked as answered, and my question remains, after trying a few other things as well.
I've tried the deprecated EXTRA_CFLAGS
option in my makefile:
debug:
$(MAKE) -C $(KDIR) M=$(PWD) EXTRA_CFLAGS="-DDEBUG" modules
as well as the newer ccflags-y
option (doesn't seem to work even outside of the debug
target):
ccflags-y := -DDEBUG
debug:
$(MAKE) -C $(KDIR) M=$(PWD) modules
and setting CFLAGS
just before the debug
target:
debug: CFLAGS_main.o=-DDEBUG
debug:
$(MAKE) -C $(KDIR) M=$(PWD) modules
but the only way I've found to accomplish what I want is with a separate build script:
#!/bin/sh
case "$1" in
debug)
make CFLAGS_main.o=-DDEBUG
;;
*)
make
;;
esac
Is there no way to do this directly in the makefile when building a kernel module??