估计编译时间: 0.02 估计所需硬盘空间: 142 MB |
我们不是要在这里编译一个新内核,这个工作会在完成本章的基本系统软件的进行。由于某些软件需要内核的一些头文件,所以我们现在需要将内核归档文件解包安装以便编译那些需要内核头文件的程序包。
拷贝内核头文件,命令如下:
ln -s /static/bin/pwd /bin/pwd && make mrproper && make include/linux/version.h && make symlinks && cp -HR include/asm /usr/include && cp -R include/asm-generic /usr/include && cp -R include/linux /usr/include && touch /usr/include/linux/autoconf.h && rm /bin/pwd |
ln -s /static/bin/pwd /bin/pwd: 在内核代码中, pwd 程序的路径是硬路径 /bin/pwd ,所以我们创建一个临时的符号链接,最后我们会删除它。
make mrproper: 这条命令确保内核树(kernel tree)是绝对干净的。内核开发组建议在 每次 编译内核之前都要运行这个命令,即使是你刚把压缩包解开,最好也运行一下,因为你不能确定打包的文件是绝对干净的。
make include/linux/version.h 和 make symlinks: 这两个命令创建 include/linux/version.h 文件和平台相关的 include/asm 符号链接。
cp -HR include/asm /usr/include 和 cp -R include/asm-generic /usr/include: 这些命令把平台相关的汇编器头文件拷贝到 /usr/include/asm 和 /usr/include/asm-generic 。
cp -R include/linux /usr/include: 这个命令把跨平台的内核头文件拷贝到 /usr/include.
touch /usr/include/linux/autoconf.h: 这个命令创建一个空的autoconf.h文件。由于我们还没有配置内核,我们不得不手动创建这个文件。有的内核头文件要用它,这样就避免了编译错误。
过去人们通常是创建从 /usr/include/{linux,asm} 目录到 /usr/src/linux/include/{linux,asm} 的符号链接。这是一种不好的行为,在下面 Linus Torvalds (Linux之父)写到 Linux Kernel Mailing List 信的节选中说:
I would suggest that people who compile new kernels should: - not have a single symbolic link in sight (except the one that the kernel build itself sets up, namely the "linux/include/asm" symlink that is only used for the internal kernel compile itself) And yes, this is what I do. My /usr/src/linux still has the old 2.2.13 header files, even though I haven't run a 2.2.13 kernel in a _loong_ time. But those headers were what glibc was compiled against, so those headers are what matches the library object files. And this is actually what has been the suggested environment for at least the last five years. I don't know why the symlink business keeps on living on, like a bad zombie. Pretty much every distribution still has that broken symlink, and people still remember that the linux sources should go into "/usr/src/linux" even though that hasn't been true in a _loong_ time. |
Linus 所说的精华部份是头文件应该是 glibc 编译时链接到的. 我们这里的头文件是你后面编译其它包时要用到的,因为它们是与对象(object-code)库文件相匹配的。通过拷贝头文件,我们保证它们在你以后升级内核后能继续使用它们。
注意,附带着说一句,内核代码在 /usr/src/linux 目录里是能正确使用的,只要你没有创建 /usr/include/{linux,asm} 的符号链接。
最后检查于 version 2.4.17.
Bash: sh
Binutils: ar, as, ld, nm, objcopy
Fileutils: cp, ln, mkdir, mv, rm, touch
Findutils: find, xargs
Gcc: cc1, collect2, cpp0, gcc
Grep: grep
Gzip: gzip
Make: make
Gawk: awk
Modutils: depmod, genksyms
Net-tools: dnsdomainname, hostname
Sed: sed
Sh-utils: basename, date, expr, pwd, stty, uname, whoami, yes
Textutils: cat, md5sum, sort, tail