build-wolfssl.bat 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. @echo off
  2. rem ***************************************************************************
  3. rem * _ _ ____ _
  4. rem * Project ___| | | | _ \| |
  5. rem * / __| | | | |_) | |
  6. rem * | (__| |_| | _ <| |___
  7. rem * \___|\___/|_| \_\_____|
  8. rem *
  9. rem * Copyright (C) 2012 - 2018, 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.haxx.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" == "x86" (
  79. set BUILD_PLATFORM=x86
  80. ) else if /i "%~1" == "x64" (
  81. set BUILD_PLATFORM=x64
  82. ) else if /i "%~1" == "debug" (
  83. set BUILD_CONFIG=debug
  84. ) else if /i "%~1" == "release" (
  85. set BUILD_CONFIG=release
  86. ) else if /i "%~1" == "-?" (
  87. goto syntax
  88. ) else if /i "%~1" == "-h" (
  89. goto syntax
  90. ) else if /i "%~1" == "-help" (
  91. goto syntax
  92. ) else (
  93. if not defined START_DIR (
  94. set START_DIR=%~1
  95. ) else (
  96. goto unknown
  97. )
  98. )
  99. shift & goto parseArgs
  100. :prerequisites
  101. rem Compiler is a required parameter
  102. if not defined VC_VER goto syntax
  103. rem Default the start directory if one isn't specified
  104. if not defined START_DIR set START_DIR=..\..\wolfssl
  105. rem Check we have a program files directory
  106. if not defined PF goto nopf
  107. rem Check we have Visual Studio installed
  108. if not exist "%PF%\%VC_PATH%" goto novc
  109. rem Check the start directory exists
  110. if not exist "%START_DIR%" goto nowolfssl
  111. :configure
  112. if "%BUILD_PLATFORM%" == "" set BUILD_PLATFORM=%OS_PLATFORM%
  113. if "%BUILD_PLATFORM%" == "x86" (
  114. set VCVARS_PLATFORM=x86
  115. ) else if "%BUILD_PLATFORM%" == "x64" (
  116. if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  117. if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
  118. if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
  119. if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
  120. if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
  121. )
  122. :start
  123. echo.
  124. set SAVED_PATH=%CD%
  125. if "%VC_VER%" == "14.1" (
  126. call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  127. ) else (
  128. call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
  129. )
  130. echo.
  131. cd /d %SAVED_PATH%
  132. if defined START_DIR cd /d %START_DIR%
  133. goto %BUILD_PLATFORM%
  134. :x64
  135. rem Calculate our output directory
  136. set OUTDIR=build\Win64\%VC_DESC%
  137. if not exist %OUTDIR% md %OUTDIR%
  138. if "%BUILD_CONFIG%" == "release" goto x64release
  139. :x64debug
  140. rem Perform 64-bit Debug Build
  141. call :build Debug x64
  142. if errorlevel 1 goto error
  143. call :build "DLL Debug" x64
  144. if errorlevel 1 goto error
  145. if "%BUILD_CONFIG%" == "debug" goto success
  146. :x64release
  147. rem Perform 64-bit Release Build
  148. call :build Release x64
  149. if errorlevel 1 goto error
  150. call :build "DLL Release" x64
  151. if errorlevel 1 goto error
  152. goto success
  153. :x86
  154. rem Calculate our output directory
  155. set OUTDIR=build\Win32\%VC_DESC%
  156. if not exist %OUTDIR% md %OUTDIR%
  157. if "%BUILD_CONFIG%" == "release" goto x86release
  158. :x86debug
  159. rem Perform 32-bit Debug Build
  160. call :build Debug Win32
  161. if errorlevel 1 goto error
  162. call :build "DLL Debug" Win32
  163. if errorlevel 1 goto error
  164. if "%BUILD_CONFIG%" == "debug" goto success
  165. :x86release
  166. rem Perform 32-bit Release Build
  167. call :build Release Win32
  168. if errorlevel 1 goto error
  169. call :build "DLL Release" Win32
  170. if errorlevel 1 goto error
  171. goto success
  172. :build
  173. rem This function builds wolfSSL.
  174. rem Usage: CALL :build <configuration> <platform>
  175. rem The current directory must be the wolfSSL directory.
  176. rem VS Configuration: Debug, Release, DLL Debug or DLL Release.
  177. rem VS Platform: Win32 or x64.
  178. rem Returns: 1 on fail, 0 on success.
  179. rem An informational message should be shown before any return.
  180. setlocal
  181. set MSBUILD_CONFIG=%~1
  182. set MSBUILD_PLATFORM=%~2
  183. if not exist wolfssl64.sln (
  184. echo.
  185. echo Error: build: wolfssl64.sln not found in "%CD%"
  186. exit /b 1
  187. )
  188. rem OUTDIR isn't a full path, only relative. MSBUILD_OUTDIR must be full and
  189. rem not have trailing backslashes, which are handled later.
  190. if "%MSBUILD_CONFIG%" == "Debug" (
  191. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Debug"
  192. ) else if "%MSBUILD_CONFIG%" == "Release" (
  193. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Release"
  194. ) else if "%MSBUILD_CONFIG%" == "DLL Debug" (
  195. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Debug"
  196. ) else if "%MSBUILD_CONFIG%" == "DLL Release" (
  197. set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Release"
  198. ) else (
  199. echo.
  200. echo Error: build: Configuration not recognized.
  201. exit /b 1
  202. )
  203. if not "%MSBUILD_PLATFORM%" == "Win32" if not "%MSBUILD_PLATFORM%" == "x64" (
  204. echo.
  205. echo Error: build: Platform not recognized.
  206. exit /b 1
  207. )
  208. copy /v /y "%~dp0\wolfssl_options.h" .\cyassl\options.h
  209. if %ERRORLEVEL% neq 0 (
  210. echo.
  211. echo Error: build: Couldn't replace .\cyassl\options.h
  212. exit /b 1
  213. )
  214. copy /v /y "%~dp0\wolfssl_options.h" .\wolfssl\options.h
  215. if %ERRORLEVEL% neq 0 (
  216. echo.
  217. echo Error: build: Couldn't replace .\wolfssl\options.h
  218. exit /b 1
  219. )
  220. rem Extra trailing \ in Dirs because otherwise it thinks a quote is escaped
  221. msbuild wolfssl64.sln ^
  222. -p:CustomAfterMicrosoftCommonTargets="%~dp0\wolfssl_override.props" ^
  223. -p:Configuration="%MSBUILD_CONFIG%" ^
  224. -p:Platform="%MSBUILD_PLATFORM%" ^
  225. -p:PlatformToolset="%VC_TOOLSET%" ^
  226. -p:OutDir="%MSBUILD_OUTDIR%\\" ^
  227. -p:IntDir="%MSBUILD_OUTDIR%\obj\\"
  228. if %ERRORLEVEL% neq 0 (
  229. echo.
  230. echo Error: Failed building wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  231. exit /b 1
  232. )
  233. rem For tests to run properly the wolfSSL directory must remain the current.
  234. set "PATH=%MSBUILD_OUTDIR%;%PATH%"
  235. "%MSBUILD_OUTDIR%\testsuite.exe"
  236. if %ERRORLEVEL% neq 0 (
  237. echo.
  238. echo Error: Failed testing wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  239. exit /b 1
  240. )
  241. echo.
  242. echo Success: Built and tested wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
  243. echo.
  244. echo.
  245. rem This is necessary to export our local variables back to the caller.
  246. endlocal & set SUCCESSFUL_BUILDS="%MSBUILD_CONFIG%|%MSBUILD_PLATFORM%" ^
  247. %SUCCESSFUL_BUILDS%
  248. exit /b 0
  249. :syntax
  250. rem Display the help
  251. echo.
  252. echo Usage: build-wolfssl ^<compiler^> [platform] [configuration] [directory]
  253. echo.
  254. echo Compiler:
  255. echo.
  256. echo vc10 - Use Visual Studio 2010
  257. echo vc11 - Use Visual Studio 2012
  258. echo vc12 - Use Visual Studio 2013
  259. echo vc14 - Use Visual Studio 2015
  260. echo vc14.1 - Use Visual Studio 2017
  261. echo.
  262. echo Platform:
  263. echo.
  264. echo x86 - Perform a 32-bit build
  265. echo x64 - Perform a 64-bit build
  266. echo.
  267. echo Configuration:
  268. echo.
  269. echo debug - Perform a debug build
  270. echo release - Perform a release build
  271. echo.
  272. echo Other:
  273. echo.
  274. echo directory - Specifies the wolfSSL source directory
  275. goto error
  276. :unknown
  277. echo.
  278. echo Error: Unknown argument '%1'
  279. goto error
  280. :nodos
  281. echo.
  282. echo Error: Only a Windows NT based Operating System is supported
  283. goto error
  284. :nopf
  285. echo.
  286. echo Error: Cannot obtain the directory for Program Files
  287. goto error
  288. :novc
  289. echo.
  290. echo Error: %VC_DESC% is not installed
  291. goto error
  292. :nox64
  293. echo.
  294. echo Error: %VC_DESC% does not support 64-bit builds
  295. goto error
  296. :nowolfssl
  297. echo.
  298. echo Error: Cannot locate wolfSSL source directory, expected "%START_DIR%"
  299. goto error
  300. :error
  301. if "%OS%" == "Windows_NT" endlocal
  302. exit /B 1
  303. :success
  304. if defined SUCCESSFUL_BUILDS (
  305. echo.
  306. echo.
  307. echo Build complete.
  308. echo.
  309. echo The following configurations were built and tested successfully:
  310. echo.
  311. echo %SUCCESSFUL_BUILDS%
  312. echo.
  313. )
  314. cd /d %SAVED_PATH%
  315. endlocal
  316. exit /B 0