Difference between revisions of "Compiling with MinGW (OpenXcom)"

From UFOpaedia
Jump to navigation Jump to search
Line 107: Line 107:
 
  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
 
  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
 
  ..\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
 
   
 
   
 
  .PHONY:all compile depends mrproper clean rebuild
 
  .PHONY:all compile depends mrproper clean rebuild
Line 134: Line 135:
 
You can also try to produce your makefile with CMake rather than using this example.
 
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 31bits one and a 64bits one).
+
Fill MINGW variable if you have several MinGW instances (such as a 32bits one and a 64bits one).
 +
Add -g -D_DEBUG
 +
 
 
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.

Revision as of 21:05, 26 August 2013

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 MinGW 32bits

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

On yaml-cpp website download a yaml-cpp source posterior to 1.5.0, such as 1.5.1. On CMake website download CMake Windows zip binaries distribution. On boost website download 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 <project>\yaml-cpp-0.5.1 directory and run 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 problem building dynamix library for 1.5.1 version, but this could work with latter versions.

Thankfully yaml-cpp need no boost build (it uses only 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)
OBJ=$(SRC:.cpp=.o)
BIN=bin\$(PROG).exe

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

.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)

%.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). Add -g -D_DEBUG

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.

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>

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!