一、現象
我將之前Redhat9.0編譯好的uboot,轉到ubuntu12.04環境。在ubuntu環境下對 uboot重新編譯提示錯誤。編譯過程如下:
root@hailin-virtual-machine:/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06# make clean
root@hailin-virtual-machine:/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06# make TX2440_config
Configuring for TX2440 board...
root@hailin-virtual-machine:/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06# make -j4
Generating include/autoconf.mk
Generating include/autoconf.mk.dep
for dir in tools examples/standalone examples/api arch/arm/cpu/arm920t /home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/arch/arm/cpu/arm920t/ ; do \
make -C $dir _depend ; done
make[1]: 正在進入目錄 `/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/tools'
make[1]: 沒有什么可以做的為 `_depend'。
make[1]:正在離開目錄 `/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/tools'
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。此處省略部分編譯輸出
make[1]: 正在進入目錄 `/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/tools'
make[1]: *** 沒有規則可以創建“crc32.o”需要的目標“/home/hailin/u-boot-2010.06/lib/crc32.c”。 停止。
make[1]:正在離開目錄 `/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/tools'
make: *** [tools] 錯誤 2
make: *** 正在等待未完成的任務....
make[1]: 正在進入目錄 `/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/examples/standalone'
make[1]: *** 沒有規則可以創建“hello_world.o”需要的目標“/home/hailin/u-boot-2010.06/include/common.h”。 停止。
make[1]:正在離開目錄 `/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06/examples/standalone'
make: *** [examples/standalone] 錯誤 2
make: *** wait: 沒有子進程。 停止。
root@hailin-virtual-machine:/home/hailin/桌面/dream/tx2440/uboot/u-boot-2010.06#
為什么之前在redhat環境中,可以成功編譯,而到ubuntu環境會出現沒有規則呢??
二、解決方法
輸入以下命令:
make disclean
make TX2440_config
make -j4
輸出結果:

為什么 將make clean 換成 make distclean就成功???
三、原理
make distclean類似make clean,但同時也將configure生成的文件全部刪除掉,包括Makefile。
從上面的解析可以看出,上面的問題的根源是因為,從redhat拿來uboot代碼里面已經有配置文件,是根據原來的編譯環境生成的,僅僅通過make clean並不能清楚之前的配置文件,沒有清除之前的配置文件就進行編譯,編譯器本着相信程序員的態度,編譯時不會產生新的configure生成的附帶文件,而是根據原來的configure生成的文件進行編譯,這樣就會導致上面的一系列編譯錯誤。make distclean可以將所有的垃圾,之前環境所有的余孽清理干凈,這樣就不會給編譯器偷懶的機會。