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