build-wolfssl.bat 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. @echo off
  2. rem ***************************************************************************
  3. rem * _ _ ____ _
  4. rem * Project ___| | | | _ \| |
  5. rem * / __| | | | |_) | |
  6. rem * | (__| |_| | _ <| |___
  7. rem * \___|\___/|_| \_\_____|
  8. rem *
  9. rem * Copyright (C) 2012 - 2020, Steve Holme, <steve_holme@hotmail.com>.
  10. rem * Copyright (C) 2015, Jay Satiro, <raysatiro@yahoo.com>.
  11. rem *
  12. rem * This software is licensed as described in the file COPYING, which
  13. rem * you should have received as part of this distribution. The terms
  14. rem * are also available at https://curl.se/docs/copyright.html.
  15. rem *
  16. rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. rem * copies of the Software, and permit persons to whom the Software is
  18. rem * furnished to do so, under the terms of the COPYING file.
  19. rem *
  20. rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. rem * KIND, either express or implied.
  22. rem *
  23. rem ***************************************************************************
  24. :begin
  25. rem Check we are running on a Windows NT derived OS
  26. if not "%OS%" == "Windows_NT" goto nodos
  27. rem Set our variables
  28. setlocal
  29. set SUCCESSFUL_BUILDS=
  30. set VC_VER=
  31. set BUILD_PLATFORM=
  32. rem Ensure we have the required arguments
  33. if /i "%~1" == "" goto syntax
  34. rem Calculate the program files directory
  35. if defined PROGRAMFILES (
  36. set "PF=%PROGRAMFILES%"
  37. set OS_PLATFORM=x86
  38. )
  39. if defined PROGRAMFILES(x86) (
  40. set "PF=%PROGRAMFILES(x86)%"
  41. set OS_PLATFORM=x64
  42. )
  43. :parseArgs
  44. if "%~1" == "" goto prerequisites
  45. if /i "%~1" == "vc10" (
  46. set VC_VER=10.0
  47. set VC_DESC=VC10
  48. set VC_TOOLSET=v100
  49. set "VC_PATH=Microsoft Visual Studio 10.0\VC"
  50. ) else if /i "%~1" == "vc11" (
  51. set VC_VER=11.0
  52. set VC_DESC=VC11
  53. set VC_TOOLSET=v110
  54. set "VC_PATH=Microsoft Visual Studio 11.0\VC"
  55. ) else if /i "%~1" == "vc12" (
  56. set VC_VER=12.0
  57. set VC_DESC=VC12
  58. set VC_TOOLSET=v120
  59. set "VC_PATH=Microsoft Visual Studio 12.0\VC"
  60. ) else if /i "%~1" == "vc14" (
  61. set VC_VER=14.0
  62. set VC_DESC=VC14
  63. set VC_TOOLSET=v140
  64. set "VC_PATH=Microsoft Visual Studio 14.0\VC"
  65. ) else if /i "%~1" == "vc14.1" (
  66. set VC_VER=14.1
  67. set VC_DESC=VC14.1
  68. set VC_TOOLSET=v141
  69. rem Determine the VC14.1 path based on the installed edition in descending
  70. rem order (Enterprise, then Professional and finally Community)
  71. if exist "%PF%\Microsoft Visual Studio\2017\Enterprise\VC" (
  72. set "VC_PATH=Microsoft Visual Studio\2017\Enterprise\VC"
  73. ) else if exist "%PF%\Microsoft Visual Studio\2017\Professional\VC" (
  74. set "VC_PATH=Microsoft Visual Studio\2017\Professional\VC"
  75. ) else (
  76. set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
  77. )
  78. ) else if /i "%~1" == "vc14.2" (
  79. set VC_VER=14.2
  80. set VC_DESC=VC14.2
  81. set VC_TOOLSET=v142
  82. rem Determine the VC14.2 path based on the installed edition in descending
  83. rem order (Enterprise, then Professional and finally Community)
  84. if exist "%PF%\Microsoft Visual Studio\2019\Enterprise\VC" (
  85. set "VC_PATH=Microsoft Visual Studio\2019\Enterprise\VC"
  86. ) else if exist "%PF%\Microsoft Visual Studio\2019\Professional\VC" (
  87. set "VC_PATH=Microsoft Visual Studio\2019\Professional\VC"
  88. ) else (
  89. set "VC_PATH=Microsoft Visual Studio\2019\Community\VC"
  90. )
  91. ) else if /i "%~1" == "x86" (
  92. set BUILD_PLATFORM=x86
  93. ) else if /i "%~1" == "x64" (
  94. set BUILD_PLATFORM=x64
  95. ) else if /i "%~1" == "debug" (
  96. set BUILD_CONFIG=debug
  97. ) else if /i "%~1" == "release" (
  98. set BUILD_CONFIG=release
  99. ) else if /i "%~1" == "-?" (
  100. goto syntax
  101. ) else if /i "%~1" == "-h" (
  102. goto syntax
  103. ) else if /i "%~1" == "-help" (
  104. goto syntax
  105. ) else (
  106. if not defined START_DIR (
  107. set START_DIR=%~1
  108. ) else (
  109. goto unknown
  110. )
  111. )
  112. shift & goto parseArgs
  113. :prerequisites
  114. rem Compiler is a required parameter
  115. if not defined VC_VER goto syntax
  116. rem Default the start directory if one isn't specified
  117. if not defined START_DIR set START_DIR=..\..\wolfssl
  118. rem Check we have a program files directory
  119. if not defined PF goto nopf
  120. rem Check we have Visual Studio installed
  121. if not exist "%PF%\%VC_PATH%" goto novc
  122. rem Check the start directory exists
  123. if not exist "%START_DIR%" goto nowolfssl
  124. :configure
  125. if "%BUILD_PLATFORM%" == "" set BUILD_PLATFORM=%OS_PLATFORM%
  126. if "%BUILD_PLATFORM%" == "x86" (
  127. set VCVARS_PLATFORM=x86
  128. ) else if "%BUILD_PLATFORM%" == "x64" (
  129. if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  130. if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
  131. if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
  132. if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
  133. if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
  134. if "%VC_VER%" == "14.2" set VCVARS_PLATFORM=amd64
  135. )
  136. :start
  137. echo.
  138. set SAVED_PATH=%CD%
  139. if "%VC_VER%" == "14.1" (
  140. call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  141. ) else if "%VC_VER%" == "14.2" (
  142. call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  143. ) else (
  144. call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
  145. )
  146. echo.
  147. cd /d %SAVED_PATH%
  148. if defined START_DIR cd /d %START_DIR%
  149. goto %BUILD_PLATFORM%
  150. :x64
  151. rem Calculate our output directory
  152. set OUTDIR=build\Win64\%VC_DESC%
  153. if not exist %OUTDIR% md %OUTDIR%
  154. if "%BUILD_CONFIG%" == "release" goto x64release
  155. :x64debug
  156. rem Perform 64-bit Debug Build
  157. call :build Debug x64
  158. if errorlevel 1 goto error
  159. call :build "DLL Debug" x64
  160. if errorlevel 1 goto error
  161. if "%BUILD_CONFIG%" == "debug" goto success
  162. :x64release
  163. rem Perform 64-bit Release Build
  164. call :build Release x64
  165. if errorlevel 1 goto error
  166. call :build "DLL Release" x64
  167. if errorlevel 1 goto error
  168. goto success
  169. :x86
  170. rem Calculate our output directory
  171. set OUTDIR=build\Win32\%VC_DESC%
  172. if not exist %OUTDIR% md %OUTDIR%
  173. if "%BUILD_CONFIG%" == "release" goto x86release
  174. :x86debug
  175. rem Perform 32-bit Debug Build
  176. call :build Debug Win32
  177. if errorlevel 1 goto error
  178. call :build "DLL Debug" Win32
  179. if errorlevel 1 goto error
  180. if "%BUILD_CONFIG%" == "debug" goto success
  181. :x86release
  182. rem Perform 32-bit Release Build
  183. call :build Release Win32
  184. if errorlevel 1 goto error
  185. call :build "DLL Release" Win32
  186. if errorlevel 1 goto error
  187. goto success
  188. :build
  189. rem This function builds wolfSSL.
  190. rem Usage: CALL :build <configuration> <platform>
  191. rem The current directory must be the wolfSSL directory.
  192. rem VS Configuration: Debug, Release, DLL Debug or DLL Release.
  193. rem VS Platform: Win32 or x64.
  194. rem Returns: 1 on fail, 0 on success.
  195. rem An informational message should be shown before any return.
  196. setlocal
  197. set MSBUILD_CONFIG=%~1
  198. set MSBUILD_PLATFORM=%~2
  199. if not exist wolfssl64.sln (
  200. echo.
  201. echo Error: build: wolfssl64.sln not found in "%CD%"
  202. exit /b 1
  203. )
  204. rem OUTDIR isn't a full path, only relative. MSBUILD_OUTDIR must be full and
  205. rem not have trailing backslashes, which are handled later.
  206. if "%MSBUILD_CONFIG%" == "Debug" (
  207. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Debug"
  208. ) else if "%MSBUILD_CONFIG%" == "Release" (
  209. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Release"
  210. ) else if "%MSBUILD_CONFIG%" == "DLL Debug" (
  211. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Debug"
  212. ) else if "%MSBUILD_CONFIG%" == "DLL Release" (
  213. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Release"
  214. ) else (
  215. echo.
  216. echo Error: build: Configuration not recognized.
  217. exit /b 1
  218. )
  219. if not "%MSBUILD_PLATFORM%" == "Win32" if not "%MSBUILD_PLATFORM%" == "x64" (
  220. echo.
  221. echo Error: build: Platform not recognized.
  222. exit /b 1
  223. )
  224. copy /v /y "%~dp0\wolfssl_options.h" .\cyassl\options.h
  225. if %ERRORLEVEL% neq 0 (
  226. echo.
  227. echo Error: build: Couldn't replace .\cyassl\options.h
  228. exit /b 1
  229. )
  230. copy /v /y "%~dp0\wolfssl_options.h" .\wolfssl\options.h
  231. if %ERRORLEVEL% neq 0 (
  232. echo.
  233. echo Error: build: Couldn't replace .\wolfssl\options.h
  234. exit /b 1
  235. )
  236. rem Extra trailing \ in Dirs because otherwise it thinks a quote is escaped
  237. msbuild wolfssl64.sln ^
  238. -p:CustomAfterMicrosoftCommonTargets="%~dp0\wolfssl_override.props" ^
  239. -p:Configuration="%MSBUILD_CONFIG%" ^
  240. -p:Platform="%MSBUILD_PLATFORM%" ^
  241. -p:PlatformToolset="%VC_TOOLSET%" ^
  242. -p:OutDir="%MSBUILD_OUTDIR%\\" ^
  243. -p:IntDir="%MSBUILD_OUTDIR%\obj\\"
  244. if %ERRORLEVEL% neq 0 (
  245. echo.
  246. echo Error: Failed building wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  247. exit /b 1
  248. )
  249. rem For tests to run properly the wolfSSL directory must remain the current.
  250. set "PATH=%MSBUILD_OUTDIR%;%PATH%"
  251. "%MSBUILD_OUTDIR%\testsuite.exe"
  252. if %ERRORLEVEL% neq 0 (
  253. echo.
  254. echo Error: Failed testing wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  255. exit /b 1
  256. )
  257. echo.
  258. echo Success: Built and tested wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  259. echo.
  260. echo.
  261. rem This is necessary to export our local variables back to the caller.
  262. endlocal & set SUCCESSFUL_BUILDS="%MSBUILD_CONFIG%|%MSBUILD_PLATFORM%" ^
  263. %SUCCESSFUL_BUILDS%
  264. exit /b 0
  265. :syntax
  266. rem Display the help
  267. echo.
  268. echo Usage: build-wolfssl ^<compiler^> [platform] [configuration] [directory]
  269. echo.
  270. echo Compiler:
  271. echo.
  272. echo vc10 - Use Visual Studio 2010
  273. echo vc11 - Use Visual Studio 2012
  274. echo vc12 - Use Visual Studio 2013
  275. echo vc14 - Use Visual Studio 2015
  276. echo vc14.1 - Use Visual Studio 2017
  277. echo vc14.2 - Use Visual Studio 2019
  278. echo.
  279. echo Platform:
  280. echo.
  281. echo x86 - Perform a 32-bit build
  282. echo x64 - Perform a 64-bit build
  283. echo.
  284. echo Configuration:
  285. echo.
  286. echo debug - Perform a debug build
  287. echo release - Perform a release build
  288. echo.
  289. echo Other:
  290. echo.
  291. echo directory - Specifies the wolfSSL source directory
  292. goto error
  293. :unknown
  294. echo.
  295. echo Error: Unknown argument '%1'
  296. goto error
  297. :nodos
  298. echo.
  299. echo Error: Only a Windows NT based Operating System is supported
  300. goto error
  301. :nopf
  302. echo.
  303. echo Error: Cannot obtain the directory for Program Files
  304. goto error
  305. :novc
  306. echo.
  307. echo Error: %VC_DESC% is not installed
  308. goto error
  309. :nox64
  310. echo.
  311. echo Error: %VC_DESC% does not support 64-bit builds
  312. goto error
  313. :nowolfssl
  314. echo.
  315. echo Error: Cannot locate wolfSSL source directory, expected "%START_DIR%"
  316. goto error
  317. :error
  318. if "%OS%" == "Windows_NT" endlocal
  319. exit /B 1
  320. :success
  321. if defined SUCCESSFUL_BUILDS (
  322. echo.
  323. echo.
  324. echo Build complete.
  325. echo.
  326. echo The following configurations were built and tested successfully:
  327. echo.
  328. echo %SUCCESSFUL_BUILDS%
  329. echo.
  330. )
  331. cd /d %SAVED_PATH%
  332. endlocal
  333. exit /B 0