#!/bin/sh
# Preparation:
# . ./msvc.sh
# Make DLLs accessible:
# PATH=/usr/local/msvc/bin:$PATH
#
# Yes, the platform name is mingw32, see config.sub.
#
# The _WIN32_WINNT setting is needed so that the header files make only
# those functions visible that are present in the specified Windows version,
# not also those present in newer Windows versions. Cf.
# "Modifying WINVER and _WIN32_WINNT"
# <http://msdn.microsoft.com/en-us/library/6sehtctf.aspx>
# and "Using the Windows Headers"
# <http://msdn.microsoft.com/en-us/library/aa383745%28v=vs.85%29.aspx>
# With _WIN32_WINNT_VISTA or newer, <winsock2.h> is not self-contained.
#
# CFLAGS="-MD" leads to problems, e.g. in _get_osfhandle call
# But without -MD, &errno in a shared lib and &errno in main() are different!
#
win32_target=_WIN32_WINNT_WINXP # 0x0501
#win32_target=_WIN32_WINNT_VISTA # 0x0600
#win32_target=_WIN32_WINNT_WIN7  # 0x0601
./configure --host=i586-pc-mingw32 --prefix=/usr/local/msvc \
            CC="$HOME/msvc/compile cl -nologo" \
            CFLAGS="-MD" \
            CXX="$HOME/msvc/compile cl -nologo" \
            CXXFLAGS="-MD" \
            CPPFLAGS="-D_WIN32_WINNT=$win32_target -I/usr/local/msvc/include" \
            LDFLAGS="-L/usr/local/msvc/lib" \
            LD="link" \
            NM="dumpbin -symbols" \
            STRIP=":" \
            AR="$HOME/msvc/ar-lib lib" \
            RANLIB=":" \
            "$@"
