2
0

build-wolfssl.bat 12 KB

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