Various fixes for cross-compilation

These commits improve the build system in various ways to improve the cross-compilation use-case