How to see the preprocessed output of a module source file

Aruna Hewapathirane aruna.hewapathirane at
Mon Nov 2 08:41:09 EST 2015

>> On Mon, Nov 2, 2015 at 7:02 AM, Shiyao Ma <i at> wrote:
>> Hi,
>> Say I am writing a module. Instead of directly compile it into a ko
file, I'd like to see the preprocessed output of that file,
>> similarly the way it's done in gcc -E.

lets say you have a module named shiyao.c the makefile will look similar

obj-m += shiyao.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD       := $(shell pwd)

    $(MAKE) -C $(KERNELDIR) M=$(PWD)

    $(MAKE) -C $(KERNELDIR) M=$(PWD) clean

change the target all to:

    $(MAKE) -C $(KERNELDIR) M=$(PWD) *shiyao.i*

run make as usual then open shiyao.i in vi(m) or your preferred editor -
done !

Thank's - Aruna
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Kernelnewbies mailing list