NAMEcross-development — operating system development from another operating system
DESCRIPTIONThe development(7) manual pages describes the primary way of building the operating system, which is under itself. The secondary way is to cross-compile it from a sufficiently similar operating system such as Linux with the GNU tools installed. The build system assumes the presence of some GNU extensions in the standard command line tools. This document will detail the process of bootstrapping a Sortix system from another operating system.
OverviewTo build Sortix you need these components:
- Sortix source code
- Sortix binutils
- Sortix gcc
- GRUB (for iso creation)
- xorriso (for iso creation)
- Retrieving all the source code.
- Installing the build tools.
- Creating a system root with the system headers.
- Creating a cross-compiler.
- Cross-compiling the operating system.
Source CodeYou can find the latest Sortix source code at https://sortix.org/source/
VariablesThis document will use shell variables to denote where you have choice. You would typically set them up like this:
# The Sortix source code is in /home/user/sortix # The cross-compiler is installed in /home/user/opt/x86_64-sortix SORTIX_PLATFORM=x86_64-sortix CROSS_PREFIX=/home/user/opt/x86_64-sortix SORTIX_SYSROOT=/home/user/sortix/sysroot export PATH="/home/user/opt/x86_64-sortix/bin:$PATH" export PATH="/home/user/opt/x86_64-sortix/sbin:$PATH"
Target PlatformYou need to decide what the platform your final Sortix system will run on. You can currently decide between i686-sortix and x86_64-sortix. In this guide we will refer to that platform triplet as SORTIX_PLATFORM. If you want to build another platform afterwards, then you will have to follow this guide again.
Cross-environmentYou should install your cross-toolchain into a useful and isolated directory such as $HOME/opt/$SORTIX_PLATFORM. This allows you to easily dispose of the directory and keeps it isolated from the rest of the system. We'll refer to that location as CROSS_PREFIX.
Build ToolsYou need to install some additional build tools as they are needed to build the operating system. The installed build tools must be in sync with the source code as described in development(7). Assuming the source code is in ~/sortix, you can install them by running:
cd ~/sortix && make PREFIX="$CROSS_PREFIX" clean-build-tools && make PREFIX="$CROSS_PREFIX" build-tools && make PREFIX="$CROSS_PREFIX" install-build-tools && make distclean
System Root with System HeadersBuilding the compiler requires the standard library headers being available. This can be satisfies by creating a system root with the system headers:
cd ~/sortix && make sysroot-base-headers HOST=$SORTIX_PLATFORM
Cross-toolchain DependenciesYou need to install these libraries (and the development packages) before building binutils and gcc:
binutilsAssuming you extracted the binutils to ~/src/sortix-binutils, you can build binutils out-of-directory by running:
mkdir ~/src/binutils-build && cd ~/src/binutils-build && ../sortix-binutils/configure \ --target=$SORTIX_PLATFORM \ --with-sysroot="$SORTIX_SYSROOT" \ --prefix="$CROSS_PREFIX" \ --disable-werror && make && make install
gccAssuming you extracted the gcc to ~/src/sortix-gcc, you can build gcc out-of-directory by running:
mkdir ~/src/gcc-build && cd ~/src/gcc-build && ../sortix-gcc/configure \ --target=$SORTIX_PLATFORM \ --with-sysroot="$SORTIX_SYSROOT" \ --prefix="$CROSS_PREFIX" \ --enable-languages=c,c++ && make all-gcc all-target-libgcc && make install-gcc install-target-libgcc
Building SortixWith the build tools and cross-compiler in the PATH is it now possible to build the operating system as described in development(7) by setting HOST to your value of SORTIX_PLATFORM. This tells the build system you are cross-compiling and it will run the appropriate cross-compiler. For instance, to build an bootable cdrom image using a x86_64-sortix cross-compiler you can run:
cd ~/sortix && make HOST=x86_64-sortix sortix.iso
TroubleshootingIf producing a bootable cdrom with grub-mkrescue(1) gives the error
xorriso: FAILURE: Cannot find path '/efi.img' in loaded ISO image