Creating a debug target in a makefile on Linux 2.6

I am trying to execute "make debug" on the command line and it will build my driver module with the definition -DDEBUG_OUTPUT, which will lead to compilation of certain sections of code.

In 2.4 make kernel files, this is pretty simple. I simply create a debugging target: target and include "-DDEBUG_OUTPUT" in the arguments to the cc compilation command for this purpose. Easy.

Unfortunately (for me), 2.6 completely changed the way the modules are compiled, and I can ONLY find the trivial "all" and "clean" examples that do not show the addition of custom definitions at compile time.

I tried this:

debug: make -C $(KERNEL_DIR) SUBDIRS='pwd' -DDEBUG_OUTPUT modules 

and received a complaint from make.

I also tried:

.PHONY: debug

 debug: make -C $(KERNEL_DIR) SUBDIRS='pwd' EXTRA_CFLAGS="$(EXTRA_CFLAGS) -DDEBUG_OUTPUT" modules 

but he does not see what EXTRA_CFLAGS contains. I see from the command line output that it appends -D correctly to existing EXTRA_CFLAGS, which includes -I for include dir. However, the driver file will not compile now because it cannot find the include dir ... so it somehow does not see what EXTRA_CFLAGS contains.

+4
source share
1 answer

The "-D" parameter is not intended to be transmitted: it is a C preprocessor (cpp) option.

To define DEBUG_OUTPUT for your build, you must add the following line to your Kbuild file:

 EXTRA_CFLAGS = -DDEBUG_OUTPUT 

Then you can call as usual:

 make -C $(KERNEL_DIR) M=`pwd` 

EDIT: If you do not want to edit the Kbuild file, you may have a debugging goal 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)" 
+5
source

All Articles