title: Writing a makefile for a kernel module
body: <p>I want to write a Kernel Module and now I have written some files: a.c, b.c, b.h and d.h.</p>
  
  <p>a.c includes b.h and d.h and b.h includes d.h too.</p>
  
  <p>I wrote a Makefile like this:</p>
  
  <pre><code>ifneq ($(KERNELRELEASE),)
  mymodule-objs :=a.c b.c
  obj-m += a.o b.o
  else
  PWD := $(shell pwd)
  KVER := $(shell uname -r)
  KDIR := /lib/modules/$(KVER)/build
  all:
      rm -rf *.o *.mod.c *.symvers *order *.markers *.cmd *-
      $(MAKE) -C $(KDIR) M=$(PWD)
  clean:
      rm -rf *.o *.mod.c *.symvers *order *.markers *.cmd *-
  endif
  </code></pre>
  
  <p>But it doesn't work, how should I write a correct Makefile? I want to get a file name x.ko in end and.</p>
  
  <p>After I use the 'make' command, and I use 'insmod' is give me a message:</p>
  
  <blockquote>
    <p>insmod: ERROR: could not insert module a.ko: Unknown symbol in module</p>
  </blockquote>
  
  <p>By the way I use Ubuntu 14.10. The kernel is 3.16.0-37-generic</p>