Freeciv
Advertisement

Introduction[]

This page covers building Freeciv from source on Mac OS X.

As an easier option, you may instead want to investigate using a package manager as described at Install-MacOSX.

As of May 2021, this page has many revisions of instructions from many different years, different versions of Freeciv, and different versions of macOS. It needs to be cleaned up. Until then, sorry for the confusion.

The contents are taken, in part, from here.

This page assumes familiarity with development tools like make [gcc.gnu.org/ gcc] and git.

The good news is that Freeciv compiles on Mac OS X without only a little source code modification. All modifications (as of May 2021) are being tracked by bug tickets, and are being fixed.

This was written with:

  • Freeciv
    • 2.1.3
    • 2.1.10 (installs via macports as freeciv-x11)
    • 2.2.0-beta2 (gtk2 client, compiles from source tarball without modifications using macports for prerequisites)
    • 2.6.4 and branch S2_6 (May 2021)
  • Mac OS X
    • 10.4.11
    • 10.5.8
    • 10.8 (Mountain Lion) - You must install XQuartz; Mountain Lion no longer includes X11 - see HT201341
    • 10.13.5 (High Sierra) - see gettext workaround below

Updated Apr 2021 - I built Freeciv 2.6.4 OK on MacOS 10.12 and 11.2.

(please add on if these instructions have worked)

Possible Clients[]

Freeciv supports several clients on Mac OS X:

  • freeciv-gtk3.22 as of FreeCiv version 2.6.0, requires gtk3 and adwaita-icon-theme packages.
  • freeciv-gtk3 requires gtk3 and adwaita-icon-theme packages.
  • freeciv-gtk2 requires gtk+ package.
    • gtk2 +x11 (ported from linux)
    • gtk2 +quartz (under development)
  • freeciv-qt requires qt5 package. freeciv 3.x may work with qt6.
  • freeciv-sdl2
  • freeciv-xaw (does not require supporting libraries -- ie. port or fink) (deprecated)

the x11 / quartz choice is purely a Mac issue, and does not seem to be covered elsewhere.

Before You Start[]

There are several tools that are useful in this process, and will make our job *much* easier. These are:

  • Git revision control system. Similar to Subversion or cvs.
  • MacPorts package system manager for many open source packages
  • Homebrew package system. Similar to MacPorts.
  • Fink package system. Similar to MacPorts.

Note - you need only one of the package system managers. Which package manager should you choose? Homebrew requires MacOS 10.14 or later, and gets you the gtk3 and adwaita-icon-theme packages. Fink gets you the gtk+ package. MacPorts gets you the gtk+ package.

Although the source code does not need modification, it takes a good bit of work to lay the foundation so that you can compile Freeciv on top of it. Thankfully heavy lifting can be done for you by a package manager like port or fink, mentioned above.

Prepare Mac OS X[]

Installing MacPorts[]

  • Head over to MacPorts, follow the installation instructions to install MacPorts.
  • Install freeciv
    % sudo port install freeciv-x11
    
    Or try:
    
    % sudo port install freeciv
    
    freeciv-x11 gets you the gtk2 package, and the gtk2 client. If you want to build the gtk3 or gtk3.22 client you will need the gtk3 and adwaita-icon-theme packages.
    sudo port install gtk3
    sudo port install adwaita-icon-theme
    
    The default install paths for macports is /opt/local/*. Because these aren't always included in the default paths, you may need to add them to the normal compiler search paths:
   % export CC="gcc -I/opt/local/include/ -L/opt/local/lib/"
  • You will notice this problem if libraries fail to link while compiling.
  • Note: as of about 2007, Apple uses clang instead of gcc, so:
    % export CC="clang -I/opt/local/include/ -L/opt/local/lib/"
  • Note: At least with MacOSX 10.5.8, only macports is needed. To ease fulfilling the requirements, the package for freeciv-x11 (pointing to 2.1.10 as of current) can be installed and disabled before building freeciv 2.2.0-beta2. This way, all required libraries are installed automagically.


Installing Homebrew[]

Installation of Homebrew is well documented on the Homebrew website

Using Homebrew to install freeciv should result in the needed packages also getting installed, and you should be able to go on to the Configure and Setup steps.

% brew install freeciv

This gets you the gtk3 and adwaita-icon-theme packages. If you want to build the gtk2 client you need to install the gtk+ package

% brew install gtk+


Similarly to MacPorts, the default install path is /usr/local/opt so you may need to do a similar trick as above, passing compiler or linker flags, and/or updating the PATH env variable itself. Luckily, the Homebrew package manager will advise you when this is necessary.

Starting with freeciv 3.0.0, there is a new requirement for the libicu-devel package and icu-uc. If running configure gives an error about this, try

% export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"

At of 2017 three libraries seem to be particularly troublesome since Apple includes old or incomplete versions of these libraries in the base OS (Sierra and High Sierra): gettext, libtool, and icu4c.

gettext - there is a clash with the MacOSX version of the gettext tools. Use

   % brew link gettext --force

to force the system to use the homebrew version before running autoconf.sh. You can use

   % brew unlink gettext

to undo this if necessary.

Libtool - Homebrew renames the binaries as 'glibtool' and 'glibtoolize' to avoid conflict which the Freeciv bootstrapping script struggles to detect. See HRM#714899 for more information.

icu4c - Homebrew does not install the metadata used by configure by default. Fix this by asking Homebrew to rebuild icu4c from source, then adding the metadata using pkg-config:

   % brew reinstall --build-from-source icu4c
   % pkg-config icu4c

Installing Fink[]

Instructions to install Fink can be found here.

Install freeciv

% fink install freeciv

This gets you the gtk2 client. Fink does not have a gtk3 package avail, so no gtk3 client is possible.


SDL[]

As of 2.2.0, the SDL client is not as plush as the GTK client. For instance, the SDL interface does not recognize a scroll wheel on a mouse. GTK not only does, it also recognizes trackpad gestures.

SDL Client with MacPorts[]

I've been able to build the SDL client using the libs provided by MacPorts. Changing the "--cflags)" section of /opt/local/bin/sdl-config to

-I${prefix}/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE \
-I${prefix}/include/ -Dmain=SDL_main


Configure and Setup[]

(1) Get Source[]

Clone the Freeciv source code repository using git, into a build directory.

  • There is a stale Freeciv 2.0.4 snapshot source tarball from here

The build directory holds the source code and the results of building.

(2) Identify dependency locations, install prefix, and set environment[]

It's a good idea to read the INSTALL file located in the top-level directory of the source code tree. It contains information on dependencies and other useful information.

When Freeciv builds, it looks for many related libraries. You need to supply paths so that the build tools can find those libraries. If you install dependencies via a package manager like MacPorts, Homebrew, or Fink, then the locations where they install software are the dependency locations. For example, MacPort typically installs libraries into /opt/local/lib , and executable code into /opt/local/bin .

The Freeciv build tools can install Freeciv into the directory you specify. The root of this directory tree is the prefix. It should usually be different than the build directory, and different from the dependency location used by MacPorts or the like. For instance, you can use a prefix of $HOME/opt/freeciv-dev .

Set environment variable CC to the path for your C language compiler. It is fine to use the clang/LLVM compiler supplied by XCode. MacPorts uses this value for CC:

% export CC="/usr/bin/clang"

Set environment variable PATH to the list of directories where the build tools look for executable programs. For instance, when using MacPorts the path should be:

% export PATH=/opt/local/bin:${PATH}

When building the freeciv-qt client using MacPorts and the Qt5 tools it provided, the path must also include the location of the Qt5 executable tools:

% export PATH=/opt/local/bin:/opt/local/libexec/qt5/bin/:${PATH}

Set environment variable LDFLAGS to the compiler flags which direct the compiler to directories of libraries it may need to include. For instance, using MacPorts the path should be:

% export LDFLAGS=-L/opt/local/lib

When building the freeciv-qt client using MacPorts and the Qt5 tools it provided, the path must also include the location of the Qt5 libraries:

% export LDFLAGS='-L/opt/local/libexec/qt5/lib -L/opt/local/lib'


(3) autogen.sh[]

This step applies only if you're building from a development version of the source (git) (Option B).

  • Note: This will also run configure. If you know what you're doing, you can pass the 'configure' arguments directly to autogen.sh, and you may then skip step (3) below.

(4) configure[]

  • Set up your environment:
% env CC="gcc -no-cpp-precomp" CFLAGS="-O3"
Note: As of High Sierra, these parameters don't seem to be necessary anymore.
  • To build the gtk3.22 client, execute this configure command from the command line, at the top-level directory of the source archive:
% ./configure \
        --enable-client=gtk3.22 \
        --with-x-funcproto='FUNCPROTO=15 NARROWPROTO'

Note: This was tested on High Sierra. On older systems with different X11 configurations the --with-x-funcproto clause may need modifications. Try omitting this clause and allowing configure to figure it out automatically - but on High Sierra the detection hangs without this clause.

  • To build the gtk2 client, execute this configure command from the command line, at the top-level directory of the source archive:
% ./configure \
       --enable-client=gtk2 \
       --prefix=/Users/your_user_name/your_chosen_directory
  • On Leopard add:
--with-readline=builtin --with-libiconv-prefix=${prefix}/include
  • As of version 2.1.13 there is a bug which requires building without readline (this bug does not seem to be present in 2.2.0-beta1 onwards):
% --without-readline
  • If ngettext isn't found, you will be prompted to add "--disable-nls".
  • You can also build for multiple clients by specifying a comma-separated list of client codes, e.g.
    --enable-client=gtk2,gtk3 \
    
    --enable-client=all \

As of May 2021, the following configure options were successful. They are based on the options used by the MacPorts freeciv port. Tested on branches S2_6, S3_0, S3_1, and master using macOS 10.13.6 High Sierra, and MacPorts.

--disable-silent-rules --enable-fcdb=sqlite3 --with-readline --enable-sdl-mixer --enable-fcmp=all --enable-client=all 

(4b) Troubleshooting configure[]

When the configuration fails partway through, it might be because the configure options require a feature (e.g. --with-readline), but the configure tool cannot find those libraries. One way to resolve this is to remove the option which requires the feature. The other way is to be sure that the configure tool can find the feature, e.g. by including the dependency location in the LDFLAGS environment variable.

The command ./configure --help will print out information on all the options which the configure tool accepts. Setting these may help you resolve configuration problems.

When the configure tool finishes, it prints out a list of clients, indicating "yes" for those which it was able to prepare for compiling. If the client you want is listed as "no", then the text printed out by the configure tool may have a hint of what was the obstacle. For instance, you may need to put another dependency location in the LDFLAGS or PATH environment variable.

Compile[]

5) Run Make[]

  • Compile the source by executing this command:
   % make

(5b) Troubleshooting[]

Potential Errors During Compiling[]

Compiling Freeciv using the before specified commands may yield the following error:

   stdinhand.c: In function 'freeciv_completion':
   stdinhand.c:4509: error: 'rl_attempted_completion_over' undeclared (first use in this function)
   stdinhand.c:4509: error: (Each undeclared identifier is reported only once
   stdinhand.c:4509: error: for each function it appears in.)
   make[3]: *** [stdinhand.o] Error 1
   make[2]: *** [all-recursive] Error 1
   make[1]: *** [all-recursive] Error 1
   make: *** [all] Error 2

A workaround for this problem was mentioned on the old Freeciv-Dev Mailing list:

   You can probably work around it by running ./configure --without-readline.
   However it would be nice to fix it if you'll help us track down the problem.

This applies to users of Mac OS X 10.4 (Tiger).

If you receive a link error like the following:

 Undefined symbols:
   "_iconv_close", referenced from:
       _convert_string in libfreeciv.a(fciconv.o)
       _convert_string in libfreeciv.a(fciconv.o)
   "_iconv_open", referenced from:
       _convert_string in libfreeciv.a(fciconv.o)
   "_iconv", referenced from:
       _convert_string in libfreeciv.a(fciconv.o)
       _convert_string in libfreeciv.a(fciconv.o)
   "_locale_charset", referenced from:
       _init_character_encodings in libfreeciv.a(fciconv.o)
 ld: symbol(s) not found
 collect2: ld returned 1 exit status
 make[3]: *** [freeciv-gtk2] Error 1
 make[2]: *** [all-recursive] Error 1
 make[1]: *** [all-recursive] Error 1
 make: *** [all] Error 2

It means you are probably linking against iconv version 1.13; you need to install the latest libiconv. You can find instructions here. Untar to a directory and change to it:

 % ./configure --prefix=/opt/local
 % make
 % sudo make install

Which will install it with the MacBuilds directory or replace /opt/local with /sw for Fink.

Now, you need to reconfigure and rebuild freeciv; switch to your freeciv source directory and type:

 % make clean
 % ./configure --enable-client=gtk2 --prefix=/opt/local --disable-nls --with-libiconv-prefix=/opt/local
 % make

Install[]

(6) Test[]

If you've gotten this far, test your shiny new program. This command will run a client of Freeciv's choosing:

 % ./fcgui

The fcgui tool lets you specify which client to run. This runs the Qt client:

 % ./fcgui --gui qt

(7) Install and Enjoy[]

Assuming everything works properly, execute this command to install it in directory you specified as the prefix:

 % make install
  • Now, you should be able to find some executables in the /prefix/bin directory:
freeciv-gtk2 [or freeciv-sdl or freeciv-gtk3 or freeciv-gtk3.22]
freeciv-server
freeciv-manual

You might have success in launching the client by simply double-clicking on the client executable from within the Finder, however this will typically pop up a terminal similar to a DOS window on a PC. In order to create a true clickable icon for the finder, you need to use AppleScript. You can find the Script Editor in the Utilities subfolder of the Applications folder. Open that and and enter:

do shell script "/opt/local/bin/freeciv-gtk2"

Or /sw instead of /opt/local depending on whether you installed via Fink; or your home directory path to the executable as the case may be. Save this to your applications folder and select "Application" for the file format and check "Run Only". Click save.

Freeciv-client

FreeCiv logo, suitable for use as Macintosh Icon

It is possible with this, the server may not be able to start. This is because even if you set the path in your .profile, the shell script is not run as a login shell and thus the .profile will not be executed so the folder where the server is located may not be in the PATH variable. There is a UNIX trick to force the PATH to include more elements. For instance, if you installed freeciv in /opt/local, you can change your script to read:

do shell script "PATH=/opt/local/bin:$PATH /opt/local/bin/freeciv-gtk2"

If you have an icon you want to use such as the one to the left, option-click and Copy Image it into the paste buffer and edit the properties through the Get Info option click on the resulting script in the finder. In the Info window, select the default icon and then press Command-V to paste in your icon.

  • Enjoy!

Optional Support[]

Sound Support[]

You need to install the following for SDL sound support:

When running Freeciv's configure script, be sure to use the following option:

--with-sdl-prefix=/opt/local

Furthermore, you need to define your CC environment variable to be the following:

gcc= " -no-cpp-precomp -I/opt/local/include -L/opt/local/lib"

After you have built the binaries, copy the .soundspec file, and the accompanying folder containing the actual sound files from the sound set archive into your path_to_freeciv/share/freeciv directory.

Localization Support[]

You need to have a functioning installation of the gettext package to be able to run Freeciv with a language other than English.

When running Freeciv's configure script, be sure to use the following option:

   --enable-nls

Furthermore, you need to define your CC environment variable to be the following (to where MacPorts install packages):

   gcc = "-no-cpp-precomp -I/opt/local/include -L/opt/local/lib"

You may start either the server or client or both in the locale of your choice by giving a full LANG prefix when executing them. E.G. the client in Swedish locale:

  LANG="sv_SE.UTF-8 freeciv-gtk2"

Note that by giving a full locale string as the example above, you avoid potential encoding conversion warnings and glitches.

Advertisement