smtp: use the upload buffer size for scratch buffer malloc
[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" == "vc15" (
86     set VC_VER=15.0
87     set VC_DESC=VC15
88
89     rem Determine the VC15 path based on the installed edition in decending
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 (
113     if not defined START_DIR (
114       set START_DIR=%~1%
115     ) else (
116       goto unknown
117     )
118   )
119
120   shift & goto parseArgs
121
122 :prerequisites
123   rem Compiler is a required parameter
124   if not defined VC_VER goto syntax
125
126   rem Default the start directory if one isn't specified
127   if not defined START_DIR set START_DIR=..\..\openssl
128
129   rem Check we have a program files directory
130   if not defined PF goto nopf
131
132   rem Check we have Visual Studio installed
133   if not exist "%PF%\%VC_PATH%" goto novc
134
135   rem Check we have Perl in our path
136   echo %PATH% | findstr /I /C:"\Perl" 1>nul
137   if errorlevel 1 (
138     rem It isn't so check we have it installed and set the path if it is
139     if exist "%SystemDrive%\Perl" (
140       set "PATH=%SystemDrive%\Perl\bin;%PATH%"
141     ) else (
142       if exist "%SystemDrive%\Perl64" (
143         set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
144       ) else (
145         goto noperl
146       )
147     )
148   )
149
150   rem Check the start directory exists
151   if not exist "%START_DIR%" goto noopenssl
152
153   rem Check that OpenSSL is not unsupported version 1.1.0
154   if not exist "%START_DIR%\ms\do_ms.bat" goto unsupported
155
156 :configure
157   if "%BUILD_PLATFORM%" == "" (
158     if "%VC_VER%" == "6.0" (
159       set BUILD_PLATFORM=x86
160     ) else if "%VC_VER%" == "7.0" (
161       set BUILD_PLATFORM=x86
162     ) else if "%VC_VER%" == "7.1" (
163       set BUILD_PLATFORM=x86
164     ) else (
165       set BUILD_PLATFORM=%OS_PLATFORM%
166     )
167   )
168
169   if "%BUILD_PLATFORM%" == "x86" (
170     set VCVARS_PLATFORM=x86
171   ) else if "%BUILD_PLATFORM%" == "x64" (
172     if "%VC_VER%" == "6.0" goto nox64
173     if "%VC_VER%" == "7.0" goto nox64
174     if "%VC_VER%" == "7.1" goto nox64
175     if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
176     if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
177     if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
178     if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
179     if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
180     if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
181     if "%VC_VER%" == "15.0" set VCVARS_PLATFORM=amd64
182   )
183
184 :start
185   echo.
186   set SAVED_PATH=%CD%
187
188   if "%VC_VER%" == "6.0" (
189     call "%PF%\%VC_PATH%\bin\vcvars32"
190   ) else if "%VC_VER%" == "7.0" (
191     call "%PF%\%VC_PATH%\bin\vcvars32"
192   ) else if "%VC_VER%" == "7.1" (
193     call "%PF%\%VC_PATH%\bin\vcvars32"
194   ) else if "%VC_VER%" == "15.0" (
195     call "%PF%\%VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
196   ) else (
197     call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
198   )
199
200   echo.
201   cd %SAVED_PATH%
202   cd %START_DIR%
203   goto %BUILD_PLATFORM%
204
205 :x64
206   rem Calculate our output directory
207   set OUTDIR=build\Win64\%VC_DESC%
208   if not exist %OUTDIR% md %OUTDIR%
209
210   if "%BUILD_CONFIG%" == "release" goto x64release
211
212 :x64debug
213   rem Configuring 64-bit Debug Build
214   perl Configure debug-VC-WIN64A --prefix=%CD%
215
216   rem Perform the build
217   call ms\do_win64a
218   nmake -f ms\nt.mak
219   nmake -f ms\ntdll.mak
220
221   rem Move the output directories
222   if exist "%OUTDIR%\LIB Debug" (
223     copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
224     rd out32.dbg /s /q
225   ) else (
226     move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
227   )
228   if exist "%OUTDIR%\DLL Debug" (
229     copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
230     rd out32dll.dbg /s /q
231   ) else (
232     move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
233   )
234
235   rem Move the PDB files
236   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
237   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
238   
239   rem Remove the intermediate directories
240   rd tmp32.dbg /s /q
241   rd tmp32dll.dbg /s /q
242
243   if "%BUILD_CONFIG%" == "debug" goto success
244   
245 :x64release
246   rem Configuring 64-bit Release Build
247   perl Configure VC-WIN64A --prefix=%CD%
248   
249   rem Perform the build
250   call ms\do_win64a
251   nmake -f ms\nt.mak
252   nmake -f ms\ntdll.mak
253
254   rem Move the output directories
255   if exist "%OUTDIR%\LIB Release" (
256     copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
257     rd out32 /s /q
258   ) else (
259     move out32 "%OUTDIR%\LIB Release" 1>nul
260   )
261   if exist "%OUTDIR%\DLL Release" (
262     copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
263     rd out32dll /s /q
264   ) else (
265     move out32dll "%OUTDIR%\DLL Release" 1>nul
266   )
267
268   rem Move the PDB files
269   move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
270   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
271
272   rem Remove the intermediate directories
273   rd tmp32 /s /q
274   rd tmp32dll /s /q
275
276   goto success
277   
278 :x86
279   rem Calculate our output directory
280   set OUTDIR=build\Win32\%VC_DESC%
281   if not exist %OUTDIR% md %OUTDIR%
282
283   if "%BUILD_CONFIG%" == "release" goto x86release
284   
285 :x86debug
286   rem Configuring 32-bit Debug Build
287   perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
288
289   rem Perform the build
290   call ms\do_ms
291   nmake -f ms\nt.mak
292   nmake -f ms\ntdll.mak
293
294   rem Move the output directories
295   if exist "%OUTDIR%\LIB Debug" (
296     copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
297     rd out32.dbg /s /q
298   ) else (
299     move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
300   )
301   if exist "%OUTDIR%\DLL Debug" (
302     copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
303     rd out32dll.dbg /s /q
304   ) else (
305     move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
306   )
307
308   rem Move the PDB files
309   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
310   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
311
312   rem Remove the intermediate directories
313   rd tmp32.dbg /s /q
314   rd tmp32dll.dbg /s /q
315
316   if "%BUILD_CONFIG%" == "debug" goto success
317   
318 :x86release
319   rem Configuring 32-bit Release Build
320   perl Configure VC-WIN32 no-asm --prefix=%CD%
321
322   rem Perform the build
323   call ms\do_ms
324   nmake -f ms\nt.mak
325   nmake -f ms\ntdll.mak
326
327   rem Move the output directories
328   if exist "%OUTDIR%\LIB Release" (
329     copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
330     rd out32 /s /q
331   ) else (
332     move out32 "%OUTDIR%\LIB Release" 1>nul
333   )
334   if exist "%OUTDIR%\DLL Release" (
335     copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
336     rd out32dll /s /q
337   ) else (
338     move out32dll "%OUTDIR%\DLL Release" 1>nul
339   )
340
341   rem Move the PDB files
342   move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
343   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
344
345   rem Remove the intermediate directories
346   rd tmp32 /s /q
347   rd tmp32dll /s /q
348
349   goto success
350
351 :syntax
352   rem Display the help
353   echo.
354   echo Usage: build-openssl ^<compiler^> [platform] [configuration] [directory]
355   echo.
356   echo Compiler:
357   echo.
358   echo vc6       - Use Visual Studio 6
359   echo vc7       - Use Visual Studio .NET
360   echo vc7.1     - Use Visual Studio .NET 2003
361   echo vc8       - Use Visual Studio 2005
362   echo vc9       - Use Visual Studio 2008
363   echo vc10      - Use Visual Studio 2010
364   echo vc11      - Use Visual Studio 2012
365   echo vc12      - Use Visual Studio 2013
366   echo vc14      - Use Visual Studio 2015
367   echo vc15      - Use Visual Studio 2017
368   echo.
369   echo Platform:
370   echo.
371   echo x86       - Perform a 32-bit build
372   echo x64       - Perform a 64-bit build
373   echo.
374   echo Configuration:
375   echo.
376   echo debug     - Perform a debug build
377   echo release   - Perform a release build
378   echo.
379   echo Other:
380   echo.
381   echo directory - Specifies the OpenSSL source directory
382   goto error
383
384 :unknown
385   echo.
386   echo Error: Unknown argument '%1'
387   goto error
388
389 :nodos
390   echo.
391   echo Error: Only a Windows NT based Operating System is supported
392   goto error
393
394 :nopf
395   echo.
396   echo Error: Cannot obtain the directory for Program Files
397   goto error
398
399 :novc
400   echo.
401   echo Error: %VC_DESC% is not installed
402   goto error
403
404 :noperl
405   echo.
406   echo Error: Perl is not installed
407   goto error
408
409 :nox64
410   echo.
411   echo Error: %VC_DESC% does not support 64-bit builds
412   goto error
413
414 :noopenssl
415   echo.
416   echo Error: Cannot locate OpenSSL source directory
417   goto error
418
419 :unsupported
420   echo.
421   echo Error: Unsupported OpenSSL version.
422   echo The pre-generated project files and this build script only support the
423   echo LTS version of OpenSSL ^(v1.0.2^). The next version of this build script
424   echo will support OpenSSL v1.1.0.
425   goto error
426
427 :error
428   if "%OS%" == "Windows_NT" endlocal
429   exit /B 1
430
431 :success
432   cd %SAVED_PATH%
433   endlocal
434   exit /B 0