xf.li | 6c8fc1e | 2023-08-12 00:11:09 -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 - 2020, Steve Holme, <steve_holme@hotmail.com>.
|
| 10 | rem * Copyright (C) 2015 - 2022, 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.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 * SPDX-License-Identifier: curl
|
| 24 | rem *
|
| 25 | rem ***************************************************************************
|
| 26 |
|
| 27 | :begin
|
| 28 | rem Check we are running on a Windows NT derived OS
|
| 29 | if not "%OS%" == "Windows_NT" goto nodos
|
| 30 |
|
| 31 | rem Set our variables
|
| 32 | setlocal
|
| 33 | set SUCCESSFUL_BUILDS=
|
| 34 | set VC_VER=
|
| 35 | set BUILD_PLATFORM=
|
| 36 | set DEFAULT_START_DIR=..\..\wolfssl
|
| 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 | rem Visual Studio was x86-only prior to 14.3
|
| 45 | if /i "%~1" == "vc14.3" (
|
| 46 | set "PF=%PROGRAMFILES%"
|
| 47 | ) else (
|
| 48 | set "PF=%PROGRAMFILES(x86)%"
|
| 49 | )
|
| 50 | set OS_PLATFORM=x64
|
| 51 | )
|
| 52 |
|
| 53 | rem Ensure we have the required arguments
|
| 54 | if /i "%~1" == "" goto syntax
|
| 55 |
|
| 56 | :parseArgs
|
| 57 | if "%~1" == "" goto prerequisites
|
| 58 |
|
| 59 | if /i "%~1" == "vc10" (
|
| 60 | set VC_VER=10.0
|
| 61 | set VC_DESC=VC10
|
| 62 | set VC_TOOLSET=v100
|
| 63 | set "VC_PATH=Microsoft Visual Studio 10.0\VC"
|
| 64 | ) else if /i "%~1" == "vc11" (
|
| 65 | set VC_VER=11.0
|
| 66 | set VC_DESC=VC11
|
| 67 | set VC_TOOLSET=v110
|
| 68 | set "VC_PATH=Microsoft Visual Studio 11.0\VC"
|
| 69 | ) else if /i "%~1" == "vc12" (
|
| 70 | set VC_VER=12.0
|
| 71 | set VC_DESC=VC12
|
| 72 | set VC_TOOLSET=v120
|
| 73 | set "VC_PATH=Microsoft Visual Studio 12.0\VC"
|
| 74 | ) else if /i "%~1" == "vc14" (
|
| 75 | set VC_VER=14.0
|
| 76 | set VC_DESC=VC14
|
| 77 | set VC_TOOLSET=v140
|
| 78 | set "VC_PATH=Microsoft Visual Studio 14.0\VC"
|
| 79 | ) else if /i "%~1" == "vc14.1" (
|
| 80 | set VC_VER=14.1
|
| 81 | set VC_DESC=VC14.10
|
| 82 | set VC_TOOLSET=v141
|
| 83 |
|
| 84 | rem Determine the VC14.1 path based on the installed edition in descending
|
| 85 | rem order (Enterprise, then Professional and finally Community)
|
| 86 | if exist "%PF%\Microsoft Visual Studio\2017\Enterprise\VC" (
|
| 87 | set "VC_PATH=Microsoft Visual Studio\2017\Enterprise\VC"
|
| 88 | ) else if exist "%PF%\Microsoft Visual Studio\2017\Professional\VC" (
|
| 89 | set "VC_PATH=Microsoft Visual Studio\2017\Professional\VC"
|
| 90 | ) else (
|
| 91 | set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
|
| 92 | )
|
| 93 | ) else if /i "%~1" == "vc14.2" (
|
| 94 | set VC_VER=14.2
|
| 95 | set VC_DESC=VC14.20
|
| 96 | set VC_TOOLSET=v142
|
| 97 |
|
| 98 | rem Determine the VC14.2 path based on the installed edition in descending
|
| 99 | rem order (Enterprise, then Professional and finally Community)
|
| 100 | if exist "%PF%\Microsoft Visual Studio\2019\Enterprise\VC" (
|
| 101 | set "VC_PATH=Microsoft Visual Studio\2019\Enterprise\VC"
|
| 102 | ) else if exist "%PF%\Microsoft Visual Studio\2019\Professional\VC" (
|
| 103 | set "VC_PATH=Microsoft Visual Studio\2019\Professional\VC"
|
| 104 | ) else (
|
| 105 | set "VC_PATH=Microsoft Visual Studio\2019\Community\VC"
|
| 106 | )
|
| 107 | ) else if /i "%~1" == "vc14.3" (
|
| 108 | set VC_VER=14.3
|
| 109 | set VC_DESC=VC14.30
|
| 110 | set VC_TOOLSET=v143
|
| 111 |
|
| 112 | rem Determine the VC14.3 path based on the installed edition in descending
|
| 113 | rem order (Enterprise, then Professional and finally Community)
|
| 114 | if exist "%PF%\Microsoft Visual Studio\2022\Enterprise\VC" (
|
| 115 | set "VC_PATH=Microsoft Visual Studio\2022\Enterprise\VC"
|
| 116 | ) else if exist "%PF%\Microsoft Visual Studio\2022\Professional\VC" (
|
| 117 | set "VC_PATH=Microsoft Visual Studio\2022\Professional\VC"
|
| 118 | ) else (
|
| 119 | set "VC_PATH=Microsoft Visual Studio\2022\Community\VC"
|
| 120 | )
|
| 121 | ) else if /i "%~1" == "x86" (
|
| 122 | set BUILD_PLATFORM=x86
|
| 123 | ) else if /i "%~1" == "x64" (
|
| 124 | set BUILD_PLATFORM=x64
|
| 125 | ) else if /i "%~1" == "debug" (
|
| 126 | set BUILD_CONFIG=debug
|
| 127 | ) else if /i "%~1" == "release" (
|
| 128 | set BUILD_CONFIG=release
|
| 129 | ) else if /i "%~1" == "-?" (
|
| 130 | goto syntax
|
| 131 | ) else if /i "%~1" == "-h" (
|
| 132 | goto syntax
|
| 133 | ) else if /i "%~1" == "-help" (
|
| 134 | goto syntax
|
| 135 | ) else (
|
| 136 | if not defined START_DIR (
|
| 137 | set START_DIR=%~1
|
| 138 | ) else (
|
| 139 | goto unknown
|
| 140 | )
|
| 141 | )
|
| 142 |
|
| 143 | shift & goto parseArgs
|
| 144 |
|
| 145 | :prerequisites
|
| 146 | rem Compiler is a required parameter
|
| 147 | if not defined VC_VER goto syntax
|
| 148 |
|
| 149 | rem Default the start directory if one isn't specified
|
| 150 | if not defined START_DIR set "START_DIR=%DEFAULT_START_DIR%"
|
| 151 |
|
| 152 | rem Check we have a program files directory
|
| 153 | if not defined PF goto nopf
|
| 154 |
|
| 155 | rem Check we have Visual Studio installed
|
| 156 | if not exist "%PF%\%VC_PATH%" goto novc
|
| 157 |
|
| 158 | rem Check the start directory exists
|
| 159 | if not exist "%START_DIR%" goto nowolfssl
|
| 160 |
|
| 161 | :configure
|
| 162 | if "%BUILD_PLATFORM%" == "" set BUILD_PLATFORM=%OS_PLATFORM%
|
| 163 |
|
| 164 | if "%BUILD_PLATFORM%" == "x86" (
|
| 165 | set VCVARS_PLATFORM=x86
|
| 166 | ) else if "%BUILD_PLATFORM%" == "x64" (
|
| 167 | if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
|
| 168 | if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
|
| 169 | if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
|
| 170 | if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
|
| 171 | if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
|
| 172 | if "%VC_VER%" == "14.2" set VCVARS_PLATFORM=amd64
|
| 173 | if "%VC_VER%" == "14.3" set VCVARS_PLATFORM=amd64
|
| 174 | )
|
| 175 |
|
| 176 | :start
|
| 177 | echo.
|
| 178 | set SAVED_PATH=%CD%
|
| 179 |
|
| 180 | if "%VC_VER%" == "14.1" (
|
| 181 | call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
|
| 182 | ) else if "%VC_VER%" == "14.2" (
|
| 183 | call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
|
| 184 | ) else if "%VC_VER%" == "14.3" (
|
| 185 | call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
|
| 186 | ) else (
|
| 187 | call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
|
| 188 | )
|
| 189 |
|
| 190 | echo.
|
| 191 | cd /d %SAVED_PATH%
|
| 192 | if defined START_DIR cd /d %START_DIR%
|
| 193 | goto %BUILD_PLATFORM%
|
| 194 |
|
| 195 | :x64
|
| 196 | rem Calculate our output directory
|
| 197 | set OUTDIR=build\Win64\%VC_DESC%
|
| 198 | if not exist %OUTDIR% md %OUTDIR%
|
| 199 |
|
| 200 | if "%BUILD_CONFIG%" == "release" goto x64release
|
| 201 |
|
| 202 | :x64debug
|
| 203 | rem Perform 64-bit Debug Build
|
| 204 |
|
| 205 | call :build Debug x64
|
| 206 | if errorlevel 1 goto error
|
| 207 |
|
| 208 | call :build "DLL Debug" x64
|
| 209 | if errorlevel 1 goto error
|
| 210 |
|
| 211 | if "%BUILD_CONFIG%" == "debug" goto success
|
| 212 |
|
| 213 | :x64release
|
| 214 | rem Perform 64-bit Release Build
|
| 215 |
|
| 216 | call :build Release x64
|
| 217 | if errorlevel 1 goto error
|
| 218 |
|
| 219 | call :build "DLL Release" x64
|
| 220 | if errorlevel 1 goto error
|
| 221 |
|
| 222 | goto success
|
| 223 |
|
| 224 | :x86
|
| 225 | rem Calculate our output directory
|
| 226 | set OUTDIR=build\Win32\%VC_DESC%
|
| 227 | if not exist %OUTDIR% md %OUTDIR%
|
| 228 |
|
| 229 | if "%BUILD_CONFIG%" == "release" goto x86release
|
| 230 |
|
| 231 | :x86debug
|
| 232 | rem Perform 32-bit Debug Build
|
| 233 |
|
| 234 | call :build Debug Win32
|
| 235 | if errorlevel 1 goto error
|
| 236 |
|
| 237 | call :build "DLL Debug" Win32
|
| 238 | if errorlevel 1 goto error
|
| 239 |
|
| 240 | if "%BUILD_CONFIG%" == "debug" goto success
|
| 241 |
|
| 242 | :x86release
|
| 243 | rem Perform 32-bit Release Build
|
| 244 |
|
| 245 | call :build Release Win32
|
| 246 | if errorlevel 1 goto error
|
| 247 |
|
| 248 | call :build "DLL Release" Win32
|
| 249 | if errorlevel 1 goto error
|
| 250 |
|
| 251 | goto success
|
| 252 |
|
| 253 | :build
|
| 254 | rem This function builds wolfSSL.
|
| 255 | rem Usage: CALL :build <configuration> <platform>
|
| 256 | rem The current directory must be the wolfSSL directory.
|
| 257 | rem VS Configuration: Debug, Release, DLL Debug or DLL Release.
|
| 258 | rem VS Platform: Win32 or x64.
|
| 259 | rem Returns: 1 on fail, 0 on success.
|
| 260 | rem An informational message should be shown before any return.
|
| 261 | setlocal
|
| 262 | set MSBUILD_CONFIG=%~1
|
| 263 | set MSBUILD_PLATFORM=%~2
|
| 264 |
|
| 265 | if not exist wolfssl64.sln (
|
| 266 | echo.
|
| 267 | echo Error: build: wolfssl64.sln not found in "%CD%"
|
| 268 | exit /b 1
|
| 269 | )
|
| 270 |
|
| 271 | rem OUTDIR isn't a full path, only relative. MSBUILD_OUTDIR must be full and
|
| 272 | rem not have trailing backslashes, which are handled later.
|
| 273 | if "%MSBUILD_CONFIG%" == "Debug" (
|
| 274 | set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Debug"
|
| 275 | ) else if "%MSBUILD_CONFIG%" == "Release" (
|
| 276 | set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\LIB Release"
|
| 277 | ) else if "%MSBUILD_CONFIG%" == "DLL Debug" (
|
| 278 | set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Debug"
|
| 279 | ) else if "%MSBUILD_CONFIG%" == "DLL Release" (
|
| 280 | set "MSBUILD_OUTDIR=%CD%\%OUTDIR%\DLL Release"
|
| 281 | ) else (
|
| 282 | echo.
|
| 283 | echo Error: build: Configuration not recognized.
|
| 284 | exit /b 1
|
| 285 | )
|
| 286 |
|
| 287 | if not "%MSBUILD_PLATFORM%" == "Win32" if not "%MSBUILD_PLATFORM%" == "x64" (
|
| 288 | echo.
|
| 289 | echo Error: build: Platform not recognized.
|
| 290 | exit /b 1
|
| 291 | )
|
| 292 |
|
| 293 | copy /v /y "%~dp0\wolfssl_options.h" .\cyassl\options.h
|
| 294 | if %ERRORLEVEL% neq 0 (
|
| 295 | echo.
|
| 296 | echo Error: build: Couldn't replace .\cyassl\options.h
|
| 297 | exit /b 1
|
| 298 | )
|
| 299 |
|
| 300 | copy /v /y "%~dp0\wolfssl_options.h" .\wolfssl\options.h
|
| 301 | if %ERRORLEVEL% neq 0 (
|
| 302 | echo.
|
| 303 | echo Error: build: Couldn't replace .\wolfssl\options.h
|
| 304 | exit /b 1
|
| 305 | )
|
| 306 |
|
| 307 | rem Extra trailing \ in Dirs because otherwise it thinks a quote is escaped
|
| 308 | msbuild wolfssl64.sln ^
|
| 309 | -p:CustomAfterMicrosoftCommonTargets="%~dp0\wolfssl_override.props" ^
|
| 310 | -p:Configuration="%MSBUILD_CONFIG%" ^
|
| 311 | -p:Platform="%MSBUILD_PLATFORM%" ^
|
| 312 | -p:PlatformToolset="%VC_TOOLSET%" ^
|
| 313 | -p:OutDir="%MSBUILD_OUTDIR%\\" ^
|
| 314 | -p:IntDir="%MSBUILD_OUTDIR%\obj\\"
|
| 315 |
|
| 316 | if %ERRORLEVEL% neq 0 (
|
| 317 | echo.
|
| 318 | echo Error: Failed building wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
|
| 319 | exit /b 1
|
| 320 | )
|
| 321 |
|
| 322 | rem For tests to run properly the wolfSSL directory must remain the current.
|
| 323 | set "PATH=%MSBUILD_OUTDIR%;%PATH%"
|
| 324 | "%MSBUILD_OUTDIR%\testsuite.exe"
|
| 325 |
|
| 326 | if %ERRORLEVEL% neq 0 (
|
| 327 | echo.
|
| 328 | echo Error: Failed testing wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
|
| 329 | exit /b 1
|
| 330 | )
|
| 331 |
|
| 332 | echo.
|
| 333 | echo Success: Built and tested wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
|
| 334 | echo.
|
| 335 | echo.
|
| 336 | rem This is necessary to export our local variables back to the caller.
|
| 337 | endlocal & set SUCCESSFUL_BUILDS="%MSBUILD_CONFIG%|%MSBUILD_PLATFORM%" ^
|
| 338 | %SUCCESSFUL_BUILDS%
|
| 339 | exit /b 0
|
| 340 |
|
| 341 | :syntax
|
| 342 | rem Display the help
|
| 343 | echo.
|
| 344 | echo Usage: build-wolfssl ^<compiler^> [platform] [configuration] [directory]
|
| 345 | echo.
|
| 346 | echo.
|
| 347 | echo Compiler:
|
| 348 | echo.
|
| 349 | echo vc10 - Use Visual Studio 2010
|
| 350 | echo vc11 - Use Visual Studio 2012
|
| 351 | echo vc12 - Use Visual Studio 2013
|
| 352 | echo vc14 - Use Visual Studio 2015
|
| 353 | echo vc14.1 - Use Visual Studio 2017
|
| 354 | echo vc14.2 - Use Visual Studio 2019
|
| 355 | echo vc14.3 - Use Visual Studio 2022
|
| 356 | echo.
|
| 357 | echo.
|
| 358 | echo Platform:
|
| 359 | echo.
|
| 360 | echo x86 - Perform a 32-bit build
|
| 361 | echo x64 - Perform a 64-bit build
|
| 362 | echo.
|
| 363 | echo If this parameter is unset the OS platform is used ^(%OS_PLATFORM%^).
|
| 364 | echo.
|
| 365 | echo.
|
| 366 | echo Configuration:
|
| 367 | echo.
|
| 368 | echo debug - Perform a debug build
|
| 369 | echo release - Perform a release build
|
| 370 | echo.
|
| 371 | echo If this parameter is unset both configurations are built.
|
| 372 | echo.
|
| 373 | echo.
|
| 374 | echo Other:
|
| 375 | echo.
|
| 376 | echo directory - Specifies the wolfSSL source directory
|
| 377 | echo.
|
| 378 | echo If this parameter is unset the directory used is "%DEFAULT_START_DIR%".
|
| 379 | echo.
|
| 380 | goto error
|
| 381 |
|
| 382 | :unknown
|
| 383 | echo.
|
| 384 | echo Error: Unknown argument '%1'
|
| 385 | goto error
|
| 386 |
|
| 387 | :nodos
|
| 388 | echo.
|
| 389 | echo Error: Only a Windows NT based Operating System is supported
|
| 390 | goto error
|
| 391 |
|
| 392 | :nopf
|
| 393 | echo.
|
| 394 | echo Error: Cannot obtain the directory for Program Files
|
| 395 | goto error
|
| 396 |
|
| 397 | :novc
|
| 398 | echo.
|
| 399 | echo Error: %VC_DESC% is not installed
|
| 400 | goto error
|
| 401 |
|
| 402 | :nox64
|
| 403 | echo.
|
| 404 | echo Error: %VC_DESC% does not support 64-bit builds
|
| 405 | goto error
|
| 406 |
|
| 407 | :nowolfssl
|
| 408 | echo.
|
| 409 | echo Error: Cannot locate wolfSSL source directory, expected "%START_DIR%"
|
| 410 | goto error
|
| 411 |
|
| 412 | :error
|
| 413 | if "%OS%" == "Windows_NT" endlocal
|
| 414 | exit /B 1
|
| 415 |
|
| 416 | :success
|
| 417 | if defined SUCCESSFUL_BUILDS (
|
| 418 | echo.
|
| 419 | echo.
|
| 420 | echo Build complete.
|
| 421 | echo.
|
| 422 | echo The following configurations were built and tested successfully:
|
| 423 | echo.
|
| 424 | echo %SUCCESSFUL_BUILDS%
|
| 425 | echo.
|
| 426 | )
|
| 427 | cd /d %SAVED_PATH%
|
| 428 | endlocal
|
| 429 | exit /B 0
|