Well, actually I hadn't had much problems compiling OpenTTD with MingW+MSYS + x86_64-w64-mingw32 GCC 4.6.3 binaries (rubenvb custom build).
The only thing I skipped is libicu compilation as I hadn't had a need for it.
OpenTTD's configure script is, well, a bit unusual comparing to traditional autoconf stuff and sometimes it uses "non-traditional" methods to search for required libs, but a bit patience while reading config.lib sources helps to sort out all the problems.
My build system is set up as following:
Mingw-MSYS installed to
c:\msys.
64 and 32 bit mingw64 toolchains are installed to
c:\mingw64 and
c:\mingw32 folders resp.
Folder
c:\mingw is a "hard link" to
c:\mingw64 (NTFS joint created by executing:
mklink /J c:\mingw c:\mingw64). It is needed to make Eclipse/CDT happy (i.e. find mingw at the place it expects it to be and stop annoying me with "configuration support is not installed on the system" messages. In other words, making this link is optional and isn't strictly required.
MSYS's fstab (
c:\msys\etc\fstab) looks like:
Code: Select all
C:/mingw64 /mingw
C:/mingw32 /mingw32
C:/mingw64 /mingw64
c:\msys\home\%USERNAME%\.profile contains:
Code: Select all
# Filter out mingw from path
export PATH="`echo $PATH | sed -r 's,(\.|/mingw64/bin|/mingw32/bin|/mingw/bin):,,g'`"
echo ""
echo "Don't forget to chose which mingw to use, 64 or 32 bit."
echo "To do it type either 32 or 64."
echo ""
alias 32=". 32bit"
alias 64=". 64bit"
alias ll="ls -l"
Files 32bit and 64bit are shell scripts I created for "switching" MSYS between 32/64 bit targets "on the fly", they are located inside c:\msys\bin folder and contain:
/bin/32bit:
Code: Select all
#!/bin/sh
# Filter out mingw from path
export PATH="`echo $PATH | sed -r 's,(\.|/mingw64/bin|/mingw32/bin|/mingw/bin):{0\,1},,g' | sed -r 's,:+,:,g' | sed -r 's,:$,,'`:/mingw32/bin"
/bin/64bit:
Code: Select all
#!/bin/sh
# Filter out mingw from path
export PATH="`echo $PATH | sed -r 's,(\.|/mingw64/bin|/mingw32/bin|/mingw/bin):{0\,1},,g' | sed -r 's,:+,:,g' | sed -r 's,:$,,'`:/mingw64/bin"
Also I have
pkg-config binary installed to
c:\msys\bin. This binary had been downloaded from official gnome FTP:
http://ftp.gnome.org/pub/gnome/binaries ... endencies/ .
My habbit for building dep libs is to install them into separate dirs that are easy to remove later on rather than doing system-wide install (MSYS-wide in this case).
Thus, I've got a separate folder per arch for libs installation located at:
$HOME/OpenTTD/deps/inst32/ and
$HOME/OpenTTD/deps/inst64/.
Selecting target arch (using "32" and "64" shell aliases defined in $HOME/.profile) if required prior to proceeding with compiling libs.
To check if correct PATH had been set up try executing "as --version" and looking at the last line of the output. Target should be "x84_64-w64-mingw32" for 64 bit and "i686-w64-mingw32" for 32 bit toolchain.
Next I import into environment some convenient vars to simplify build process. There are two shell scripts created specifically for this purpose placed into
$HOME/OpenTTD/ folder:
$HOME/OpenTTD/settings-32bit.sh:
Code: Select all
export MYP=$HOME/OpenTTD/deps/inst32
export HOST=i686-w64-mingw32
# Construct pkg-config paths
PKG_CONFIG_PATH=""
for i in $MYP/*/lib/pkgconfig ; do
[ -d $i ] || continue
PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$i"
done
export PKG_CONFIG_PATH
$HOME/OpenTTD/settings-64bit.sh:
Code: Select all
export MYP=$HOME/OpenTTD/deps/inst64
export HOST=x86_64-w64-mingw32
# Construct pkg-config paths
PKG_CONFIG_PATH=""
for i in $MYP/*/lib/pkgconfig ; do
[ -d $i ] || continue
PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$i"
done
export PKG_CONFIG_PATH
This scripts should be run prior to configuring/building any dep lib or openttd itself, and also after successful build and installation of any of dep lib (so pkg-config search path gets updated with the path to newly built/installed lib). Scripts should be run like this:
Code: Select all
# . $HOME/OpenTTD/settings-64bit.sh
Notice dot and space typed in before path and script name. It is just shortcut for "source" bash command, i.e. above command is equivalent to "source $HOME/OpenTTD/settings-64bit.sh", just a bit shorter.
Next, to the libs. Each lib except for xz requires no patches to work correctly. xz hits unfortunate mingw64 bug I had reported to mingw64 devs yesterday and today it had been fixed in mingw64 trunk. As prebuilt toolchains hadn't been updated with this fix yet it is required to patch xz sources a bit to workaround this compiler bug. Build order for dep libs isn't strictly defined, the only real requirement is to build libpng after zlib as first requires later. To simplify libs build process I had created one shell script per dep lib. Each script should be placed to resp. dep lib unpacked source tree and executed from there. I place unpacked dep. libs sources to
$HOME/OpenTTD/deps/src/, for example zlib goes to: $HOME/OpenTTD/deps/src/zlib-1.2.7.
Zlib "to_make.sh" script:
Code: Select all
#!/bin/bash
[ -z ${MYP} ] && exit 1
which gcc 2>/dev/null >/dev/null || exit 1
make -f win32/Makefile.gcc BINARY_PATH=${MYP}/zlib/bin INCLUDE_PATH=${MYP}/zlib/include LIBRARY_PATH=${MYP}/zlib/lib SHARED_MODE=1 all install clean && \
make -f win32/Makefile.gcc BINARY_PATH=${MYP}/zlib/bin INCLUDE_PATH=${MYP}/zlib/include LIBRARY_PATH=${MYP}/zlib/lib SHARED_MODE=0 all install clean
libpng "to_make.sh" script:
Code: Select all
#!/bin/bash
[ -z ${MYP} ] && exit 1
[ -z ${HOST} ] && exit 1
pkg-config --exists zlib || {
echo "pkg-config reports no zlib, build failed."
exit 1
}
which gcc 2>/dev/null >/dev/null || exit 1
CFLAGS="$CFLAGS `pkg-config --cflags zlib`" \
LDFLAGS="$LDFLAGS `pkg-config --libs-only-L zlib`" \
./configure --prefix=${MYP}/libpng --build=${HOST} --enable-shared --enable-static && \
make -j8 all && \
make -j8 install && \
make -j8 clean
lzo "to_make.sh":
Code: Select all
#!/bin/bash
[ -z ${MYP} ] && exit 1
[ -z ${HOST} ] && exit 1
which gcc 2>/dev/null >/dev/null || exit 1
./configure --prefix=${MYP}/liblzo --build=${HOST} --enable-shared --enable-static && \
make -j8 all && \
make -j8 install && \
make -j8 clean
freetype2 "to_make.sh":
Code: Select all
#!/bin/bash
[ -z ${MYP} ] && exit 1
[ -z ${HOST} ] && exit 1
which gcc 2>/dev/null >/dev/null || exit 1
./configure --prefix=${MYP}/freetype --build=${HOST} --enable-shared --enable-static && \
make -j8 all && \
make -j8 install && \
make -j8 clean
xz "to_make.sh":
Code: Select all
#!/bin/bash
[ -z ${MYP} ] && exit 1
[ -z ${HOST} ] && exit 1
which gcc 2>/dev/null >/dev/null || exit 1
./configure \
--prefix=${MYP}/xz --build=${HOST} --enable-shared --enable-static \
--disable-xz --disable-xzdec --disable-lzmadec --disable-lzmainfo \
--disable-lzma-links --disable-scripts --disable-nls && \
make -j8 all && \
make -j8 check && \
make -j8 install && \
make -j8 clean
Now, back to xz vs. compiler bug patch. It's as simple as changing
{xz source folder}/src/common/sysdefs.h file commenting out following lines:
Code: Select all
// Get standard-compliant stdio functions under MinGW and MinGW-w64.
//===>Commented out to workaround compiler bug<=== #ifdef __MINGW32__
//===>Commented out to workaround compiler bug<=== # define __USE_MINGW_ANSI_STDIO 1
//===>Commented out to workaround compiler bug<=== #endif
Thus, build process looks like this:
Code: Select all
# 64
# cd $HOME/OpenTTD
# . settings-64bit
# pushd ./deps/src/zlip-1.2.7/
# ./to_make.sh
# popd
# . settings-64bit
# pushd ./deps/src/libpng-1.5.12/
# ./to_make.sh
# popd
# . settings-64bit
# pushd ./deps/src/lzo-2.06/
# ./to_make.sh
# popd
# . settings-64bit
# pushd ./deps/src/freetype-2.4.5/
# ./to_make.sh
# popd
# . settings-64bit
# pushd ./deps/src/xz-5.0.4/
# ./to_make.sh
# popd
# . settings-64bit
At this point all required deps should be built, but it's nice to check if pkg-config knows about it:
Code: Select all
# pkg-config --list-all
libpng libpng - Loads and saves PNG files
freetype2 FreeType 2 - A free, high-quality, and portable font engine.
zlib zlib - zlib compression library
libpng15 libpng - Loads and saves PNG files
liblzma liblzma - General purpose data compression library
Nice! All libs are there except for lzo - which simply doesn't support integration with pkg-config.
Time to build OpenTTD itself. Yet another shell script to handle configure:
OpenTTD's "to_conf.sh":
Code: Select all
#!/bin/bash
[ -z ${MYP} ] && {
echo "Export correct MYP first!"
exit 1
}
[ -z ${HOST} ] && {
echo "Export correct HOST first!"
exit 1
}
for i in zlib libpng liblzma freetype2 ; do
pkg-config --exists $i || {
echo "pkg-config reports no $i, build failed."
exit 1
}
done
which gcc 2>/dev/null >/dev/null || {
echo "No usable gcc found on PATH."
exit 1
}
CFLAGS="$CFLAGS `pkg-config --cflags zlib` -I${MYP}/liblzo/include" \
LDFLAGS="$LDFLAGS `pkg-config --libs-only-L zlib` -L${MYP}/liblzo/lib" \
./configure \
--prefix-dir=$MYP/OpenTTD/ --with-zlib=`pkg-config --variable=libdir zlib` \
--with-lzma --with-lzo2=${MYP}/liblzo/lib --with-png=`pkg-config --variable=exec_prefix libpng`/bin/libpng-config \
--with-freetype=`pkg-config --variable=exec_prefix freetype2`/bin/freetype-config \
"$@"
Place it into root of OpenTTD source dir and you're set to go. For "release" build you could simply run "
./to_conf.sh", check that no errors are reported and follow up with "
make -j5" (assuming that you've got 4 core CPU; adjust number after "-j" to match number of the CPU cores + 1). For "debug" build containing info that is required to conveniently debug produced binary under gdb run
to_conf.sh script like this:
Code: Select all
# CFLAGS="-O0 -g" ./to_conf.sh --disable-strip
Check for errors and if none proceed with
make -j5. Upon (hopefully) successful end of compilation process you would end up with fresh openttd.exe binary in {openttd source}/bin folder.
"
make install" wouldn't work correctly under MSYS as "install" target wasn't designed with MSYS in mind, it's best suited for various *nix-es. If you want to get "installation bunble" - run "
make bundle" and collect all the goodies from {openttd source}/bundle folder.
Had successfully built binary for 64 bit and want to repeat it for 32bit? No problems, it is as simple as (assuming you're at openttd source dir root and have all dep libs built/instaled for 32bit arch):
Code: Select all
# make clean
# 32
# . $HOME/OpenTTD/settings-32bit
# ./to_conf.sh
# make -j5
Hope that helps.