Difference between revisions of "Compiling with MinGW (OpenXcom)"
(→Set up yaml-cpp: Proofread) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
=== Install the cross-compiler === | === Install the cross-compiler === | ||
− | + | <code>apt-get install g++-mingw-w64-i686</code> | |
This is the compiler targeting Win32/x86. If you want to build a 64-bit binary, you're on your own for libraries. | This is the compiler targeting Win32/x86. If you want to build a 64-bit binary, you're on your own for libraries. | ||
Line 9: | Line 9: | ||
=== Grab the source === | === Grab the source === | ||
− | e.g., | + | e.g., <code>git clone https://github.com/SupSuper/OpenXcom.git</code> |
− | Don't have git installed? Install it with | + | Don't have git installed? Install it with <code>apt-get install git</code>. |
=== Download the prerequisite libraries === | === Download the prerequisite libraries === | ||
Line 17: | Line 17: | ||
Building all the prerequisites from source is a good way to waste a day of your life. Some of them are availalbe in the stock package repositries, such as libsdl and libogg, but the majority are not. I recommend downloading [http://bumba.net/~hmaon/oxc/OXC-mingw32-cross-tools.tar.xz the tarball of static libraries I've compiled]. | Building all the prerequisites from source is a good way to waste a day of your life. Some of them are availalbe in the stock package repositries, such as libsdl and libogg, but the majority are not. I recommend downloading [http://bumba.net/~hmaon/oxc/OXC-mingw32-cross-tools.tar.xz the tarball of static libraries I've compiled]. | ||
− | Supposing that you've downloaded the file to ~/Downloads, install the contents with the following commands: | + | Supposing that you've downloaded the file to ~/Downloads, install the contents with the following commands: <code>cd / ; tar xvJf ~/Downloads/OXC-mingw32-cross-tools.tar.xz</code>. This will place a bunch of files in <code>/usr/local/cross-tools/i386-mingw32</code>. |
This fileset includes a 64-bit pkg-config binary. If you need a 32-bit one, build it with the following steps: | This fileset includes a 64-bit pkg-config binary. If you need a 32-bit one, build it with the following steps: | ||
Line 28: | Line 28: | ||
=== Get the Makefile and make === | === Get the Makefile and make === | ||
− | [http://bumba.net/~hmaon/oxc/Makefile.mingw-hmaon Download my Makefile.] It's based on Makefile.simple and Michal's gitbuilder file. Place the file in OpenXcom/src and | + | [http://bumba.net/~hmaon/oxc/Makefile.mingw-hmaon Download my Makefile.] It's based on Makefile.simple and Michal's gitbuilder file. Place the file in OpenXcom/src and <code>make</code>! |
− | Note: -lws2_32 is only needed for ntohl(), used by the FLAC library iirc. | + | Note: <code>-lws2_32</code> is only needed for <code>ntohl()</code>, used by the FLAC library iirc. |
== Compiling 32bits on Windows == | == Compiling 32bits on Windows == | ||
Line 43: | Line 43: | ||
=== Set up your project directory with SDL === | === Set up your project directory with SDL === | ||
− | Choose your project directory. Let's call it <project>. | + | Choose your project directory. Let's call it <code><project></code>. |
On [http://www.libsdl.org/index.php SDL website] download SDL 1.2 win32 development library for Mingw32. | On [http://www.libsdl.org/index.php SDL website] download SDL 1.2 win32 development library for Mingw32. | ||
− | Extract it in <project> keeping directory hierarchy, you should get it in a directory such as <project>\SDL-1.2.15. | + | Extract it in <code><project></code> keeping directory hierarchy, you should get it in a directory such as <code><project>\SDL-1.2.15</code>. |
− | On [http://www.libsdl.org/projects/SDL_mixer/ SDL_mixer website] download SDL_mixer 1.2 source and SDL_mixer 1.2 Win32 32bits binaries. Extract the source in <project>, you should get it in a directory such as <project>\SDL_mixer-1.2.12. Create a <project>\SDL_mixer-1.2.12\bin directory and extract the binaries here. | + | On [http://www.libsdl.org/projects/SDL_mixer/ SDL_mixer website] download SDL_mixer 1.2 source and SDL_mixer 1.2 Win32 32bits binaries. Extract the source in <code><project></code>, you should get it in a directory such as <code><project>\SDL_mixer-1.2.12</code>. Create a <code><project>\SDL_mixer-1.2.12\bin</code> directory and extract the binaries here. |
− | On [http://www.libsdl.org/projects/SDL_image/ SDL_image website] download SDL_image 1.2 source and SDL_image 1.2 Win32 32bits binaries. Extract the source in <project>, you should get it in a directory such as <project>\SDL_image-1.2.12. Create a <project>\SDL_image-1.2.12\bin directory and extract the binaries here. | + | On [http://www.libsdl.org/projects/SDL_image/ SDL_image website] download SDL_image 1.2 source and SDL_image 1.2 Win32 32bits binaries. Extract the source in <code><project></code>, you should get it in a directory such as <code><project>\SDL_image-1.2.12</code>. Create a <code><project>\SDL_image-1.2.12\bin</code> directory and extract the binaries here. |
=== Set up SDL_gfx === | === Set up SDL_gfx === | ||
− | On [http://www.ferzkopp.net/joomla/content/view/19/14/ SDL_gfx website] download last SDL_gfx source and extract it in <project>. You should get it in a directory such as <project>\SDL_gfx-2.0.24. Go to Other builds subdirectory and extract Makefile from mingw32.zip in the <project>\SDL_gfx-2.0.24 directory. Edit the Makefile to modify it to have: | + | On [http://www.ferzkopp.net/joomla/content/view/19/14/ SDL_gfx website] download last SDL_gfx source and extract it in <code><project></code>. You should get it in a directory such as <code><project>\SDL_gfx-2.0.24</code>. Go to Other builds subdirectory and extract Makefile from mingw32.zip in the <code><project>\SDL_gfx-2.0.24</code> directory. Edit the Makefile to modify it to have: |
CFLAGS = -O3 -march=athlon-xp -mmmx -msse -m3dnow -DBUILD_DLL -DWIN32 -I..\SDL-1.2.15\include\SDL | CFLAGS = -O3 -march=athlon-xp -mmmx -msse -m3dnow -DBUILD_DLL -DWIN32 -I..\SDL-1.2.15\include\SDL | ||
Line 61: | Line 61: | ||
OBJS = SDL_framerate.o SDL_gfxBlitFunc.o SDL_gfxPrimitives.o SDL_imageFilter.o SDL_rotozoom.o | OBJS = SDL_framerate.o SDL_gfxBlitFunc.o SDL_gfxPrimitives.o SDL_imageFilter.o SDL_rotozoom.o | ||
− | Then run in the <project>\SDL_gfx-2.0.24 directory: | + | Then run in the <code><project>\SDL_gfx-2.0.24</code> directory: |
mingw32-make SDL_gfx.dll | mingw32-make SDL_gfx.dll | ||
− | You should get a <project>\SDL_gfx-2.0.24\SDL_gfx.dll file. | + | You should get a <code><project>\SDL_gfx-2.0.24\SDL_gfx.dll</code> file. |
=== Set up yaml-cpp === | === Set up yaml-cpp === | ||
Line 72: | Line 72: | ||
From the [http://www.cmake.org/ CMake website] download the CMake Windows zip binaries distribution. | From the [http://www.cmake.org/ CMake website] download the CMake Windows zip binaries distribution. | ||
From the [http://www.boost.org/ boost website] download the current release. | From the [http://www.boost.org/ boost website] download the current release. | ||
− | Extract the three archives in <project>; you should get directories such as <project>\yaml-cpp-0.5.1, <project>\cmake-2.8.11.2-win32-x86 and <project>\boost_1_54_0 | + | Extract the three archives in <project>; you should get directories such as <code><project>\yaml-cpp-0.5.1</code>, <code><project>\cmake-2.8.11.2-win32-x86</code> and <code><project>\boost_1_54_0</code> |
− | Go to the <project>\yaml-cpp-0.5.1 directory and run the following commands: | + | Go to the <code><project>\yaml-cpp-0.5.1</code> directory and run the following commands: |
set Path=%Path%;<project>\cmake-2.8.11.2-win32-x86\bin | set Path=%Path%;<project>\cmake-2.8.11.2-win32-x86\bin | ||
Line 82: | Line 82: | ||
mingw32-make | mingw32-make | ||
− | This should build a static library <project>\yaml-cpp-0.5.1\build\libyaml-cpp.a. | + | This should build a static library <code><project>\yaml-cpp-0.5.1\build\libyaml-cpp.a</code>. |
There are problems [http://stackoverflow.com/questions/18390694/undefined-reference-linking-yaml-cpp-program-with-mingw-w64-cmake building a dynamix library] with the 0.5.1 version, but this could work with later versions. | There are problems [http://stackoverflow.com/questions/18390694/undefined-reference-linking-yaml-cpp-program-with-mingw-w64-cmake building a dynamix library] with the 0.5.1 version, but this could work with later versions. | ||
Line 89: | Line 89: | ||
=== Build and run OpenXcom === | === Build and run OpenXcom === | ||
− | Download the last available source and extract it in <project> directory, you should get a <project>\OpenXcom-master directory. | + | Download the last available source and extract it in <code><project></code> directory, you should get a <code><project>\OpenXcom-master</code> directory. |
− | Copy original game directories in <project>\OpenXcom-master\bin\data directory. | + | Copy original game directories in <code><project>\OpenXcom-master\bin\data</code> directory. |
− | Create a <project>\OpenXcom-master\makefile such as this one: | + | Create a <code><project>\OpenXcom-master\makefile</code> such as this one: |
PROG=OpenXCom | PROG=OpenXCom | ||
Line 143: | Line 143: | ||
Fill MINGW variable if you have several MinGW instances (such as a 32bits one and a 64bits one). | Fill MINGW variable if you have several MinGW instances (such as a 32bits one and a 64bits one). | ||
− | Consider adding | + | Consider adding <code>-g -D_DEBUG</code> to CXXFLAGS variable to generate debug information. |
AppDep utility can be downloaded [http://julien.darthenay.free.fr/progcmingw.php here]. | AppDep utility can be downloaded [http://julien.darthenay.free.fr/progcmingw.php here]. | ||
If you don't want to use it, just add a #Dependencies line at the end of your makefile, remove the AppDep call, and clear all lines after #Dependencies before using make depends. | If you don't want to use it, just add a #Dependencies line at the end of your makefile, remove the AppDep call, and clear all lines after #Dependencies before using make depends. | ||
− | Go to <project>\OpenXcom-master and run: | + | Go to <code><project>\OpenXcom-master</code> and run: |
mingw32-make depends | mingw32-make depends | ||
mingw32-make all | mingw32-make all | ||
− | The file <project>\OpenXcom-master\bin\OpenXcom.exe should be produced. | + | The file <code><project>\OpenXcom-master\bin\OpenXcom.exe</code> should be produced. |
− | If windres fails because of null characters, convert src\resource.h and src\OpenXcom.rc from UTF-16LE to ANSI. | + | If windres fails because of null characters, convert <code>src\resource.h</code> and <code>src\OpenXcom.rc</code> from UTF-16LE to ANSI. |
To run the game, use the following commands in the same directory: | To run the game, use the following commands in the same directory: | ||
Line 160: | Line 160: | ||
set Path=%Path;<project>\SDL-1.2.15\bin;<project>\SDL_mixer-1.2.12\bin;<project>\SDL_image-1.2.12\bin;<project>\SDL_gfx-2.0.24\bin | set Path=%Path;<project>\SDL-1.2.15\bin;<project>\SDL_mixer-1.2.12\bin;<project>\SDL_image-1.2.12\bin;<project>\SDL_gfx-2.0.24\bin | ||
bin\OpenXcom.exe -user <your name> | bin\OpenXcom.exe -user <your name> | ||
+ | |||
+ | == Compiling 32bits and 64bits on Windows == | ||
+ | You can see instructions on how to build with MinGW-w64 in [https://github.com/JDarthenay/OpenXcom/tree/MinGW-w64 this GitHub fork of OpenXcom]. (By the author of previous section). | ||
== MXE == | == MXE == | ||
Michal uses a different setup for his own builds and gitbuilder, based on [http://mxe.cc/ MXE]. I haven't tried MXE myself but supposedly its compiler rejects the -msse2 flag. On the other hand, it looks like it'll build all the libraries for you! | Michal uses a different setup for his own builds and gitbuilder, based on [http://mxe.cc/ MXE]. I haven't tried MXE myself but supposedly its compiler rejects the -msse2 flag. On the other hand, it looks like it'll build all the libraries for you! | ||
+ | |||
+ | == Compiling and cross-compiling OpenXcom Extended == | ||
+ | |||
+ | See [https://openxcom.org/forum/index.php/topic,7048.0.html Compiling and cross-compiling OXCE] | ||
[[Category:OpenXcom]] | [[Category:OpenXcom]] |
Latest revision as of 17:11, 27 March 2019
Compiling on Ubuntu 12.10 or 12.04LTS
Install the cross-compiler
apt-get install g++-mingw-w64-i686
This is the compiler targeting Win32/x86. If you want to build a 64-bit binary, you're on your own for libraries.
Grab the source
e.g., git clone https://github.com/SupSuper/OpenXcom.git
Don't have git installed? Install it with apt-get install git
.
Download the prerequisite libraries
Building all the prerequisites from source is a good way to waste a day of your life. Some of them are availalbe in the stock package repositries, such as libsdl and libogg, but the majority are not. I recommend downloading the tarball of static libraries I've compiled.
Supposing that you've downloaded the file to ~/Downloads, install the contents with the following commands: cd / ; tar xvJf ~/Downloads/OXC-mingw32-cross-tools.tar.xz
. This will place a bunch of files in /usr/local/cross-tools/i386-mingw32
.
This fileset includes a 64-bit pkg-config binary. If you need a 32-bit one, build it with the following steps:
- apt-get source pkg-config
- cd pkg-config-*
- ./configure --prefix=/usr/local/cross-tools/i386-mingw32
- make
- sudo make install
Get the Makefile and make
Download my Makefile. It's based on Makefile.simple and Michal's gitbuilder file. Place the file in OpenXcom/src and make
!
Note: -lws2_32
is only needed for ntohl()
, used by the FLAC library iirc.
Compiling 32bits on Windows
Here comes a way to build OpenXcom in a Windows environment having installed only MinGW (no MSYS, no bash, no sh, no Visual IDE or compiler). There could be others way to do, this is only an example. Some directories names will change to match the libraries versions, just adapt the paths.
Install MinGW32
See the MinGW website. Install at least C compiler, C++ compiler and GNU make.
Set up your project directory with SDL
Choose your project directory. Let's call it <project>
.
On SDL website download SDL 1.2 win32 development library for Mingw32.
Extract it in <project>
keeping directory hierarchy, you should get it in a directory such as <project>\SDL-1.2.15
.
On SDL_mixer website download SDL_mixer 1.2 source and SDL_mixer 1.2 Win32 32bits binaries. Extract the source in <project>
, you should get it in a directory such as <project>\SDL_mixer-1.2.12
. Create a <project>\SDL_mixer-1.2.12\bin
directory and extract the binaries here.
On SDL_image website download SDL_image 1.2 source and SDL_image 1.2 Win32 32bits binaries. Extract the source in <project>
, you should get it in a directory such as <project>\SDL_image-1.2.12
. Create a <project>\SDL_image-1.2.12\bin
directory and extract the binaries here.
Set up SDL_gfx
On SDL_gfx website download last SDL_gfx source and extract it in <project>
. You should get it in a directory such as <project>\SDL_gfx-2.0.24
. Go to Other builds subdirectory and extract Makefile from mingw32.zip in the <project>\SDL_gfx-2.0.24
directory. Edit the Makefile to modify it to have:
CFLAGS = -O3 -march=athlon-xp -mmmx -msse -m3dnow -DBUILD_DLL -DWIN32 -I..\SDL-1.2.15\include\SDL LIBS = -L..\SDL-1.2.15\lib -lSDL OBJS = SDL_framerate.o SDL_gfxBlitFunc.o SDL_gfxPrimitives.o SDL_imageFilter.o SDL_rotozoom.o
Then run in the <project>\SDL_gfx-2.0.24
directory:
mingw32-make SDL_gfx.dll
You should get a <project>\SDL_gfx-2.0.24\SDL_gfx.dll
file.
Set up yaml-cpp
From the yaml-cpp website download a yaml-cpp source higher than 0.5.0, such as 0.5.1.
From the CMake website download the CMake Windows zip binaries distribution.
From the boost website download the current release.
Extract the three archives in <project>; you should get directories such as <project>\yaml-cpp-0.5.1
, <project>\cmake-2.8.11.2-win32-x86
and <project>\boost_1_54_0
Go to the <project>\yaml-cpp-0.5.1
directory and run the following commands:
set Path=%Path%;<project>\cmake-2.8.11.2-win32-x86\bin mkdir build cd build cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=OFF -DBoost_INCLUDE_DIR=<project>\boost_1_54_0 .. mingw32-make
This should build a static library <project>\yaml-cpp-0.5.1\build\libyaml-cpp.a
.
There are problems building a dynamix library with the 0.5.1 version, but this could work with later versions.
Thankfully yaml-cpp does not need boost to build (it only uses the header files) because boost does not support MinGW compiling.
Build and run OpenXcom
Download the last available source and extract it in <project>
directory, you should get a <project>\OpenXcom-master
directory.
Copy original game directories in <project>\OpenXcom-master\bin\data
directory.
Create a <project>\OpenXcom-master\makefile
such as this one:
PROG=OpenXCom MINGW= SRC=$(wildcard src/*.cpp src/*/*.cpp src/*/*/*.cpp) OBJRES=src\$(PROG)_res.o OBJ=$(OBJRES) $(SRC:.cpp=.o) BIN=bin\$(PROG).exe RES=src\$(PROG).rc src\resource.h src\version.h res\windows\openxcom.ico WINVER=0x0400 CXX=$(MINGW)g++ CXXFLAGS=-DWINVER=$(WINVER) -I..\SDL-1.2.15\include\SDL -I..\SDL_mixer-1.2.12 -I..\SDL_image-1.2.12 -I..\SDL_gfx-2.0.24 -I..\yaml-cpp-0.5.1\include -I..\boost_1_54_0 -Wall -Wextra -Wno-unused-function -O2 LDFLAGS=-L..\SDL-1.2.15\lib -L..\yaml-cpp-0.5.1\build -lshlwapi -lmingw32 -lopengl32 -lSDLmain ..\SDL-1.2.15\bin\SDL.dll ..\SDL_mixer-1.2.12\bin\SDL_mixer.dll ..\SDL_image-1.2.12\bin\SDL_image.dll ..\SDL_gfx-2.0.24\bin\SDL_gfx.dll -lyaml-cpp -mwindows RC=$(MINGW)windres RFLAGS= .PHONY:all compile depends mrproper clean rebuild all:compile compile:$(BIN) depends: AppDep -n -l "# Dependencies" makefile for %%i in ($(SRC:.cpp=)) do $(CXX) $(CXXFLAGS) -MM "%%i.cpp" -MT "%%i.o" >> makefile $(BIN):$(OBJ) $(CXX) $(CXXFLAGS) -o $(BIN) $(OBJ) $(LDFLAGS) $(OBJRES):$(RES) $(RC) $(RFLAGS) -o $@ $< %.o:%.cpp $(CXX) $(CXXFLAGS) -o $@ -c $< mrproper:clean for %%i in ($(BIN)) do if exist "%%~fi" del "%%~fi" clean: for %%i in ($(OBJ)) do if exist "%%~fi" del "%%~fi" rebuild:mrproper all
You can also try to produce your makefile with CMake rather than using this example.
Fill MINGW variable if you have several MinGW instances (such as a 32bits one and a 64bits one).
Consider adding -g -D_DEBUG
to CXXFLAGS variable to generate debug information.
AppDep utility can be downloaded here. If you don't want to use it, just add a #Dependencies line at the end of your makefile, remove the AppDep call, and clear all lines after #Dependencies before using make depends.
Go to <project>\OpenXcom-master
and run:
mingw32-make depends mingw32-make all
The file <project>\OpenXcom-master\bin\OpenXcom.exe
should be produced.
If windres fails because of null characters, convert src\resource.h
and src\OpenXcom.rc
from UTF-16LE to ANSI.
To run the game, use the following commands in the same directory:
set Path=%Path;<project>\SDL-1.2.15\bin;<project>\SDL_mixer-1.2.12\bin;<project>\SDL_image-1.2.12\bin;<project>\SDL_gfx-2.0.24\bin bin\OpenXcom.exe -user <your name>
Compiling 32bits and 64bits on Windows
You can see instructions on how to build with MinGW-w64 in this GitHub fork of OpenXcom. (By the author of previous section).
MXE
Michal uses a different setup for his own builds and gitbuilder, based on MXE. I haven't tried MXE myself but supposedly its compiler rejects the -msse2 flag. On the other hand, it looks like it'll build all the libraries for you!