I'll post the solution, should anyone ever fall into this problem. The same issue exists when building QtWebKit.

FreeBSD make(1) silently auto-descends into obj/ subdirectories, and there is one in src/script, that's why relative paths don't work from there. Setting MAKEOBJDIR=. fixes the issue (that's what we use in the official FreeBSD port).