0
votes
  • Compile this driver with:

    echo "obj-m := tiny_i2c_adap.o" > Makefile make -C SUBDIRS=$PWD modules

Makefile: obj-m := tiny_i2c_adap.o

Error : prashanth@prashanth-Lenovo-ideapad-520-15IKB:~$ make -C /usr/src/linux-headers-$(uname -r) M=$PWD modules make: Entering directory '/usr/src/linux-headers-5.1.7-050107-generic' make[1]: * No rule to make target '/home/prashanth/tiny_i2c_adap.c', needed by '/home/prashanth/tiny_i2c_adap.o'. Stop. Makefile:1571: recipe for target 'module/home/prashanth' failed make: * [module/home/prashanth] Error 2 make: Leaving directory '/usr/src/linux-headers-5.1.7-050107-generic'

1
You are intended to execute that build command from the directory containing the C source file (tiny_i2c_adap.c). You are not doing so.John Bollinger
After you post your question, you should re-read it to make sure it's clear. When you do that you will notice that the formatting of your question is all messed up making it unreadable. You should then proceed to edit it to correct the formatting: see stackoverflow.com/editing-helpMadScientist
Of course better would be to notice that the formatting was all messed up and the question was unreadable before you posted it, by checking the preview of your question right below the entry text box :)MadScientist

1 Answers

0
votes

Remember $PWD is a shell variable, which contains the current working directory. So when you run:

~$ make -C /usr/src/linux-headers-$(uname -r) M=$PWD modules

the value of $PWD here is the directory you are in when you run make (in this case your home directory) so you're running:

~$ make -C /usr/src/linux-headers-$(uname -r) M=/home/prashanth modules

So the kernel makefile assumes that your module lives in /home/prashanth because that's where you set the M variable to.

You need to either use the correct path for M, or else use cd to switch to the directory containing your source before invoking make so that $PWD will contain the right path.