#!/bin/bash -ex
# Cross-compilation instructions

# Copyright (C) 2007, 2008, 2009, 2010  Sylvain Beucler

# This file is part of GNU FreeDink

# GNU FreeDink is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# GNU FreeDink is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see
# <http://www.gnu.org/licenses/>.


# Time: < 30mn
# Space: ~50MB sources + ~150MB build + ~20MB install

# Super-user commands can be disabled using 'SUDO=: ./cross.sh'
# Idem for wget if you already downloaded the tarballs
SUDO=${SUDO=sudo}
WGET=${WGET=wget -c}

# Default ./configure params
HOST=i586-mingw32msvc
PREFIX=/usr/local/$HOST
# whenever you specify `--host', be sure to specify `--build' too;
# this will be fixed in the future - (autoconf.info)Specifying Names
BUILD=i686-pc-linux-gnu

# Install a cross-compiler version of GCC
$SUDO aptitude install mingw32

# To store cross-compiled libraries
$SUDO mkdir -p -m 775 $PREFIX
$SUDO chgrp src $PREFIX
# To store source tarballs that will be distributed along with static
# binaries to comply with the GNU GPL and LGPL
if [ ! -e depsources ]; then
  mkdir -m 755 depsources
fi


# Cross-compile yourself
# ----------------------

# This is necessary for static builds (no static libraries are
# provided with the official releases). If feeling lazy and ok with
# .dlls, check "Install precompiled SDL binaries" below.

# SDL
VERSION=1.2.14
cd /usr/src/
# Get non-free DX headers from libsdl.org
$WGET -P depsources/ http://www.libsdl.org/extras/win32/common/directx-devel.tar.gz
tar xzf depsources/directx-devel.tar.gz -C $PREFIX/
# Alternative: get free DX headers from libwine
# Unfortunately src/video/windx5/SDL_dx5video.c fails to compile as of
# 2009-09-17 :/
#aptitude install libwine-dev
#CPPFLAGS="-I /usr/include/wine/windows"
$WGET -P depsources/ http://libsdl.org/release/SDL-$VERSION.tar.gz
tar xzf depsources/SDL-$VERSION.tar.gz
cd SDL-$VERSION
CPPFLAGS="-I $PREFIX/include" \
  ./configure --build=$BUILD --host=$HOST \
    --prefix=$PREFIX
# If you don't want stdout.txt and stderr.txt to be created:
#  --disable-stdio-redirect
# Note: no need for -L, mingw already has libdsound.a, etc.
# Cross-prefix would be /usr/local/cross-tools/i386-mingw32 by default
make
make install
# make install-strip not supported :/
$HOST-strip $PREFIX/bin/SDL.dll


# pkgconfig (used to detect ziplib and zzip in the build system, also
# used by Vorbis to detect Ogg)
VERSION=0.25
cd /usr/src/
$WGET -P depsources/ http://pkgconfig.freedesktop.org/releases/pkg-config-$VERSION.tar.gz
tar xzf depsources/pkg-config-$VERSION.tar.gz
cd pkg-config-$VERSION
./configure --prefix=$PREFIX
make
make install-strip
$SUDO ln -nfs $PREFIX/bin/pkg-config \
  /usr/local/bin/$HOST-pkg-config
# or set
# PKG_CONFIG="$PREFIX/bin/pkg-config"


# libogg (libvorbis dependency)
cd /usr/src/
VERSION=1.2.1
$WGET -P depsources/ http://downloads.xiph.org/releases/ogg/libogg-$VERSION.tar.gz
tar xzf depsources/libogg-$VERSION.tar.gz
cd libogg-$VERSION
./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# libvorbis and libvorbisfile (SDL_mixer dependencies)
cd /usr/src/
VERSION=1.3.1
$WGET -P depsources/ http://downloads.xiph.org/releases/vorbis/libvorbis-$VERSION.tar.gz
tar xzf depsources/libvorbis-$VERSION.tar.gz
cd libvorbis-$VERSION
CPPFLAGS="-I$PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# SDL_mixer
VERSION=1.2.11
cd /usr/src/
$WGET -P depsources/ http://libsdl.org/projects/SDL_mixer/release/SDL_mixer-$VERSION.tar.gz
tar xzf depsources/SDL_mixer-$VERSION.tar.gz
cd SDL_mixer-$VERSION

# libmikmod (not just 'mikmod', 'libmikmod'; SDL_mixer dependency)
#VERSION=3.1.11
#$WGET -P depsources/ http://mikmod.raphnet.net/files/libmikmod-$VERSION.tar.gz
#tar xzf depsources/libmikmod-$VERSION.tar.gz
#cd libmikmod-$VERSION
#wget -O- http://mikmod.raphnet.net/files/libmikmod-3.1.11-a.diff | patch -p1
# +CVE-2007-6720
# +CVE-2009-0179
# ... let's use the one in SDL_mixer... ;)

## libmikmod's autotools-based build system is absolutely not meant for
## cross compiling, it only support Unix builds (with ESD, OSS, etc.).
## Let's try a mingw32-specific build:
## http://www.finiderire.com/post/2007/12/16/MikMod-Windows-et-moi
## another (older) source: http://basic.xullum.net/clanlib/MikModMakefile.mingw
#MIKMOD_VERSION=3.1.12
#unzip libmikmod-$MIKMOD_VERSION.zip
#pushd libmikmod-$MIKMOD_VERSION.patched/win32
## copy Makefile from website...
#cat <<EOF >> Makefile
#CC=i586-mingw32msvc-gcc
#CXXFLAGS+=-I. -I $PREFIX/include
#EOF
##cp -a mikmod_build.h ../include/
##cp -a mikmod_build.h ../include/mikmod.h
#make
#mv libmikmod.a libmikmod.dll.a 
#$HOST-ar cru libmikmod.a objets/*.o
#$HOST-ranlib libmikmod.dll.a
#$HOST-ranlib libmikmod.a
#install -m 644 libmikmod.dll.a $PREFIX/lib/
#install -m 644 libmikmod.a $PREFIX/lib/
#install -m 644 mikmod.dll $PREFIX/bin/
#$HOST-strip /usr/local/i586-mingw32msvc/bin/mikmod.dll
#install -m 644 mikmod_build.h $PREFIX/include/mikmod.h
## test: $HOST-gcc -I../include -L$PREFIX/lib objets/*.o test.c -lwinmm -ldsound
## The .dll.a is apparently broken...

# mikmod's build system is not suitable for woe cross-compiling, so
# let's use some autotools skills :)
# TODO: I can't manage to build a complete static+shared lib, so for
# now it'll be a minimum lib to support SDL_mixer.
MIKMOD_VERSION=3.1.12
unzip libmikmod-$MIKMOD_VERSION.zip
pushd libmikmod-$MIKMOD_VERSION.patched
cat <<EOF > configure.ac
AC_PREREQ(2.61)
AC_INIT([mikmod],[$VERSION])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF
# Cf. '(libtool.info)Updating version info' for the versioning scheme
# Using 'echo' to remove newlines
# -version-info from libmikmod/Makefile.in
# No '-DDRV_DS -DDRV_WIN' because it's just for use in SDL_mixer
cat <<EOF > Makefile.am
AM_CPPFLAGS=-DWIN32 -DHAVE_FCNTL_H -DHAVE_MALLOC_H -DHAVE_LIMITS_H -Iinclude
lib_LTLIBRARIES = libmikmod.la
libmikmod_la_SOURCES = loaders/load_669.c loaders/load_amf.c            \
loaders/load_dsm.c loaders/load_far.c loaders/load_gdm.c                \
loaders/load_imf.c loaders/load_it.c loaders/load_m15.c                 \
loaders/load_med.c loaders/load_mod.c loaders/load_mtm.c                \
loaders/load_okt.c loaders/load_s3m.c loaders/load_stm.c                \
loaders/load_stx.c loaders/load_ult.c loaders/load_uni.c                \
loaders/load_xm.c mmio/mmalloc.c mmio/mmerror.c mmio/mmio.c             \
playercode/mdreg.c playercode/mdriver.c playercode/mdulaw.c             \
playercode/mloader.c playercode/mlreg.c playercode/mlutil.c             \
playercode/mplayer.c playercode/munitrk.c playercode/mwav.c             \
playercode/npertab.c playercode/sloader.c playercode/virtch.c           \
playercode/virtch2.c playercode/virtch_common.c drivers/drv_nos.c       \
drivers/drv_stdout.c drivers/drv_wav.c drivers/drv_raw.c
libmikmod_la_LDFLAGS = -no-undefined -version-info 2:4:0 -lwinmm -ldsound
include_HEADERS = include/mikmod.h
EOF
ln -nfs ../win32/mikmod_build.h include/mikmod.h
ln -nfs ../win32/mikmod_build.h include/mikmod_build.h
rm -f configure.in
autoreconf -fis
CPPFLAGS="-I$PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip
cat <<'EOF' > $PREFIX/bin/libmikmod-config
#!/bin/bash
while test $# -gt 0; do
    case "$1" in
        --cflags) echo "-I$(readlink -f $(dirname $0)/../include)";;
        # should be ldflags, but SDL_mixer doesn't use it properly
        --libs) echo "-L$(readlink -f $(dirname $0)/../lib) -lmikmod";;
    esac
    shift
done
EOF
chmod 755 $PREFIX/bin/libmikmod-config
popd

# Cross-prefix would be /usr/local/cross-tools/i386-mingw32 by default
# Disable MP3 support (there are patents treats, and there's the Ogg
# Vorbis alternative)
# Adding -L.../bin so it can find .dll. This enables lazy loading
# (e.g. SDL_mixer.dll won't depend on libvorbis-0.dll, but will load
# it at run-time. For normal linking: --disable-music-ogg-shared)
# Let's choose normal linking to avoid inconsistencies and support
# static linking.
SDL_CONFIG=$PREFIX/bin/sdl-config \
  CPPFLAGS="-I$PREFIX/include"
  LDFLAGS="-L$PREFIX/lib" \
  ./configure \
  PATH=$PREFIX/bin:$PATH \
  --build=$BUILD --host=$HOST \
  --prefix=$PREFIX \
  --disable-music-mp3 --enable-music-native-midi-gpl \
  --disable-music-ogg-shared --disable-music-mod-shared
# TODO: flac?
# http://downloads.sourceforge.net/project/flac/flac-src/flac-1.2.1-src/flac-1.2.1.tar.gz?use_mirror=freefr
# It doesn't cross-compile directly...
make
make install
# make install-strip not supported :/
$HOST-strip $PREFIX/bin/SDL_mixer.dll


# FreeType (dependency of SDL_ttf)
VERSION=2.4.3
cd /usr/src/
$WGET -P depsources/ http://download.savannah.gnu.org/releases/freetype/freetype-$VERSION.tar.bz2
tar xjf depsources/freetype-$VERSION.tar.bz2
cd freetype-$VERSION
# Enable bytecode interpreter, that's what distros use most, and we
# need it for compatibility in font metrics. It's disabled by default
# for fear of patent attacks.
# Check:
# - http://freetype.org/patents.html
# - http://bugs.debian.org/447801
# - freetype-2.3.9/docs/TRUETYPE
sed -i -e 's,/\* #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER \*/,#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER,' \
    include/freetype/config/ftoption.h
./configure --build=$BUILD --host=$HOST --prefix=$PREFIX
make
make install
# make install-strip not supported :/
$HOST-strip $PREFIX/bin/libfreetype*.dll


# SDL_ttf
VERSION=2.0.9
cd /usr/src/
$WGET -P depsources/ http://libsdl.org/projects/SDL_ttf/release/SDL_ttf-$VERSION.tar.gz
tar xzf depsources/SDL_ttf-$VERSION.tar.gz
cd SDL_ttf-$VERSION
# Cross-prefix would be /usr/local/cross-tools/i386-mingw32 by default
SDL_CONFIG=$PREFIX/bin/sdl-config \
  FREETYPE_CONFIG=$PREFIX/bin/freetype-config \
  ./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# SDL_gfx
VERSION=2.0.22
cd /usr/src
$WGET -P depsources/ http://www.ferzkopp.net/Software/SDL_gfx-2.0/SDL_gfx-$VERSION.tar.gz
tar xzf depsources/SDL_gfx-$VERSION.tar.gz
cd SDL_gfx-$VERSION
# Cross-prefix would be /usr/local/cross-tools/i386-mingw32msvc by default
SDL_CONFIG=$PREFIX/bin/sdl-config \
  ./configure --build=$BUILD --host=$HOST \
    --prefix=$PREFIX
make
make install-strip

# libjpeg (dependency of SDL_image and libtiff)
VERSION=8b
cd /usr/src/
$WGET -P depsources/ http://www.ijg.org/files/jpegsrc.v$VERSION.tar.gz
tar xzf depsources/jpegsrc.v$VERSION.tar.gz
cd jpeg-$VERSION
./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# zlib (dependency of libzip and libpng)
VERSION=1.2.5
cd /usr/src
$WGET -P depsources/ http://zlib.net/zlib-$VERSION.tar.gz
tar xzf depsources/zlib-$VERSION.tar.gz
cd zlib-$VERSION
# Generate zconf.h
./configure
# zlib's build system is not suitable for woe cross-compiling, so
# let's use some autotools skills :)
cat <<EOF > configure.ac
AC_PREREQ(2.61)
AC_INIT([zlib],[$VERSION])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF
# Cf. '(libtool.info)Updating version info' for the versioning scheme
# Using 'echo' to remove newlines
files=$(echo $(ls *.c *.h | grep -v example.c | grep -v minigzip.c))
cat <<EOF > Makefile.am
lib_LTLIBRARIES = libz.la
libz_la_SOURCES = $files
libz_la_LDFLAGS = -no-undefined -version-info 3:3:2
include_HEADERS = zlib.h zconf.h
EOF
autoreconf -fis
./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# libpng
VERSION=1.4.4
cd /usr/src/
# Download version "with config script"
$WGET -P depsources/ ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-$VERSION.tar.bz2
tar xjf depsources/libpng-$VERSION.tar.bz2
cd libpng-$VERSION
# Need zlib
CPPFLAGS="-I$PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# libtiff
VERSION=3.9.4
cd /usr/src/
# Download version "with config script"
$WGET -P depsources/ ftp://ftp.remotesensing.org/pub/libtiff/tiff-$VERSION.tar.gz
tar xzf depsources/tiff-$VERSION.tar.gz
cd tiff-$VERSION
# Optional zlib and jpeg support OK
# OpenGL support???
CPPFLAGS="-I$PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip


# SDL_image
VERSION=1.2.10
cd /usr/src/
$WGET -P depsources/ http://libsdl.org/projects/SDL_image/release/SDL_image-$VERSION.tar.gz
tar xzf depsources/SDL_image-$VERSION.tar.gz
cd SDL_image-$VERSION
# Cross-prefix would be /usr/local/cross-tools/i386-mingw32 by default.
# See SDL_mixer for explanations about disabled dynamic loading.
SDL_CONFIG=$PREFIX/bin/sdl-config \
  CPPFLAGS="-I $PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure \
  --build=$BUILD --host=$HOST \
  --prefix=$PREFIX \
  --disable-jpg-shared --disable-png-shared --disable-tif-shared
make
make install-strip

# libzip
VERSION=0.9.3
cd /usr/src/
$WGET -P depsources/ http://www.nih.at/libzip/libzip-$VERSION.tar.gz
tar xzf depsources/libzip-$VERSION.tar.gz
cd libzip-$VERSION/
CPPFLAGS="-I$PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure --build=$BUILD --host=$HOST \
    --prefix=$PREFIX
make
make install-strip

# iconv - gettext dependency
# Without it, gettext cannot convert the strings from the .mo file to
# the requested encoding, resulting in weird characters.
VERSION=1.13.1
cd /usr/src/
$WGET -P depsources/ http://ftp.gnu.org/pub/gnu/libiconv/libiconv-$VERSION.tar.gz
tar xzf depsources/libiconv-$VERSION.tar.gz
cd libiconv-$VERSION/
# --disable-shared because there's no libiconv.a otherwise
  ./configure --build=$BUILD --host=$HOST \
    --prefix=$PREFIX --disable-shared
make
make install-strip


# gettext
VERSION=0.18.1.1
cd /usr/src/
$WGET -P depsources/ http://ftp.gnu.org/pub/gnu/gettext/gettext-$VERSION.tar.gz
tar xzf depsources/gettext-$VERSION.tar.gz
cd gettext-$VERSION/
cd gettext-runtime/
# --disable-shared because otherwise it because a real mess
# (AM_GETTEXT* try to link from .dll.a even with -static, it can't
# load static iconv from above requiring double compilation, etc.),
# and I suppose nobody want an external libintl-8.dll.
CPPFLAGS="-I$PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ./configure --build=$BUILD --host=$HOST \
    --prefix=$PREFIX --disable-shared
make
make install-strip


# Apparently automake's 'install-strip' doesn't necessarily work on
# installed .dll's:
$HOST-strip $PREFIX/bin/*.dll


exit


Cross-compile FreeDink
----------------------

$SUDO aptitude install upx-ucl 
cd ~/freedink/
mkdir cross
cd cross/
SDL_CONFIG=$PREFIX/bin/sdl-config \
  CPPFLAGS="-I $PREFIX/include" \
  LDFLAGS="-L$PREFIX/lib" \
  ../configure --host=$HOST --build=$BUILD \
  --enable-static --enable-upx
make install-strip DESTDIR=`pwd`/destdir
ls -lh destdir/usr/local/bin/*.exe


Install precompiled SDL binaries
--------------------------------

(.dll only)

VERSION=1.2.13
# Cf. http://libsdl.org/download-1.2.php
$WGET http://libsdl.org/release/SDL-devel-$VERSION-mingw32.tar.gz
tar xzf SDL-devel-$VERSION-mingw32.tar.gz
mv SDL-$VERSION/* i386-mingw32msvc/
rmdir SDL-$VERSION

# Install precompiled SDL_mixer binaries
VERSION=1.2.11
$WGET http://libsdl.org/projects/SDL_mixer/release/SDL_mixer-devel-$VERSION-VC8.zip
unzip SDL_mixer-devel-$VERSION-VC8.zip
cp -r SDL_mixer-$VERSION/include/* i386-mingw32msvc/include/SDL/
cp -r SDL_mixer-$VERSION/lib/* i386-mingw32msvc/lib/
rm -rf SDL_mixer-$VERSION/

# Install precompiled SDL_ttf binaries
VERSION=2.0.9
$WGET http://libsdl.org/projects/SDL_ttf/release/SDL_ttf-devel-$VERSION-VC8.zip
unzip SDL_ttf-devel-$VERSION-VC8.zip
cp -r SDL_ttf-$VERSION/include/* i386-mingw32msvc/include/SDL/
cp -r SDL_ttf-$VERSION/lib/* i386-mingw32msvc/lib/
rm -rf SDL_ttf-$VERSION/

# (Install precompiled SDL_image binaries)
VERSION=1.2.10
$WGET http://libsdl.org/projects/SDL_image/release/SDL_image-devel-$VERSION-VC8.zip
unzip SDL_image-devel-$VERSION-VC8.zip
cp -r SDL_image-$VERSION/include/* i386-mingw32msvc/include/SDL/
\cp -r SDL_image-$VERSION/lib/* i386-mingw32msvc/lib/
rm -rf SDL_image-$VERSION/

# Cross-compile SDL_gfx (no binaries available)
# (see above)

# Cross-compile libzip (no binaries available)
# (see above)

See also http://www.gtk.org/download-windows.html which has links to
various binaries and dev packages for Windows.


Details on static build
-----------------------

I want to cross-compile statically, to provide a single .exe that
includes SDL and SDL_* :)

- You specify -static

- You add -lwinmm

i586-mingw32msvc-gcc mousetest.c \
  `/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config --cflags \
  --static-libs` -lwinmm

- If you have some troubles with SDL_gfx which tries to use
  __imp__SDL_setFramerate, you need a build system patch (see above) -
  maybe it will make it to 2.0.18 ;)

- You add -lfreetype, a dependency of SDL_ttf

You get a 1.1MB standalone stripped executable.

Now directly available with:
SDL_CONFIG=/usr/local/cross-tools/i386-mingw32msvc/bin/sdl-config \
   ../configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu \
   --enable-static ...


Misc
----

Those may be used later on.

# zziplib 0.12
$WGET http://dfn.dl.sourceforge.net/sourceforge/zziplib/zziplib-0.12.83.tar.bz2
CPPFLAGS="-I/usr/local/cross-tools/i386-mingw32msvc/include" \
  LDFLAGS="-L/usr/local/cross-tools/i386-mingw32msvc/lib" \
  ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu \
    --prefix=/usr/local/cross-tools/i386-mingw32msvc
# avoid compiling bins/ which has compilation errors:
cd i586-pc-mingw32msvc/zzip
make
make install-strip
# I think I remember it crashes under woe?


# zziplib 0.13
$WGET http://ovh.dl.sourceforge.net/sourceforge/zziplib/zziplib-0.13.49.tar.bz2
# --disable-mmap because of compilation errors in zzip/mmapped.c
CPPFLAGS="-I/usr/local/cross-tools/i386-mingw32msvc/include" \
  LDFLAGS="-L/usr/local/cross-tools/i386-mingw32msvc/lib" \
  ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu \
    --prefix=/usr/local/cross-tools/i386-mingw32msvc --disable-mmap
make
# => doesn't work, it tries to use ftello which is apparently missing from mingw
# => MXE made it 0.13.59 work, but when loading the embedded font FreeDink says:
#   Could not open font 'LiberationSans-Regular.ttf': Couldn't load font file
# while it works fine with libzip.

# Guile - dep: libltdl
VERSION=2.2.4
http://ftp.gnu.org/pub/gnu/libtool/libtool-$VERSION.tar.bz2
tar xjf libtool-$VERSION.tar.bz2 
cd libtool-$VERSION
./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu \
  --prefix=/usr/local/cross-tools/i386-mingw32msvc
make
make install-strip


# Guile - dep: GNU MP
VERSION=4.2.2
$WGET ftp://ftp.gnu.org/gnu/gmp/gmp-$VERSION.tar.bz2
tar xjf gmp-$VERSION.tar.bz2
cd gmp-$VERSION
./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu \
  --prefix=/usr/local/cross-tools/i386-mingw32msvc
make
make install-strip

# Guile
VERSION=1.8.5
http://ftp.gnu.org/pub/gnu/guile/guile-$VERSION.tar.gz
tar xzf guile-$VERSION.tar.gz
cd guile-$VERSION
CPPFLAGS="-I/usr/local/cross-tools/i386-mingw32msvc/include" \
  LDFLAGS="-L/usr/local/cross-tools/i386-mingw32msvc/lib" \
  ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu \
    --prefix=/usr/local/cross-tools/i386-mingw32msvc \
    --disable-shared
make
make install-strip

Some problems need to be fixed:

- Comment obsolete AC_SYS_RESTARTABLE_SYSCALLS in configure.in, plus
  refresh ./configure by running 'autoconf'

- Replace '#ifndef tzname' with '#ifndef HAVE_DECL_TZNAME' in
  libguile/stime.c

- Comment '# define SCM_IMPORT 1' in libguile/guile.c

See:
http://lists.gnu.org/archive/html/bug-guile/2008-05/msg00016.html
A few of them were fixed in 2009.


# SDL_stretch (alternative to SDL_gfx that has more accurate scaling,
# but this this is being fixed in SDL_gfx)
$WGET http://kent.dl.sourceforge.net/sourceforge/sdl-stretch/SDL_stretch-0.2.3.tar.bz2
tar xjf SDL_stretch-0.2.3.tar.bz2  # 07 Dec 2003...
cd SDL_stretch-0.2.3
...lots errors...


# libffi (DinkC to C bindings, not used anymore because it didn't
# support PSP)
# Note: the build system only creates static libs for woe, creating
# .dll's would require some libtool tuning, but is pretty useless
# since libffi.a is ~10kB.
cd /usr/src/
VERSION=3.0.7
$WGET -P depsources/ ftp://sourceware.org/pub/libffi/libffi-$VERSION.tar.gz
tar xzf depsources/libffi-$VERSION.tar.gz
cd libffi-$VERSION
./configure --build=$BUILD --host=$HOST \
  --prefix=$PREFIX
make
make install-strip



See also
--------

http://gnuwin32.sourceforge.net/ distributes precompiled binaries with
static and shared libraries. The binaries are created using MinGW but
from Windows, so they are not cross-compiled. There is no well-defined
source format, and rebuilding binaries can be difficult because they
can rely on heavily modified gnuwin32-specific build system, and on a
set of helpers (http://gnuwin32.sourceforge.net/compile.html). So
binary packages are probably fine to use as-is. Source instructions
however are not always reusable for cross-compiling by our own means.

http://www.profv.de/mingw_cross_env/ provides a scripted way to
cross-build various libraries (static only though).

http://www.profv.de/debian/ repackages gnuwin32 binaries under the
.deb format for easy installation in a cross-compilation
environment. Again this is fine to use as-is but there is no
recompilation nor instructions for re(cross)compilation.
