]>
Commit | Line | Data |
---|---|---|
dce7d295 JH |
1 | @ECHO OFF |
2 | REM ================================================================ | |
3 | REM You can use either GCC (the default) or MSVC to build git | |
4 | REM using the GIT-SDK command line tools. | |
5 | REM $ make | |
6 | REM $ make MSVC=1 | |
7 | REM | |
8 | REM GIT-SDK BASH windows inherit environment variables with all of | |
9 | REM the bin/lib/include paths for GCC. It DOES NOT inherit values | |
10 | REM for the corresponding MSVC tools. | |
11 | REM | |
12 | REM During normal (non-git) Windows development, you launch one | |
13 | REM of the provided "developer command prompts" to set environment | |
14 | REM variables for the MSVC tools. | |
15 | REM | |
16 | REM Therefore, to allow MSVC command line builds of git from BASH | |
17 | REM and MAKE, we must blend these two different worlds. This script | |
18 | REM attempts to do that. | |
19 | REM ================================================================ | |
20 | REM This BAT file starts in a plain (non-developer) command prompt, | |
15beaaa3 | 21 | REM searches for the "best" command prompt setup script, installs |
dce7d295 JH |
22 | REM it into the current CMD process, and exports the various MSVC |
23 | REM environment variables for use by MAKE. | |
24 | REM | |
25 | REM The output of this script should be written to a make "include | |
26 | REM file" and referenced by the top-level Makefile. | |
27 | REM | |
28 | REM See "config.mak.uname" (look for compat/vcbuild/MSVC-DEFS-GEN). | |
29 | REM ================================================================ | |
30 | REM The provided command prompts are custom to each VS release and | |
31 | REM filled with lots of internal knowledge (such as Registry settings); | |
32 | REM even their names vary by release, so it is not appropriate for us | |
33 | REM to look inside them. Rather, just run them in a subordinate | |
34 | REM process and extract the settings we need. | |
35 | REM ================================================================ | |
36 | REM | |
37 | REM Current (VS2017 and beyond) | |
38 | REM ------------------- | |
39 | REM Visual Studio 2017 introduced a new installation layout and | |
40 | REM support for side-by-side installation of multiple versions of | |
41 | REM VS2017. Furthermore, these can all coexist with installations | |
42 | REM of previous versions of VS (which have a completely different | |
43 | REM layout on disk). | |
44 | REM | |
45 | REM VS2017 Update 2 introduced a "vswhere.exe" command: | |
46 | REM https://github.com/Microsoft/vswhere | |
47 | REM https://blogs.msdn.microsoft.com/heaths/2017/02/25/vswhere-available/ | |
48 | REM https://blogs.msdn.microsoft.com/vcblog/2017/03/06/finding-the-visual-c-compiler-tools-in-visual-studio-2017/ | |
49 | REM | |
50 | REM VS2015 | |
51 | REM ------ | |
52 | REM Visual Studio 2015 uses the traditional VcVarsAll. | |
53 | REM | |
54 | REM Earlier Versions | |
55 | REM ---------------- | |
56 | REM Currently unsupported. | |
57 | REM | |
58 | REM ================================================================ | |
59 | REM Note: Throughout this script we use "dir <path> && <cmd>" rather | |
60 | REM than "if exist <path>" because of script problems with pathnames | |
61 | REM containing spaces. | |
62 | REM ================================================================ | |
63 | ||
64 | REM Sanitize PATH to prevent git-sdk paths from confusing "wmic.exe" | |
65 | REM (called internally in some of the system BAT files). | |
66 | SET PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; | |
67 | ||
68 | REM ================================================================ | |
69 | ||
70 | :current | |
71 | SET vs_where=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe | |
72 | dir "%vs_where%" >nul 2>nul && GOTO have_vs_where | |
73 | GOTO not_2017 | |
74 | ||
75 | :have_vs_where | |
76 | REM Try to use VsWhere to get the location of VsDevCmd. | |
77 | ||
78 | REM Keep VsDevCmd from cd'ing away. | |
79 | SET VSCMD_START_DIR=. | |
80 | ||
81 | REM Get the root of the VS product installation. | |
82 | FOR /F "usebackq tokens=*" %%i IN (`"%vs_where%" -latest -requires Microsoft.VisualStudio.Workload.NativeDesktop -property installationPath`) DO @SET vs_ip=%%i | |
83 | ||
84 | SET vs_devcmd=%vs_ip%\Common7\Tools\VsDevCmd.bat | |
85 | dir "%vs_devcmd%" >nul 2>nul && GOTO have_vs_devcmd | |
86 | GOTO not_2017 | |
87 | ||
88 | :have_vs_devcmd | |
89 | REM Use VsDevCmd to setup the environment of this process. | |
90 | REM Setup CL for building 64-bit apps using 64-bit tools. | |
91 | @call "%vs_devcmd%" -no_logo -arch=x64 -host_arch=x64 | |
92 | ||
93 | SET tgt=%VSCMD_ARG_TGT_ARCH% | |
94 | ||
95 | SET mn=%VCToolsInstallDir% | |
96 | SET msvc_includes=-I"%mn%INCLUDE" | |
97 | SET msvc_libs=-L"%mn%lib\%tgt%" | |
98 | SET msvc_bin_dir=%mn%bin\Host%VSCMD_ARG_HOST_ARCH%\%tgt% | |
99 | ||
100 | SET sdk_dir=%WindowsSdkDir% | |
101 | SET sdk_ver=%WindowsSDKVersion% | |
102 | SET si=%sdk_dir%Include\%sdk_ver% | |
103 | SET sdk_includes=-I"%si%ucrt" -I"%si%um" -I"%si%shared" | |
104 | SET sl=%sdk_dir%lib\%sdk_ver% | |
105 | SET sdk_libs=-L"%sl%ucrt\%tgt%" -L"%sl%um\%tgt%" | |
106 | ||
107 | SET vs_ver=%VisualStudioVersion% | |
108 | ||
109 | GOTO print_vars | |
110 | ||
111 | REM ================================================================ | |
112 | ||
113 | :not_2017 | |
114 | REM See if VS2015 is installed. | |
115 | ||
116 | SET vs_2015_bat=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat | |
117 | dir "%vs_2015_bat%" >nul 2>nul && GOTO have_vs_2015 | |
118 | GOTO not_2015 | |
119 | ||
120 | :have_vs_2015 | |
121 | REM Use VcVarsAll like the "x64 Native" command prompt. | |
122 | REM Setup CL for building 64-bit apps using 64-bit tools. | |
123 | @call "%vs_2015_bat%" amd64 | |
124 | ||
125 | REM Note that in VS2015 they use "x64" in some contexts and "amd64" in others. | |
126 | SET mn=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ | |
127 | SET msvc_includes=-I"%mn%INCLUDE" | |
128 | SET msvc_libs=-L"%mn%lib\amd64" | |
129 | SET msvc_bin_dir=%mn%bin\amd64 | |
130 | ||
131 | SET sdk_dir=%WindowsSdkDir% | |
132 | SET sdk_ver=%WindowsSDKVersion% | |
133 | SET si=%sdk_dir%Include\%sdk_ver% | |
134 | SET sdk_includes=-I"%si%ucrt" -I"%si%um" -I"%si%shared" -I"%si%winrt" | |
135 | SET sl=%sdk_dir%lib\%sdk_ver% | |
136 | SET sdk_libs=-L"%sl%ucrt\x64" -L"%sl%um\x64" | |
137 | ||
138 | SET vs_ver=%VisualStudioVersion% | |
139 | ||
140 | GOTO print_vars | |
141 | ||
142 | REM ================================================================ | |
143 | ||
144 | :not_2015 | |
145 | echo "ERROR: unsupported VS version (older than VS2015)" >&2 | |
146 | EXIT /B 1 | |
147 | ||
148 | REM ================================================================ | |
149 | ||
150 | :print_vars | |
151 | REM Dump the essential vars to stdout to allow the main | |
152 | REM Makefile to include it. See config.mak.uname. | |
153 | REM Include DOS-style and BASH-style path for bin dir. | |
154 | ||
155 | echo msvc_bin_dir=%msvc_bin_dir% | |
156 | SET X1=%msvc_bin_dir:C:=/C% | |
157 | SET X2=%X1:\=/% | |
158 | echo msvc_bin_dir_msys=%X2% | |
159 | ||
160 | echo msvc_includes=%msvc_includes% | |
161 | echo msvc_libs=%msvc_libs% | |
162 | ||
163 | echo sdk_includes=%sdk_includes% | |
164 | echo sdk_libs=%sdk_libs% | |
165 | ||
166 | echo vs_ver=%vs_ver% | |
167 | ||
168 | EXIT /B 0 |