Linux  的编译使用 GNU make 工具来检查整个系统的文件和调用 gcc 工具以及脚本完毕编译源码生成 image 等操作。要了解整个编译系统,我们首先要了解 Linux 内核的 Makefile 文件。

Linux 的 编译系统包含 5 个部分

Makefile
        顶层的 Makefile 文件

.config
内核配置文件

arch/$(ARCH)/Makefile
平台 Makefile 文件

scripts/Makefile.*
               脚本规则

kbuild Makefiles
            大概 500 多个其它的 Makefile 文件

Makefile

查看版本号

在内核源码的根文件夹有一个 Makefile 文件,这是编译内核的入口,无论运行配置还是编译,make 命令首先读取这个文件。这个文件首先指明了内核的版本号:

我们这里是 3.10

VERSION = 3

PATCHLEVEL = 10

SUBLEVEL = 0

EXTRAVERSION =

NAME = Unicycling Gorilla

处理參数

然后处理 command line ,一共同拥有 5  个 command line

V : 设定编译时,输出信息的等级,比如你能够用 make V=1, 查看编译时运行的全部命令,包含 gcc 參数都会打印出来

C :  代码检查,使用 sparse,检查源文件。

M : 指定不在当前文件夹(外部模块)的编译,也能够指定当前文件夹的子文件夹,那么将仅仅会编译子文件夹的内容

O :指定编译生成的目标文件位置,当设置了 O 參数,内核生成的 obj 和 builtin 文件都会依照文件夹结构组织到 O 參数指定的文件夹里面

W: 使能外部 gcc 检查

这几个命令參数,在特定的情况下,将会很实用,比方我们想编译一个单独的模块就常常使用 M 參数,用 M 指定模块的路径,make 的时候将会不编译整个内核,而编译我们须要的模块:(M 參数会覆盖  KBUILD_EXTMOD 变量)

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 參数的指定,会改变整个编译出来的文件的结构,比如哦我们有多个平台要编译,你就须要为每一个平台 clone 一份内核代码了,仅仅须要设置不同的输出路径就可以:

make O=atmel,  make O=asus  (O 參数会覆盖 KBUILD_OUTPUT 变量),对应的文件也会生成在目标路径下,比如 uImage 就在 atmel/arch/arm/boot/uImage

获取信息

接下来系统就会获取交叉编译环境和选择不同的 gcc 和 bin 工具集

ARCH            ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)

arch 变量设置目标平台, cross compile 设置交叉编译链。

伪目标

当系统信息获取成功,就能够运行编译命令了,每个伪目标都能够作为一个编译命令:(大概有 40 个左右的伪目标),可是我们会使用到的并没有这么多,能够用 make help 查看我们使用的编译命令:

 make help
Cleaning targets:
clean - Remove most generated files but keep the config and
enough build support to build external modules
mrproper - Remove all generated files + config + various backup files
distclean - mrproper + remove editor backup and patch files
Configuration 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 current config utilising a provided .config as base
localmodconfig - Update current config disabling modules not loaded
localyesconfig - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
defconfig - New config with default from ARCH supplied defconfig
savedefconfig - Save current config as ./defconfig (minimal config)
allnoconfig - New config where all options are answered with no
allyesconfig - New config where all options are 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 value
Other generic targets:
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 firmware 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
modules_prepare - Set up for building external modules
tags/TAGS - Generate tags file for editors
cscope - Generate cscope index
gtags - Generate GNU GLOBAL index
kernelrelease - Output the release version string
kernelversion - 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 stack hogs
namespacecheck - Name space analysis on compiled kernel
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 - Build 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 tarball
perf-tar-src-pkg - Build perf-3.10.0.tar source tarball
perf-targz-src-pkg - Build perf-3.10.0.tar.gz source tarball
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 tarball
Documentation targets:
Linux kernel internal documentation in different formats:
htmldocs - HTML
pdfdocs - PDF
psdocs - Postscript
xmldocs - XML DocBook
mandocs - man pages
installmandocs - install man pages generated by mandocs
cleandocs - clean all generated DocBook files
Architecture 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 - Combined 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 compressed kernel
uinstall - Install U-Boot wrapped compressed kernel
Install using (your) ~/bin/installkernel or
(distribution) /sbin/installkernel or
install to $(INSTALL_PATH) and run lilo

内容很之多。这里仅仅介绍几个经常使用的:

make menuconfig  图形化配置 config

make uImage          编译生成 uImage

make clean              删除大部分生成的文件,可是保留配置,以便能够编译模块

make distclean       删除全部生成的文件,补丁和配置,以及一些备份文件

make mrproper       删除全部生成的文件,补丁和配置

总的来说,顶层 Makefile 文件读取 config 文件生成 Linux 的两大目标文件 vmlinux 和 模块文件

Linux 内核的编译系统的更多相关文章

  1. 《linux内核设计与实现》读书笔记第三章

    第3章 进程管理 3.1 进程 1.进程 进程就是处于执行期的程序. 进程包括: 可执行程序代码 打开的文件 挂起的信号 内核内部数据 处理器状态 一个或多个具有内存映射的内存地址空间 一个或多个执行 ...

  2. Linux内核Makefile文件(翻译自内核手册)

    --译自Linux3.9.5 Kernel Makefiles(内核目录documention/kbuild/makefiles.txt) kbuild(kernel build) 内核编译器 Thi ...

  3. linux内核编译相关

    参考:http://www.arm.linux.org.uk/docs/kerncomp.php 一. 内核编译1) linux 2.4make clean/make mrpropermake dep ...

  4. 重新编译Linux内核必要性及其准备工作

    内核简介 内核,是一个操作系统的核心.它负责管理系统的进程.内存.设备驱动程序.文件和网络系统,决定着系统的性能和稳定性. Linux的一个重要的特点就是其源代码的公开性,所有的内核源程序都可以在/u ...

  5. Linux 内核的 Makefile

    Linux内核的配置系统的基本结构 Linux内核的配置系统由三个部分组成,分别是: 1.Makefile:分布在 Linux 内核源代码根目录及各层目录中,定义 Linux 内核的编译规则: 2.配 ...

  6. Linux内核调试方法总结

    Linux内核调试方法总结 一  调试前的准备 二  内核中的bug 三  内核调试配置选项 1  内核配置 2  调试原子操作 四  引发bug并打印信息 1  BUG()和BUG_ON() 2   ...

  7. Linux内核分析——期中总结

    期中总结 一.MOOC课程 (一)计算机是如何工作的 1.冯诺依曼体系结构的核心思想是存储程序计算机. 2.CPU在实际取指令时根据cs:eip来准确定位一个指令. 3.寄存器模式,以%开头的寄存器标 ...

  8. Linux内核调试方法【转】

    转自:http://www.cnblogs.com/shineshqw/articles/2359114.html kdb:只能在汇编代码级进行调试: 优点是不需要两台机器进行调试. gdb:在调试模 ...

  9. 为什么要编译Linux内核?

    新的内核修订了旧内核的bug,并增加了许多新的特性.如果用户想要使用这些新特性,或想根据自己的系统度身定制一个更高效,更稳定的内核,就需要重新编译Linux内核. 通常,更新的内核会支持更多的硬件,具 ...

随机推荐

  1. BZOJ 1066: [SCOI2007]蜥蜴( 最大流 )

    结点容量..拆点然后随便写 --------------------------------------------------------------- #include<cstdio> ...

  2. C/C++中使用的正则表达式库

    正则表达式 正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑. 正则引擎主要可以分 ...

  3. Anndroid 开发架构读书笔记

    市面上大部分应用不外乎就是颠过来倒过去地做以下这些事情: --------------- --------------- --------------- --------------- | | | | ...

  4. K-Modes算法[聚类算法]

    聚类算法k-Modes的实现 <?php /* *Kmodes算法(聚类算法的实现) */ /* *获取簇的数目 */ //----------------------------------- ...

  5. android-通知Notification

    发送通知 public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstan ...

  6. 线性规划问题的matlab求解

    函数:[x, fval] = linprog(f, A, b, Aeq, Beq, LB, UB) 返回的x:是一个向量——在取得目标函数最小时各个xi的取值: 返回的fval:目标函数的最小值: 参 ...

  7. 关于js封装框架类库之样式操作

    在js中,对样式的操作我们并不感到陌生,在很多框架中都是用极少的代码,实现更强大的功能,在这做出一些的总结.存在不足还望指出! 1.封装一个添加css的方法(这篇引用了前面的框架结构) 在 js 中 ...

  8. HTTP学习笔记——URL与资源

    什么是URL? 所有的东西都有一个标准化的东西,公交有线路号,飞机有航班号,个人有身份证号,你坐出租车,告诉司机师傅我要到石牌华师,他就能明白你的意思了.URL就是因特网资源的标准化名称.URL指向一 ...

  9. XMLHttpRequest对象的使用

    1.首先要创建XMLHttpRequest对象,这个对象是前台与后台进行异步的重要对象,现在的浏览器有很多种,创建 XMLHttpRequest 的方法也不相同,所以为了兼容各种浏览器,在创建XMLH ...

  10. Jquery 方法大全

    一.JQuery常用的方法 :(JQuery中90%都是方法,没有参数是获取,带参数是设置) $("#id").css('backgroundColor','blue'); .cs ...