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