Port build system changes from bug 1031291 for im/ (following m-c changes in bug 762358). rs=florian over IRC