title: Linux Kernel generate compile-commands.json for module
body: <p><strong>The problem</strong>: Most of macro definition and even header files are not looked up by an IDE because include path is not specified in the IDE configuration. It inhibits autocompletion and navigation. </p>
  
  <p>Here is my <code>Makefile</code>:</p>
  
  <pre><code>#-Wno-declaration-after-statement
  ccflags-y := -std=gnu11 -Wno-declaration-after-statement -Werror
  obj-m += pfsw.o
  pfsw-objs := src/init.o
  
  all:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
  
  clean:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
  </code></pre>
  
  <p>I ran <code>make V=1</code> and noticed that the compile command along with include path is actually pretty cumbersome (counting Linux Specific <code>-include</code> for parameters): </p>
  
  <pre><code>gcc -Wp,-MD,/home/memyself/lkm/procfs_write/src/.init.o.d  -nostdinc 
     -isystem /usr/lib/gcc/x86_64-linux-gnu/7/include  
     -I./arch/x86/include -I./arch/x86/include/generated  -I./include -I./arch/x86/include/uapi
     -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi 
     -include ./include/linux/kconfig.h -Iubuntu/include  -include ./include/linux/compiler_types.h 
     -D__KERNEL__
     //tons of options ommitted...
     -c -o /home/memyself/lkm/procfs_write/src/init.o
      /home/memyself/lkm/procfs_write/src/init.c
  </code></pre>
  
  <p><strong>Question:</strong> Is there a way to generate <code>compile-command.json</code> to inform IDE about include paths? Or the only solution is to manually pass the include path to the IDE one by one?</p>