Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

M option in make command, Makefile

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 ?

like image 461
user1047069 Avatar asked Nov 30 '13 14:11

user1047069


People also ask

What is M in makefile?

The M= option causes that makefile to move back into your module source directory before trying to build the modules target.

What is option in makefile?

Options include control over which components get generated, assigning customized names to makefiles, and others.

What is make all command?

'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.

What is Obj Y in makefile?

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"


2 Answers

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.

like image 161
mcabreb Avatar answered Sep 28 '22 02:09

mcabreb


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.

like image 26
4pie0 Avatar answered Sep 28 '22 00:09

4pie0