====== Cross-compiling MINIX 3 ======
**Note:** This is for cross-compiling MINIX from another Unix-like system. To build MINIX from within MINIX, [[.:rebuildingsystem|check this page]] instead.
Cross-compilation is the act of building MINIX from another operating system. Since MINIX now uses the build.sh framework from NetBSD, cross-compilation should work on most mainstream UNIX-compatible systems. A build compatibility table is available at the end of this document. ===== Install dependencies ===== Before attempting to cross-compile MINIX, you need a working C toolchain, Git and some additional software on your host platform. For Debian-based operating systems, run the following command as super-user: # apt-get install build-essential curl git zlibc zlib1g zlib1g-dev **Note**: Also on Ubuntu, if you get an error stating that "'/lib/cpp' fails sanity check", you need to install the GNU C++ compiler: $ sudo apt-get install g++ **Note**: On FreeBSD and Minix ([[developersguide:minixonarm#building_minix_arm |compiling for ARM on x86, e.g.)]], if you get a message along the lines of "Skipping image creation: missing tool 'mcopy'", please install the emulators/mtools package. ===== Getting the sources ===== Once the required tools are installed, the next step is to obtain the sources. Run the following commands in a terminal: $ mkdir minix $ cd minix $ git clone git://git.minix3.org/minix src $ cd src NOTE: The releasetools script will generate object files and put them //outside// the source directory; i.e., if you've cloned to ~/minix/src/ and build from there, things will start showing up in ~/minix/ as an artifact of the build process. ===== Cross-building for x86 ===== It's time to build MINIX itself. There are some wrapper scripts that will build ready-to-boot images from scratch (i.e. just the minix source tree) for either x86 or ARM. These scripts produce a lot of output and will take a while to complete the first time - a cross-toolchain based on LLVM is built from scratch. $ bash ./releasetools/x86_hdimage.sh [..] Writing Minix filesystem images - ROOT - USR - HOME Part First Last Base Size Kb 0 0/000/00 0/000/07 0 8 4 1 0/000/08 64/000/07 8 131072 65536 2 64/000/08 1856/000/07 131080 3670016 1835008 3 1856/000/08 1984/000/07 3801096 262144 131072 To boot this image on kvm: [..] A command line for running the result in a KVM virtual machine is printed at the end of the process. ===== Cross-building for ARM ===== A similar procedure exists for ARM. Please see [[.:MinixOnARM]] for much more information. ===== Using build.sh directly ===== Please refer to NetBSD's documentation on build.sh for details. From a source directory: $ sh build.sh -mi386 -O ../build tools Please note that by default, the build.sh script will output the built objects to ''/usr/obj'', so make sure it exists. Alternatively, use as above the "-O" option to redirect the output to somewhere else. When this process is completed, you'll have a ../build/tooldir. directory. The is roughly equivalent to $ echo ''uname -s''-''uname -r''-''uname -m'' Among the tools that are built are ''gcc'', ''binutils'', and ''gmake''. The sources for these tools are not provided by us. Instead, they are downloaded on-the-fly as tarballs from the minix webserver ===== Building world ===== The next step is to actually build MINIX: $ sh build.sh -mi386 -O ../build -U distribution This process will create a ../build/destdir.i386 directory that holds the built distribution of MINIX. Other useful options for qemu are ''-monitor telnet::4444,server,nowait'' (to access some interesting internal state by telnet) and ''-serial stdio'' - for convenient debug output over 'serial.' ===== Compiling things without build.sh ===== To run make in the cross-environment, i.e. to rebuild a tool (host target) or minix item (minix target), without running the full build.sh procedure all over again, use nbmake-i386, a make wrapper that sets all the right environment. First expand your $PATH to include it: $ PATH=$PATH:OBJDIR/tooldir.OS-VERSION-ARCH/bin/ $ cd SRCDIR/tools $ nbmake-i386 clean $ nbmake-i386 will rebuild all the tools. After that you can e.g. $ cd zic $ nbmake-i386 clean $ nbmake-i386 to just rebuild zic. As you can tell if you set MAKEVERBOSE=2, tools/zic/ will invoke cc (to run on the host platform), whereas nbmake-i386 will invoke i486--netbsdelf-gcc from your tools dir if you run it in usr.sbin/zic/, so a Minix-targeted binary is produced. ===== Caveats ===== The ''build.sh'' is tailored towards NetBSD and as such not all features make sense for MINIX. For example, we don't have a kernel configuration file. Also, you can't use ''build.sh'' for native builds on MINIX at the time of this writing. You can consult ''build.sh'''s documentation by invoking: $ sh build.sh But know that not all operations and options are supported. For example, we only support the ''distribution'' build operation. You can't generate iso images with the ''build.sh'' script. ==== Build flags for build.sh ==== It is possible to tweak the build using build flags. Here are some you might find useful. |Option name |value |example |Description | |COPTS |c flags |COPTS=-g |**c** compiler **opt**ions | ==== Build flags for nbmake ==== It is also possible to tweak when building separate components using nbmake-i386 | Option name | value | example | Description | | MAKEVERBOSE | [1] | MAKEVERBOSE=2 | Instruct make to be more verbose | ==== Mounting a MINIX disk image on Linux ==== 1. Load the loop kernel module, or adapt kernel command line: $ modprobe loop max_part=15 or add to your kernel commandline : **max_part=15** 2. Setup a loopback device to point to your disk image: $ losetup /dev/loop0 minix.img 3. (Optional) list the available partitions: $ dmesg | tail or use $ ls /dev/loop0* 4. Mount the desired partition somewhere $ mount /dev/loop0p5 /mnt ===== Build compatibility ===== ^ Host platform ^ Version ^ Buildable MINIX architectures ^ Version ^ Updated | | Ubuntu x86 32-bit | 14.04 | x86 32-bit / ARMv7 | 3.4.0rc | 2016-02 | | Ubuntu x86 64-bit | 14.04 | x86 32-bit / ARMv7 | 3.4.0rc | 2016-02 | | Arch Linux x86 32-bit | | x86 32-bit | 3.2.1 | 2013-08 | | Arch Linux x86 64-bit | | x86 32-bit / ARMv7 | 3.2.1 | 2013-08 | | Mac OS X Lion x86 64-bit | | x86 32-bit / ARMv7 | 3.2.1 | 2013-08 | | Mac OS X Maverick x86 64-bit | | x86 32-bit / ARMv7 | 3.3.0 | 2014-10 | | FreeBSD x86 32-bit | 10-CURR. | x86 32-bit / ARMv7 | 3.2.1 | 2013-08 | | FreeBSD x86 64-bit | 10-CURR. | x86 32-bit / ARMv7 | 3.2.1 | 2013-08 | | Windows Subsystem for Linux 64-bit | 10.14393 | x86 32-bit / ARMv7 | 3.4.0rc | 2016-08 | | Debian x86 32-bit | 8.8.0 | x86 32-bit | 3.3.0 | 2017-05 | | Debian x86 64-bit ((Apply [[https://github.com/Stichting-MINIX-Research-Foundation/minix/pull/301|this]] patch)) | 10.9.0 | x86 32-bit / ARMv7 | 3.4.0rc | 2021-03 |