title: Compiling kernel modules on Debian 9
body: <p>I'm trying to build a kernel module under Debian 9.
  I installed the necessary packages using</p>
  
  <pre><code>sudo apt-get install build-essential linux-headers-4.9.0-5-amd64
  </code></pre>
  
  <p>but I get the following error message when I try to compile my module:</p>
  
  <pre><code>&gt; make
  make -C /lib/modules/4.9.0-5-amd64/build M=/home/sven/tmp/kernel modules
  make[1]: Entering directory '/lib/modules/4.9.0-5-amd64/build'
  make[1]: *** No rule to make target 'modules'.  Stop.
  make[1]: Leaving directory '/lib/modules/4.9.0-5-amd64/build'
  Makefile:6: recipe for target 'all' failed
  make: *** [all] Error 2
  </code></pre>
  
  <p>The problem seems to be that there is no Makefile in the </p>
  
  <pre><code>/lib/modules/4.9.0-5-amd64/build
  </code></pre>
  
  <p>directory. In fact, this directory is empty ...
  This might be a beginner's question, but does anybody know how to fix this?
  The source code for the kernel module as well as the corresponding Makefile are listed below.</p>
  
  <p>Thank you very much for your help!</p>
  
  <p>C Code for module:</p>
  
  <pre><code>#include &lt;linux/module.h&gt;
  #include &lt;linux/kernel.h&gt;
  #include &lt;linux/init.h&gt;
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Homer S.");
  MODULE_DESCRIPTION("hmmmm ...");
  MODULE_VERSION("1.0")
  
  
  static int __init
  start(void) {
    printk(KERN_INFO "\nCHELLAS!\n\n");
    return 0;
  }
  
  
  static void __exit
  end(void) {
    printk(KERN_INFO "\nCIAO!\n\n");
    return 0;
  }
  
  
  module_init(start);
  module_exit(end);
  </code></pre>
  
  <p>Makefile to compile the module:</p>
  
  <pre><code>obj-m+=foo.o
  
  KVERSION=$(shell uname -r)
  
  all:
      make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
  
  clean:
      make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
  </code></pre>