Sortix
Sortix Download Manual Development Source Code News Blog More
current nightly

NAME

cross-development — operating system development from another operating system

DESCRIPTION

The 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.

Overview

To build Sortix you need these components:
  • Sortix source code
  • Sortix binutils
  • Sortix gcc
  • GRUB (for iso creation)
  • xorriso (for iso creation)
The overall process is:
  • 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 Code

You can find the latest Sortix source code at https://sortix.org/source/
You can find the latest Sortix binutils source code at https://sortix.org/toolchain/sortix-binutils-latest.tar.xz
You can find the latest Sortix gcc source code at https://sortix.org/toolchain/sortix-gcc-latest.tar.xz
This is a compiler toolchain that has been modified to support Sortix. The toolchain is sometimes updated and you will need the latest toolchain to keep building the latest code.

Variables

This 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"
The following sections describe these variables in detail.

Target Platform

You 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-environment

You 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.
You need to add $CROSS_PREFIX/bin and $CROSS_PREFIX/sbin to your PATH variable:
    export PATH="$CROSS_PREFIX/sbin:$CROSS_PREFIX/bin:$PATH"
This will modify the PATH variable in this particular shell session. You can make this permanent by adding that line to your ~/.profile or the applicable file for your shell and system. Consult your shell documentation. Otherwise type it in all Sortix-related shells before doing anything.

Build Tools

You 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
These tools produce platform independent output so you may wish to install them into $HOME/bin and $HOME/sbin or /usr/local/bin and /usr/local/sbin or where it suits you in your PATH.

System Root with System Headers

Building 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
This will create a system root at ~/sortix/sysroot. Refer to that directory as SORTIX_SYSROOT.

Cross-toolchain Dependencies

You need to install these libraries (and the development packages) before building binutils and gcc:
  • bison
  • flex
  • libgmp
  • libmpfr
  • libmpc
Consult the official binutils and gcc documentation for the exact dependencies.

binutils

Assuming 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
You can remove the temporary ~/src/binutils-build directory when finished.

gcc

Assuming 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
You can remove the temporary ~/src/gcc-build directory when finished. Notice how special make targets are used to not build all of gcc.

Building Sortix

With 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
This creates a bootable sortix.iso. See the development(7) manual page for how to use the build system.

Troubleshooting

If producing a bootable cdrom with grub-mkrescue(1) gives the error
xorriso: FAILURE: Cannot find path '/efi.img' in loaded ISO image
then your GRUB installation is defective. You need to install mformat(1) to use grub-mkrescue(1) in your case.

SEE ALSO

make(1), development(7), installation(7), porting-guide(7), sysinstall(8)
Copyright 2011-2025 Jonas 'Sortie' Termansen and contributors.
Sortix's source code is free software under the ISC license.
#sortix on irc.sortix.org
@sortix_org