2
0

build-wolfssl.bat 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 - 2022, 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. set DEFAULT_START_DIR=..\..\wolfssl
  33. rem Calculate the program files directory
  34. if defined PROGRAMFILES (
  35. set "PF=%PROGRAMFILES%"
  36. set OS_PLATFORM=x86
  37. )
  38. if defined PROGRAMFILES(x86) (
  39. rem Visual Studio was x86-only prior to 14.3
  40. if /i "%~1" == "vc14.3" (
  41. set "PF=%PROGRAMFILES%"
  42. ) else (
  43. set "PF=%PROGRAMFILES(x86)%"
  44. )
  45. set OS_PLATFORM=x64
  46. )
  47. rem Ensure we have the required arguments
  48. if /i "%~1" == "" goto syntax
  49. :parseArgs
  50. if "%~1" == "" goto prerequisites
  51. if /i "%~1" == "vc10" (
  52. set VC_VER=10.0
  53. set VC_DESC=VC10
  54. set VC_TOOLSET=v100
  55. set "VC_PATH=Microsoft Visual Studio 10.0\VC"
  56. ) else if /i "%~1" == "vc11" (
  57. set VC_VER=11.0
  58. set VC_DESC=VC11
  59. set VC_TOOLSET=v110
  60. set "VC_PATH=Microsoft Visual Studio 11.0\VC"
  61. ) else if /i "%~1" == "vc12" (
  62. set VC_VER=12.0
  63. set VC_DESC=VC12
  64. set VC_TOOLSET=v120
  65. set "VC_PATH=Microsoft Visual Studio 12.0\VC"
  66. ) else if /i "%~1" == "vc14" (
  67. set VC_VER=14.0
  68. set VC_DESC=VC14
  69. set VC_TOOLSET=v140
  70. set "VC_PATH=Microsoft Visual Studio 14.0\VC"
  71. ) else if /i "%~1" == "vc14.1" (
  72. set VC_VER=14.1
  73. set VC_DESC=VC14.1
  74. set VC_TOOLSET=v141
  75. rem Determine the VC14.1 path based on the installed edition in descending
  76. rem order (Enterprise, then Professional and finally Community)
  77. if exist "%PF%\Microsoft Visual Studio\2017\Enterprise\VC" (
  78. set "VC_PATH=Microsoft Visual Studio\2017\Enterprise\VC"
  79. ) else if exist "%PF%\Microsoft Visual Studio\2017\Professional\VC" (
  80. set "VC_PATH=Microsoft Visual Studio\2017\Professional\VC"
  81. ) else (
  82. set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
  83. )
  84. ) else if /i "%~1" == "vc14.2" (
  85. set VC_VER=14.2
  86. set VC_DESC=VC14.2
  87. set VC_TOOLSET=v142
  88. rem Determine the VC14.2 path based on the installed edition in descending
  89. rem order (Enterprise, then Professional and finally Community)
  90. if exist "%PF%\Microsoft Visual Studio\2019\Enterprise\VC" (
  91. set "VC_PATH=Microsoft Visual Studio\2019\Enterprise\VC"
  92. ) else if exist "%PF%\Microsoft Visual Studio\2019\Professional\VC" (
  93. set "VC_PATH=Microsoft Visual Studio\2019\Professional\VC"
  94. ) else (
  95. set "VC_PATH=Microsoft Visual Studio\2019\Community\VC"
  96. )
  97. ) else if /i "%~1" == "vc14.3" (
  98. set VC_VER=14.3
  99. set VC_DESC=VC14.3
  100. set VC_TOOLSET=v143
  101. rem Determine the VC14.3 path based on the installed edition in descending
  102. rem order (Enterprise, then Professional and finally Community)
  103. if exist "%PF%\Microsoft Visual Studio\2022\Enterprise\VC" (
  104. set "VC_PATH=Microsoft Visual Studio\2022\Enterprise\VC"
  105. ) else if exist "%PF%\Microsoft Visual Studio\2022\Professional\VC" (
  106. set "VC_PATH=Microsoft Visual Studio\2022\Professional\VC"
  107. ) else (
  108. set "VC_PATH=Microsoft Visual Studio\2022\Community\VC"
  109. )
  110. ) else if /i "%~1" == "x86" (
  111. set BUILD_PLATFORM=x86
  112. ) else if /i "%~1" == "x64" (
  113. set BUILD_PLATFORM=x64
  114. ) else if /i "%~1" == "debug" (
  115. set BUILD_CONFIG=debug
  116. ) else if /i "%~1" == "release" (
  117. set BUILD_CONFIG=release
  118. ) else if /i "%~1" == "-?" (
  119. goto syntax
  120. ) else if /i "%~1" == "-h" (
  121. goto syntax
  122. ) else if /i "%~1" == "-help" (
  123. goto syntax
  124. ) else (
  125. if not defined START_DIR (
  126. set START_DIR=%~1
  127. ) else (
  128. goto unknown
  129. )
  130. )
  131. shift & goto parseArgs
  132. :prerequisites
  133. rem Compiler is a required parameter
  134. if not defined VC_VER goto syntax
  135. rem Default the start directory if one isn't specified
  136. if not defined START_DIR set "START_DIR=%DEFAULT_START_DIR%"
  137. rem Check we have a program files directory
  138. if not defined PF goto nopf
  139. rem Check we have Visual Studio installed
  140. if not exist "%PF%\%VC_PATH%" goto novc
  141. rem Check the start directory exists
  142. if not exist "%START_DIR%" goto nowolfssl
  143. :configure
  144. if "%BUILD_PLATFORM%" == "" set BUILD_PLATFORM=%OS_PLATFORM%
  145. if "%BUILD_PLATFORM%" == "x86" (
  146. set VCVARS_PLATFORM=x86
  147. ) else if "%BUILD_PLATFORM%" == "x64" (
  148. if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  149. if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
  150. if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
  151. if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
  152. if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
  153. if "%VC_VER%" == "14.2" set VCVARS_PLATFORM=amd64
  154. if "%VC_VER%" == "14.3" set VCVARS_PLATFORM=amd64
  155. )
  156. :start
  157. echo.
  158. set SAVED_PATH=%CD%
  159. if "%VC_VER%" == "14.1" (
  160. call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  161. ) else if "%VC_VER%" == "14.2" (
  162. call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  163. ) else if "%VC_VER%" == "14.3" (
  164. call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  165. ) else (
  166. call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
  167. )
  168. echo.
  169. cd /d %SAVED_PATH%
  170. if defined START_DIR cd /d %START_DIR%
  171. goto %BUILD_PLATFORM%
  172. :x64
  173. rem Calculate our output directory
  174. set OUTDIR=build\Win64\%VC_DESC%
  175. if not exist %OUTDIR% md %OUTDIR%
  176. if "%BUILD_CONFIG%" == "release" goto x64release
  177. :x64debug
  178. rem Perform 64-bit Debug Build
  179. call :build Debug x64
  180. if errorlevel 1 goto error
  181. call :build "DLL Debug" x64
  182. if errorlevel 1 goto error
  183. if "%BUILD_CONFIG%" == "debug" goto success
  184. :x64release
  185. rem Perform 64-bit Release Build
  186. call :build Release x64
  187. if errorlevel 1 goto error
  188. call :build "DLL Release" x64
  189. if errorlevel 1 goto error
  190. goto success
  191. :x86
  192. rem Calculate our output directory
  193. set OUTDIR=build\Win32\%VC_DESC%
  194. if not exist %OUTDIR% md %OUTDIR%
  195. if "%BUILD_CONFIG%" == "release" goto x86release
  196. :x86debug
  197. rem Perform 32-bit Debug Build
  198. call :build Debug Win32
  199. if errorlevel 1 goto error
  200. call :build "DLL Debug" Win32
  201. if errorlevel 1 goto error
  202. if "%BUILD_CONFIG%" == "debug" goto success
  203. :x86release
  204. rem Perform 32-bit Release Build
  205. call :build Release Win32
  206. if errorlevel 1 goto error
  207. call :build "DLL Release" Win32
  208. if errorlevel 1 goto error
  209. goto success
  210. :build
  211. rem This function builds wolfSSL.
  212. rem Usage: CALL :build <configuration> <platform>
  213. rem The current directory must be the wolfSSL directory.
  214. rem VS Configuration: Debug, Release, DLL Debug or DLL Release.
  215. rem VS Platform: Win32 or x64.
  216. rem Returns: 1 on fail, 0 on success.
  217. rem An informational message should be shown before any return.
  218. setlocal
  219. set MSBUILD_CONFIG=%~1
  220. set MSBUILD_PLATFORM=%~2
  221. if not exist wolfssl64.sln (
  222. echo.
  223. echo Error: build: wolfssl64.sln not found in "%CD%"
  224. exit /b 1
  225. )
  226. rem OUTDIR isn't a full path, only relative. MSBUILD_OUTDIR must be full and
  227. rem not have trailing backslashes, which are handled later.
  228. if "%MSBUILD_CONFIG%" == "Debug" (
  229. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Debug"
  230. ) else if "%MSBUILD_CONFIG%" == "Release" (
  231. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Release"
  232. ) else if "%MSBUILD_CONFIG%" == "DLL Debug" (
  233. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Debug"
  234. ) else if "%MSBUILD_CONFIG%" == "DLL Release" (
  235. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Release"
  236. ) else (
  237. echo.
  238. echo Error: build: Configuration not recognized.
  239. exit /b 1
  240. )
  241. if not "%MSBUILD_PLATFORM%" == "Win32" if not "%MSBUILD_PLATFORM%" == "x64" (
  242. echo.
  243. echo Error: build: Platform not recognized.
  244. exit /b 1
  245. )
  246. copy /v /y "%~dp0\wolfssl_options.h" .\cyassl\options.h
  247. if %ERRORLEVEL% neq 0 (
  248. echo.
  249. echo Error: build: Couldn't replace .\cyassl\options.h
  250. exit /b 1
  251. )
  252. copy /v /y "%~dp0\wolfssl_options.h" .\wolfssl\options.h
  253. if %ERRORLEVEL% neq 0 (
  254. echo.
  255. echo Error: build: Couldn't replace .\wolfssl\options.h
  256. exit /b 1
  257. )
  258. rem Extra trailing \ in Dirs because otherwise it thinks a quote is escaped
  259. msbuild wolfssl64.sln ^
  260. -p:CustomAfterMicrosoftCommonTargets="%~dp0\wolfssl_override.props" ^
  261. -p:Configuration="%MSBUILD_CONFIG%" ^
  262. -p:Platform="%MSBUILD_PLATFORM%" ^
  263. -p:PlatformToolset="%VC_TOOLSET%" ^
  264. -p:OutDir="%MSBUILD_OUTDIR%\\" ^
  265. -p:IntDir="%MSBUILD_OUTDIR%\obj\\"
  266. if %ERRORLEVEL% neq 0 (
  267. echo.
  268. echo Error: Failed building wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  269. exit /b 1
  270. )
  271. rem For tests to run properly the wolfSSL directory must remain the current.
  272. set "PATH=%MSBUILD_OUTDIR%;%PATH%"
  273. "%MSBUILD_OUTDIR%\testsuite.exe"
  274. if %ERRORLEVEL% neq 0 (
  275. echo.
  276. echo Error: Failed testing wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  277. exit /b 1
  278. )
  279. echo.
  280. echo Success: Built and tested wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  281. echo.
  282. echo.
  283. rem This is necessary to export our local variables back to the caller.
  284. endlocal & set SUCCESSFUL_BUILDS="%MSBUILD_CONFIG%|%MSBUILD_PLATFORM%" ^
  285. %SUCCESSFUL_BUILDS%
  286. exit /b 0
  287. :syntax
  288. rem Display the help
  289. echo.
  290. echo Usage: build-wolfssl ^<compiler^> [platform] [configuration] [directory]
  291. echo.
  292. echo.
  293. echo Compiler:
  294. echo.
  295. echo vc10 - Use Visual Studio 2010
  296. echo vc11 - Use Visual Studio 2012
  297. echo vc12 - Use Visual Studio 2013
  298. echo vc14 - Use Visual Studio 2015
  299. echo vc14.1 - Use Visual Studio 2017
  300. echo vc14.2 - Use Visual Studio 2019
  301. echo vc14.3 - Use Visual Studio 2022
  302. echo.
  303. echo.
  304. echo Platform:
  305. echo.
  306. echo x86 - Perform a 32-bit build
  307. echo x64 - Perform a 64-bit build
  308. echo.
  309. echo If this parameter is unset the OS platform is used ^(%OS_PLATFORM%^).
  310. echo.
  311. echo.
  312. echo Configuration:
  313. echo.
  314. echo debug - Perform a debug build
  315. echo release - Perform a release build
  316. echo.
  317. echo If this parameter is unset both configurations are built.
  318. echo.
  319. echo.
  320. echo Other:
  321. echo.
  322. echo directory - Specifies the wolfSSL source directory
  323. echo.
  324. echo If this parameter is unset the directory used is "%DEFAULT_START_DIR%".
  325. echo.
  326. goto error
  327. :unknown
  328. echo.
  329. echo Error: Unknown argument '%1'
  330. goto error
  331. :nodos
  332. echo.
  333. echo Error: Only a Windows NT based Operating System is supported
  334. goto error
  335. :nopf
  336. echo.
  337. echo Error: Cannot obtain the directory for Program Files
  338. goto error
  339. :novc
  340. echo.
  341. echo Error: %VC_DESC% is not installed
  342. goto error
  343. :nox64
  344. echo.
  345. echo Error: %VC_DESC% does not support 64-bit builds
  346. goto error
  347. :nowolfssl
  348. echo.
  349. echo Error: Cannot locate wolfSSL source directory, expected "%START_DIR%"
  350. goto error
  351. :error
  352. if "%OS%" == "Windows_NT" endlocal
  353. exit /B 1
  354. :success
  355. if defined SUCCESSFUL_BUILDS (
  356. echo.
  357. echo.
  358. echo Build complete.
  359. echo.
  360. echo The following configurations were built and tested successfully:
  361. echo.
  362. echo %SUCCESSFUL_BUILDS%
  363. echo.
  364. )
  365. cd /d %SAVED_PATH%
  366. endlocal
  367. exit /B 0