2011-07-30 21:50:37 -06:00
###############
Building DFHACK
###############
2010-07-19 21:27:12 -06:00
.. contents ::
2011-07-30 21:50:37 -06:00
2015-07-24 08:49:17 -06:00
===================
2012-02-24 12:25:53 -07:00
How to get the code
===================
DFHack doesn't have any kind of system of code snapshots in place, so you will have to get code from the github repository using git.
2015-07-24 08:49:17 -06:00
The code resides here: https://github.com/DFHack/dfhack
On Linux and OS X, having a 'git' package installed is the minimal requirement (see below for OS X instructions),
but some sort of git gui or git integration for your favorite text editor/IDE will certainly help.
On Windows, you will need some sort of Windows port of git, or a GUI. Some examples:
* http://msysgit.github.io/ - this is a command line version of git for windows. Most tutorials on git usage will apply.
* http://code.google.com/p/tortoisegit/ - this puts a pretty, graphical face on top of msysgit
2012-02-24 12:25:53 -07:00
2014-08-06 12:55:22 -06:00
The code resides here: https://github.com/DFHack/dfhack
2012-02-24 12:25:53 -07:00
2015-07-24 08:49:17 -06:00
To get the code::
git clone --recursive https://github.com/DFHack/dfhack
cd dfhack
If your version of git does not support the `` --recursive `` flag, you will need to omit it and run
`` git submodule update --init `` after entering the dfhack directory.
If you just want to compile DFHack or work on it by contributing patches, it's quite enough to clone from the read-only address instead::
2015-03-04 15:33:12 -07:00
2015-07-24 08:49:17 -06:00
git clone --recursive git://github.com/DFHack/dfhack.git
2012-02-24 12:25:53 -07:00
cd dfhack
2015-07-24 08:49:17 -06:00
The tortoisegit GUI should have the equivalent options included.
If you want to get really involved with the development, create an account on Github, make a clone there and then use that as your remote repository instead. Detailed instructions are beyond the scope of this document. If you need help, join us on IRC (#dfhack channel on freenode).
=====
Linux
=====
On Linux, DFHack acts as a library that shadows parts of the SDL API using LD_PRELOAD.
2012-02-24 12:25:53 -07:00
2010-07-19 21:27:12 -06:00
Dependencies
============
2011-07-30 21:50:37 -06:00
DFHack is meant to be installed into an existing DF folder, so get one ready.
2010-07-19 21:27:12 -06:00
2011-07-30 21:50:37 -06:00
For building, you need a 32-bit version of GCC. For example, to build DFHack on
a 64-bit distribution like Arch, you'll need the multilib development tools and libraries.
2014-08-15 22:18:33 -06:00
Alternatively, you might be able to use `` lxc `` to
`create a virtual 32-bit environment <http://www.bay12forums.com/smf/index.php?topic=139553.msg5435310#msg5435310> `_ .
2011-07-30 21:50:37 -06:00
Before you can build anything, you'll also need `` cmake `` . It is advisable to also get
`` ccmake `` on distributions that split the cmake package into multiple parts.
2015-02-05 19:24:19 -07:00
You also need perl and the XML::LibXML and XML::LibXSLT perl packages (for the code generation parts).
You should be able to find them in your distro repositories (on Arch linux 'perl-xml-libxml' and 'perl-xml-libxslt') or through `` cpan `` .
2011-12-24 06:44:14 -07:00
2014-08-15 22:18:33 -06:00
To build Stonesense, you'll also need OpenGL headers.
2015-08-10 08:12:40 -06:00
Some additional dependencies for other distros are listed on the `wiki <https://github.com/DFHack/dfhack/wiki/Linux-dependencies> `_ .
2011-07-30 21:50:37 -06:00
Build
=====
2015-07-24 08:49:17 -06:00
Building is fairly straightforward. Enter the `` build `` folder (or create an empty folder in the DFHack directory to use instead) and start the build like this::
2015-03-04 15:33:12 -07:00
2010-07-19 21:27:12 -06:00
cd build
2011-07-30 21:50:37 -06:00
cmake .. -DCMAKE_BUILD_TYPE:string=Release -DCMAKE_INSTALL_PREFIX=/home/user/DF
make install
2011-03-13 12:38:32 -06:00
2011-07-30 21:50:37 -06:00
Obviously, replace the install path with path to your DF. This will build the library
along with the normal set of plugins and install them into your DF folder.
2011-03-13 12:38:32 -06:00
2011-07-30 21:50:37 -06:00
Alternatively, you can use ccmake instead of cmake::
2015-03-04 15:33:12 -07:00
2011-03-13 12:38:32 -06:00
cd build
ccmake ..
2011-07-30 21:50:37 -06:00
make install
2011-03-13 12:38:32 -06:00
This will show a curses-based interface that lets you set all of the
extra options.
2011-03-17 23:07:13 -06:00
You can also use a cmake-friendly IDE like KDevelop 4 or the cmake-gui
2010-07-19 21:27:12 -06:00
program.
2013-04-03 14:28:11 -06:00
Fixing the libstdc++ version bug
================================
When compiling dfhack yourself, it builds against your system libc.
When Dwarf Fortress runs, it uses a libstdc++ shipped with the binary, which
2015-07-24 08:49:17 -06:00
comes from GCC 4.5 and is incompatible with code compiled with newer GCC versions.
This manifests itself with the error message::
2013-04-03 14:28:11 -06:00
./libs/Dwarf_Fortress: /pathToDF/libs/libstdc++.so.6: version
`GLIBCXX_3.4.15' not found (required by ./hack/libdfhack.so)
To fix this, simply remove the libstdc++ shipped with DF, it will fall back
to your system lib and everything will work fine::
cd /path/to/DF/
rm libs/libstdc++.so.6
2015-07-24 08:49:17 -06:00
Alternatively, this issue can be avoided by compiling DFHack with GCC 4.5.
2012-10-16 13:58:34 -06:00
========
Mac OS X
========
2015-07-24 08:49:17 -06:00
DFHack functions similarly on OS X and Linux, and the majority of the
information above regarding the build process (cmake and make) applies here
as well.
* If you are building on 10.6, please read the subsection below titled "Snow Leopard Changes" FIRST.
* If you are building on 10.10+, read the "Yosemite Changes" subsection before building.
2013-03-14 12:42:15 -06:00
2012-10-16 13:58:34 -06:00
1. Download and unpack a copy of the latest DF
2. Install Xcode from Mac App Store
3. Open Xcode, go to Preferences > Downloads, and install the Command Line Tools.
2014-02-18 17:23:09 -07:00
4. Install dependencies
2012-10-20 07:06:33 -06:00
2015-07-24 08:49:17 -06:00
Option 1: Using Homebrew:
* `Install Homebrew <http://brew.sh/> `_ and run:
* `` brew tap homebrew/versions ``
* `` brew install git ``
* `` brew install cmake ``
* `` brew install gcc45 ``
Option 2: Using MacPorts:
2015-03-04 15:33:12 -07:00
2014-02-18 17:23:09 -07:00
* `Install MacPorts <http://www.macports.org/> `_
* Run `` sudo port install gcc45 +universal cmake +universal git-core +universal ``
2014-04-12 07:21:10 -06:00
This will take some time—maybe hours, depending on your machine.
2015-03-04 15:33:12 -07:00
2014-02-18 17:23:09 -07:00
At some point during this process, it may ask you to install a Java environment; let it do so.
2012-10-20 07:06:33 -06:00
2014-02-18 17:23:09 -07:00
5. Install perl dependencies
2012-10-20 07:06:33 -06:00
1. `` sudo cpan ``
If this is the first time you've run cpan, you will need to go through the setup
process. Just stick with the defaults for everything and you'll be fine.
2. `` install XML::LibXML ``
3. `` install XML::LibXSLT ``
2014-02-18 17:23:09 -07:00
6. Get the dfhack source::
2012-10-20 07:06:33 -06:00
2015-07-24 08:49:17 -06:00
git clone --recursive https://github.com/DFHack/dfhack.git
2012-10-20 07:06:33 -06:00
cd dfhack
2014-02-24 15:46:08 -07:00
7. Set environment variables:
2015-07-24 08:49:17 -06:00
Homebrew (if installed elsewhere, replace /usr/local with `` $(brew --prefix) `` )::
export CC=/usr/local/bin/gcc-4.5
export CXX=/usr/local/bin/g++-4.5
2014-02-24 15:46:08 -07:00
Macports::
2012-10-20 07:06:33 -06:00
export CC=/opt/local/bin/gcc-mp-4.5
export CXX=/opt/local/bin/g++-mp-4.5
2014-02-24 15:46:08 -07:00
2012-10-20 07:06:33 -06:00
8. Build dfhack::
mkdir build-osx
cd build-osx
cmake .. -DCMAKE_BUILD_TYPE:string=Release -DCMAKE_INSTALL_PREFIX=/path/to/DF/directory
make
make install
2012-10-16 13:58:34 -06:00
2013-03-14 12:42:15 -06:00
Snow Leopard Changes
====================
1. Add a step 6.2a (before Install XML::LibXSLT)::
2015-03-04 15:33:12 -07:00
In a separate Terminal window or tab, run:
`` sudo ln -s /usr/include/libxml2/libxml /usr/include/libxml ``
2013-03-14 12:42:15 -06:00
2. Add a step 7a (before building)::
2015-03-04 15:33:12 -07:00
In <dfhack directory>/library/LuaTypes.cpp, change line 467 to
`` int len = strlen((char*)ptr); ``
2013-03-14 12:42:15 -06:00
2015-02-23 20:56:44 -07:00
Yosemite Changes
2015-02-03 22:47:47 -07:00
================
2015-02-23 20:56:44 -07:00
If you have issues building on OS X Yosemite (or above), try definining the following environment variable:
2015-02-03 22:47:47 -07:00
export MACOSX_DEPLOYMENT_TARGET=10.9
2012-02-24 12:25:53 -07:00
=======
Windows
=======
2012-02-24 12:28:17 -07:00
On Windows, DFHack replaces the SDL library distributed with DF.
2012-02-24 12:25:53 -07:00
Dependencies
============
2011-07-30 21:50:37 -06:00
First, you need `` cmake `` . Get the win32 installer version from the official
2010-07-19 21:27:12 -06:00
site: http://www.cmake.org/cmake/resources/software.html
2011-07-30 21:50:37 -06:00
It has the usual installer wizard. Make sure you let it add its binary folder
to your binary search PATH so the tool can be later run from anywhere.
2010-07-19 21:27:12 -06:00
2011-12-24 06:44:14 -07:00
You'll need a copy of Microsoft Visual C++ 2010. The Express version is sufficient.
2011-07-30 21:50:37 -06:00
Grab it from Microsoft's site.
2010-07-19 21:27:12 -06:00
2013-12-24 06:08:39 -07:00
You'll also need the Visual Studio 2010 SP1 update.
2014-08-06 12:55:22 -06:00
For the code generation parts, you'll need perl with XML::LibXML and XML::LibXSLT. Strawberry Perl works nicely for this: http://strawberryperl.com/
2011-12-24 06:44:14 -07:00
2012-02-04 20:28:20 -07:00
If you already have a different version of perl (for example the one from cygwin), you can run into some trouble. Either remove the other perl install from PATH, or install libxml and libxslt for it instead. Strawberry perl works though and has all the required packages.
2011-07-30 21:50:37 -06:00
Build
=====
2012-02-04 20:28:20 -07:00
There are several different batch files in the `` build `` folder along with a script that's used for picking the DF path.
First, run set_df_path.vbs and point the dialog that pops up at your DF folder that you want to use for development.
Next, run one of the scripts with `` generate `` prefix. These create the MSVC solution file(s):
* `` all `` will create a solution with everything enabled (and the kitchen sink).
* `` gui `` will pop up the cmake gui and let you pick and choose what to build. This is probably what you want most of the time. Set the options you are interested in, then hit configure, then generate. More options can appear after the configure step.
* `` minimal `` will create a minimal solution with just the bare necessities - the main library and standard plugins.
2010-07-19 21:27:12 -06:00
2012-02-04 20:28:20 -07:00
Then you can either open the solution with MSVC or use one of the msbuild scripts:
2010-07-19 21:27:12 -06:00
2012-02-04 20:28:20 -07:00
* Scripts with `` build `` prefix will only build.
* Scripts with `` install `` prefix will build DFHack and install it to the previously selected DF path.
* Scripts with `` package `` prefix will build and create a .zip package of DFHack.
When you open the solution in MSVC, make sure you never use the Debug builds. Those aren't
2011-07-30 21:50:37 -06:00
binary-compatible with DF. If you try to use a debug build with DF, you'll only get crashes.
So pick either Release or RelWithDebInfo build and build the INSTALL target.
2010-07-19 21:27:12 -06:00
2012-02-04 20:28:20 -07:00
The `` debug `` scripts actually do RelWithDebInfo builds.
2010-07-19 21:27:12 -06:00
2011-07-30 21:50:37 -06:00
===========
2010-07-19 21:27:12 -06:00
Build types
===========
`` cmake `` allows you to pick a build type by changing this
variable: `` CMAKE_BUILD_TYPE ``
::
2015-03-04 15:33:12 -07:00
2010-07-19 21:27:12 -06:00
cmake .. -DCMAKE_BUILD_TYPE:string=BUILD_TYPE
Without specifying a build type or 'None', cmake uses the
`` CMAKE_CXX_FLAGS `` variable for building.
2011-07-30 21:50:37 -06:00
Valid and useful build types include 'Release', 'Debug' and
'RelWithDebInfo'. 'Debug' is not available on Windows.
2011-03-13 12:38:32 -06:00
================================
Using the library as a developer
================================
2012-06-22 10:41:15 -06:00
Currently, the most direct way to use the library is to write a plugin that can be loaded by it.
2011-07-30 21:50:37 -06:00
All the plugins can be found in the 'plugins' folder. There's no in-depth documentation
on how to write one yet, but it should be easy enough to copy one and just follow the pattern.
2012-06-22 10:41:15 -06:00
Other than through plugins, it is possible to use DFHack via remote access interface, or by writing Lua scripts.
2011-07-30 21:50:37 -06:00
The most important parts of DFHack are the Core, Console, Modules and Plugins.
2011-03-13 12:38:32 -06:00
2011-07-30 21:50:37 -06:00
* Core acts as the centerpiece of DFHack - it acts as a filter between DF and SDL and synchronizes the various plugins with DF.
* Console is a thread-safe console that can be used to invoke commands exported by Plugins.
2015-07-24 08:49:17 -06:00
* Modules actually describe the way to access information in DF's memory. You can get them from the Core. Most modules are split into two parts: high-level and low-level. High-level is mostly method calls, low-level publicly visible pointers to DF's data structures.
2011-07-30 21:50:37 -06:00
* Plugins are the tools that use all the other stuff to make things happen. A plugin can have a list of commands that it exports and an onupdate function that will be called each DF game tick.
Rudimentary API documentation can be built using doxygen (see build options with `` ccmake `` or `` cmake-gui `` ).
DFHack consists of variously licensed code, but invariably weak copyleft.
The main license is zlib/libpng, some bits are MIT licensed, and some are BSD licensed.
Feel free to add your own extensions and plugins. Contributing back to
the dfhack repository is welcome and the right thing to do :)
2011-03-13 12:38:32 -06:00
2012-06-22 10:41:15 -06:00
DF data structure definitions
=============================
DFHack uses information about the game data structures, represented via xml files in the library/xml/ submodule.
2015-07-24 08:49:17 -06:00
Data structure layouts are described in files following the df.\*.xml name pattern. This information is transformed by a perl script into C++ headers describing the structures, and associated metadata for the Lua wrapper. These headers and data are then compiled into the DFHack libraries, thus necessitating a compatibility break every time layouts change; in return it significantly boosts the efficiency and capabilities of DFHack code.
2012-06-22 10:41:15 -06:00
Global object addresses are stored in symbols.xml, which is copied to the dfhack release package and loaded as data at runtime.
Remote access interface
=======================
DFHack supports remote access by exchanging Google protobuf messages via a TCP socket. Both the core and plugins can define remotely accessible methods. The `` dfhack-run `` command uses this interface to invoke ordinary console commands.
Currently the supported set of requests is limited, because the developers don't know what exactly is most useful.
Protocol client implementations exist for Java and C#.
2015-01-22 21:05:46 -07:00