build-all-msvc.bat 29 KB

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