Building a2x on FreeBSD
My game framework a2x is a Linux project, and last year I wanted to try building it on FreeBSD. I only had to make very few changes to get it to run, according to Git it was only 18 additions and 9 deletions. This was the first time I booted a BSD system, so I thought I'd write a few lines about it here.
Setup the VM#
Boot the VHD#
I installed the
virtualbox-ext packages for my Debian-based Linux OS, and grabbed the i386 VHD of FreeBSD 10.3. I had to run
dhclient em0 after booting to get network access, so I could install packages and clone my projects' git repos.
Install a Graphical Environment#
pkg install xorg gnome3 from the terminal and restart the system. There is a
gnome3-lite package that I wanted to use instead, but it would not start so I moved on.
Install Tools and Libraries#
Install GNU Make and Git with
pkg install git gmake. Running
make on a GNU/Linux system will probably call GNU Make, but on FreeBSD it calls BSD Make which expects makefiles with a slightly different syntax and a reduced feature set.
SDL 1.2 and libpng are pre-installed, but a2x uses SDL 2 on desktop platforms that support it, so run
pkg install devel/sdl20 audio/sdl2_mixer to get it. All the available SDL packages are conveniently listed in the FreeBSD Porter's Handbook.
Git was set to use colored text by default, but that was broken in both Xterm and Gnome Terminal. You can run
git config --global color.ui false to disable it and get clean output.
- The BSD
mkdirdoes not accept the long form
--parentsflag, so I changed all calls to use
-pinstead. I like using verbose flags in my scripts because the meaning is easier to decipher when I go over them later.
- I updated the Python install script to check if the
sys.platformscript starts with "linux" or "freebsd", based on which it calls
- SDL 2 is not in the default library paths that Clang looks at. I had to add
$(shell sdl2-config --libs)to the linker flags, which is good practice anyway.
Since a2x cross-compiles for several different platforms, the Makefile uses the
$(CC) variable to call the C compiler instead of a hardcoded name like
gcc. On FreeBSD this had the unintended but welcome effect of using Clang to build the code, which I had never used on a2x before.
I had to add
#include <zlib.h> to the PNG support module, because the FreeBSD libpng
png.h does not include this header like it does on Linux. This header is needed for the
Z_BEST_COMPRESSION symbol that I pass to
And that was the only code change, really. I didn't expect a big fight given this was porting a C project from one Unix-like to another, but I still thought there would be more work involved to build my games on FreeBSD!
Maintainability & Future Plans#
This was only an exploratory port. I did not set up a permanent FreeBSD system to regularly build on, so I expect the code to eventually take on unintended Linux-only dependencies.
Working with VirtualBox on Linux Mint was not a polished experience, but I do believe that a nice VM farm is the long-term solution to maintaining support for all platforms, not just operating systems but also aging prebuilt toolchains and cross-compilers that will someday stop working on contemporary systems.