2
0

build-wolfssl.bat 9.0 KB

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