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