if [ -z "$VSHOME" ] ; then
    for KEY in \
        "Microsoft/VisualStudio/10.0/Setup/VS/ProductDir" \
        "Wow6432Node/Microsoft/VisualStudio/10.0/Setup/VS/ProductDir" \
        "Microsoft/VisualStudio/9.0/Setup/VS/ProductDir" \
        "Wow6432Node/Microsoft/VisualStudio/9.0/Setup/VS/ProductDir"
    do
        KEY="/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/$KEY"
        if [ -e "$KEY" ] ; then
            KEY="`cat "$KEY"`"
            KEY="`cygpath -u "$KEY"`"
            if [ -d "$KEY" ] ; then
                VSHOME="$KEY"
                break
            fi
        fi
    done
    if [ -z "$VSHOME" ] ; then
        for VAR in VS100COMNTOOLS VS90COMNTOOLS
        do
            DIR="${!VAR}"
            if [ ! -z "$DIR" ] ; then
                DIR="`cygpath -u "$DIR"`"
                if [ -d "$DIR" ] ; then
                    VSHOME="$DIR/../.."
                    break
                fi
            fi
        done
        if [ -z "$VSHOME" ] ; then
            for DIR in \
                "/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 10.0" \
                "/cygdrive/c/Program Files/Microsoft Visual Studio 10.0" \
                "/cygdrive/c/Program Files (x86)/Microsoft Visual Studio 9.0" \
                "/cygdrive/c/Program Files/Microsoft Visual Studio 9.0"
            do
                if [ -d "$DIR" ] ; then
                    VSHOME="$DIR"
                    break
                fi
            done
        fi
    fi
fi

if [ ! -d "$VSHOME" ] ; then
    echo Invalid VSHOME - Microsoft Visual Studio directory name
    exit 1
fi

if [ -z "$WINSDK" ] ; then
    for KEY in \
        "Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder" \
        "Wow6432Node/Microsoft/Microsoft SDKs/Windows/CurrentInstallFolder"
    do
        KEY="/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/$KEY"
        if [ -e "$KEY" ] ; then
            KEY="`cat "$KEY"`"
            KEY="`cygpath -u "$KEY"`"
            if [ -d "$KEY" ] ; then
                WINSDK="$KEY"
                break
            fi
        fi
    done
    if [ -z "$WINSDK" ] ; then
        for DIR in \
            "/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v7.1" \
            "/cygdrive/c/Program Files/Microsoft SDKs/Windows/v7.1" \
            "/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v7.0A" \
            "/cygdrive/c/Program Files/Microsoft SDKs/Windows/v7.0A" \
            "/cygdrive/c/Program Files/Microsoft SDKs/Windows/v6.1" \
            "/cygdrive/c/Program Files/Microsoft SDKs/Windows/v6.0A"
        do
            if [ -d "$DIR" ] ; then
                WINSDK="$DIR"
                break
            fi
        done
    fi
fi

if [ ! -d "$WINSDK" ] ; then
    echo Invalid WINSDK - Microsoft SDK directory name
    exit 1
fi

export WindowsSdkDir=$(cygpath -am "$WINSDK/")
export VSINSTALLDIR=$(cygpath -am "$VSHOME")
export VCINSTALLDIR="$VSINSTALLDIR/VC"
export DevEnvDir="$VSINSTALLDIR/Common7/IDE"
export FrameworkDir=Framework32
export LIB="$VSINSTALLDIR/VC/lib"\;"$WindowsSdkDir/Lib"
export INCLUDE="$VSINSTALLDIR/VC/include"\;"$WindowsSdkDir/Include"
export PATH="$VSHOME/Common7/IDE:$VSHOME/VC/bin:$VSHOME/Common7/Tools:$VSHOME/VC/VCPackages:$PATH"

unset MAKEFLAGS
unset MAKELEVEL
unset MAKEOVERRIDES



