The NetBSD pkgsrc is available for all of NetBSD's more than 50 ports (on 13 distinct processor architectures). Many of these machines are slow, so it is desirable to cross-build packages for them. Cross-building does also make it easier to provide a complete set of binary packages, since you could use a small number of fast build servers instead of needing to gather all different architectures.
The build process of most software packages are however not written with cross-building in mind. Most may probably be fixed with minor work, but even doing minor changes to the 5000 packages in the NetBSD pkgsrc is a daunting task.
This paper describes a novel method to automatically cross-build software, without any need of modifying the original source code.
The basic idea is to intercept the exec system call, and modify the commands in such a way that they do the corresponding operation for the target architecture. For example: execution of "cat" is done without any modification, and execution of "gcc" is changed to execute a cross-compiler. Some programs cannot be transformed (for example test programs compiled by the "configure" scripts). These are automatically being run in an emulator instead.
Experiences with running this cross-building framework on the NetBSD pkgsrc shows that the approach is efficient; only about one percent of the packages need significantly longer time to cross-build than building natively on the build machine, and only 3 packages need more than 24 hours to cross-build on a modern PC. This technique does thus drastically reduce the number of packages that need to be modified in order to be cross-buildable.