19b7357cfb48bd29c6c3a5d006b892152981545f
[platform/upstream/curl.git] / projects / build-openssl.bat
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 *
11 rem * This software is licensed as described in the file COPYING, which
12 rem * you should have received as part of this distribution. The terms
13 rem * are also available at http://curl.haxx.se/docs/copyright.html.
14 rem *
15 rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 rem * copies of the Software, and permit persons to whom the Software is
17 rem * furnished to do so, under the terms of the COPYING file.
18 rem *
19 rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 rem * KIND, either express or implied.
21 rem *
22 rem ***************************************************************************
23
24 :begin
25   rem Check we are running on a Windows NT derived OS
26   if not "%OS%" == "Windows_NT" goto nodos
27
28   rem Set our variables
29   setlocal
30   set VC_VER=
31   set BUILD_PLATFORM=
32
33   rem Ensure we have the required arguments
34   if /i "%~1" == "" goto syntax
35
36 :parseArgs
37   if "%~1" == "" goto prerequisites
38
39   if /i "%~1" == "vc6" (
40     set VC_VER=6.0
41     set VC_DESC=VC6
42     set "VC_PATH=Microsoft Visual Studio\VC98"
43   ) else if /i "%~1" == "vc7" (
44     set VC_VER=7.0
45     set VC_DESC=VC7
46     set "VC_PATH=Microsoft Visual Studio .NET\Vc7"
47   ) else if /i "%~1" == "vc7.1" (
48     set VC_VER=7.1
49     set VC_DESC=VC7.1
50     set "VC_PATH=Microsoft Visual Studio .NET 2003\Vc7"
51   ) else if /i "%~1" == "vc8" (
52     set VC_VER=8.0
53     set VC_DESC=VC8
54     set "VC_PATH=Microsoft Visual Studio 8\VC"
55   ) else if /i "%~1" == "vc9" (
56     set VC_VER=9.0
57     set VC_DESC=VC9
58     set "VC_PATH=Microsoft Visual Studio 9.0\VC"
59   ) else if /i "%~1" == "vc10" (
60     set VC_VER=10.0
61     set VC_DESC=VC10
62     set "VC_PATH=Microsoft Visual Studio 10.0\VC"
63   ) else if /i "%~1" == "vc11" (
64     set VC_VER=11.0
65     set VC_DESC=VC11
66     set "VC_PATH=Microsoft Visual Studio 11.0\VC"
67   ) else if /i "%~1" == "vc12" (
68     set VC_VER=12.0
69     set VC_DESC=VC12
70     set "VC_PATH=Microsoft Visual Studio 12.0\VC"
71   ) else if /i "%~1" == "vc14" (
72     set VC_VER=14.0
73     set VC_DESC=VC14
74     set "VC_PATH=Microsoft Visual Studio 14.0\VC"
75   ) else if /i "%~1%" == "x86" (
76     set BUILD_PLATFORM=x86
77   ) else if /i "%~1%" == "x64" (
78     set BUILD_PLATFORM=x64
79   ) else if /i "%~1%" == "debug" (
80     set BUILD_CONFIG=debug
81   ) else if /i "%~1%" == "release" (
82     set BUILD_CONFIG=release
83   ) else if /i "%~1" == "-?" (
84     goto syntax
85   ) else if /i "%~1" == "-h" (
86     goto syntax
87   ) else if /i "%~1" == "-help" (
88     goto syntax
89   ) else (
90     if not defined START_DIR (
91       set START_DIR=%~1%
92     ) else (
93       goto unknown
94     )
95   )
96
97   shift & goto parseArgs
98
99 :prerequisites
100   rem Compiler and platform are required parameters.
101   if not defined VC_VER goto syntax
102   if not defined BUILD_PLATFORM goto syntax
103
104   rem Default the start directory if one isn't specified
105   if not defined START_DIR set START_DIR=..\..\openssl
106
107   rem Calculate the program files directory
108   if defined PROGRAMFILES (
109     set "PF=%PROGRAMFILES%"
110     set OS_PLATFORM=x86
111   )
112   if defined PROGRAMFILES(x86) (
113     set "PF=%PROGRAMFILES(x86)%"
114     set OS_PLATFORM=x64
115   )
116
117   rem Check we have a program files directory
118   if not defined PF goto nopf
119
120   rem Check we have Visual Studio installed
121   if not exist "%PF%\%VC_PATH%" goto novc
122
123   rem Check we have Perl installed
124   echo %PATH% | findstr /I /C:"\Perl" 1>nul
125   if errorlevel 1 (
126     if not exist "%SystemDrive%\Perl" (
127       if not exist "%SystemDrive%\Perl64" goto noperl
128     )
129   )
130
131   rem Check the start directory exists
132   if not exist "%START_DIR%" goto noopenssl
133
134 :configure
135   if "%BUILD_PLATFORM%" == "" (
136     if "%VC_VER%" == "6.0" (
137       set BUILD_PLATFORM=x86
138     ) else if "%VC_VER%" == "7.0" (
139       set BUILD_PLATFORM=x86
140     ) else if "%VC_VER%" == "7.1" (
141       set BUILD_PLATFORM=x86
142     ) else (
143       set BUILD_PLATFORM=%OS_PLATFORM%
144     )
145   )
146
147   if "%BUILD_PLATFORM%" == "x86" (
148     set VCVARS_PLATFORM=x86
149   ) else if "%BUILD_PLATFORM%" == "x64" (
150     if "%VC_VER%" == "6.0" goto nox64
151     if "%VC_VER%" == "7.0" goto nox64
152     if "%VC_VER%" == "7.1" goto nox64
153     if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
154     if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
155     if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
156     if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
157     if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
158     if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
159   )
160
161 :start
162   echo.
163   if "%VC_VER%" == "6.0" (
164     call "%PF%\%VC_PATH%\bin\vcvars32"
165   ) else if "%VC_VER%" == "7.0" (
166     call "%PF%\%VC_PATH%\bin\vcvars32"
167   ) else if "%VC_VER%" == "7.1" (
168     call "%PF%\%VC_PATH%\bin\vcvars32"
169   ) else (
170     call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
171   )
172
173   echo.
174   set SAVED_PATH=%CD%
175   if defined START_DIR CD %START_DIR%
176   goto %BUILD_PLATFORM%
177
178 :x64
179   rem Calculate our output directory
180   set OUTDIR=build\Win64\%VC_DESC%
181   if not exist %OUTDIR% md %OUTDIR%
182
183   if "%BUILD_CONFIG%" == "release" goto x64release
184
185 :x64debug
186   rem Configuring 64-bit Debug Build
187   perl Configure debug-VC-WIN64A --prefix=%CD%
188
189   rem Perform the build
190   call ms\do_win64a
191   nmake -f ms\nt.mak
192   nmake -f ms\ntdll.mak
193
194   rem Move the output directories
195   move out32.dbg "%OUTDIR%\LIB Debug"
196   move out32dll.dbg "%OUTDIR%\DLL Debug"
197
198   rem Move the PDB files
199   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
200   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
201   
202   rem Remove the intermediate directories
203   rd tmp32.dbg /s /q
204   rd tmp32dll.dbg /s /q
205
206   if "%BUILD_CONFIG%" == "debug" goto success
207   
208 :x64release
209   rem Configuring 64-bit Release Build
210   perl Configure VC-WIN64A --prefix=%CD%
211   
212   rem Perform the build
213   call ms\do_win64a
214   nmake -f ms\nt.mak
215   nmake -f ms\ntdll.mak
216   
217   rem Move the output directories
218   move out32 "%OUTDIR%\LIB Release"
219   move out32dll "%OUTDIR%\DLL Release"
220
221   rem Move the PDB files
222   move tmp32\lib.pdb "%OUTDIR%\LIB Release"
223   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
224
225   rem Remove the intermediate directories
226   rd tmp32 /s /q
227   rd tmp32dll /s /q
228
229   goto success
230   
231 :x86
232   rem Calculate our output directory
233   set OUTDIR=build\Win32\%VC_DESC%
234   if not exist %OUTDIR% md %OUTDIR%
235
236   if "%BUILD_CONFIG%" == "release" goto x86release
237   
238 :x86debug
239   rem Configuring 32-bit Debug Build
240   perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
241
242   rem Perform the build
243   call ms\do_ms
244   nmake -f ms\nt.mak
245   nmake -f ms\ntdll.mak
246
247   rem Move the output directories
248   move out32.dbg "%OUTDIR%\LIB Debug"
249   move out32dll.dbg "%OUTDIR%\DLL Debug"
250
251   rem Move the PDB files
252   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
253   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
254
255   rem Remove the intermediate directories
256   rd tmp32.dbg /s /q
257   rd tmp32dll.dbg /s /q
258
259   if "%BUILD_CONFIG%" == "debug" goto success
260   
261 :x86release
262   rem Configuring 32-bit Release Build
263   perl Configure VC-WIN32 no-asm --prefix=%CD%
264
265   rem Perform the build
266   call ms\do_ms
267   nmake -f ms\nt.mak
268   nmake -f ms\ntdll.mak
269   
270   rem Move the output directories
271   move out32 "%OUTDIR%\LIB Release"
272   move out32dll "%OUTDIR%\DLL Release"
273
274   rem Move the PDB files
275   move tmp32\lib.pdb "%OUTDIR%\LIB Release"
276   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
277
278   rem Remove the intermediate directories
279   rd tmp32 /s /q
280   rd tmp32dll /s /q
281
282   goto success
283
284 :syntax
285   rem Display the help
286   echo.
287   echo Usage: build-openssl ^<compiler^> ^<platform^> [configuration] [directory]
288   echo.
289   echo Compiler:
290   echo.
291   echo vc6       - Use Visual Studio 6
292   echo vc7       - Use Visual Studio .NET
293   echo vc7.1     - Use Visual Studio .NET 2003
294   echo vc8       - Use Visual Studio 2005
295   echo vc9       - Use Visual Studio 2008
296   echo vc10      - Use Visual Studio 2010
297   echo vc11      - Use Visual Studio 2012
298   echo vc12      - Use Visual Studio 2013
299   echo vc14      - Use Visual Studio 2015
300   echo.
301   echo Platform:
302   echo.
303   echo x86       - Perform a 32-bit build
304   echo x64       - Perform a 64-bit build
305   echo.
306   echo Configuration:
307   echo.
308   echo debug     - Perform a debug build
309   echo release   - Perform a release build
310   echo.
311   echo Other:
312   echo.
313   echo directory - Specifies the OpenSSL source directory
314   goto error
315
316 :unknown
317   echo.
318   echo Error: Unknown argument '%1'
319   goto error
320
321 :nodos
322   echo.
323   echo Error: Only a Windows NT based Operating System is supported
324   goto error
325
326 :nopf
327   echo.
328   echo Error: Cannot obtain the directory for Program Files
329   goto error
330
331 :novc
332   echo.
333   echo Error: %VC_DESC% is not installed
334   goto error
335
336 :noperl
337   echo.
338   echo Error: Perl is not installed
339   goto error
340
341 :nox64
342   echo.
343   echo Error: %VC_DESC% does not support 64-bit builds
344   goto error
345
346 :noopenssl
347   echo.
348   echo Error: Cannot locate OpenSSL source directory
349   goto error
350
351 :error
352   if "%OS%" == "Windows_NT" endlocal
353   exit /B 1
354
355 :success
356   cd %SAVED_PATH%
357   endlocal
358   exit /B 0