Compiling BerryBots on Mac OS X command line

From BerryBots Wiki
Jump to: navigation, search

Note: These instructions build a version of BerryBots that's launched from the command line. The official BerryBots release for Mac OS X is an application file (BerryBots.app) built with XCode. See: Compiling BerryBots app on Mac OS X with XCode.

Contents

Overview

Before compiling anything, you need to install some build tools. Download and install the XCode developer tools from Apple. This installs some things we need, like g++ (C++ compiler). Note that we're not going to be launching the XCode application.

The BerryBots source code is available at the GitHub repo or on the Downloads page.

If you have the required dependencies installed, you can just use configure and make straight away. (But that's pretty unlikely.)

~> unzip berrybots_src_1.3.1.zip
~> cd berrybots
~/berrybots> ./configure
~/berrybots> make
~/berrybots> sudo make install

After installing, you should be able to run berrybots from a terminal.

Note that this build process for Mac OS X is mostly similar to Compiling BerryBots on Linux.

Dependencies

BerryBots depends on SFML 2, wxWidgets 2.9, and libarchive. For each, you'll need to either download a binary or compile it from source.

SFML 2

BerryBots uses SFML 2 for the main game graphics. If SFML 2 is installed, configure will detect it and use it. Otherwise, you need to pass the path to SFML using --with-sfml-src (compiled from source) or --with-sfml-dl (downloaded libs).

There are some notable OS X resizing/scaling issues in SFML 2.1+ ([1]), so you should use SFML 2.0 for now.

Compiling SFML

Note that SFML has their own instructions for building SFML 2 with CMake, which may be helpful.

SFML for Mac depends on Freetype. The easiest way to get this is to just install XQuartz X Window system for Mac. You could also rip freetype.framework from the Frameworks directory of the BerryBots.app binary release, and drop it in /Library/Frameworks.

Download and install CMake from cmake.org. During installation, you'll be asked about installing the command line tools - install them where ever you like and add them to your PATH. If you don't know how to do that, there are a bunch of Google results that might help.

Next, grab the source from the SFML downloads page or the GitHub repo and extract it. Open a terminal and change into the SFML source directory. Use CMake to generate the build files that are used for actual compilation, then use make to compile SFML.

~> cd ~/SFML-2.0
~/SFML-2.0> mkdir build
~/SFML-2.0> cd build
~/SFML-2.0/build> cmake ..
~/SFML-2.0/build> make

When it completes, you should have a lib subdirectory with the SFML library files. For a user named "voidious", this would translate to: --with-sfml-src=/Users/voidious/SFML-2.0

wxWidgets 2.9

BerryBots uses wxWidgets 2.9 for everything besides the main game window: all the dialogs and menus for configuring battles, packaging ships and stages, and viewing output consoles. If wxWidgets 2.9 is installed, configure will detect it and use it. Otherwise, you need to pass the path to wxWidgets using --with-wxdir or --with-wx-config.

Compiling wxWidgets

wxWidgets has their own instructions for compiling wxWidgets on OS X in a terminal, which may be helpful.

Download wxWidgets 2.9.x source code from the wxWidgets downloads page and extract it. Open a terminal and navigate to the wxWidgets directory. Then compile wxWidgets with configure and make.

~> cd ~/wxWidgets-2.9.5
~/wxWidgets-2.9.5> ./configure --disable-shared --with-osx_cocoa
~/wxWidgets-2.9.5> make

The --disable-shared parameter means that wxWidgets libraries will be built for static linking. So you don't need to keep the wxWidgets libraries around - the required wxWidgets code is baked right into the executable.

This will take a few minutes to compile. When it completes, you should have a lib subdirectory with the wxWidgets library files. For a user named "voidious", this would translate to: --with-wxdir=/Users/voidious/wxWidgets-2.9.5

libarchive

BerryBots uses libarchive for packaging ships and stages as tarred / gzipped (.tar.gz) files. The gzip compression itself is handled by zlib, which is included with OS X. If libarchive is installed, configure will detect it and use it. Otherwise, you need to pass the path to libarchive using --with-libarchive.

Compiling libarchive

Download libarchive from libarchive.org. Extract it, open a terminal, and change into the libarchive directory. Then compile libarchive with configure and make.

~> cd ~/libarchive-3.1.2
~/libarchive-3.1.2> ./configure
~/libarchive-3.1.2> make

When it completes, you should have .libs/libarchive.a under the build directory. (Note that .libs is a hidden directory.) For a user named "voidious", this would translate to: --with-libarchive=/Users/voidious/libarchive-3.1.2

Compiling everything from source

If you're building everything from source, the whole process would look something like this:

~> unzip ~/Downloads/SFML-2.0-sources.zip
~> cd SFML-2.0
~/SFML-2.0> mkdir build
~/SFML-2.0> cd build
~/SFML-2.0/build> cmake ..
~/SFML-2.0/build> make
~/SFML-2.0/build> cd ~

~> tar xfv ~/Downloads/wxWidgets-2.9.5.tar.bz2
~> cd wxWidgets-2.9.5
~/wxWidgets-2.9.5> ./configure --disable-shared
~/wxWidgets-2.9.5> make
~/wxWidgets-2.9.5> cd ~

~> tar xfv ~/Downloads/libarchive-3.1.2.tar.gz
~> cd libarchive-3.1.2.tar.gz
~/libarchive-3.1.2> ./configure
~/libarchive-3.1.2> make
~/libarchive-3.1.2> cd ~

~> unzip ~/Downloads/berrybots_src_1.3.1.zip
~> cd berrybots
~/berrybots> ./configure --with-sfml-src=/Users/voidious/SFML-2.0 \
    --with-wxdir=/Users/voidious/wxWidgets-2.9.5 \
    --with-libarchive=/Users/voidious/libarchive-3.1.2
~/berrybots> make
~/berrybots> sudo make install

CLI version

The BerryBots source package also contains a version of BerryBots that launches individual matches from the command line. This is how things worked on Mac and Linux in v1.0.x, and how things still work on the Raspberry Pi.

You may find this useful, such as for running matches from other programs or running BerryBots from the command line on a remote system - you could use -nodisplay -savereplay and then view the replay in a browser. The code for this is in bbsfmlmain.cpp.

To compile this version of BerryBots on Mac OS X, run make osxcli. Then run matches or package ships or stages with berrybots.

./berrybots
Usage:
  berrybots [-nodisplay] [-savereplay] <stage.lua> <bot1.lua> [<bot2.lua> ...]
  OR
  berrybots -packstage <stage.lua> <version>
  OR
  berrybots -packbot <bot.lua> <version>
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox