Linux is compiled using the GNU make tool to examine the entire system's files and invoke the GCC tools and scripts to complete the compilation of source code generation image. To understand the entire compilation system, we first need to understand the Linux kernel's Makefile file.
The Linux compilation system consists of 5 parts
Makefile Top-level Makefile file
. config kernel configuration file
arch/$ (ARCH)/makefile platform Makefile file
scripts/makefile.* Script rules
Kbuild makefiles about 500 + other Makefile files
Makefile
View version
There is a Makefile file at the root of the kernel source code, which is the portal to the kernel, and the make command reads the file first, regardless of the configuration or compilation. This file first indicates the version of the kernel:
We are 3.10 here.
VERSION = 3
Patchlevel = 10
Sublevel = 0
Extraversion =
NAME = unicycling Gorilla
Processing parameters
And then you handle command line, a total of 5 command line
V: Set the level of output information at compile time, for example you can use make v=1 to see all the commands executed at compile time, including the GCC parameters will print out
C: Code check, use sparse, check source file.
M: Specifies that no compilation of the current directory (external module), or a subdirectory of the current directory, will compile only the contents of the subdirectory
O: Specify the target file location of the build, and when the O parameter is set, the kernel-generated obj and builtin files will be organized into the directory specified by the O parameter according to the directory structure.
W: Enable external gcc to check
These command parameters, in certain circumstances, will be very useful, for example, we want to compile a separate module often use the M parameter, with m to specify the path of the module, make will not compile the entire kernel, and compile the module we need: (M parameter will overwrite kbuild_extmod variable)
Make m=drivers/misc/ld drivers/misc/eeprom/built-in.o CC [M] drivers/misc/eeprom/eeprom_93cx6.o LD DRIVERS/MISC/BUILT-IN.O Building modules, Stage 2. Modpost 1 Modules CC drivers/misc/eeprom/eeprom_93cx6.mod.o LD [M] Drivers/misc/eeprom/eeprom_93cx6.ko
O parameter designation, will change the structure of the entire compiled file, for example, oh we have multiple platforms to compile, you need to clone a copy of the kernel code for each platform, only need to set a different output path:
Make O=atmel, make O=asus (O parameter overrides kbuild_output variable), the corresponding file will also be generated under the target path, for example uimage in Atmel/arch/arm/boot/uimage
Get information
The system then acquires a cross-compilation environment and chooses a different set of gcc and bin Toolsets
ARCH = $ (subarch) cross_compile ? = $ (config_cross_compile: "%" =%)
The arch variable sets the target platform, cross compile sets the crossover compilation chain.
Pseudo target
When the system information gets successful, the compile command can be executed, each pseudo-target can be used as a compile command: (about 40 pseudo-target), but we will use not so much, you can use make to help to see the compile command we use:
Make helpcleaning Targets:clean-remove most generated files but keep the config and Enou GH Build Support-build external modules Mrproper-remove all generated Files + config + various backup files Distclean-mrproper + Remove editor backup and patch filesconfiguration targets:config-update current Config utilising a line-oriented program Nconfig-update current config utilising a ncurses menu based program Menuconfig-update Current config utilising a menu based program Xconfig-update Current config utilising A QT based front-end Gconfig-update current config utilising a GTK based front-end oldconfig-update CU Rrent config utilising a provided. config as base localmodconfig-update current config disabling modules not loaded L Ocalyesconfig-update current config converting local mods to core Silentoldconfig-same as Oldconfig, but quietly, ad ditionally Update DepsDefconfig-new config with the default from the ARCH supplied defconfig Savedefconfig-save current config as./defconf IG (minimal config) allnoconfig-new config where all options is answered with no allyesconfig-new config whe Re all options is accepted with Yes allmodconfig-new Config selecting modules when possible alldefconfig-new Config with all symbols set to default randconfig-new config with random answer to all options Listnewconfig- List new options Olddefconfig-same as Silentoldconfig but sets new symbols to their default valueother generic Targe Ts:all-build all targets marked with [*]* vmlinux-build the bare kernel* modules-build All modules Modules_install-install all modules to Install_mod_path (default:/) Firmware_install-install all FIRMWA Re to Install_fw_path (default: $ (install_mod_path)/lib/firmware) dir/-Build All files in Dir and below Dir/file. [Oiss]-Build specified target only dir/file.lst-build specified mixed source/assembly target only (Requires a recent binutils and recent build (SYSTEM.MAP)) Dir/file.ko-build module including final link module S_prepare-set up for building external modules tags/tags-generate tags file for editors cscope-gene Rate Cscope Index gtags-generate GNU GLOBAL index kernelrelease-output the release version string Kerne Lversion-output the version stored in Makefile Headers_install-install sanitised kernel headers to Install_hdr_path (Default:/MEDIA/ANDROID/JIANGXD/WORKSPACE/MIURA/KERNEL/USR) Static analysers checkstack-generate A list of stacks hogs namespacecheck-name space analysis on compiled Kerne L versioncheck-sanity Check on version.h usage Includecheck-check for duplicate included header files Export_ Report-list the usages of all exported symbols Headers_check -Sanity check on exported headers Headerdep-detect inclusion cycles in headers Coccicheck-check with Coccinelle.kernel Packaging:rpm-pkg-build both source and binary rpm Kernel packages binrpm-pkg -Build only the binary kernel package deb-pkg-build the kernel as a deb package Tar-pkg-bui LD the kernel as an uncompressed tarball targz-pkg-build the kernel as a gzip compressed tarball tarbz2-pkg -Build the kernel as a bzip2 compressed tarball tarxz-pkg-build The kernel as a XZ compressed Tarba ll perf-tar-src-pkg-build Perf-3.10.0.tar Source tarball perf-targz-src-pkg-build perf-3.10.0.tar.gz Source Tarb All perf-tarbz2-src-pkg-build perf-3.10.0.tar.bz2 source tarball perf-tarxz-src-pkg-build Perf-3.10.0.tar.xz Source Tarballdocumentation targets:linux kernel internal documentation in different formats:htmldocs-html Pdfdocs -PDF Psdocs -Postscript xmldocs-xml DocBook mandocs-man pages installmandocs-install man pages gener Ated by Mandocs Cleandocs-clean all generated DocBook filesarchitecture specific targets (ARM):* Zimage- Compressed kernel image (Arch/arm/boot/zimage) image-uncompressed kernel image (arch/arm/boot/image) * Xipimage -XIP kernel image, if configured (Arch/arm/boot/xipimage) uimage-u-boot wrapped zimage Bootpimage-co mbined zimage and initial RAM disk (supply INITRD image via make variable initrd=<path>) * Dtbs -Build device tree blobs for enabled boards Install-install uncompressed Kernel Zinstall-install Co mpressed kernel Uinstall-install u-boot wrapped compressed kernel Install using (your) ~/bin/inst Allkernel or (distribution)/sbin/installkernel or install to $ (install_path) and run Li Lo
The content is very much. Here are just a few of the commonly used:
Make menuconfig graphical configuration config
Make Uimage compile Build uimage
Make clean deletes most of the generated files, but retains the configuration so that the module can be compiled
Make Distclean Delete all generated files, patches and configurations, as well as some backup files
Make Mrproper Delete all generated files, patches and configurations
In general, the top-level Makefile file reads the config file to generate two major target files for Linux vmlinux and module files