NetBSD uses a framework, build.sh, to build both the operating system's kernel and the whole userland for either the same platform as the host machine, or for a different platform, using cross-compilation. build.sh will take care of creating all the tools required to build NetBSD for a given platform, and make them available ready to use for development work.
In this chapter, we will show how to use build.sh to first create a toolchain, including compiler, assembler, linker and so on, then use it to cross-compile a NetBSD kernel and userspace for AArch64 on an AMD64 host machine. While native kernel builds are covered in Chapter 34, Compiling the kernel, using the build.sh script is generally preferred for building the entire of NetBSD.
Before starting, we have placed the sources in a subdirectory of our user's home directory: /home/nia/cvs/src. While /usr/src is the traditional location for NetBSD sources, as described in Chapter 32, Obtaining the sources, we would like to build the operating system as an unprivileged (non-root) user.