Accreted Drivel

Steven Tattersall's personal blog

Building Hatari for Windows

Created on: 2020-12-21

Posted in atari hatari


I've been doing a little work on some personal hacks for Hatari. I wanted to make sure they were cross-platform, so doing a Windows build was vital. Unfortunately, building Hatari for Windows seems to require several magical incantations, none of which are widely known. Here are some instructions for how I did it.

The Hatari build process is very Linux-orientated. My only successful strategy was to cross-compile the Windows executable from inside a Linux environment; I had no success using MSYS or Cygwin.

A native Linux system will do, but for quick testing turnaround, I built on a Windows machine, using Windows Subsystem for Linux to host an Ubuntu distribution. On my Linux laptop, I use the same process with a Mint distribution based on Debian.

Here are the main steps:

Open up the terminal and mkdir a directory to put things in.

Install the cross-compiler, cmake and git:

	sudo apt-get install gcc-mingw-w64 cmake git

LibSDL

The compile process needs a copy of LibSDL that the cross-compiler can use. On the download page, the latest build is this one. To download and install from the command-line:

	curl https://www.libsdl.org/release/SDL2-devel-2.0.12-mingw.tar.gz > sdl.gz
	tar -xvf sdl.gz
	cd SDL2-2.0.12
	sudo make cross

When running the 'make cross' part, the output will tell you where it is copying all the library and C include files (on my Linux machine it's /usr/local/i686-w64-mingw32 for the 32 bit versions, and /usr/local/x86_64-w64-mingw32 for the 64-bit version). Remember this directory!

Downloading Hatari

Now we should be able to grab the Hatari code from Github. It's best to use git, since it makes it easier to update the code rather than downloading new zip files every time:

	mkdir hatari
	cd hatari
	git clone https://github.com/hatari/hatari.git

Configuring

"Configuring" is the process that checks your machine for the right tools and libraries, then generates matching build scripts that you run to create the final binaries.

Before configuring, we need to tell the configure process where your SDL install lives. Assuming that we are making a Win32 build, you need to edit cmake/Toolchain-mingw32-win64_32.cmake with the directory you saved. Using a simple CLI editor like 'nano' should be enough. Change the line containing MINGW_ROOT_PATH to where libsdl copied its files. In my setup I change it to this:

	set (MINGW_ROOT_PATH "/usr/local/i686-w64-mingw32/")

This should be the only change needed to the codebase. In this example, I'm building a 32-bit build. For a 64-bit build, the file to edit and the path to set are cmake/Toolchain-mingw32-win64_64.cmake and /usr/local/x86_64-w64-mingw32 respectively.

Now we should be able to configure the build to generate Makefiles, using cmake. In the Hatari base directory run

	./configure --cross-compile-win64_32

Hatari will search for the necessary compilers and libraries. This is the difficult bit. Often it will fail because it will not find libsdl. In that case, check MINGW_ROOT_PATH again: the directory should have 'bin/', 'include/', 'lib/', and 'share/' as subdirectories.

Building

Fingers crossed, and you should be successful. Then it is a case of simply running "make" and hoping that the build process completes. After that there should be a "hatari.exe" in the "src" directory that you can copy to your Windows drive. Additionally you will need a copy of SDL.dll, which you can either download from the SDL website, or copy from your freshly-built version of LibSDL (e.g. from /usr/local/x86_64-w64-mingw32/bin/SDL2.dll in my example.

Advanced: multiple target platforms

By default, the configure script puts all the build process files in the same directory as the source code. This is a bit messy, and makes switching between target types (Win32, Win64, Linux) more time-consuming, since you need to re-run the configure scripts and rebuild from scratch.

Rather than using the configure script, which is a wrapper for cmake, we can call cmake directly and use the ‐B option to make build directories to build in instead. Here's a script to configure the 3 build types in different directories:

    mkdir build_linux
    cmake . -B build_linux
    mkdir build_win64
    cmake . -B build_win64 -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchain-mingw32-win64_64.cmake
    mkdir build_win32
    cmake . -B build_win32 -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchain-mingw32-win64_32.cmake

To build, cd to the build directory (e.g. build_linux and type "make" from there.

Back to Index