Fossil SCM

fossil-scm / win / buildmsvc.bat
Blame History Raw 414 lines
1
@ECHO OFF
2
3
::
4
:: buildmsvc.bat --
5
::
6
:: This batch file attempts to build Fossil using the latest version of
7
:: Microsoft Visual Studio installed on this machine.
8
::
9
:: For VS 2017 and later, it uses the x64 build tools by default;
10
:: pass "x86" as the first argument to use the x86 tools.
11
::
12
13
SETLOCAL
14
15
REM SET __ECHO=ECHO
16
REM SET __ECHO2=ECHO
17
IF NOT DEFINED _AECHO (SET _AECHO=REM)
18
IF NOT DEFINED _CECHO (SET _CECHO=REM)
19
IF NOT DEFINED _VECHO (SET _VECHO=REM)
20
21
REM
22
REM NOTE: Setup local environment variables that point to the root directory
23
REM of the Fossil source checkout and to the directory containing this
24
REM build tool.
25
REM
26
SET ROOT=%~dp0\..
27
SET ROOT=%ROOT:\\=\%
28
29
%_VECHO% Root = '%ROOT%'
30
31
SET TOOLS=%~dp0
32
SET TOOLS=%TOOLS:~0,-1%
33
34
%_VECHO% Tools = '%TOOLS%'
35
36
REM
37
REM Visual C++ ????
38
REM
39
IF DEFINED VCINSTALLDIR IF EXIST "%VCINSTALLDIR%" (
40
%_AECHO% Build environment appears to be set up.
41
GOTO skip_setupVisualStudio
42
)
43
44
REM
45
REM Visual Studio ????
46
REM
47
IF DEFINED VSVARS32 IF EXIST "%VSVARS32%" (
48
%_AECHO% Build environment batch file manually overridden to "%VSVARS32%"...
49
GOTO skip_detectVisualStudio
50
)
51
52
REM
53
REM Visual Studio 2017 / 2019 / 2022
54
REM
55
CALL :fn_TryUseVsWhereExe
56
IF NOT DEFINED VSWHEREINSTALLDIR GOTO skip_detectVisualStudio2017
57
SET VSVARS32=%VSWHEREINSTALLDIR%\VC\Auxiliary\Build\vcvars64.bat
58
IF "%~1" == "x86" (
59
SET VSVARS32=%VSWHEREINSTALLDIR%\VC\Auxiliary\Build\vcvars32.bat
60
)
61
IF EXIST "%VSVARS32%" (
62
%_AECHO% Using Visual Studio 2017 / 2019 / 2022...
63
GOTO skip_detectVisualStudio
64
)
65
:skip_detectVisualStudio2017
66
67
REM
68
REM Visual Studio 2015
69
REM
70
IF NOT DEFINED VS140COMNTOOLS GOTO skip_detectVisualStudio2015
71
SET VSVARS32=%VS140COMNTOOLS%\vsvars32.bat
72
IF EXIST "%VSVARS32%" (
73
%_AECHO% Using Visual Studio 2015...
74
GOTO skip_detectVisualStudio
75
)
76
:skip_detectVisualStudio2015
77
78
REM
79
REM Visual Studio 2013
80
REM
81
IF NOT DEFINED VS120COMNTOOLS GOTO skip_detectVisualStudio2013
82
SET VSVARS32=%VS120COMNTOOLS%\vsvars32.bat
83
IF EXIST "%VSVARS32%" (
84
%_AECHO% Using Visual Studio 2013...
85
GOTO skip_detectVisualStudio
86
)
87
:skip_detectVisualStudio2013
88
89
REM
90
REM Visual Studio 2012
91
REM
92
IF NOT DEFINED VS110COMNTOOLS GOTO skip_detectVisualStudio2012
93
SET VSVARS32=%VS110COMNTOOLS%\vsvars32.bat
94
IF EXIST "%VSVARS32%" (
95
%_AECHO% Using Visual Studio 2012...
96
GOTO skip_detectVisualStudio
97
)
98
:skip_detectVisualStudio2012
99
100
REM
101
REM Visual Studio 2010
102
REM
103
IF NOT DEFINED VS100COMNTOOLS GOTO skip_detectVisualStudio2010
104
SET VSVARS32=%VS100COMNTOOLS%\vsvars32.bat
105
IF EXIST "%VSVARS32%" (
106
%_AECHO% Using Visual Studio 2010...
107
GOTO skip_detectVisualStudio
108
)
109
:skip_detectVisualStudio2010
110
111
REM
112
REM Visual Studio 2008
113
REM
114
IF NOT DEFINED VS90COMNTOOLS GOTO skip_detectVisualStudio2008
115
SET VSVARS32=%VS90COMNTOOLS%\vsvars32.bat
116
IF EXIST "%VSVARS32%" (
117
%_AECHO% Using Visual Studio 2008...
118
GOTO skip_detectVisualStudio
119
)
120
:skip_detectVisualStudio2008
121
122
REM
123
REM Visual Studio 2005
124
REM
125
IF NOT DEFINED VS80COMNTOOLS GOTO skip_detectVisualStudio2005
126
SET VSVARS32=%VS80COMNTOOLS%\vsvars32.bat
127
IF EXIST "%VSVARS32%" (
128
%_AECHO% Using Visual Studio 2005...
129
GOTO skip_detectVisualStudio
130
)
131
:skip_detectVisualStudio2005
132
133
REM
134
REM Visual Studio 2003
135
REM
136
IF NOT DEFINED VS71COMNTOOLS GOTO skip_detectVisualStudio2003
137
SET VSVARS32=%VS71COMNTOOLS%\vsvars32.bat
138
IF EXIST "%VSVARS32%" (
139
%_AECHO% Using Visual Studio 2003...
140
GOTO skip_detectVisualStudio
141
)
142
:skip_detectVisualStudio2003
143
144
REM
145
REM Visual Studio 2002
146
REM
147
IF NOT DEFINED VS70COMNTOOLS GOTO skip_detectVisualStudio2002
148
SET VSVARS32=%VS70COMNTOOLS%\vsvars32.bat
149
IF EXIST "%VSVARS32%" (
150
%_AECHO% Using Visual Studio 2002...
151
GOTO skip_detectVisualStudio
152
)
153
:skip_detectVisualStudio2002
154
155
REM
156
REM NOTE: If we get to this point, no Visual Studio build environment batch
157
REM files were found.
158
REM
159
ECHO No Visual Studio build environment batch files were found.
160
GOTO errors
161
162
REM
163
REM NOTE: At this point, the appropriate Visual Studio version should be
164
REM selected.
165
REM
166
:skip_detectVisualStudio
167
168
REM
169
REM NOTE: Remove any double-backslash sequences that may be present in the
170
REM selected Visual Studio common tools path. This is not strictly
171
REM necessary; however, it makes reading the output easier.
172
REM
173
SET VSVARS32=%VSVARS32:\\=\%
174
175
%_VECHO% VsVars32 = '%VSVARS32%'
176
177
REM
178
REM NOTE: After this point, a clean ERRORLEVEL is required; therefore, make
179
REM sure it is reset now.
180
REM
181
CALL :fn_ResetErrorLevel
182
183
REM
184
REM NOTE: Attempt to call the selected batch file to setup the environment
185
REM variables for building with MSVC.
186
REM
187
%__ECHO3% CALL "%VSVARS32%"
188
189
IF ERRORLEVEL 1 (
190
ECHO Visual Studio build environment batch file "%VSVARS32%" failed.
191
GOTO errors
192
)
193
194
REM
195
REM NOTE: After this point, the environment should already be setup for
196
REM building with MSVC.
197
REM
198
:skip_setupVisualStudio
199
200
%_VECHO% VcInstallDir = '%VCINSTALLDIR%'
201
202
REM
203
REM NOTE: Attempt to create the build output directory, if necessary.
204
REM In order to build using the current directory as the build
205
REM output directory, use the following command before executing
206
REM this tool:
207
REM
208
REM SET BUILDDIR=%CD%
209
REM
210
IF DEFINED BUILDDIR (
211
IF DEFINED BUILDSUFFIX (
212
CALL :fn_FindVarInVar BUILDSUFFIX BUILDDIR
213
214
IF ERRORLEVEL 1 (
215
REM
216
REM NOTE: The build suffix is already present, do nothing.
217
REM
218
) ELSE (
219
REM
220
REM NOTE: The build suffix is not present, add it now.
221
REM
222
SET BUILDDIR=%BUILDDIR%%BUILDSUFFIX%
223
)
224
225
CALL :fn_ResetErrorLevel
226
)
227
) ELSE (
228
REM
229
REM NOTE: By default, when BUILDDIR is unset, build in the "msvcbld"
230
REM sub-directory relative to the root of the source checkout.
231
REM This retains backward compatibility with third-party build
232
REM scripts, etc,
233
REM
234
SET BUILDDIR=%ROOT%\msvcbld%BUILDSUFFIX%
235
)
236
237
%_VECHO% BuildSuffix = '%BUILDSUFFIX%'
238
%_VECHO% BuildDir = '%BUILDDIR%'
239
240
IF NOT EXIST "%BUILDDIR%" (
241
%__ECHO% MKDIR "%BUILDDIR%"
242
243
IF ERRORLEVEL 1 (
244
ECHO Could not make directory "%BUILDDIR%".
245
GOTO errors
246
)
247
)
248
249
REM
250
REM NOTE: Attempt to change to the created build output directory so that
251
REM the generated files will be placed there, if needed.
252
REM
253
%__ECHO2% PUSHD "%BUILDDIR%"
254
255
IF ERRORLEVEL 1 (
256
ECHO Could not change to directory "%BUILDDIR%".
257
GOTO errors
258
)
259
260
SET NEED_POPD=1
261
262
REM
263
REM NOTE: If requested, setup the build environment to refer to the Windows
264
REM SDK v7.1A, which is required if the binaries are being built with
265
REM Visual Studio 201x and need to work on Windows XP.
266
REM
267
IF DEFINED USE_V110SDK71A (
268
%_AECHO% Forcing use of the Windows SDK v7.1A...
269
CALL :fn_UseV110Sdk71A
270
)
271
272
%_VECHO% Path = '%PATH%'
273
%_VECHO% Include = '%INCLUDE%'
274
%_VECHO% Lib = '%LIB%'
275
%_VECHO% Tools = '%TOOLS%'
276
%_VECHO% Root = '%ROOT%'
277
%_VECHO% NmakeArgs = '%NMAKE_ARGS%'
278
279
REM
280
REM NOTE: Attempt to execute NMAKE for the Fossil MSVC makefile, passing
281
REM anything extra from our command line along (e.g. extra options).
282
REM Also, pass the base directory of the Fossil source tree as this
283
REM allows an out-of-source-tree build.
284
REM
285
%__ECHO% nmake /f "%TOOLS%\Makefile.msc" B="%ROOT%" %NMAKE_ARGS% %*
286
287
IF ERRORLEVEL 1 (
288
GOTO errors
289
)
290
291
REM
292
REM NOTE: Attempt to restore the previously saved directory, if needed.
293
REM
294
IF DEFINED NEED_POPD (
295
%__ECHO2% POPD
296
297
IF ERRORLEVEL 1 (
298
ECHO Could not restore directory.
299
GOTO errors
300
)
301
302
CALL :fn_UnsetVariable NEED_POPD
303
)
304
305
GOTO no_errors
306
307
:fn_UseV110Sdk71A
308
IF "%PROCESSOR_ARCHITECTURE%" == "x86" GOTO set_v110Sdk71A_x86
309
SET PFILES_SDK71A=%ProgramFiles(x86)%
310
GOTO set_v110Sdk71A_done
311
:set_v110Sdk71A_x86
312
SET PFILES_SDK71A=%ProgramFiles%
313
:set_v110Sdk71A_done
314
SET PATH=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Bin;%PATH%
315
SET INCLUDE=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Include;%INCLUDE%
316
IF "%PLATFORM%" == "x64" GOTO set_v110Sdk71A_lib_x64
317
SET LIB=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Lib;%LIB%
318
GOTO set_v110Sdk71A_lib_done
319
:set_v110Sdk71A_lib_x64
320
SET LIB=%PFILES_SDK71A%\Microsoft SDKs\Windows\7.1A\Lib\x64;%LIB%
321
:set_v110Sdk71A_lib_done
322
CALL :fn_UnsetVariable PFILES_SDK71A
323
SET NMAKE_ARGS=%NMAKE_ARGS% FOSSIL_ENABLE_WINXP=1
324
GOTO :EOF
325
326
:fn_FindVarInVar
327
IF NOT DEFINED %1 GOTO :EOF
328
IF NOT DEFINED %2 GOTO :EOF
329
SETLOCAL
330
CALL :fn_UnsetVariable VALUE
331
SET __ECHO_CMD=ECHO %%%2%% ^^^| FIND /I "%%%1%%"
332
FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
333
SET VALUE=%%V
334
)
335
IF DEFINED VALUE (
336
CALL :fn_SetErrorLevel
337
) ELSE (
338
CALL :fn_ResetErrorLevel
339
)
340
ENDLOCAL
341
GOTO :EOF
342
343
:fn_UnsetVariable
344
SETLOCAL
345
SET VALUE=%1
346
IF DEFINED VALUE (
347
SET VALUE=
348
ENDLOCAL
349
SET %VALUE%=
350
) ELSE (
351
ENDLOCAL
352
)
353
CALL :fn_ResetErrorLevel
354
GOTO :EOF
355
356
:fn_ResetErrorLevel
357
VERIFY > NUL
358
GOTO :EOF
359
360
:fn_SetErrorLevel
361
VERIFY MAYBE 2> NUL
362
GOTO :EOF
363
364
:fn_TryUseVsWhereExe
365
IF DEFINED VSWHERE_EXE GOTO skip_setVsWhereExe
366
SET VSWHERE_EXE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
367
IF NOT EXIST "%VSWHERE_EXE%" SET VSWHERE_EXE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe
368
:skip_setVsWhereExe
369
IF NOT EXIST "%VSWHERE_EXE%" (
370
%_AECHO% The "VsWhere" tool does not appear to be installed.
371
GOTO :EOF
372
)
373
SET VS_WHEREIS_CMD="%VSWHERE_EXE%" -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -latest
374
IF DEFINED __ECHO (
375
%__ECHO% %VS_WHEREIS_CMD%
376
REM
377
REM NOTE: This will not be executed, any reasonable fake path will work.
378
REM
379
SET VSWHEREINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2017\Community
380
GOTO skip_setVsWhereInstallDir
381
)
382
FOR /F "delims=" %%D IN ('%VS_WHEREIS_CMD%') DO (SET VSWHEREINSTALLDIR=%%D)
383
:skip_setVsWhereInstallDir
384
%_VECHO% VsWhereInstallDir = '%VSWHEREINSTALLDIR%'
385
IF NOT DEFINED VSWHEREINSTALLDIR (
386
%_AECHO% Visual Studio 2017 / 2019 / 2022 is not installed.
387
GOTO :EOF
388
)
389
%_AECHO% Visual Studio 2017 / 2019 / 2022 is installed.
390
GOTO :EOF
391
392
:usage
393
ECHO.
394
ECHO Usage: %~nx0 [...]
395
ECHO.
396
GOTO errors
397
398
:errors
399
CALL :fn_SetErrorLevel
400
ENDLOCAL
401
ECHO.
402
ECHO Build failure, errors were encountered.
403
GOTO end_of_file
404
405
:no_errors
406
CALL :fn_ResetErrorLevel
407
ENDLOCAL
408
ECHO.
409
ECHO Build success, no errors were encountered.
410
GOTO end_of_file
411
412
:end_of_file
413
%__ECHO% EXIT /B %ERRORLEVEL%
414

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button