From fb13870f871d6961572a4ee5c063fdd02c4347e9 Mon Sep 17 00:00:00 2001
From: Evan Lloyd <evan.lloyd@arm.com>
Date: Fri, 17 Jan 2014 19:06:39 +0000
Subject: [PATCH 4/4] BaseTools: Add the latests versions of Visual Studio to
 build

Both edksetup.bat and BaseTools/toolsetup.bat had chunks of code to
identify the version of Visual Studio from the environment.
They both needed updating to allow for more recent versions.
To simplify future maintenance a common .bat file is added and
used by both.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
---
 BaseTools/get_vsvars.bat | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 BaseTools/toolsetup.bat  | 29 +++++++----------------------
 edksetup.bat             | 37 +++++++++----------------------------
 3 files changed, 62 insertions(+), 50 deletions(-)
 create mode 100755 BaseTools/get_vsvars.bat

diff --git a/BaseTools/get_vsvars.bat b/BaseTools/get_vsvars.bat
new file mode 100755
index 0000000..b67a81d
--- /dev/null
+++ b/BaseTools/get_vsvars.bat
@@ -0,0 +1,46 @@
+@REM @file
+@REM   Windows batch file to find the Visual Studio set up script
+@REM
+@REM Copyright (c) 2013-2014, ARM Limited. All rights reserved.
+
+@REM This program and the accompanying materials
+@REM are licensed and made available under the terms and conditions of the BSD License
+@REM which accompanies this distribution.  The full text of the license may be found at
+@REM http://opensource.org/licenses/bsd-license.php
+@REM
+@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+@REM
+
+
+@echo off
+goto  :main
+
+:read_vsvars
+@rem Do nothing if already found, otherwise call vsvars32.bat if there
+if defined VCINSTALLDIR goto :EOF
+  set GET_VSVARS_BAT_CHECK_DIR=%*
+  set GET_VSVARS_BAT_CHECK_DIR=%GET_VSVARS_BAT_CHECK_DIR:"=%
+  if exist  "%GET_VSVARS_BAT_CHECK_DIR%\vsvars32.bat"  call "%GET_VSVARS_BAT_CHECK_DIR%\vsvars32.bat"
+:vsvars_done
+goto :EOF
+
+
+REM NOTE: This file will find the most recent Visual Studio installation
+REM       apparent from the environment.
+REM       To use an older version, modify your environment set up.
+REM       (Or invoke the relevant vsvars32 file beforehand).
+
+:main
+if defined VCINSTALLDIR goto :done
+  if defined VS140COMNTOOLS  call :read_vsvars  "%VS140COMNTOOLS%"
+  if defined VS130COMNTOOLS  call :read_vsvars  "%VS130COMNTOOLS%"
+  if defined VS120COMNTOOLS  call :read_vsvars  "%VS120COMNTOOLS%"
+  if defined VS110COMNTOOLS  call :read_vsvars  "%VS110COMNTOOLS%"
+  if defined VS100COMNTOOLS  call :read_vsvars  "%VS100COMNTOOLS%"
+  if defined VS90COMNTOOLS   call :read_vsvars  "%VS90COMNTOOLS%"
+  if defined VS80COMNTOOLS   call :read_vsvars  "%VS80COMNTOOLS%"
+  if defined VS71COMNTOOLS   call :read_vsvars  "%VS71COMNTOOLS%"
+
+:done
+set GET_VSVARS_BAT_CHECK_DIR=
diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 71c3811..2afa810 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -292,31 +292,16 @@ goto end
   echo PYTHON_FREEZER_PATH = %PYTHON_FREEZER_PATH%
   echo.
 
-  if defined VCINSTALLDIR goto VisualStudioAvailable
-  if defined VS100COMNTOOLS (
-    call "%VS100COMNTOOLS%\vsvars32.bat"
-  ) else (
-    if defined VS90COMNTOOLS (
-      call "%VS90COMNTOOLS%\vsvars32.bat"
-    ) else (
-      if defined VS80COMNTOOLS (
-        call "%VS80COMNTOOLS%\vsvars32.bat"
-      ) else (
-        if defined VS71COMNTOOLS (
-          call "%VS71COMNTOOLS%\vsvars32.bat"
-        ) else (
-          echo.
-          echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!
-          echo.
-          goto end
-        )
-      )
-    )
+  call "%EDK_TOOLS_PATH%\get_vsvars.bat"
+  if not defined VCINSTALLDIR (
+    @echo.
+    @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!
+    @echo.
+    goto end
   )
 
 :VisualStudioAvailable
-  if defined FORCE_REBUILD goto CleanAndBuild
-  goto IncrementalBuild
+  if not defined FORCE_REBUILD goto IncrementalBuild
 
 :CleanAndBuild
   pushd .
diff --git a/edksetup.bat b/edksetup.bat
index ba775ce..5b68475 100755
--- a/edksetup.bat
+++ b/edksetup.bat
@@ -25,10 +25,9 @@
 @echo off
 
 @REM
-@REM Set the WORKSPACE to the current working directory
+@REM Set the WORKSPACE to the directory of this file
 @REM
-pushd .
-cd %~dp0
+pushd  %~dp0
 
 if not defined WORKSPACE (
   goto SetWorkSpace
@@ -54,43 +53,25 @@ if /I "%1"=="/h" goto Usage
 if /I "%1"=="/?" goto Usage
 if /I "%1"=="/help" goto Usage
 
+if not defined EDK_TOOLS_PATH set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools
+IF NOT EXIST "%EDK_TOOLS_PATH%\toolsetup.bat" goto BadBaseTools
+
 if /I not "%1"=="--nt32" goto no_nt32
 
 @REM Flag, --nt32 is set
 @REM The Nt32 Emluation Platform requires Microsoft Libraries
 @REM and headers to interface with Windows.
 
+call "%EDK_TOOLS_PATH%\get_vsvars.bat"
 if not defined VCINSTALLDIR (
-  if defined VS110COMNTOOLS (
-    call "%VS110COMNTOOLS%\vsvars32.bat"
-  ) else (
-    if defined VS100COMNTOOLS (
-      call "%VS100COMNTOOLS%\vsvars32.bat"
-    ) else (
-      if defined VS90COMNTOOLS (
-        call "%VS90COMNTOOLS%\vsvars32.bat"
-      ) else (
-        if defined VS80COMNTOOLS (
-          call "%VS80COMNTOOLS%\vsvars32.bat"
-        ) else (
-          if defined VS71COMNTOOLS (
-            call "%VS71COMNTOOLS%\vsvars32.bat"
-          ) else (
-            echo.
-            echo !!! WARNING !!! Cannot find Visual Studio !!!
-            echo.
-          )
-        )
-      )
-    )
-  )
+  @echo.
+  @echo !!! WARNING !!! Cannot find Visual Studio !!!
+  @echo.
 )
 shift
 
 :no_nt32
 if /I "%1"=="NewBuild" shift
-if not defined EDK_TOOLS_PATH set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools
-IF NOT EXIST "%EDK_TOOLS_PATH%\toolsetup.bat" goto BadBaseTools
 call %EDK_TOOLS_PATH%\toolsetup.bat %*
 if /I "%1"=="Reconfig" shift
 goto check_cygwin
-- 
1.8.5

