2 rem ***************************************************************************
4 rem * Project ___| | | | _ \| |
5 rem * / __| | | | |_) | |
6 rem * | (__| |_| | _ <| |___
7 rem * \___|\___/|_| \_\_____|
9 rem * Copyright (C) 2012 - 2018, Steve Holme, <steve_holme@hotmail.com>.
10 rem * Copyright (C) 2015, Jay Satiro, <raysatiro@yahoo.com>.
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.
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.
20 rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 rem * KIND, either express or implied.
23 rem ***************************************************************************
26 rem Check we are running on a Windows NT derived OS
27 if not "%OS%" == "Windows_NT" goto nodos
31 set SUCCESSFUL_BUILDS=
35 rem Ensure we have the required arguments
36 if /i "%~1" == "" goto syntax
38 rem Calculate the program files directory
39 if defined PROGRAMFILES (
40 set "PF=%PROGRAMFILES%"
43 if defined PROGRAMFILES(x86) (
44 set "PF=%PROGRAMFILES(x86)%"
49 if "%~1" == "" goto prerequisites
51 if /i "%~1" == "vc10" (
55 set "VC_PATH=Microsoft Visual Studio 10.0\VC"
56 ) else if /i "%~1" == "vc11" (
60 set "VC_PATH=Microsoft Visual Studio 11.0\VC"
61 ) else if /i "%~1" == "vc12" (
65 set "VC_PATH=Microsoft Visual Studio 12.0\VC"
66 ) else if /i "%~1" == "vc14" (
70 set "VC_PATH=Microsoft Visual Studio 14.0\VC"
71 ) else if /i "%~1" == "vc15" (
76 rem Determine the VC15 path based on the installed edition in decending
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"
83 set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
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" == "-?" (
95 ) else if /i "%~1" == "-h" (
97 ) else if /i "%~1" == "-help" (
100 if not defined START_DIR (
107 shift & goto parseArgs
110 rem Compiler is a required parameter
111 if not defined VC_VER goto syntax
113 rem Default the start directory if one isn't specified
114 if not defined START_DIR set START_DIR=..\..\wolfssl
116 rem Check we have a program files directory
117 if not defined PF goto nopf
119 rem Check we have Visual Studio installed
120 if not exist "%PF%\%VC_PATH%" goto novc
122 rem Check the start directory exists
123 if not exist "%START_DIR%" goto nowolfssl
126 if "%BUILD_PLATFORM%" == "" set BUILD_PLATFORM=%OS_PLATFORM%
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%" == "15.0" set VCVARS_PLATFORM=amd64
142 if "%VC_VER%" == "15.0" (
143 call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
145 call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
151 goto %BUILD_PLATFORM%
154 rem Calculate our output directory
155 set OUTDIR=build\Win64\%VC_DESC%
156 if not exist %OUTDIR% md %OUTDIR%
158 if "%BUILD_CONFIG%" == "release" goto x64release
161 rem Perform 64-bit Debug Build
163 call :build Debug x64
164 if errorlevel 1 goto error
166 call :build "DLL Debug" x64
167 if errorlevel 1 goto error
169 if "%BUILD_CONFIG%" == "debug" goto success
172 rem Perform 64-bit Release Build
174 call :build Release x64
175 if errorlevel 1 goto error
177 call :build "DLL Release" x64
178 if errorlevel 1 goto error
183 rem Calculate our output directory
184 set OUTDIR=build\Win32\%VC_DESC%
185 if not exist %OUTDIR% md %OUTDIR%
187 if "%BUILD_CONFIG%" == "release" goto x86release
190 rem Perform 32-bit Debug Build
192 call :build Debug Win32
193 if errorlevel 1 goto error
195 call :build "DLL Debug" Win32
196 if errorlevel 1 goto error
198 if "%BUILD_CONFIG%" == "debug" goto success
201 rem Perform 32-bit Release Build
203 call :build Release Win32
204 if errorlevel 1 goto error
206 call :build "DLL Release" Win32
207 if errorlevel 1 goto error
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.
220 set MSBUILD_CONFIG=%~1
221 set MSBUILD_PLATFORM=%~2
223 if not exist wolfssl64.sln (
225 echo Error: build: wolfssl64.sln not found in "%CD%"
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"
241 echo Error: build: Configuration not recognized.
245 if not "%MSBUILD_PLATFORM%" == "Win32" if not "%MSBUILD_PLATFORM%" == "x64" (
247 echo Error: build: Platform not recognized.
251 copy /v /y "%~dp0\wolfssl_options.h" .\cyassl\options.h
252 if %ERRORLEVEL% neq 0 (
254 echo Error: build: Couldn't replace .\cyassl\options.h
258 copy /v /y "%~dp0\wolfssl_options.h" .\wolfssl\options.h
259 if %ERRORLEVEL% neq 0 (
261 echo Error: build: Couldn't replace .\wolfssl\options.h
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\\"
274 if %ERRORLEVEL% neq 0 (
276 echo Error: Failed building wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
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"
284 if %ERRORLEVEL% neq 0 (
286 echo Error: Failed testing wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
291 echo Success: Built and tested wolfSSL %MSBUILD_CONFIG%^|%MSBUILD_PLATFORM%.
294 rem This is necessary to export our local variables back to the caller.
295 endlocal & set SUCCESSFUL_BUILDS="%MSBUILD_CONFIG%|%MSBUILD_PLATFORM%" ^
302 echo Usage: build-wolfssl ^<compiler^> [platform] [configuration] [directory]
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 vc15 - Use Visual Studio 2017
314 echo x86 - Perform a 32-bit build
315 echo x64 - Perform a 64-bit build
319 echo debug - Perform a debug build
320 echo release - Perform a release build
324 echo directory - Specifies the wolfSSL source directory
329 echo Error: Unknown argument '%1'
334 echo Error: Only a Windows NT based Operating System is supported
339 echo Error: Cannot obtain the directory for Program Files
344 echo Error: %VC_DESC% is not installed
349 echo Error: %VC_DESC% does not support 64-bit builds
354 echo Error: Cannot locate wolfSSL source directory, expected "%START_DIR%"
358 if "%OS%" == "Windows_NT" endlocal
362 if defined SUCCESSFUL_BUILDS (
367 echo The following configurations were built and tested successfully:
369 echo %SUCCESSFUL_BUILDS%