-export VCINSTALLDIR="$VSINSTALLDIR/VC"
-export VSCOMMONROOT="$VSINSTALLDIR/Common7"
-export VS_TOOLS_DIR="$VSCOMMONROOT/tools"
-export DevEnvDir="$VSCOMMONROOT/IDE"
-export MSVCDir="$VCINSTALLDIR"
-export FrameworkDir="$WINDIR/Microsoft.NET/Framework"
-export FrameworkVersion=v4.0.30319
-#old export FrameworkSDKDir="$VSINSTALLDIR/SDK/v2.0"
+function setup_visual_studio_variables()
+{
+ # we try to use the most recent compiler location, and work backwards as
+ # needed for the supported range (10 = vs 2010, 9 = vs 2008, 8 = vs 2005).
+ export VSxTOOLS="$VS100COMNTOOLS"
+ if [ -z "$VSxTOOLS" ]; then
+ export VSxTOOLS="$VS90COMNTOOLS"
+ if [ -z "$VSxTOOLS" ]; then
+ export VSxTOOLS="$VS80COMNTOOLS"
+ fi
+ fi
+
+ if [ -z "$VSxTOOLS" ]; then
+ return 33
+ fi
+ export VSxTOOLS="$(cygpath -w -s "$VSxTOOLS" | tr "A-Z" "a-z" | sed -e 's/\\/\//g' )"
+#| sed -e 's/^\(.\):/\/\1/' )"
+
+ export VIS_STU_ROOT="$(echo $VSxTOOLS | sed -e 's/^\(.*\)\/[^\/]*\/[^\/]*[\/]$/\1/' )"
+#| sed -e 's/^\(.\):/\/\1/' )"
+ export VSINSTALLDIR="$VIS_STU_ROOT"
+
+ export WINDIR="$(cygpath -w -s "$WINDIR" | tr A-Z a-z | sed -e 's/\\/\//g' )"
+#| sed -e 's/^\(.\):/\/\1/' )"
+
+ export VCINSTALLDIR="$VSINSTALLDIR/VC"
+ export VSCOMMONROOT="$VSINSTALLDIR/Common7"
+ export VS_TOOLS_DIR="$VSCOMMONROOT/tools"
+ export DevEnvDir="$VSCOMMONROOT/IDE"
+ export MSVCDir="$VCINSTALLDIR"
+ export FrameworkDir="$WINDIR/Microsoft.NET/Framework"
+ export FrameworkVersion=v4.0.30319
+ #old export FrameworkSDKDir="$VSINSTALLDIR/SDK/v2.0"
+
+ export PLATFORM_DIR="$VCINSTALLDIR/PlatformSDK"
+ if [ ! -d "$PLATFORM_DIR" ]; then