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