moo-poelzi / mingw-configure

#!/bin/sh

#
# mignw-configure - configure for cross-compiling with mingw
# by Yevgen Muntyan <muntyan@math.tamu.edu>
# Ditributed under the terms of WTFL license
#

#
# If you are not using this script, do not forget to use --build.
# If you think --build is not needed because blah blah blah, then
# read docs. Or just use --build. Or just use this script damn it.
#

write_pkg_config()
{
rm -f $1
cat > $1 << ENDSRIPT
#!/bin/sh

export PKG_CONFIG_LIBDIR="$GTK_PREFIX/lib/pkgconfig":"$PYTHON_PREFIX/Lib/pkgconfig"
export PKG_CONFIG_PATH=\$PKG_CONFIG_LIBDIR

# pkg-config doesn't like --define-variable with these
if [ "x\`echo "\$*" | grep -- --atleast-pkgconfig-version\`" != x -o \\
     "x\`echo "\$*" | grep -- --atleast-version\`" != x ]; then
  exec "$PKG_CONFIG_PROGRAM" \$*
else
  # pygtk pulls gtk and friends, so if they sit in different prefixes then
  # we're screwed anyway, so pygtk and friends must be relocated to the
  # same prefix as gtk after install, if installed with win32 installer
  exec "$PKG_CONFIG_PROGRAM" --define-variable=prefix="$GTK_PREFIX" \$*
fi
ENDSRIPT
chmod +x $1
}

# Path to host pkg-config
PKG_CONFIG_PROGRAM=${PKG_CONFIG_PROGRAM:-/usr/bin/pkg-config}
# Prefix of mingw tools. prefix + tool should make up full path
# to the tool, e.g. prefix is '/usr/bin/i586-mingw32msvc-' on Debian
# or '/usr/local/mingw32/bin/' on FreeBSD.
MINGW_TOOL_PREFIX=${MINGW_TOOL_PREFIX:-/usr/bin/i586-mingw32msvc-}

# Where gtk libraries are installed
export GTK_PREFIX=${GTK_PREFIX:-/usr/local/win/gtk}

if [ "x$1" = "x--with-python=2.4" -o "x$2" = "x--with-python=2.4" ]; then
  export PYTHON_PREFIX=${PYTHON_PREFIX:-/usr/local/win/Python24}
else
  export PYTHON_PREFIX=${PYTHON_PREFIX:-/usr/local/win/Python25}
fi
export PYTHON_HOME=$PYTHON_PREFIX
export PYTHON=${PYTHON:-python}

# Find configure script to run
if [ x$CONFIGURE = x ]; then
    CONFIGURE="configure"
    if [ ! -e $CONFIGURE ]; then
        CONFIGURE=`dirname $0`/configure
    fi
    if [ ! -e $CONFIGURE ]; then
        echo "Can't find configure script"
        exit 1
    fi
    configure_dir=`dirname "$CONFIGURE"`
    configure_dir=`cd "$configure_dir" && pwd`
    CONFIGURE="$configure_dir"/configure
    CONFIG_GUESS="$configure_dir"/config.guess
fi

# autoconf is not intelligent enough to guess that
# i586-pc-mingw32msvc target has anything to do with
# debian /usr/bin/i586-mingw32msvc-gcc or freebsd
# /usr/local/mingw32/bin/gcc, hence these variables
export ADDR2LINE="${MINGW_TOOL_PREFIX}addr2line"
export AS="${MINGW_TOOL_PREFIX}as"
export CC="${MINGW_TOOL_PREFIX}gcc"
export OBJC="${MINGW_TOOL_PREFIX}gcc"
export CPP="${MINGW_TOOL_PREFIX}cpp"
export CPPFILT="${MINGW_TOOL_PREFIX}c++filt"
export CXX="${MINGW_TOOL_PREFIX}g++"
export DLLTOOL="${MINGW_TOOL_PREFIX}dlltool"
export DLLWRAP="${MINGW_TOOL_PREFIX}dllwrap"
export GCOV="${MINGW_TOOL_PREFIX}gcov"
export LD="${MINGW_TOOL_PREFIX}ld"
export NM="${MINGW_TOOL_PREFIX}nm"
export OBJCOPY="${MINGW_TOOL_PREFIX}objcopy"
export OBJDUMP="${MINGW_TOOL_PREFIX}objdump"
export READELF="${MINGW_TOOL_PREFIX}readelf"
export SIZE="${MINGW_TOOL_PREFIX}size"
export STRINGS="${MINGW_TOOL_PREFIX}strings"
export WINDRES="${MINGW_TOOL_PREFIX}windres"
export AR="${MINGW_TOOL_PREFIX}ar"
export RANLIB="${MINGW_TOOL_PREFIX}ranlib"
export STRIP="${MINGW_TOOL_PREFIX}strip"

export LDFLAGS="-L$GTK_PREFIX/lib $LDFLAGS"
export CPPFLAGS="-I$GTK_PREFIX/include $CPPFLAGS"
export CFLAGS="-I$GTK_PREFIX/include -mms-bitfields -march=i686 ${CFLAGS:-"-O2"}"
export CXXFLAGS="-I$GTK_PREFIX/include -mms-bitfields -march=i686 ${CXXFLAGS:-"-O2"}"
export OBJCFLAGS="-I$GTK_PREFIX/include -mms-bitfields -march=i686 ${OBJCFLAGS:-"-O2"}"

# Set up pkg-config invocation. Some broken packages do not use PKG_CONFIG macros
# to find pkg-config, so the script must be named 'pkg-config'. Hence it's put
# into a separate directory and the directory is pushed in front of PATH
mkdir -p fake-bin
write_pkg_config fake-bin/pkg-config
export PKG_CONFIG="`pwd`/fake-bin/pkg-config"
# Some stupid packages try to run stuff like 'gcc' and 'ld' even when cross-compiling, so
# cross-tools bin directory should better be in PATH. /usr/i586-mingw32msvc/bin and
# /usr/local/mingw32/bin are Debian's and FreeBSD's, add yours if needed.
export PATH=`pwd`/fake-bin:$MINGW_BIN:/usr/i586-mingw32msvc/bin:/usr/local/mingw32/bin:$PATH

TARGET=i586-pc-mingw32msvc
libs_flags="--enable-shared --disable-static"

# Now actually run configure. FOO=foo arguments *must* be there if you
# want automatic re-configuring (which happens if you modify configure.ac and
# run make) work.
# NOTE: --build *must* be here, it's autoconf bug (aka 'feature'), confirmed and
# *documented*.
echo sh $CONFIGURE --prefix=$GTK_PREFIX --build=`$CONFIG_GUESS` --host=$TARGET --target=$TARGET \
--enable-all-warnings --enable-maintainer-mode $libs_flags \
PKG_CONFIG="$PKG_CONFIG" GTK_PREFIX="$GTK_PREFIX" \
PYTHON_PREFIX="$PYTHON_PREFIX" PYTHON_HOME="$PYTHON_HOME" \
AR="$AR" RANLIB="$RANLIB" STRIP="$STRIP" AS="$AS" DLLTOOL="$DLLTOOL" \
OBJDUMP="$OBJDUMP" NM="$NM" WINDRES="$WINDRES" $@
exec sh $CONFIGURE --prefix=$GTK_PREFIX --build=`$CONFIG_GUESS` --host=$TARGET --target=$TARGET \
--enable-all-warnings --enable-maintainer-mode $libs_flags \
PKG_CONFIG="$PKG_CONFIG" GTK_PREFIX="$GTK_PREFIX" \
PYTHON_PREFIX="$PYTHON_PREFIX" PYTHON_HOME="$PYTHON_HOME" \
AR="$AR" RANLIB="$RANLIB" STRIP="$STRIP" AS="$AS" DLLTOOL="$DLLTOOL" \
OBJDUMP="$OBJDUMP" NM="$NM" WINDRES="$WINDRES" $@
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.