Enhance the command-line completion extension to return the names of
[sqlite.git] / tool / build-all-msvc.bat
blobaaeb67bdfb98df1ad7730dc161d289fd7f29014d
1 @ECHO OFF\r
2 \r
3 ::\r
4 :: build-all-msvc.bat --\r
5 ::\r
6 :: Multi-Platform Build Tool for MSVC\r
7 ::\r
8 \r
9 REM\r
10 REM This batch script is used to build the SQLite DLL for multiple platforms\r
11 REM and configurations using MSVC.  The built SQLite DLLs, their associated\r
12 REM import libraries, and optionally their symbols files, are placed within\r
13 REM the directory specified on the command line, in sub-directories named for\r
14 REM their respective platforms and configurations.  This batch script must be\r
15 REM run from inside a Visual Studio Command Prompt for the desired version of\r
16 REM Visual Studio ^(the initial platform configured for the command prompt does\r
17 REM not really matter^).  Exactly one command line argument is required, the\r
18 REM name of an existing directory to be used as the final destination directory\r
19 REM for the generated output files, which will be placed in sub-directories\r
20 REM created therein.  Ideally, the directory specified should be empty.\r
21 REM\r
22 REM Example:\r
23 REM\r
24 REM                        CD /D C:\dev\sqlite\core\r
25 REM                        CALL tool\build-all-msvc.bat C:\Temp\r
26 REM\r
27 REM In the example above, "C:\dev\sqlite\core" represents the root of the\r
28 REM source tree for SQLite and "C:\Temp" represents the final destination\r
29 REM directory for the generated output files.\r
30 REM\r
31 REM Please note that the SQLite build process performed by the Makefile\r
32 REM associated with this batch script requires a Tcl shell to be present\r
33 REM in a directory contained in the PATH environment variable unless a\r
34 REM pre-existing amalgamation file is used.\r
35 REM\r
36 REM There are several environment variables that may be set to modify the\r
37 REM behavior of this batch script and its associated Makefile.  The list of\r
38 REM platforms to build may be overriden by using the PLATFORMS environment\r
39 REM variable, which should contain a list of platforms ^(e.g. x86 x86_amd64\r
40 REM x86_arm^).  All platforms must be supported by the version of Visual Studio\r
41 REM being used.  The list of configurations to build may be overridden by\r
42 REM setting the CONFIGURATIONS environment variable, which should contain a\r
43 REM list of configurations to build ^(e.g. Debug Retail^).  Neither of these\r
44 REM variable values may contain any double quotes, surrounding or embedded.\r
45 REM\r
46 REM Finally, the NCRTLIBPATH, NUCRTLIBPATH, and NSDKLIBPATH environment\r
47 REM variables may be set to specify the location of the CRT, Universal CRT, and\r
48 REM Windows SDK, respectively, that may be needed to compile executables native\r
49 REM to the architecture of the build machine during any cross-compilation that\r
50 REM may be necessary, depending on the platforms to be built.  These values in\r
51 REM these three variables should be surrounded by double quotes if they contain\r
52 REM spaces.\r
53 REM\r
54 REM There are a few other environment variables that impact the build process\r
55 REM when set ^(to anything^), they are:\r
56 REM\r
57 REM                        USE_AUTOCONF_MAKEFILE\r
58 REM\r
59 REM When set, the "autoconf" Makefile for MSVC will be used instead of the main\r
60 REM Makefile for MSVC.  It must exist at "%ROOT%\autoconf\Makefile.msc".\r
61 REM\r
62 REM                        NOCLEAN\r
63 REM\r
64 REM When set, the "clean" target will not be used during each build iteration.\r
65 REM However, the target binaries, if any, will still be deleted manually prior\r
66 REM to being rebuilt.  Setting this environment variable is only rarely needed\r
67 REM and could cause issues in some circumstances; therefore, setting it is not\r
68 REM recommended.\r
69 REM\r
70 REM                        NOSYMBOLS\r
71 REM\r
72 REM When set, copying of symbol files ^(*.pdb^) created during the build will\r
73 REM be skipped and they will not appear in the final destination directory.\r
74 REM Setting this environment variable is never strictly needed and could cause\r
75 REM issues in some circumstances; therefore, setting it is not recommended.\r
76 REM\r
77 REM                        NOMEMDEBUG\r
78 REM\r
79 REM When set, disables use of MEMDEBUG when building binaries for the "Debug"\r
80 REM configuration.\r
81 REM\r
82 REM                        BUILD_ALL_SHELL\r
83 REM\r
84 REM When set, the command line shell will be built for each selected platform\r
85 REM and configuration as well.  In addition, the command line shell binaries\r
86 REM will be copied, with their symbols, to the final destination directory.\r
87 REM\r
88 REM                        USE_WINV63_NSDKLIBPATH\r
89 REM\r
90 REM When set, modifies how the NSDKLIBPATH environment variable is built, based\r
91 REM on the WindowsSdkDir environment variable.  It forces this batch script to\r
92 REM assume the Windows 8.1 SDK location should be used.\r
93 REM\r
94 REM                        USE_WINV100_NSDKLIBPATH\r
95 REM\r
96 REM When set, modifies how the NSDKLIBPATH environment variable is built, based\r
97 REM on the WindowsSdkDir environment variable.  It causes this batch script to\r
98 REM assume the Windows 10.0 SDK location should be used.\r
99 REM\r
100 REM                        NMAKE_ARGS\r
101 REM                        NMAKE_ARGS_DEBUG\r
102 REM                        NMAKE_ARGS_RETAIL\r
103 REM\r
104 REM When set, these values are expanded and passed to the NMAKE command line,\r
105 REM after its other arguments.  These may be used to specify additional NMAKE\r
106 REM options, for example:\r
107 REM\r
108 REM                        SET NMAKE_ARGS=FOR_WINRT=1\r
109 REM                        SET NMAKE_ARGS_DEBUG=MEMDEBUG=1\r
110 REM                        SET NMAKE_ARGS_RETAIL=WIN32HEAP=1\r
111 REM\r
112 REM Using the above command before running this tool will cause the compiled\r
113 REM binaries to target the WinRT environment, which provides a subset of the\r
114 REM Win32 API.\r
115 REM\r
116 REM                        DLL_FILE_NAME\r
117 REM                        DLL_PDB_FILE_NAME\r
118 REM                        LIB_FILE_NAME\r
119 REM                        EXE_FILE_NAME\r
120 REM                        EXE_PDB_FILE_NAME\r
121 REM\r
122 REM When set, these values will override the associated target file name used\r
123 REM for the build.\r
124 REM\r
125 SETLOCAL\r
127 REM SET __ECHO=ECHO\r
128 REM SET __ECHO2=ECHO\r
129 REM SET __ECHO3=ECHO\r
130 IF NOT DEFINED _AECHO (SET _AECHO=REM)\r
131 IF NOT DEFINED _CECHO (SET _CECHO=REM)\r
132 IF NOT DEFINED _VECHO (SET _VECHO=REM)\r
134 SET REDIRECT=^>\r
135 IF DEFINED __ECHO SET REDIRECT=^^^>\r
137 %_AECHO% Running %0 %*\r
139 REM SET DFLAGS=/L\r
141 %_VECHO% DFlags = '%DFLAGS%'\r
143 SET FFLAGS=/V /F /G /H /I /R /Y /Z\r
145 %_VECHO% FFlags = '%FFLAGS%'\r
147 SET ROOT=%~dp0\..\r
148 SET ROOT=%ROOT:\\=\%\r
150 %_VECHO% Root = '%ROOT%'\r
152 REM\r
153 REM NOTE: The first and only argument to this batch file should be the output\r
154 REM       directory where the platform-specific binary directories should be\r
155 REM       created.\r
156 REM\r
157 SET BINARYDIRECTORY=%1\r
159 IF NOT DEFINED BINARYDIRECTORY (\r
160   GOTO usage\r
163 %_VECHO% BinaryDirectory = '%BINARYDIRECTORY%'\r
165 SET DUMMY=%2\r
167 IF DEFINED DUMMY (\r
168   GOTO usage\r
171 REM\r
172 REM NOTE: From this point, we need a clean error level.  Reset it now.\r
173 REM\r
174 CALL :fn_ResetErrorLevel\r
176 REM\r
177 REM NOTE: Change the current directory to the root of the source tree, saving\r
178 REM       the current directory on the directory stack.\r
179 REM\r
180 %__ECHO2% PUSHD "%ROOT%"\r
182 IF ERRORLEVEL 1 (\r
183   ECHO Could not change directory to "%ROOT%".\r
184   GOTO errors\r
187 REM\r
188 REM NOTE: This batch file requires the ComSpec environment variable to be set,\r
189 REM       typically to something like "C:\Windows\System32\cmd.exe".\r
190 REM\r
191 IF NOT DEFINED ComSpec (\r
192   ECHO The ComSpec environment variable must be defined.\r
193   GOTO errors\r
196 REM\r
197 REM NOTE: This batch file requires the VcInstallDir environment variable to be\r
198 REM       set.  Tyipcally, this means this batch file needs to be run from an\r
199 REM       MSVC command prompt.\r
200 REM\r
201 IF NOT DEFINED VCINSTALLDIR (\r
202   ECHO The VCINSTALLDIR environment variable must be defined.\r
203   GOTO errors\r
206 REM\r
207 REM NOTE: If the list of platforms is not already set, use the default list.\r
208 REM\r
209 IF NOT DEFINED PLATFORMS (\r
210   SET PLATFORMS=x86 x86_amd64 x86_arm\r
213 %_VECHO% Platforms = '%PLATFORMS%'\r
215 REM\r
216 REM NOTE: If the list of configurations is not already set, use the default\r
217 REM       list.\r
218 REM\r
219 IF NOT DEFINED CONFIGURATIONS (\r
220   SET CONFIGURATIONS=Debug Retail\r
223 %_VECHO% Configurations = '%CONFIGURATIONS%'\r
225 REM\r
226 REM NOTE: If the command used to invoke NMAKE is not already set, use the\r
227 REM       default.\r
228 REM\r
229 IF NOT DEFINED NMAKE_CMD (\r
230   IF DEFINED USE_AUTOCONF_MAKEFILE (\r
231     SET NMAKE_CMD=nmake -B -f autoconf\Makefile.msc\r
232   ) ELSE (\r
233     SET NMAKE_CMD=nmake -B -f Makefile.msc\r
234   )\r
237 %_VECHO% NmakeCmd = '%NMAKE_CMD%'\r
238 %_VECHO% NmakeArgs = '%NMAKE_ARGS%'\r
239 %_VECHO% NmakeArgsDebug = '%NMAKE_ARGS_DEBUG%'\r
240 %_VECHO% NmakeArgsRetail = '%NMAKE_ARGS_RETAIL%'\r
242 REM\r
243 REM NOTE: Setup environment variables to translate between the MSVC platform\r
244 REM       names and the names to be used for the platform-specific binary\r
245 REM       directories.\r
246 REM\r
247 SET amd64_NAME=x64\r
248 SET arm_NAME=ARM\r
249 SET x64_NAME=x64\r
250 SET x86_NAME=x86\r
251 SET x86_amd64_NAME=x64\r
252 SET x86_arm_NAME=ARM\r
253 SET x86_x64_NAME=x64\r
255 %_VECHO% amd64_Name = '%amd64_NAME%'\r
256 %_VECHO% arm_Name = '%arm_NAME%'\r
257 %_VECHO% x64_Name = '%x64_NAME%'\r
258 %_VECHO% x86_Name = '%x86_NAME%'\r
259 %_VECHO% x86_amd64_Name = '%x86_amd64_NAME%'\r
260 %_VECHO% x86_arm_Name = '%x86_arm_NAME%'\r
261 %_VECHO% x86_x64_Name = '%x86_x64_NAME%'\r
263 REM\r
264 REM NOTE: Check for the external tools needed during the build process ^(i.e.\r
265 REM       those that do not get compiled as part of the build process itself^)\r
266 REM       along the PATH.\r
267 REM\r
268 IF DEFINED TCLSH_CMD (\r
269   SET TCLSH_FILE=%TCLSH_CMD%\r
270 ) ELSE (\r
271   SET TCLSH_FILE=tclsh.exe\r
274 FOR %%T IN (%TCLSH_FILE%) DO (\r
275   SET %%T_PATH=%%~dp$PATH:T\r
278 REM\r
279 REM NOTE: A Tcl shell executable is required during the SQLite build process\r
280 REM       unless a pre-existing amalgamation file is used.\r
281 REM\r
282 IF NOT DEFINED %TCLSH_FILE%_PATH (\r
283   ECHO The Tcl shell executable "%TCLSH_FILE%" is required to be in the PATH.\r
284   GOTO errors\r
287 REM\r
288 REM NOTE: Setup the default names for the build targets we are creating.  Any\r
289 REM       ^(or all^) of these may end up being overridden.\r
290 REM\r
291 IF NOT DEFINED DLL_FILE_NAME (\r
292   SET DLL_FILE_NAME=sqlite3.dll\r
295 IF NOT DEFINED DLL_PDB_FILE_NAME (\r
296   SET DLL_PDB_FILE_NAME=sqlite3.pdb\r
299 IF NOT DEFINED LIB_FILE_NAME (\r
300   SET LIB_FILE_NAME=sqlite3.lib\r
303 IF NOT DEFINED EXE_FILE_NAME (\r
304   SET EXE_FILE_NAME=sqlite3.exe\r
307 IF NOT DEFINED EXE_PDB_FILE_NAME (\r
308   SET EXE_PDB_FILE_NAME=sqlite3sh.pdb\r
311 REM\r
312 REM NOTE: Set the TOOLPATH variable to contain all the directories where the\r
313 REM       external tools were found in the search above.\r
314 REM\r
315 CALL :fn_CopyVariable %TCLSH_FILE%_PATH TOOLPATH\r
317 %_VECHO% ToolPath = '%TOOLPATH%'\r
319 REM\r
320 REM NOTE: Setting the Windows SDK library path is only required for MSVC\r
321 REM       2012, 2013, and 2015.\r
322 REM\r
323 CALL :fn_UnsetVariable SET_NSDKLIBPATH\r
325 REM\r
326 REM NOTE: Setting the Universal CRT library path is only required for MSVC\r
327 REM       2015.\r
328 REM\r
329 CALL :fn_UnsetVariable SET_NUCRTLIBPATH\r
331 REM\r
332 REM NOTE: Check for MSVC 2012, 2013, and 2015 specially because the Windows\r
333 REM       SDK directory handling is slightly different for those versions.\r
334 REM\r
335 IF "%VisualStudioVersion%" == "11.0" (\r
336   REM\r
337   REM NOTE: If the Windows SDK library path has already been set, do not set\r
338   REM       it to something else later on.\r
339   REM\r
340   IF NOT DEFINED NSDKLIBPATH (\r
341     SET SET_NSDKLIBPATH=1\r
342   )\r
343 ) ELSE IF "%VisualStudioVersion%" == "12.0" (\r
344   REM\r
345   REM NOTE: If the Windows SDK library path has already been set, do not set\r
346   REM       it to something else later on.\r
347   REM\r
348   IF NOT DEFINED NSDKLIBPATH (\r
349     SET SET_NSDKLIBPATH=1\r
350   )\r
351 ) ELSE IF "%VisualStudioVersion%" == "14.0" (\r
352   REM\r
353   REM NOTE: If the Windows SDK library path has already been set, do not set\r
354   REM       it to something else later on.\r
355   REM\r
356   IF NOT DEFINED NSDKLIBPATH (\r
357     SET SET_NSDKLIBPATH=1\r
358   )\r
360   REM\r
361   REM NOTE: If the Universal CRT library path has already been set, do not set\r
362   REM       it to something else later on.\r
363   REM\r
364   IF NOT DEFINED NUCRTLIBPATH (\r
365     SET SET_NUCRTLIBPATH=1\r
366   )\r
369 REM\r
370 REM NOTE: This is the name of the sub-directory where the UCRT libraries may\r
371 REM       be found.  It is only used when compiling against the UCRT.\r
372 REM\r
373 IF DEFINED UCRTVersion (\r
374   SET NUCRTVER=%UCRTVersion%\r
375 ) ELSE (\r
376   SET NUCRTVER=10.0.10586.0\r
379 REM\r
380 REM NOTE: This is the name of the sub-directory where the Windows 10.0 SDK\r
381 REM       libraries may be found.  It is only used when compiling with the\r
382 REM       Windows 10.0 SDK.\r
383 REM\r
384 IF DEFINED WindowsSDKLibVersion (\r
385   SET WIN10SDKVER=%WindowsSDKLibVersion:\=%\r
386 ) ELSE (\r
387   SET WIN10SDKVER=%NUCRTVER%\r
390 REM\r
391 REM NOTE: Check if this is the Windows Phone SDK.  If so, a different batch\r
392 REM       file is necessary to setup the build environment.  Since the variable\r
393 REM       values involved here may contain parenthesis, using GOTO instead of\r
394 REM       an IF block is required.\r
395 REM\r
396 IF DEFINED WindowsPhoneKitDir GOTO set_vcvarsall_phone\r
397 SET VCVARSALL=%VCINSTALLDIR%\vcvarsall.bat\r
398 GOTO set_vcvarsall_done\r
399 :set_vcvarsall_phone\r
400 SET VCVARSALL=%VCINSTALLDIR%\WPSDK\WP80\vcvarsphoneall.bat\r
401 :set_vcvarsall_done\r
402 SET VCVARSALL=%VCVARSALL:\\=\%\r
404 REM\r
405 REM NOTE: This is the outer loop.  There should be exactly one iteration per\r
406 REM       platform.\r
407 REM\r
408 FOR %%P IN (%PLATFORMS%) DO (\r
409   REM\r
410   REM NOTE: Using the MSVC platform name, lookup the simpler platform name to\r
411   REM       be used for the name of the platform-specific binary directory via\r
412   REM       the environment variables setup earlier.\r
413   REM\r
414   CALL :fn_CopyVariable %%P_NAME PLATFORMNAME\r
416   REM\r
417   REM NOTE: This is the second loop.  There should be exactly one iteration.\r
418   REM       This loop is necessary because the PlatformName environment\r
419   REM       variable was set above and that value is needed by some of the\r
420   REM       commands contained in the inner loop.  If these commands were\r
421   REM       directly contained in the outer loop, the PlatformName environment\r
422   REM       variable would be stuck with its initial empty value instead.\r
423   REM\r
424   FOR /F "tokens=2* delims==" %%D IN ('SET PLATFORMNAME') DO (\r
425     REM\r
426     REM NOTE: Attempt to clean the environment of all variables used by MSVC\r
427     REM       and/or Visual Studio.  This block may need to be updated in the\r
428     REM       future to account for additional environment variables.\r
429     REM\r
430     CALL :fn_UnsetVariable CommandPromptType\r
431     CALL :fn_UnsetVariable DevEnvDir\r
432     CALL :fn_UnsetVariable DNX_HOME\r
433     CALL :fn_UnsetVariable ExtensionSdkDir\r
434     CALL :fn_UnsetVariable Framework35Version\r
435     CALL :fn_UnsetVariable Framework40Version\r
436     CALL :fn_UnsetVariable FrameworkDir\r
437     CALL :fn_UnsetVariable FrameworkDir32\r
438     CALL :fn_UnsetVariable FrameworkVersion\r
439     CALL :fn_UnsetVariable FrameworkVersion32\r
440     CALL :fn_UnsetVariable FSHARPINSTALLDIR\r
441     CALL :fn_UnsetVariable INCLUDE\r
442     CALL :fn_UnsetVariable LIB\r
443     CALL :fn_UnsetVariable LIBPATH\r
444     CALL :fn_UnsetVariable NETFXSDKDir\r
445     CALL :fn_UnsetVariable Platform\r
446     CALL :fn_UnsetVariable UCRTVersion\r
447     CALL :fn_UnsetVariable UniversalCRTSdkDir\r
448     REM CALL :fn_UnsetVariable VCINSTALLDIR\r
449     CALL :fn_UnsetVariable VSINSTALLDIR\r
450     CALL :fn_UnsetVariable WindowsLibPath\r
451     CALL :fn_UnsetVariable WindowsPhoneKitDir\r
452     CALL :fn_UnsetVariable WindowsSdkDir\r
453     CALL :fn_UnsetVariable WindowsSdkDir_35\r
454     CALL :fn_UnsetVariable WindowsSdkDir_old\r
455     CALL :fn_UnsetVariable WindowsSDKLibVersion\r
456     CALL :fn_UnsetVariable WindowsSDKVersion\r
457     CALL :fn_UnsetVariable WindowsSDK_ExecutablePath_x86\r
458     CALL :fn_UnsetVariable WindowsSDK_ExecutablePath_x64\r
460     REM\r
461     REM NOTE: Reset the PATH here to the absolute bare minimum required.\r
462     REM\r
463     CALL :fn_ResetPath\r
465     REM\r
466     REM NOTE: This is the inner loop.  There are normally two iterations, one\r
467     REM       for each supported build configuration, e.g. Debug or Retail.\r
468     REM\r
469     FOR %%B IN (%CONFIGURATIONS%) DO (\r
470       REM\r
471       REM NOTE: When preparing the debug build, set the DEBUG and MEMDEBUG\r
472       REM       environment variables to be picked up by the MSVC makefile\r
473       REM       itself.\r
474       REM\r
475       %_AECHO% Building the %%B configuration for platform %%P with name %%D...\r
477       IF /I "%%B" == "Debug" (\r
478         REM\r
479         REM NOTE: Using this level for the DEBUG environment variable should\r
480         REM       disable all compiler optimizations and prevent use of the\r
481         REM       NDEBUG define.  Additionally, both SQLITE_ENABLE_API_ARMOR\r
482         REM       and SQLITE_DEBUG defines should be enabled.\r
483         REM\r
484         SET DEBUG=3\r
486         REM\r
487         REM NOTE: Setting this to non-zero should enable the SQLITE_MEMDEBUG\r
488         REM       define.\r
489         REM\r
490         IF NOT DEFINED NOMEMDEBUG (\r
491           SET MEMDEBUG=1\r
492         )\r
493       ) ELSE (\r
494         CALL :fn_UnsetVariable DEBUG\r
495         CALL :fn_UnsetVariable MEMDEBUG\r
496       )\r
498       REM\r
499       REM NOTE: Copy the extra NMAKE arguments for this configuration into the\r
500       REM       common variable used by the actual commands.\r
501       REM\r
502       CALL :fn_CopyVariable NMAKE_ARGS_%%B NMAKE_ARGS_CFG\r
504       REM\r
505       REM NOTE: Launch a nested command shell to perform the following steps:\r
506       REM\r
507       REM       1. Setup the MSVC environment for this platform using the\r
508       REM          official batch file.\r
509       REM\r
510       REM       2. Make sure that no stale build output files are present.\r
511       REM\r
512       REM       3. Build the "sqlite3.dll" and "sqlite3.lib" binaries for this\r
513       REM          platform.\r
514       REM\r
515       REM       4. Copy the "sqlite3.dll" and "sqlite3.lib" binaries for this\r
516       REM          platform to the platform-specific directory beneath the\r
517       REM          binary directory.\r
518       REM\r
519       REM       5. Unless prevented from doing so, copy the "sqlite3.pdb"\r
520       REM          symbols file for this platform to the platform-specific\r
521       REM          directory beneath the binary directory.\r
522       REM\r
523       "%ComSpec%" /C (\r
524         REM\r
525         REM NOTE: Attempt to setup the MSVC environment for this platform.\r
526         REM\r
527         %__ECHO3% CALL "%VCVARSALL%" %%P\r
529         IF ERRORLEVEL 1 (\r
530           ECHO Failed to call "%VCVARSALL%" for platform %%P.\r
531           GOTO errors\r
532         )\r
534         REM\r
535         REM NOTE: If this batch file is not running in "what-if" mode, check to\r
536         REM       be sure we were actually able to setup the MSVC environment\r
537         REM       as current versions of their official batch file do not set\r
538         REM       the exit code upon failure.\r
539         REM\r
540         IF NOT DEFINED __ECHO3 (\r
541           IF NOT DEFINED WindowsPhoneKitDir (\r
542             IF NOT DEFINED WindowsSdkDir (\r
543               ECHO Cannot build, Windows SDK not found for platform %%P.\r
544               GOTO errors\r
545             )\r
546           )\r
547         )\r
549         REM\r
550         REM NOTE: When using MSVC 2012, 2013, or 2015, the native SDK path\r
551         REM       cannot simply be the "lib" sub-directory beneath the location\r
552         REM       specified in the WindowsSdkDir environment variable because\r
553         REM       that location does not actually contain the necessary library\r
554         REM       files for x86.  This must be done for each iteration because\r
555         REM       it relies upon the WindowsSdkDir environment variable being\r
556         REM       set by the batch file used to setup the MSVC environment.\r
557         REM\r
558         IF DEFINED SET_NSDKLIBPATH (\r
559           REM\r
560           REM NOTE: The Windows Phone SDK has a slightly different directory\r
561           REM       structure and must be handled specially here.\r
562           REM\r
563           IF DEFINED WindowsPhoneKitDir (\r
564             CALL :fn_CopyVariable WindowsPhoneKitDir NSDKLIBPATH\r
565             CALL :fn_AppendVariable NSDKLIBPATH \lib\x86\r
566           ) ELSE IF DEFINED WindowsSdkDir (\r
567             CALL :fn_CopyVariable WindowsSdkDir NSDKLIBPATH\r
569             REM\r
570             REM NOTE: The Windows 8.x and Windows 10.0 SDKs have a slightly\r
571             REM       different directory naming conventions.\r
572             REM\r
573             IF DEFINED USE_WINV100_NSDKLIBPATH (\r
574               CALL :fn_AppendVariable NSDKLIBPATH \..\10\lib\%WIN10SDKVER%\um\x86\r
575               CALL :fn_CopyVariable WindowsSdkDir PSDKLIBPATH\r
576               CALL :fn_AppendVariable PSDKLIBPATH lib\%WIN10SDKVER%\um\%%D\r
577             ) ELSE IF DEFINED USE_WINV63_NSDKLIBPATH (\r
578               CALL :fn_AppendVariable NSDKLIBPATH \lib\winv6.3\um\x86\r
579             ) ELSE IF "%VisualStudioVersion%" == "12.0" (\r
580               CALL :fn_AppendVariable NSDKLIBPATH \..\8.0\lib\win8\um\x86\r
581             ) ELSE IF "%VisualStudioVersion%" == "14.0" (\r
582               CALL :fn_AppendVariable NSDKLIBPATH \..\8.0\lib\win8\um\x86\r
583             ) ELSE (\r
584               CALL :fn_AppendVariable NSDKLIBPATH \lib\win8\um\x86\r
585             )\r
586           )\r
587         )\r
589         REM\r
590         REM NOTE: When using MSVC 2015, setting the Universal CRT library path\r
591         REM       for x86 may be required as well.  This must also be done for\r
592         REM       each iteration because it relies upon the UniversalCRTSdkDir\r
593         REM       environment variable being set by the batch file used to\r
594         REM       setup the MSVC environment.\r
595         REM\r
596         IF DEFINED SET_NUCRTLIBPATH (\r
597           IF DEFINED UniversalCRTSdkDir (\r
598             CALL :fn_CopyVariable UniversalCRTSdkDir NUCRTLIBPATH\r
599             CALL :fn_AppendVariable NUCRTLIBPATH \lib\%NUCRTVER%\ucrt\x86\r
600           )\r
601         )\r
603         REM\r
604         REM NOTE: Unless prevented from doing so, invoke NMAKE with the MSVC\r
605         REM       makefile to clean any stale build output from previous\r
606         REM       iterations of this loop and/or previous runs of this batch\r
607         REM       file, etc.\r
608         REM\r
609         IF NOT DEFINED NOCLEAN (\r
610           CALL :fn_MakeClean %%D\r
612           IF ERRORLEVEL 1 (\r
613             ECHO Failed to clean for platform %%P.\r
614             GOTO errors\r
615           )\r
616         ) ELSE (\r
617           REM\r
618           REM NOTE: Even when the cleaning step has been disabled, we still\r
619           REM       need to remove the build output for all the files we are\r
620           REM       specifically wanting to build for each platform.\r
621           REM\r
622           %_AECHO% Cleaning final core library output files only...\r
623           %__ECHO% DEL /Q *.lo "%DLL_FILE_NAME%" "%LIB_FILE_NAME%" "%DLL_PDB_FILE_NAME%" 2%REDIRECT% NUL\r
624         )\r
626         REM\r
627         REM NOTE: Call NMAKE with the MSVC makefile to build the "sqlite3.dll"\r
628         REM       binary.  The x86 compiler will be used to compile the native\r
629         REM       command line tools needed during the build process itself.\r
630         REM       Also, disable looking for and/or linking to the native Tcl\r
631         REM       runtime library.\r
632         REM\r
633         CALL :fn_MakeDll %%D\r
635         IF ERRORLEVEL 1 (\r
636           ECHO Failed to build %%B "%DLL_FILE_NAME%" for platform %%P.\r
637           GOTO errors\r
638         )\r
640         REM\r
641         REM NOTE: Copy the "sqlite3.dll" file to the appropriate directory for\r
642         REM       the build and platform beneath the binary directory.\r
643         REM\r
644         %__ECHO% XCOPY "%DLL_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%\r
646         IF ERRORLEVEL 1 (\r
647           ECHO Failed to copy "%DLL_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\".\r
648           GOTO errors\r
649         )\r
651         REM\r
652         REM NOTE: Copy the "sqlite3.lib" file to the appropriate directory for\r
653         REM       the build and platform beneath the binary directory.\r
654         REM\r
655         %__ECHO% XCOPY "%LIB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%\r
657         IF ERRORLEVEL 1 (\r
658           ECHO Failed to copy "%LIB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\".\r
659           GOTO errors\r
660         )\r
662         REM\r
663         REM NOTE: Copy the "sqlite3.pdb" file to the appropriate directory for\r
664         REM       the build and platform beneath the binary directory unless we\r
665         REM       are prevented from doing so.\r
666         REM\r
667         IF NOT DEFINED NOSYMBOLS (\r
668           IF EXIST "%DLL_PDB_FILE_NAME%" (\r
669             %__ECHO% XCOPY "%DLL_PDB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%\r
671             IF ERRORLEVEL 1 (\r
672               ECHO Failed to copy "%DLL_PDB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\".\r
673               GOTO errors\r
674             )\r
675           )\r
676         )\r
678         REM\r
679         REM NOTE: If requested, also build the shell executable.\r
680         REM\r
681         IF DEFINED BUILD_ALL_SHELL (\r
682           REM\r
683           REM NOTE: If necessary, make sure any previous build output for the\r
684           REM       shell executable is deleted.\r
685           REM\r
686           IF DEFINED NOCLEAN (\r
687             REM\r
688             REM NOTE: Even when the cleaning step has been disabled, we still\r
689             REM       need to remove the build output for all the files we are\r
690             REM       specifically wanting to build for each platform.\r
691             REM\r
692             %_AECHO% Cleaning final shell executable output files only...\r
693             %__ECHO% DEL /Q "%EXE_FILE_NAME%" "%EXE_PDB_FILE_NAME%" 2%REDIRECT% NUL\r
694           )\r
696           REM\r
697           REM NOTE: Call NMAKE with the MSVC makefile to build the "sqlite3.exe"\r
698           REM       binary.  The x86 compiler will be used to compile the native\r
699           REM       command line tools needed during the build process itself.\r
700           REM       Also, disable looking for and/or linking to the native Tcl\r
701           REM       runtime library.\r
702           REM\r
703           CALL :fn_MakeExe %%D\r
705           IF ERRORLEVEL 1 (\r
706             ECHO Failed to build %%B "%EXE_FILE_NAME%" for platform %%P.\r
707             GOTO errors\r
708           )\r
710           REM\r
711           REM NOTE: Copy the "sqlite3.exe" file to the appropriate directory\r
712           REM       for the build and platform beneath the binary directory.\r
713           REM\r
714           %__ECHO% XCOPY "%EXE_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%\r
716           IF ERRORLEVEL 1 (\r
717             ECHO Failed to copy "%EXE_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\".\r
718             GOTO errors\r
719           )\r
721           REM\r
722           REM NOTE: Copy the "sqlite3sh.pdb" file to the appropriate directory\r
723           REM       for the build and platform beneath the binary directory\r
724           REM       unless we are prevented from doing so.\r
725           REM\r
726           IF NOT DEFINED NOSYMBOLS (\r
727             IF EXIST "%EXE_PDB_FILE_NAME%" (\r
728               %__ECHO% XCOPY "%EXE_PDB_FILE_NAME%" "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%\r
730               IF ERRORLEVEL 1 (\r
731                 ECHO Failed to copy "%EXE_PDB_FILE_NAME%" to "%BINARYDIRECTORY%\%%B\%%D\".\r
732                 GOTO errors\r
733               )\r
734             )\r
735           )\r
736         )\r
737       )\r
738     )\r
739   )\r
741   REM\r
742   REM NOTE: Handle any errors generated during the nested command shell.\r
743   REM\r
744   IF ERRORLEVEL 1 (\r
745     GOTO errors\r
746   )\r
749 REM\r
750 REM NOTE: Restore the saved current directory from the directory stack.\r
751 REM\r
752 %__ECHO2% POPD\r
754 IF ERRORLEVEL 1 (\r
755   ECHO Could not restore directory.\r
756   GOTO errors\r
759 REM\r
760 REM NOTE: If we get to this point, we have succeeded.\r
761 REM\r
762 GOTO no_errors\r
764 :fn_MakeClean\r
765   %__ECHO% %NMAKE_CMD% clean "PLATFORM=%1" XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% %NMAKE_ARGS_CFG%\r
766   GOTO :EOF\r
768 :fn_MakeDll\r
769   %__ECHO% %NMAKE_CMD% "%DLL_FILE_NAME%" "PLATFORM=%1" XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% %NMAKE_ARGS_CFG%\r
770   GOTO :EOF\r
772 :fn_MakeExe\r
773   %__ECHO% %NMAKE_CMD% "%EXE_FILE_NAME%" "PLATFORM=%1" XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS% %NMAKE_ARGS_CFG%\r
774   GOTO :EOF\r
776 :fn_ShowVariable\r
777   SETLOCAL\r
778   SET __ECHO_CMD=ECHO %%%2%%\r
779   FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (\r
780     IF NOT "%%V" == "" (\r
781       IF NOT "%%V" == "%%%2%%" (\r
782         %_VECHO% %1 = '%%V'\r
783       )\r
784     )\r
785   )\r
786   ENDLOCAL\r
787   GOTO :EOF\r
789 :fn_ResetErrorLevel\r
790   VERIFY > NUL\r
791   GOTO :EOF\r
793 :fn_SetErrorLevel\r
794   VERIFY MAYBE 2> NUL\r
795   GOTO :EOF\r
797 :fn_CopyVariable\r
798   IF NOT DEFINED %1 GOTO :EOF\r
799   IF "%2" == "" GOTO :EOF\r
800   SETLOCAL\r
801   SET __ECHO_CMD=ECHO %%%1%%\r
802   FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (\r
803     SET VALUE=%%V\r
804   )\r
805   ENDLOCAL && SET %2=%VALUE%\r
806   GOTO :EOF\r
808 :fn_UnsetVariable\r
809   SETLOCAL\r
810   SET VALUE=%1\r
811   IF DEFINED VALUE (\r
812     SET VALUE=\r
813     ENDLOCAL\r
814     SET %VALUE%=\r
815   ) ELSE (\r
816     ENDLOCAL\r
817   )\r
818   CALL :fn_ResetErrorLevel\r
819   GOTO :EOF\r
821 :fn_ResetPath\r
822   SET PATH=%TOOLPATH%;%SystemRoot%\System32;%SystemRoot%\r
823   GOTO :EOF\r
825 :fn_AppendVariable\r
826   SET __ECHO_CMD=ECHO %%%1%%\r
827   IF DEFINED %1 (\r
828     FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (\r
829       SET %1=%%V%~2\r
830     )\r
831   ) ELSE (\r
832     SET %1=%~2\r
833   )\r
834   SET __ECHO_CMD=\r
835   CALL :fn_ResetErrorLevel\r
836   GOTO :EOF\r
838 :usage\r
839   ECHO.\r
840   ECHO Usage: %~nx0 ^<binaryDirectory^>\r
841   ECHO.\r
842   GOTO errors\r
844 :errors\r
845   CALL :fn_SetErrorLevel\r
846   ENDLOCAL\r
847   ECHO.\r
848   ECHO Failure, errors were encountered.\r
849   GOTO end_of_file\r
851 :no_errors\r
852   CALL :fn_ResetErrorLevel\r
853   ENDLOCAL\r
854   ECHO.\r
855   ECHO Success, no errors were encountered.\r
856   GOTO end_of_file\r
858 :end_of_file\r
859 %__ECHO% EXIT /B %ERRORLEVEL%\r