make -C ~/kernel-2.6 M=`pwd` modules
What is the meaning in M='pwd' in the line above ?
I could not understand the explanation :
The M= option causes that makefile to move back into your module source directory before trying to build the modules target.
Can you make this more clear ?
The M= option causes that makefile to move back into your module source directory before trying to build the modules target.
Options include control over which components get generated, assigning customized names to makefiles, and others.
'make all' simply tells the make tool to build the target 'all' in the makefile (usually called ' Makefile '). You may have a look at such file in order to understand how the source code will be processed. As about the error you are getting, it looks the compile_mg1g1.
obj-y += something/ This means that kbuild should go into the directory "something". Once it moves to this directory, it looks at the Makefile in "something" to decide what objects should be built. It is analogous to saying- go to the directory "something" and execute "make"
M
is not an option for make
. Note it lacks the hyphen. M
is a variable assigned to the execution of make
. If make
executes a Makefile
script, this script can read the variable M
and use its contents.
In the example you provide, make
will read Makefile
in ~/kernel-2.6
and assign your present working directory to variable M
. Typically, this will allow for make
to return to your current directory after processing Makefile
.
I had similar quiz with
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
Here the make is called within my project's directory. -C
is make option:
-C dir, --directory=dir Change to directory dir before reading the makefiles or doing anything else. If multiple -C options are specified, each is interpreted relative to the previous one: -C / -C etc is equivalent to -C /etc. This is typically used with recursive invocations of make.
M
is not make option but argument passed to it. Since -C
changes make directory we know that make will read make file in that directory. By inspection of make file in that directory I have discovered what it is going then to do with M
:
From make file (named Makefile) in the directory pointed to by -C
(btw it is kernel build directory):
# Use make M=dir to specify directory of external module to build # Old syntax make ... SUBDIRS=$PWD is still supported # Setting the environment variable KBUILD_EXTMOD takes precedence ifdef SUBDIRS KBUILD_EXTMOD ?= $(SUBDIRS) endif
Explanation from Linux Device Drivers, 3rd Edition, Jonathan Corbet et al.:
This command starts by changing its directory to the one provided with the -C option (that is, your kernel source directory). There it finds the kernel's top-level makefile. The M= option causes that makefile to move back into your module source directory before trying to build the modules target.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With