在编译内核时, 常常碰到make clean, make mrproer 和 make distclean, 总结一下三者之间的区别:
内核源码包解压后, 转到内核源代码目录树的顶层目录, 执行# 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
看帮助发现删除的文件范围从小到大依次为: make clean < make mrproper < make distclean。
查看源码(以Linux-2.6.34为例)目录树的顶层目录下的Makefile求证, 可以发现:
1176 clean: archclean $(clean-dirs)
1177 $(call cmd,rmdirs)
1178 $(call cmd,rmfiles)
1179 @find . $(RCS_FIND_IGNORE) \
1180 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1181 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1182 -o -name '*.symtypes' -o -name 'modules.order' \
1183 -o -name modules.builtin -o -name '.tmp_*.o.*' \
1184 -o -name '*.gcno' \) -type f -print | xargs rm -f
1196 mrproper: clean archmrproper $(mrproper-dirs)
1197 $(call cmd,rmdirs)
1198 $(call cmd,rmfiles)
1199
1200 # distclean
1201 #
1202 PHONY += distclean
1203
1204 distclean: mrproper
1205 @find $(srctree) $(RCS_FIND_IGNORE) \
1206 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1207 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
1208 -o -name '.*.rej' -o -size 0 \
1209 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
1210 -type f -print | xargs rm -f
执行make mrproper会先执行make clean, 执行make distclean之前, 会先执行make mrproper。
再回到make help的结果:
make clean 删除大多数的编译生成文件, 但是会保留内核的配置文件.config, 还有足够的编译支持来建立扩展模块
make mrproper 删除所有的编译生成文件, 还有内核配置文件, 再加上各种备份文件
make distclean mrproper删除的文件, 加上编辑备份文件和一些补丁文件。
总结: 对于一个刚刚从官方Linux内核网站kernel.org上下载的内核源码包, 可以不用执行make clean/make mrproper/make distclean, 因为源码包的状态本身就是make clean过的。