在Ubuntu下编译Linux-xen时碰到arch/i386/kernel/head-xen.o无法找到的问题,而该目录下有head-xen.S这个文件,说明make之前的的工作并没有把这个.S文件编译成.o。而同样的代码,在ArchLinux和Fedora上svn checkout后编译没有任何问题。

最后发现问题在于Ubuntu默认会把/bin/sh指向/bin/dash,在scripts/Makefile.build里面加上一行SHELL=/bin/bash指定$(shell)使用bash即可。后来还搜了一下为什么Ubuntu使用dash而不是bash,其理由是dash的执行效率更高,但不可否认的是这个改动也导致了一些项目无法成功编译,虽然无法成功编译的原因可能是Makefile里使用了一些bash的特性而非POSIX shell所提供的那些。

另外在debug过程中在网上找到了一些debug Makefile的技巧:

make -n 可以仅仅打印出将要被执行的命令,而不去实际执行

make -np 可以打印出更多的信息(使用的规则和变量),并执行每一条命令

remake也是个不错的选择:“remake is a patched and modernized version of GNU make utility that adds improved error reporting, the ability to trace execution in a comprehensible way, and a debugger.”

在检查shell命令的时候,可以使用set -x使得所有shell命令在执行前都能被输出。