build-all-msvc.bat 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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 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 There are several environment variables that may be set to modify the
  30. REM behavior of this batch script and its associated Makefile. The list of
  31. REM platforms to build may be overriden by using the PLATFORMS environment
  32. REM variable, which should contain a list of platforms ^(e.g. x86 x86_amd64
  33. REM x86_arm^). All platforms must be supported by the version of Visual Studio
  34. REM being used. The list of configurations to build may be overridden by
  35. REM setting the CONFIGURATIONS environment variable, which should contain a
  36. REM list of configurations to build ^(e.g. Debug Retail^). Neither of these
  37. REM variable values may contain any double quotes, surrounding or embedded.
  38. REM Finally, the NCRTLIBPATH and NSDKLIBPATH environment variables may be set
  39. REM to specify the location of the CRT and SDK, respectively, needed to compile
  40. REM executables native to the architecture of the build machine during any
  41. REM cross-compilation that may be necessary, depending on the platforms to be
  42. REM built. These values in these two variables should be surrounded by double
  43. REM quotes if they contain spaces.
  44. REM
  45. REM Please note that the SQLite build process performed by the Makefile
  46. REM associated with this batch script requires both Gawk ^(gawk.exe^) and Tcl
  47. REM 8.5 ^(tclsh85.exe^) to be present in a directory contained in the PATH
  48. REM environment variable unless a pre-existing amalgamation file is used.
  49. REM
  50. SETLOCAL
  51. REM SET __ECHO=ECHO
  52. REM SET __ECHO2=ECHO
  53. REM SET __ECHO3=ECHO
  54. IF NOT DEFINED _AECHO (SET _AECHO=REM)
  55. IF NOT DEFINED _CECHO (SET _CECHO=REM)
  56. IF NOT DEFINED _VECHO (SET _VECHO=REM)
  57. %_AECHO% Running %0 %*
  58. REM SET DFLAGS=/L
  59. %_VECHO% DFlags = '%DFLAGS%'
  60. SET FFLAGS=/V /F /G /H /I /R /Y /Z
  61. %_VECHO% FFlags = '%FFLAGS%'
  62. SET ROOT=%~dp0\..
  63. SET ROOT=%ROOT:\\=\%
  64. %_VECHO% Root = '%ROOT%'
  65. REM
  66. REM NOTE: The first and only argument to this batch file should be the output
  67. REM directory where the platform-specific binary directories should be
  68. REM created.
  69. REM
  70. SET BINARYDIRECTORY=%1
  71. IF NOT DEFINED BINARYDIRECTORY (
  72. GOTO usage
  73. )
  74. %_VECHO% BinaryDirectory = '%BINARYDIRECTORY%'
  75. SET DUMMY=%2
  76. IF DEFINED DUMMY (
  77. GOTO usage
  78. )
  79. REM
  80. REM NOTE: From this point, we need a clean error level. Reset it now.
  81. REM
  82. CALL :fn_ResetErrorLevel
  83. REM
  84. REM NOTE: Change the current directory to the root of the source tree, saving
  85. REM the current directory on the directory stack.
  86. REM
  87. %__ECHO2% PUSHD "%ROOT%"
  88. IF ERRORLEVEL 1 (
  89. ECHO Could not change directory to "%ROOT%".
  90. GOTO errors
  91. )
  92. REM
  93. REM NOTE: This batch file requires the ComSpec environment variable to be set,
  94. REM typically to something like "C:\Windows\System32\cmd.exe".
  95. REM
  96. IF NOT DEFINED ComSpec (
  97. ECHO The ComSpec environment variable must be defined.
  98. GOTO errors
  99. )
  100. REM
  101. REM NOTE: This batch file requires the VcInstallDir environment variable to be
  102. REM set. Tyipcally, this means this batch file needs to be run from an
  103. REM MSVC command prompt.
  104. REM
  105. IF NOT DEFINED VCINSTALLDIR (
  106. ECHO The VCINSTALLDIR environment variable must be defined.
  107. GOTO errors
  108. )
  109. REM
  110. REM NOTE: If the list of platforms is not already set, use the default list.
  111. REM
  112. IF NOT DEFINED PLATFORMS (
  113. SET PLATFORMS=x86 x86_amd64 x86_arm
  114. )
  115. %_VECHO% Platforms = '%PLATFORMS%'
  116. REM
  117. REM NOTE: If the list of configurations is not already set, use the default
  118. REM list.
  119. REM
  120. IF NOT DEFINED CONFIGURATIONS (
  121. SET CONFIGURATIONS=Debug Retail
  122. )
  123. %_VECHO% Configurations = '%CONFIGURATIONS%'
  124. REM
  125. REM NOTE: Setup environment variables to translate between the MSVC platform
  126. REM names and the names to be used for the platform-specific binary
  127. REM directories.
  128. REM
  129. SET amd64_NAME=x64
  130. SET arm_NAME=ARM
  131. SET x64_NAME=x64
  132. SET x86_NAME=x86
  133. SET x86_amd64_NAME=x64
  134. SET x86_arm_NAME=ARM
  135. SET x86_x64_NAME=x64
  136. %_VECHO% amd64_Name = '%amd64_NAME%'
  137. %_VECHO% arm_Name = '%arm_NAME%'
  138. %_VECHO% x64_Name = '%x64_NAME%'
  139. %_VECHO% x86_Name = '%x86_NAME%'
  140. %_VECHO% x86_amd64_Name = '%x86_amd64_NAME%'
  141. %_VECHO% x86_arm_Name = '%x86_arm_NAME%'
  142. %_VECHO% x86_x64_Name = '%x86_x64_NAME%'
  143. REM
  144. REM NOTE: Check for the external tools needed during the build process ^(i.e.
  145. REM those that do not get compiled as part of the build process itself^)
  146. REM along the PATH.
  147. REM
  148. FOR %%T IN (gawk.exe tclsh85.exe) DO (
  149. SET %%T_PATH=%%~dp$PATH:T
  150. )
  151. REM
  152. REM NOTE: The Gawk executable "gawk.exe" is required during the SQLite build
  153. REM process unless a pre-existing amalgamation file is used.
  154. REM
  155. IF NOT DEFINED gawk.exe_PATH (
  156. ECHO The Gawk executable "gawk.exe" is required to be in the PATH.
  157. GOTO errors
  158. )
  159. REM
  160. REM NOTE: The Tcl 8.5 executable "tclsh85.exe" is required during the SQLite
  161. REM build process unless a pre-existing amalgamation file is used.
  162. REM
  163. IF NOT DEFINED tclsh85.exe_PATH (
  164. ECHO The Tcl 8.5 executable "tclsh85.exe" is required to be in the PATH.
  165. GOTO errors
  166. )
  167. REM
  168. REM NOTE: Set the TOOLPATH variable to contain all the directories where the
  169. REM external tools were found in the search above.
  170. REM
  171. SET TOOLPATH=%gawk.exe_PATH%;%tclsh85.exe_PATH%
  172. %_VECHO% ToolPath = '%TOOLPATH%'
  173. REM
  174. REM NOTE: Check for MSVC 2012/2013 because the Windows SDK directory handling
  175. REM is slightly different for those versions.
  176. REM
  177. IF "%VisualStudioVersion%" == "11.0" (
  178. REM
  179. REM NOTE: If the Windows SDK library path has already been set, do not set
  180. REM it to something else later on.
  181. REM
  182. IF NOT DEFINED NSDKLIBPATH (
  183. SET SET_NSDKLIBPATH=1
  184. )
  185. ) ELSE IF "%VisualStudioVersion%" == "12.0" (
  186. REM
  187. REM NOTE: If the Windows SDK library path has already been set, do not set
  188. REM it to something else later on.
  189. REM
  190. IF NOT DEFINED NSDKLIBPATH (
  191. SET SET_NSDKLIBPATH=1
  192. )
  193. ) ELSE (
  194. CALL :fn_UnsetVariable SET_NSDKLIBPATH
  195. )
  196. REM
  197. REM NOTE: Check if this is the Windows Phone SDK. If so, a different batch
  198. REM file is necessary to setup the build environment. Since the variable
  199. REM values involved here may contain parenthesis, using GOTO instead of
  200. REM an IF block is required.
  201. REM
  202. IF DEFINED WindowsPhoneKitDir GOTO set_vcvarsall_phone
  203. SET VCVARSALL=%VCINSTALLDIR%\vcvarsall.bat
  204. GOTO set_vcvarsall_done
  205. :set_vcvarsall_phone
  206. SET VCVARSALL=%VCINSTALLDIR%\WPSDK\WP80\vcvarsphoneall.bat
  207. :set_vcvarsall_done
  208. REM
  209. REM NOTE: This is the outer loop. There should be exactly one iteration per
  210. REM platform.
  211. REM
  212. FOR %%P IN (%PLATFORMS%) DO (
  213. REM
  214. REM NOTE: Using the MSVC platform name, lookup the simpler platform name to
  215. REM be used for the name of the platform-specific binary directory via
  216. REM the environment variables setup earlier.
  217. REM
  218. CALL :fn_CopyVariable %%P_NAME PLATFORMNAME
  219. REM
  220. REM NOTE: This is the inner loop. There should be exactly one iteration.
  221. REM This loop is necessary because the PlatformName environment
  222. REM variable was set above and that value is needed by some of the
  223. REM commands contained in the inner loop. If these commands were
  224. REM directly contained in the outer loop, the PlatformName environment
  225. REM variable would be stuck with its initial empty value instead.
  226. REM
  227. FOR /F "tokens=2* delims==" %%D IN ('SET PLATFORMNAME') DO (
  228. REM
  229. REM NOTE: Attempt to clean the environment of all variables used by MSVC
  230. REM and/or Visual Studio. This block may need to be updated in the
  231. REM future to account for additional environment variables.
  232. REM
  233. CALL :fn_UnsetVariable DevEnvDir
  234. CALL :fn_UnsetVariable ExtensionSdkDir
  235. CALL :fn_UnsetVariable Framework35Version
  236. CALL :fn_UnsetVariable FrameworkDir
  237. CALL :fn_UnsetVariable FrameworkDir32
  238. CALL :fn_UnsetVariable FrameworkVersion
  239. CALL :fn_UnsetVariable FrameworkVersion32
  240. CALL :fn_UnsetVariable FSHARPINSTALLDIR
  241. CALL :fn_UnsetVariable INCLUDE
  242. CALL :fn_UnsetVariable LIB
  243. CALL :fn_UnsetVariable LIBPATH
  244. CALL :fn_UnsetVariable Platform
  245. REM CALL :fn_UnsetVariable VCINSTALLDIR
  246. CALL :fn_UnsetVariable VSINSTALLDIR
  247. CALL :fn_UnsetVariable WindowsPhoneKitDir
  248. CALL :fn_UnsetVariable WindowsSdkDir
  249. CALL :fn_UnsetVariable WindowsSdkDir_35
  250. CALL :fn_UnsetVariable WindowsSdkDir_old
  251. REM
  252. REM NOTE: Reset the PATH here to the absolute bare minimum required.
  253. REM
  254. SET PATH=%TOOLPATH%;%SystemRoot%\System32;%SystemRoot%
  255. FOR %%B IN (%CONFIGURATIONS%) DO (
  256. REM
  257. REM NOTE: When preparing the debug build, set the DEBUG and MEMDEBUG
  258. REM environment variables to be picked up by the MSVC makefile
  259. REM itself.
  260. REM
  261. IF /I "%%B" == "Debug" (
  262. SET DEBUG=2
  263. SET MEMDEBUG=1
  264. ) ELSE (
  265. CALL :fn_UnsetVariable DEBUG
  266. CALL :fn_UnsetVariable MEMDEBUG
  267. )
  268. REM
  269. REM NOTE: Launch a nested command shell to perform the following steps:
  270. REM
  271. REM 1. Setup the MSVC environment for this platform using the
  272. REM official batch file.
  273. REM
  274. REM 2. Make sure that no stale build output files are present.
  275. REM
  276. REM 3. Build the "sqlite3.dll" and "sqlite3.lib" binaries for this
  277. REM platform.
  278. REM
  279. REM 4. Copy the "sqlite3.dll" and "sqlite3.lib" binaries for this
  280. REM platform to the platform-specific directory beneath the
  281. REM binary directory.
  282. REM
  283. "%ComSpec%" /C (
  284. REM
  285. REM NOTE: Attempt to setup the MSVC environment for this platform.
  286. REM
  287. %__ECHO3% CALL "%VCVARSALL%" %%P
  288. IF ERRORLEVEL 1 (
  289. ECHO Failed to call "%VCVARSALL%" for platform %%P.
  290. GOTO errors
  291. )
  292. REM
  293. REM NOTE: If this batch file is not running in "what-if" mode, check to
  294. REM be sure we were actually able to setup the MSVC environment
  295. REM as current versions of their official batch file do not set
  296. REM the exit code upon failure.
  297. REM
  298. IF NOT DEFINED __ECHO3 (
  299. IF NOT DEFINED WindowsPhoneKitDir (
  300. IF NOT DEFINED WindowsSdkDir (
  301. ECHO Cannot build, Windows SDK not found for platform %%P.
  302. GOTO errors
  303. )
  304. )
  305. )
  306. REM
  307. REM NOTE: When using MSVC 2012, the native SDK path cannot simply use
  308. REM the "lib" sub-directory beneath the location specified in the
  309. REM WindowsSdkDir environment variable because that location does
  310. REM not actually contain the necessary library files for x86.
  311. REM This must be done for each iteration because it relies upon
  312. REM the WindowsSdkDir environment variable being set by the batch
  313. REM file used to setup the MSVC environment.
  314. REM
  315. IF DEFINED SET_NSDKLIBPATH (
  316. IF DEFINED WindowsPhoneKitDir (
  317. CALL :fn_CopyVariable WindowsPhoneKitDir NSDKLIBPATH
  318. CALL :fn_AppendVariable NSDKLIBPATH \lib\x86
  319. ) ELSE IF DEFINED WindowsSdkDir (
  320. CALL :fn_CopyVariable WindowsSdkDir NSDKLIBPATH
  321. IF "%VisualStudioVersion%" == "12.0" (
  322. CALL :fn_AppendVariable NSDKLIBPATH \lib\winv6.3\um\x86
  323. ) ELSE (
  324. CALL :fn_AppendVariable NSDKLIBPATH \lib\win8\um\x86
  325. )
  326. )
  327. )
  328. REM
  329. REM NOTE: Unless prevented from doing so, invoke NMAKE with the MSVC
  330. REM makefile to clean any stale build output from previous
  331. REM iterations of this loop and/or previous runs of this batch
  332. REM file, etc.
  333. REM
  334. IF NOT DEFINED NOCLEAN (
  335. %__ECHO% nmake -f Makefile.msc clean
  336. IF ERRORLEVEL 1 (
  337. ECHO Failed to clean for platform %%P.
  338. GOTO errors
  339. )
  340. ) ELSE (
  341. REM
  342. REM NOTE: Even when the cleaning step has been disabled, we still
  343. REM need to remove the build output for the files we are
  344. REM specifically wanting to build for each platform.
  345. REM
  346. %__ECHO% DEL /Q *.lo sqlite3.dll sqlite3.lib sqlite3.pdb
  347. )
  348. REM
  349. REM NOTE: Call NMAKE with the MSVC makefile to build the "sqlite3.dll"
  350. REM binary. The x86 compiler will be used to compile the native
  351. REM command line tools needed during the build process itself.
  352. REM Also, disable looking for and/or linking to the native Tcl
  353. REM runtime library.
  354. REM
  355. %__ECHO% nmake -f Makefile.msc sqlite3.dll XCOMPILE=1 USE_NATIVE_LIBPATHS=1 NO_TCL=1 %NMAKE_ARGS%
  356. IF ERRORLEVEL 1 (
  357. ECHO Failed to build %%B "sqlite3.dll" for platform %%P.
  358. GOTO errors
  359. )
  360. REM
  361. REM NOTE: Copy the "sqlite3.dll" file to the appropriate directory for
  362. REM the build and platform beneath the binary directory.
  363. REM
  364. %__ECHO% XCOPY sqlite3.dll "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%
  365. IF ERRORLEVEL 1 (
  366. ECHO Failed to copy "sqlite3.dll" to "%BINARYDIRECTORY%\%%B\%%D\".
  367. GOTO errors
  368. )
  369. REM
  370. REM NOTE: Copy the "sqlite3.lib" file to the appropriate directory for
  371. REM the build and platform beneath the binary directory.
  372. REM
  373. %__ECHO% XCOPY sqlite3.lib "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%
  374. IF ERRORLEVEL 1 (
  375. ECHO Failed to copy "sqlite3.lib" to "%BINARYDIRECTORY%\%%B\%%D\".
  376. GOTO errors
  377. )
  378. REM
  379. REM NOTE: Copy the "sqlite3.pdb" file to the appropriate directory for
  380. REM the build and platform beneath the binary directory unless we
  381. REM are prevented from doing so.
  382. REM
  383. IF NOT DEFINED NOSYMBOLS (
  384. %__ECHO% XCOPY sqlite3.pdb "%BINARYDIRECTORY%\%%B\%%D\" %FFLAGS% %DFLAGS%
  385. IF ERRORLEVEL 1 (
  386. ECHO Failed to copy "sqlite3.pdb" to "%BINARYDIRECTORY%\%%B\%%D\".
  387. GOTO errors
  388. )
  389. )
  390. )
  391. )
  392. )
  393. REM
  394. REM NOTE: Handle any errors generated during the nested command shell.
  395. REM
  396. IF ERRORLEVEL 1 (
  397. GOTO errors
  398. )
  399. )
  400. REM
  401. REM NOTE: Restore the saved current directory from the directory stack.
  402. REM
  403. %__ECHO2% POPD
  404. IF ERRORLEVEL 1 (
  405. ECHO Could not restore directory.
  406. GOTO errors
  407. )
  408. REM
  409. REM NOTE: If we get to this point, we have succeeded.
  410. REM
  411. GOTO no_errors
  412. :fn_ResetErrorLevel
  413. VERIFY > NUL
  414. GOTO :EOF
  415. :fn_SetErrorLevel
  416. VERIFY MAYBE 2> NUL
  417. GOTO :EOF
  418. :fn_CopyVariable
  419. SETLOCAL
  420. IF NOT DEFINED %1 GOTO :EOF
  421. IF "%2" == "" GOTO :EOF
  422. SET __ECHO_CMD=ECHO %%%1%%
  423. FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
  424. SET VALUE=%%V
  425. )
  426. ENDLOCAL && SET %2=%VALUE%
  427. GOTO :EOF
  428. :fn_UnsetVariable
  429. IF NOT "%1" == "" (
  430. SET %1=
  431. CALL :fn_ResetErrorLevel
  432. )
  433. GOTO :EOF
  434. :fn_AppendVariable
  435. SET __ECHO_CMD=ECHO %%%1%%
  436. IF DEFINED %1 (
  437. FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
  438. SET %1=%%V%~2
  439. )
  440. ) ELSE (
  441. SET %1=%~2
  442. )
  443. SET __ECHO_CMD=
  444. CALL :fn_ResetErrorLevel
  445. GOTO :EOF
  446. :usage
  447. ECHO.
  448. ECHO Usage: %~nx0 ^<binaryDirectory^>
  449. ECHO.
  450. GOTO errors
  451. :errors
  452. CALL :fn_SetErrorLevel
  453. ENDLOCAL
  454. ECHO.
  455. ECHO Failure, errors were encountered.
  456. GOTO end_of_file
  457. :no_errors
  458. CALL :fn_ResetErrorLevel
  459. ENDLOCAL
  460. ECHO.
  461. ECHO Success, no errors were encountered.
  462. GOTO end_of_file
  463. :end_of_file
  464. %__ECHO% EXIT /B %ERRORLEVEL%