linux 内核代码精简

#为了提高性能,文件系统一般都是以 relatime形式挂载进来的,见:/etc/fstab
#更新一下mtime,这样,编译过程中用到的文件的atime都会被更新
find . -exec touch -m {} \; && touch ../tag

make mrproper && make allnoconfig && make menuconfig
#在allnoconfig的基础下,通过menuconfig加入如下配置,以方便调试
************************************************************
General setup
  --Initial RAM filesystem and RAM disk (initramfs/initrd) support
Executable file formats / Enulations
  --Kernel support for ELF binaries
Networking support
Kernel hacking
  --Kernel debugging
  --Compile the kernel with debug info
  --Compile the kernel with frame pointers
************************************************************

make #编译

#删除编译过程中没有用到的文件 
find . -type f ! -anewer ../tag | grep -v '/\.svn' | xargs rm

#删除所有空目录,经过本步骤后还可以通过编译
loop=found; while [ ! -z $loop ]; do loop=$(find . -type d | grep -v '/\.svn' | while read dirname; do cnt=$(ls $dirname | wc -l); if [ 0 -eq $cnt ]; then rm -rf $dirname; echo -n found; fi; done;); done;

#清理不包含源文件和头文件的目录:经过本步骤后不可以通过编译
find . -type d | while read dirname; do cnt=`find $dirname -name '*.[cSh]' | wc -l`; if [ 0 -eq $cnt ]; then rm -rf $dirname; fi; done;

猜你喜欢

转载自blog.csdn.net/ancjf/article/details/9381475