mirror of
https://github.com/0xAX/linux-insides.git
synced 2024-12-22 22:58:08 +00:00
revise explaination of the content of Makefile!
This commit is contained in:
parent
90cc6f01e3
commit
e8e854f3bf
@ -57,7 +57,7 @@ endif
|
|||||||
export quiet Q KBUILD_VERBOSE
|
export quiet Q KBUILD_VERBOSE
|
||||||
```
|
```
|
||||||
|
|
||||||
If this option is passed to `make` we set the `KBUILD_VERBOSE` variable to the value of the `V` option. Otherwise we set the `KBUILD_VERBOSE` variable to zero. After this we check value of the `KBUILD_VERBOSE` variable and set values of the `quiet` and `Q` variables depends on the `KBUILD_VERBOSE` value. The `@` symbols suppress the output of the command and if it is present before a command the output will be something like this: `CC scripts/mod/empty.o` instead of `Compiling .... scripts/mod/empty.o`. In the end we just export all of these variables. The next `ifeq` statement checks that `O=/dir` option was passed to the `make`. This option allows to locate all output files in the given `dir`:
|
If this option is passed to `make`, we set the `KBUILD_VERBOSE` variable to the value of `V` option. Otherwise we set the `KBUILD_VERBOSE` variable to zero. After this we check the value of `KBUILD_VERBOSE` variable and set values of the `quiet` and `Q` variables depending on the value of `KBUILD_VERBOSE` variable. The `@` symbols suppress the output of command. And if it is present before a command the output will be something like this: `CC scripts/mod/empty.o` instead of `Compiling .... scripts/mod/empty.o`. In the end we just export all of these variables. The next `ifeq` statement checks that `O=/dir` option was passed to the `make`. This option allows to locate all output files in the given `dir`:
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
ifeq ($(KBUILD_SRC),)
|
ifeq ($(KBUILD_SRC),)
|
||||||
@ -82,14 +82,14 @@ endif # ifneq ($(KBUILD_OUTPUT),)
|
|||||||
endif # ifeq ($(KBUILD_SRC),)
|
endif # ifeq ($(KBUILD_SRC),)
|
||||||
```
|
```
|
||||||
|
|
||||||
We check the `KBUILD_SRC` that represents the top directory of the kernel source code and if it is empty (it is empty when the makefile is executed for the first timea.) We then set the `KBUILD_OUTPUT` variable to the value that passed with the `O` option (if this option was passed). In the next step we check this `KBUILD_OUTPUT` variable and if it is set, we do following things:
|
We check the `KBUILD_SRC` that represents the top directory of the kernel source code and whether it is empty (it is empty when the makefile is executed for the first time). We then set the `KBUILD_OUTPUT` variable to the value passed with the `O` option (if this option was passed). In the next step we check this `KBUILD_OUTPUT` variable and if it is set, we do following things:
|
||||||
|
|
||||||
* Store value of the `KBUILD_OUTPUT` in the temp `saved-output` variable;
|
* Store the value of `KBUILD_OUTPUT` in the temporary `saved-output` variable;
|
||||||
* Try to create given output directory;
|
* Try to create the given output directory;
|
||||||
* Check that directory created, in other way print error;
|
* Check that directory created, in other way print error message;
|
||||||
* If the custom output directory was created successfully, execute `make` again with the new directory (see the `-C` option).
|
* If the custom output directory was created successfully, execute `make` again with the new directory (see the `-C` option).
|
||||||
|
|
||||||
The next `ifeq` statements checks that the `C` or `M` options were passed to `make`:
|
The next `ifeq` statements check that the `C` or `M` options passed to `make`:
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
ifeq ("$(origin C)", "command line")
|
ifeq ("$(origin C)", "command line")
|
||||||
@ -104,7 +104,7 @@ ifeq ("$(origin M)", "command line")
|
|||||||
endif
|
endif
|
||||||
```
|
```
|
||||||
|
|
||||||
The `C` option tells the `makefile` that we need to check all `c` source code with a tool provided by the `$CHECK` environment variable, by default it is [sparse](https://en.wikipedia.org/wiki/Sparse). The second `M` option provides build for the external modules (will not see this case in this part). We also check if the `KBUILD_SRC` variable is set, and if it isn't we set the `srctree` variable to `.`:
|
The `C` option tells the `makefile` that we need to check all `c` source code with a tool provided by the `$CHECK` environment variable, by default it is [sparse](https://en.wikipedia.org/wiki/Sparse). The second `M` option provides build for the external modules (will not see this case in this part). We also check whether the `KBUILD_SRC` variable is set, and if it isn't, we set the `srctree` variable to `.`:
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
ifeq ($(KBUILD_SRC),)
|
ifeq ($(KBUILD_SRC),)
|
||||||
@ -118,7 +118,7 @@ obj := $(objtree)
|
|||||||
export srctree objtree VPATH
|
export srctree objtree VPATH
|
||||||
```
|
```
|
||||||
|
|
||||||
That tells to `Makefile` that the kernel source tree will be in the current directory where `make` was executed. We then set `objtree` and other variables to this directory and export them. The next step is the getting value for the `SUBARCH` variable that represents what the underlying architecture is:
|
That tells `Makefile` that the kernel source tree will be in the current directory where `make` was executed. We then set `objtree` and other variables to this directory and export them. The next step is to get value for the `SUBARCH` variable that represents what the underlying architecture is:
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
|
SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
|
||||||
@ -129,7 +129,7 @@ SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
|
|||||||
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
|
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see it executes the [uname](https://en.wikipedia.org/wiki/Uname) util that prints information about machine, operating system and architecture. As it gets the output of `uname`, it parses it and assigns the result to the `SUBARCH` variable. Now that we have `SUBARCH`, we set the `SRCARCH` variable that provides the directory of the certain architecture and `hfr-arch` that provides directory for the header files:
|
As you can see, it executes the [uname](https://en.wikipedia.org/wiki/Uname) util that prints information about machine, operating system and architecture. As it gets the output of `uname`, it parses the ouput and assigns the result to the `SUBARCH` variable. Now that we have `SUBARCH`, we set the `SRCARCH` variable that provides the directory of the certain architecture and `hfr-arch` that provides the directory for the header files:
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
ifeq ($(ARCH),i386)
|
ifeq ($(ARCH),i386)
|
||||||
@ -142,7 +142,7 @@ endif
|
|||||||
hdr-arch := $(SRCARCH)
|
hdr-arch := $(SRCARCH)
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that `ARCH` is an alias for `SUBARCH`. In the next step we set the `KCONFIG_CONFIG` variable that represents path to the kernel configuration file and if it was not set before, it is set to `.config` by default:
|
Note `ARCH` is an alias for `SUBARCH`. In the next step we set the `KCONFIG_CONFIG` variable that represents path to the kernel configuration file and if it was not set before, it is set to `.config` by default:
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
KCONFIG_CONFIG ?= .config
|
KCONFIG_CONFIG ?= .config
|
||||||
@ -166,7 +166,7 @@ HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-p
|
|||||||
HOSTCXXFLAGS = -O2
|
HOSTCXXFLAGS = -O2
|
||||||
```
|
```
|
||||||
|
|
||||||
Next we get to the `CC` variable that represents compiler too, so why do we need the `HOST*` variables? `CC` is the target compiler that will be used during kernel compilation, but `HOSTCC` will be used during compilation of the set of the `host` programs (we will see it soon). After this we can see definition of the `KBUILD_MODULES` and `KBUILD_BUILTIN` variables that are used to determine what to compile (kernel, modules or both):
|
Next we get to the `CC` variable that represents compiler too, so why do we need the `HOST*` variables? `CC` is the target compiler that will be used during kernel compilation, but `HOSTCC` will be used during compilation of the set of the `host` programs (we will see it soon). After this we can see the definition of `KBUILD_MODULES` and `KBUILD_BUILTIN` variables that are used to determine what to compile (kernel, modules or both):
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
KBUILD_MODULES :=
|
KBUILD_MODULES :=
|
||||||
@ -177,13 +177,13 @@ ifeq ($(MAKECMDGOALS),modules)
|
|||||||
endif
|
endif
|
||||||
```
|
```
|
||||||
|
|
||||||
Here we can see definition of these variables and the value of the `KBUILD_BUILTIN` will depend on the `CONFIG_MODVERSIONS` kernel configuration parameter if we pass only `modules` to `make`. The next step is including of the:
|
Here we can see definition of these variables and the value of `KBUILD_BUILTIN` variable will depend on the `CONFIG_MODVERSIONS` kernel configuration parameter if we pass only `modules` to `make`. The next step is to include the `kbuild` file.
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
include scripts/Kbuild.include
|
include scripts/Kbuild.include
|
||||||
```
|
```
|
||||||
|
|
||||||
`kbuild` file. The [Kbuild](https://github.com/torvalds/linux/blob/master/Documentation/kbuild/kbuild.txt) or `Kernel Build System` is the special infrastructure to manage the build of the kernel and its modules. The `kbuild` files has the same syntax that makefiles do. The [scripts/Kbuild.include](https://github.com/torvalds/linux/blob/master/scripts/Kbuild.include) file provides some generic definitions for the `kbuild` system. As we included this `kbuild` files we can see definition of the variables that are related to the different tools that will be used during kernel and modules compilation (like linker, compilers, utils from the [binutils](http://www.gnu.org/software/binutils/), etc...):
|
The [Kbuild](https://github.com/torvalds/linux/blob/master/Documentation/kbuild/kbuild.txt) or `Kernel Build System` is the special infrastructure to manage the build of the kernel and its modules. The `kbuild` files has the same syntax that makefiles do. The [scripts/Kbuild.include](https://github.com/torvalds/linux/blob/master/scripts/Kbuild.include) file provides some generic definitions for the `kbuild` system. As we included this `kbuild` files we can see definition of the variables that are related to the different tools that will be used during kernel and modules compilation (like linker, compilers, utils from the [binutils](http://www.gnu.org/software/binutils/), etc...):
|
||||||
|
|
||||||
```Makefile
|
```Makefile
|
||||||
AS = $(CROSS_COMPILE)as
|
AS = $(CROSS_COMPILE)as
|
||||||
|
Loading…
Reference in New Issue
Block a user