I am attempting to build a basic module outside of the Linux source tree (3.18.0-rc6). When I build it, I get an error saying it couldn't find scripts/...

My directory setup looks like this

  # rest of the source tree

I am running: make -C ../linux SUBDIRS=$(pwd)/src modules from mymodule.

Here's the actual error:

make: Entering directory '/home/me/linux'
  Building modules, stage 2.
  MODPOST 1 modules
/bin/sh: scripts/mod/modpost: No such file or directory
scripts/Makefile.modpost:90: recipe for target '__modpost' failed
make[1]: *** [__modpost] Error 127
Makefile:1384: recipe for target 'modules' failed
make: *** [modules] Error 2
make: Leaving directory '/home/me/linux'

Is there a setting to make Make look in linux/ for the scripts?


To build a kernel module, you need more than an unpacked kernel source. You need some companion programs and header files generated during the kernel build. The makefile is looking for modpost in the right place but it isn't there yet. Distributions typically ship this in a package called linux-headers-VERSION or kernel-headers-VERSION or something similar.

First, you need to configure the kernel. The kernel version and the kernel configuration must match the kernel that you're going to run the module with. If you have the .config file from somewhere, copy it to the kernel directory. Then, do build the necessary files to build extra modules, run the following command in the kernel source directory:

make modules_prepare

Then you can go to the source directory of a module and run

make -C ../linux M=$PWD/src

See Building external modules in the kernel documentation (Documentation/kbuild/modules.txt) for more information.


When building a custom kernel, most people DO NOT BUILD the source inside the source tarball either. Please consider using a soft link:

User Source Directory Listing

As you can see the /usr/src/linux link points to /usr/src/linux-3.12.21-gentoo-r1 directory Thus, when issuing the make command, the resulting output is put in the top level directory of the build tree, which doesn't pollute the original source. To build the link issue (as root):

ln -sf /usr/src/linux-_some-kernel-version_ /usr/src/linux && cd /usr/src/linux

After doing so, refer to Giles' answer to complete the task.


  1. Kernel/Upgrade - Gentoo Wiki

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.