Merge "Force to use getifaddrs() to get interface addresses" into tizen_base
[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 - 2018, 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 https://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   rem Calculate the program files directory
37   if defined PROGRAMFILES (
38     set "PF=%PROGRAMFILES%"
39     set OS_PLATFORM=x86
40   )
41   if defined PROGRAMFILES(x86) (
42     set "PF=%PROGRAMFILES(x86)%"
43     set OS_PLATFORM=x64
44   )
45
46 :parseArgs
47   if "%~1" == "" goto prerequisites
48
49   if /i "%~1" == "vc6" (
50     set VC_VER=6.0
51     set VC_DESC=VC6
52     set "VC_PATH=Microsoft Visual Studio\VC98"
53   ) else if /i "%~1" == "vc7" (
54     set VC_VER=7.0
55     set VC_DESC=VC7
56     set "VC_PATH=Microsoft Visual Studio .NET\Vc7"
57   ) else if /i "%~1" == "vc7.1" (
58     set VC_VER=7.1
59     set VC_DESC=VC7.1
60     set "VC_PATH=Microsoft Visual Studio .NET 2003\Vc7"
61   ) else if /i "%~1" == "vc8" (
62     set VC_VER=8.0
63     set VC_DESC=VC8
64     set "VC_PATH=Microsoft Visual Studio 8\VC"
65   ) else if /i "%~1" == "vc9" (
66     set VC_VER=9.0
67     set VC_DESC=VC9
68     set "VC_PATH=Microsoft Visual Studio 9.0\VC"
69   ) else if /i "%~1" == "vc10" (
70     set VC_VER=10.0
71     set VC_DESC=VC10
72     set "VC_PATH=Microsoft Visual Studio 10.0\VC"
73   ) else if /i "%~1" == "vc11" (
74     set VC_VER=11.0
75     set VC_DESC=VC11
76     set "VC_PATH=Microsoft Visual Studio 11.0\VC"
77   ) else if /i "%~1" == "vc12" (
78     set VC_VER=12.0
79     set VC_DESC=VC12
80     set "VC_PATH=Microsoft Visual Studio 12.0\VC"
81   ) else if /i "%~1" == "vc14" (
82     set VC_VER=14.0
83     set VC_DESC=VC14
84     set "VC_PATH=Microsoft Visual Studio 14.0\VC"
85   ) else if /i "%~1" == "vc14.1" (
86     set VC_VER=14.1
87     set VC_DESC=VC14.1
88
89     rem Determine the VC14.1 path based on the installed edition in descending
90     rem order (Enterprise, then Professional and finally Community)
91     if exist "%PF%\Microsoft Visual Studio\2017\Enterprise\VC" (
92       set "VC_PATH=Microsoft Visual Studio\2017\Enterprise\VC"
93     ) else if exist "%PF%\Microsoft Visual Studio\2017\Professional\VC" (
94       set "VC_PATH=Microsoft Visual Studio\2017\Professional\VC"
95     ) else (
96       set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
97     )
98   ) else if /i "%~1%" == "x86" (
99     set BUILD_PLATFORM=x86
100   ) else if /i "%~1%" == "x64" (
101     set BUILD_PLATFORM=x64
102   ) else if /i "%~1%" == "debug" (
103     set BUILD_CONFIG=debug
104   ) else if /i "%~1%" == "release" (
105     set BUILD_CONFIG=release
106   ) else if /i "%~1" == "-?" (
107     goto syntax
108   ) else if /i "%~1" == "-h" (
109     goto syntax
110   ) else if /i "%~1" == "-help" (
111     goto syntax
112   ) else if /i "%~1" == "-VSpath" (
113     if "%~2" == "" (
114       echo.
115       echo Error. Please provide VS Path.
116       goto error
117     ) else (
118       set "ABS_VC_PATH=%~2\VC"
119       shift
120     )
121   ) else if /i "%~1" == "-perlpath" (
122     if "%~2" == "" (
123       echo.
124       echo Error. Please provide Perl root Path.
125       goto error
126     ) else (
127       set "PERL_PATH=%~2"
128       shift
129     )
130   ) else (
131     if not defined START_DIR (
132       set START_DIR=%~1%
133     ) else (
134       goto unknown
135     )
136   )
137
138   shift & goto parseArgs
139
140 :prerequisites
141   rem Compiler is a required parameter
142   if not defined VC_VER goto syntax
143
144   rem Default the start directory if one isn't specified
145   if not defined START_DIR set START_DIR=..\..\openssl
146
147   if not defined ABS_VC_PATH (
148     rem Check we have a program files directory
149     if not defined PF goto nopf
150     set "ABS_VC_PATH=%PF%\%VC_PATH%"
151   )
152
153   rem Check we have Visual Studio installed
154   if not exist "%ABS_VC_PATH%" goto novc
155
156   if not defined PERL_PATH (
157     rem Check we have Perl in our path
158     perl --version <NUL 1>NUL 2>&1
159     if errorlevel 1 (
160       rem It isn't so check we have it installed and set the path if it is
161       if exist "%SystemDrive%\Perl" (
162         set "PATH=%SystemDrive%\Perl\bin;%PATH%"
163       ) else (
164         if exist "%SystemDrive%\Perl64" (
165           set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
166         ) else (
167           goto noperl
168         )
169       )
170     )
171   ) else (
172     set "PATH=%PERL_PATH%\Perl\bin;%PATH%"
173   )
174
175   rem Check the start directory exists
176   if not exist "%START_DIR%" goto noopenssl
177
178   rem Check that OpenSSL is not unsupported version 1.1.0
179   if not exist "%START_DIR%\ms\do_ms.bat" goto unsupported
180
181 :configure
182   if "%BUILD_PLATFORM%" == "" (
183     if "%VC_VER%" == "6.0" (
184       set BUILD_PLATFORM=x86
185     ) else if "%VC_VER%" == "7.0" (
186       set BUILD_PLATFORM=x86
187     ) else if "%VC_VER%" == "7.1" (
188       set BUILD_PLATFORM=x86
189     ) else (
190       set BUILD_PLATFORM=%OS_PLATFORM%
191     )
192   )
193
194   if "%BUILD_PLATFORM%" == "x86" (
195     set VCVARS_PLATFORM=x86
196   ) else if "%BUILD_PLATFORM%" == "x64" (
197     if "%VC_VER%" == "6.0" goto nox64
198     if "%VC_VER%" == "7.0" goto nox64
199     if "%VC_VER%" == "7.1" goto nox64
200     if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
201     if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
202     if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
203     if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
204     if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
205     if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
206     if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
207   )
208
209 :start
210   echo.
211   set SAVED_PATH=%CD%
212
213   if "%VC_VER%" == "6.0" (
214     call "%ABS_VC_PATH%\bin\vcvars32"
215   ) else if "%VC_VER%" == "7.0" (
216     call "%ABS_VC_PATH%\bin\vcvars32"
217   ) else if "%VC_VER%" == "7.1" (
218     call "%ABS_VC_PATH%\bin\vcvars32"
219   ) else if "%VC_VER%" == "14.1" (
220     call "%ABS_VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
221   ) else (
222     call "%ABS_VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
223   )
224
225   echo.
226   cd /d %SAVED_PATH%
227   if defined START_DIR cd /d %START_DIR%
228   goto %BUILD_PLATFORM%
229
230 :x64
231   rem Calculate our output directory
232   set OUTDIR=build\Win64\%VC_DESC%
233   if not exist %OUTDIR% md %OUTDIR%
234
235   if "%BUILD_CONFIG%" == "release" goto x64release
236
237 :x64debug
238   rem Configuring 64-bit Debug Build
239   perl Configure debug-VC-WIN64A --prefix=%CD%
240
241   rem Perform the build
242   call ms\do_win64a
243   nmake -f ms\nt.mak
244   nmake -f ms\ntdll.mak
245
246   rem Move the output directories
247   if exist "%OUTDIR%\LIB Debug" (
248     copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
249     rd out32.dbg /s /q
250   ) else (
251     move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
252   )
253   if exist "%OUTDIR%\DLL Debug" (
254     copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
255     rd out32dll.dbg /s /q
256   ) else (
257     move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
258   )
259
260   rem Move the PDB files
261   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
262   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
263
264   rem Remove the intermediate directories
265   rd tmp32.dbg /s /q
266   rd tmp32dll.dbg /s /q
267
268   if "%BUILD_CONFIG%" == "debug" goto success
269
270 :x64release
271   rem Configuring 64-bit Release Build
272   perl Configure VC-WIN64A --prefix=%CD%
273
274   rem Perform the build
275   call ms\do_win64a
276   nmake -f ms\nt.mak
277   nmake -f ms\ntdll.mak
278
279   rem Move the output directories
280   if exist "%OUTDIR%\LIB Release" (
281     copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
282     rd out32 /s /q
283   ) else (
284     move out32 "%OUTDIR%\LIB Release" 1>nul
285   )
286   if exist "%OUTDIR%\DLL Release" (
287     copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
288     rd out32dll /s /q
289   ) else (
290     move out32dll "%OUTDIR%\DLL Release" 1>nul
291   )
292
293   rem Move the PDB files
294   move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
295   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
296
297   rem Remove the intermediate directories
298   rd tmp32 /s /q
299   rd tmp32dll /s /q
300
301   goto success
302
303 :x86
304   rem Calculate our output directory
305   set OUTDIR=build\Win32\%VC_DESC%
306   if not exist %OUTDIR% md %OUTDIR%
307
308   if "%BUILD_CONFIG%" == "release" goto x86release
309
310 :x86debug
311   rem Configuring 32-bit Debug Build
312   perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
313
314   rem Perform the build
315   call ms\do_ms
316   nmake -f ms\nt.mak
317   nmake -f ms\ntdll.mak
318
319   rem Move the output directories
320   if exist "%OUTDIR%\LIB Debug" (
321     copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
322     rd out32.dbg /s /q
323   ) else (
324     move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
325   )
326   if exist "%OUTDIR%\DLL Debug" (
327     copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
328     rd out32dll.dbg /s /q
329   ) else (
330     move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
331   )
332
333   rem Move the PDB files
334   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
335   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
336
337   rem Remove the intermediate directories
338   rd tmp32.dbg /s /q
339   rd tmp32dll.dbg /s /q
340
341   if "%BUILD_CONFIG%" == "debug" goto success
342
343 :x86release
344   rem Configuring 32-bit Release Build
345   perl Configure VC-WIN32 no-asm --prefix=%CD%
346
347   rem Perform the build
348   call ms\do_ms
349   nmake -f ms\nt.mak
350   nmake -f ms\ntdll.mak
351
352   rem Move the output directories
353   if exist "%OUTDIR%\LIB Release" (
354     copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
355     rd out32 /s /q
356   ) else (
357     move out32 "%OUTDIR%\LIB Release" 1>nul
358   )
359   if exist "%OUTDIR%\DLL Release" (
360     copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
361     rd out32dll /s /q
362   ) else (
363     move out32dll "%OUTDIR%\DLL Release" 1>nul
364   )
365
366   rem Move the PDB files
367   move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
368   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
369
370   rem Remove the intermediate directories
371   rd tmp32 /s /q
372   rd tmp32dll /s /q
373
374   goto success
375
376 :syntax
377   rem Display the help
378   echo.
379   echo Usage: build-openssl ^<compiler^> [platform] [configuration] [directory] [-VSpath] ["VSpath"] [-perlpath] ["perlpath"]
380   echo.
381   echo Compiler:
382   echo.
383   echo vc6       - Use Visual Studio 6
384   echo vc7       - Use Visual Studio .NET
385   echo vc7.1     - Use Visual Studio .NET 2003
386   echo vc8       - Use Visual Studio 2005
387   echo vc9       - Use Visual Studio 2008
388   echo vc10      - Use Visual Studio 2010
389   echo vc11      - Use Visual Studio 2012
390   echo vc12      - Use Visual Studio 2013
391   echo vc14      - Use Visual Studio 2015
392   echo vc14.1    - Use Visual Studio 2017
393   echo.
394   echo Platform:
395   echo.
396   echo x86       - Perform a 32-bit build
397   echo x64       - Perform a 64-bit build
398   echo.
399   echo Configuration:
400   echo.
401   echo debug     - Perform a debug build
402   echo release   - Perform a release build
403   echo.
404   echo Other:
405   echo.
406   echo directory - Specifies the OpenSSL source directory
407   echo.
408   echo -VSpath - Specify the custom VS path if Visual Studio is installed at other location
409   echo           then "C:/<ProgramFiles>/Microsoft Visual Studio[version]
410   echo           For e.g. -VSpath "C:\apps\MVS14"
411   echo.
412   echo -perlpath - Specify the custom perl root path if perl is not located at "C:\Perl" and it is a
413   echo             portable copy of perl and not installed on the win system
414   echo             For e.g. -perlpath "D:\strawberry-perl-5.24.3.1-64bit-portable"
415   goto error
416
417 :unknown
418   echo.
419   echo Error: Unknown argument '%1'
420   goto error
421
422 :nodos
423   echo.
424   echo Error: Only a Windows NT based Operating System is supported
425   goto error
426
427 :nopf
428   echo.
429   echo Error: Cannot obtain the directory for Program Files
430   goto error
431
432 :novc
433   echo.
434   echo Error: %VC_DESC% is not installed
435   echo Error: Please check whether Visual compiler is installed at the path "%ABS_VC_PATH%"
436   echo Error: Please provide proper VS Path by using -VSpath
437   goto error
438
439 :noperl
440   echo.
441   echo Error: Perl is not installed
442   echo Error: Please check whether Perl is installed or it is at location "C:\Perl"
443   echo Error: If Perl is portable please provide perl root path by using -perlpath
444   goto error
445
446 :nox64
447   echo.
448   echo Error: %VC_DESC% does not support 64-bit builds
449   goto error
450
451 :noopenssl
452   echo.
453   echo Error: Cannot locate OpenSSL source directory
454   goto error
455
456 :unsupported
457   echo.
458   echo Error: Unsupported OpenSSL version.
459   echo The pre-generated project files and this build script only support the
460   echo LTS version of OpenSSL ^(v1.0.2^). The next version of this build script
461   echo will support OpenSSL v1.1.0.
462   goto error
463
464 :error
465   if "%OS%" == "Windows_NT" endlocal
466   exit /B 1
467
468 :success
469   cd /d %SAVED_PATH%
470   endlocal
471   exit /B 0