Creating a debug target in Linux 2.6 driver module makefile

你说的曾经没有我的故事 提交于 2019-12-07 11:22:11

问题


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 $(KERNEL_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.


回答1:


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)"


来源:https://stackoverflow.com/questions/7714714/creating-a-debug-target-in-linux-2-6-driver-module-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!