Creating a debug target in Linux 2.6 driver module makefile
I'm trying to be able to execute "make debug" at the command line and it will build my driver module with the -DDEBUG_OUTPUT define, which will cause certain sections of code to be compiled in.
In 2.4 kernel makefiles, this is pretty easy. I just create a debug: target and included "-DDEBUG_OUTPUT" in the cc compilation command arguments for that target. Easy.
Unfortunately (for me), 2.6 completely changed how modules are compiled, and I can ONLY seem to find the trivial "all" and "clean" examples, which don't show adding custom defines at compilation time.
I tried this:
debug:
make -C $(KERNE开发者_如何转开发L_DIR) SUBDIRS='pwd' -DDEBUG_OUTPUT modules
and got a complaint from make.
I've also tried:
.PHONY: debug
debug:
make -C $(KERNEL_DIR) SUBDIRS='pwd' EXTRA_CFLAGS="$(EXTRA_CFLAGS) -DDEBUG_OUTPUT" modules
but it is not seeing what EXTRA_CFLAGS contains. I can see from the command line output that it does correctly append the -D onto the existing EXTRA_CFLAGS, which includes the -I for includes dir. However, the driver file won't compile now because it cannot find the includes dir...so somehow it is not seeing what EXTRA_CFLAGS contains.
A "-D" option is not meant to be passed to make: it is a C preprocesseor (cpp) option.
To define DEBUG_OUTPUT for your build you have to add the following line to your Kbuild file:
EXTRA_CFLAGS = -DDEBUG_OUTPUT
Afterwards you can call, as usual:
make -C $(KERNEL_DIR) M=`pwd`
EDIT: If you don't want to edit the Kbuild file, you can have a debug target like this:
INCLUDES="-Imy_include_dir1 -Imy_include_dir2"
.PHONY: debug
debug:
$(MAKE) -C $(KDIR) M=`pwd` EXTRA_CFLAGS="$(INCLUDES) -DDEBUG_OUTPUT"
EDIT#2:
MY_CFLAGS=-DFOO -DBAR -Imydir1
all:
$(MAKE) -C $(KDIR) M=`pwd` EXTRA_CFLAGS="$(MY_CFLAGS)"
debug: MY_CFLAGS+=-DDEBUG_OUTPUT
debug:
$(MAKE) -C $(KDIR) M=`pwd` EXTRA_CFLAGS="$(MY_CFLAGS)"
精彩评论