最后发现问题在于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命令在执行前都能被输出。