1@echo off
2rem ***************************************************************************
3rem *                                  _   _ ____  _
4rem *  Project                     ___| | | |  _ \| |
5rem *                             / __| | | | |_) | |
6rem *                            | (__| |_| |  _ <| |___
7rem *                             \___|\___/|_| \_\_____|
8rem *
9rem * Copyright (C) 2012 - 2021, Steve Holme, <steve_holme@hotmail.com>.
10rem *
11rem * This software is licensed as described in the file COPYING, which
12rem * you should have received as part of this distribution. The terms
13rem * are also available at https://curl.se/docs/copyright.html.
14rem *
15rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16rem * copies of the Software, and permit persons to whom the Software is
17rem * furnished to do so, under the terms of the COPYING file.
18rem *
19rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20rem * KIND, either express or implied.
21rem *
22rem ***************************************************************************
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 ENABLEDELAYEDEXPANSION
30  set BUILD_CONFIG=
31  set BUILD_PLATFORM=
32  set SAVED_PATH=
33  set SOURCE_PATH=
34  set TMP_BUILD_PATH=
35  set TMP_INSTALL_PATH=
36  set VC_VER=
37
38  rem Ensure we have the required arguments
39  if /i "%~1" == "" goto syntax
40
41  rem Calculate the program files directory
42  if defined PROGRAMFILES (
43    set "PF=%PROGRAMFILES%"
44    set OS_PLATFORM=x86
45  )
46  if defined PROGRAMFILES(x86) (
47    set "PF=%PROGRAMFILES(x86)%"
48    set OS_PLATFORM=x64
49  )
50
51:parseArgs
52  if not "%~1" == "" (
53    if /i "%~1" == "vc6" (
54      set VC_VER=6.0
55      set VC_DESC=VC6
56      set "VC_PATH=Microsoft Visual Studio\VC98"
57    ) else if /i "%~1" == "vc7" (
58      set VC_VER=7.0
59      set VC_DESC=VC7
60      set "VC_PATH=Microsoft Visual Studio .NET\Vc7"
61    ) else if /i "%~1" == "vc7.1" (
62      set VC_VER=7.1
63      set VC_DESC=VC7.1
64      set "VC_PATH=Microsoft Visual Studio .NET 2003\Vc7"
65    ) else if /i "%~1" == "vc8" (
66      set VC_VER=8.0
67      set VC_DESC=VC8
68      set "VC_PATH=Microsoft Visual Studio 8\VC"
69    ) else if /i "%~1" == "vc9" (
70      set VC_VER=9.0
71      set VC_DESC=VC9
72      set "VC_PATH=Microsoft Visual Studio 9.0\VC"
73    ) else if /i "%~1" == "vc10" (
74      set VC_VER=10.0
75      set VC_DESC=VC10
76      set "VC_PATH=Microsoft Visual Studio 10.0\VC"
77    ) else if /i "%~1" == "vc11" (
78      set VC_VER=11.0
79      set VC_DESC=VC11
80      set "VC_PATH=Microsoft Visual Studio 11.0\VC"
81    ) else if /i "%~1" == "vc12" (
82      set VC_VER=12.0
83      set VC_DESC=VC12
84      set "VC_PATH=Microsoft Visual Studio 12.0\VC"
85    ) else if /i "%~1" == "vc14" (
86      set VC_VER=14.0
87      set VC_DESC=VC14
88      set "VC_PATH=Microsoft Visual Studio 14.0\VC"
89    ) else if /i "%~1" == "vc14.1" (
90      set VC_VER=14.1
91      set VC_DESC=VC14.1
92
93      rem Determine the VC14.1 path based on the installed edition in descending
94      rem order (Enterprise, then Professional and finally Community)
95      if exist "%PF%\Microsoft Visual Studio\2017\Enterprise\VC" (
96        set "VC_PATH=Microsoft Visual Studio\2017\Enterprise\VC"
97      ) else if exist "%PF%\Microsoft Visual Studio\2017\Professional\VC" (
98        set "VC_PATH=Microsoft Visual Studio\2017\Professional\VC"
99      ) else (
100        set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
101      )
102    ) else if /i "%~1" == "vc14.2" (
103      set VC_VER=14.2
104      set VC_DESC=VC14.2
105
106      rem Determine the VC14.2 path based on the installed edition in descending
107      rem order (Enterprise, then Professional and finally Community)
108      if exist "%PF%\Microsoft Visual Studio\2019\Enterprise\VC" (
109        set "VC_PATH=Microsoft Visual Studio\2019\Enterprise\VC"
110      ) else if exist "%PF%\Microsoft Visual Studio\2019\Professional\VC" (
111        set "VC_PATH=Microsoft Visual Studio\2019\Professional\VC"
112      ) else (
113        set "VC_PATH=Microsoft Visual Studio\2019\Community\VC"
114      )
115    ) else if /i "%~1%" == "x86" (
116      set BUILD_PLATFORM=x86
117    ) else if /i "%~1%" == "x64" (
118      set BUILD_PLATFORM=x64
119    ) else if /i "%~1%" == "debug" (
120      set BUILD_CONFIG=debug
121    ) else if /i "%~1%" == "release" (
122      set BUILD_CONFIG=release
123    ) else if /i "%~1" == "-?" (
124      goto syntax
125    ) else if /i "%~1" == "-h" (
126      goto syntax
127    ) else if /i "%~1" == "-help" (
128      goto syntax
129    ) else if /i "%~1" == "-VSpath" (
130      if "%~2" == "" (
131        echo.
132        echo Error. Please provide VS Path.
133        goto error
134      ) else (
135        set "ABS_VC_PATH=%~2\VC"
136        shift
137      )
138    ) else if /i "%~1" == "-perlpath" (
139      if "%~2" == "" (
140        echo.
141        echo Error. Please provide Perl root Path.
142        goto error
143      ) else (
144        set "PERL_PATH=%~2"
145        shift
146      )
147    ) else (
148      if not defined START_DIR (
149        set "START_DIR=%~1%"
150      ) else (
151        goto unknown
152      )
153    )
154
155    shift & goto parseArgs
156  )
157
158:prerequisites
159  rem Compiler is a required parameter
160  if not defined VC_VER goto syntax
161
162  rem Default the start directory if one isn't specified
163  if not defined START_DIR set START_DIR=..\..\openssl
164
165  if not defined ABS_VC_PATH (
166    rem Check we have a program files directory
167    if not defined PF goto nopf
168    set "ABS_VC_PATH=%PF%\%VC_PATH%"
169  )
170
171  rem Check we have Visual Studio installed
172  if not exist "%ABS_VC_PATH%" goto novc
173
174  if not defined PERL_PATH (
175    rem Check we have Perl in our path
176    perl --version <NUL 1>NUL 2>&1
177    if errorlevel 1 (
178      rem It isn't so check we have it installed and set the path if it is
179      if exist "%SystemDrive%\Perl" (
180        set "PATH=%SystemDrive%\Perl\bin;%PATH%"
181      ) else (
182        if exist "%SystemDrive%\Perl64" (
183          set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
184        ) else (
185          goto noperl
186        )
187      )
188    )
189  ) else (
190    set "PATH=%PERL_PATH%\Perl\bin;%PATH%"
191  )
192
193  rem Check the start directory exists
194  if not exist "%START_DIR%" goto noopenssl
195
196:setup
197  if "%BUILD_PLATFORM%" == "" (
198    if "%VC_VER%" == "6.0" (
199      set BUILD_PLATFORM=x86
200    ) else if "%VC_VER%" == "7.0" (
201      set BUILD_PLATFORM=x86
202    ) else if "%VC_VER%" == "7.1" (
203      set BUILD_PLATFORM=x86
204    ) else (
205      set BUILD_PLATFORM=%OS_PLATFORM%
206    )
207  )
208
209  if "%BUILD_PLATFORM%" == "x86" (
210    set VCVARS_PLATFORM=x86
211  ) else if "%BUILD_PLATFORM%" == "x64" (
212    if "%VC_VER%" == "6.0" goto nox64
213    if "%VC_VER%" == "7.0" goto nox64
214    if "%VC_VER%" == "7.1" goto nox64
215    if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
216    if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
217    if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
218    if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
219    if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
220    if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
221    if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
222    if "%VC_VER%" == "14.2" set VCVARS_PLATFORM=amd64
223  )
224
225  if exist "%START_DIR%\ms\do_ms.bat" (
226    set LEGACY_BUILD=TRUE
227  ) else (
228    set LEGACY_BUILD=FALSE
229  )
230
231:start
232  echo.
233  set "SAVED_PATH=%CD%"
234
235  if "%VC_VER%" == "6.0" (
236    call "%ABS_VC_PATH%\bin\vcvars32"
237  ) else if "%VC_VER%" == "7.0" (
238    call "%ABS_VC_PATH%\bin\vcvars32"
239  ) else if "%VC_VER%" == "7.1" (
240    call "%ABS_VC_PATH%\bin\vcvars32"
241  ) else if "%VC_VER%" == "14.1" (
242    call "%ABS_VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
243  ) else if "%VC_VER%" == "14.2" (
244    call "%ABS_VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
245  ) else (
246    call "%ABS_VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
247  )
248
249  echo.
250
251  cd /d "%START_DIR%" || (echo Error: Failed cd start & exit /B 1)
252  rem Save the full path of the openssl source dir
253  set "SOURCE_PATH=%CD%"
254
255  rem Set temporary paths for building and installing OpenSSL. If a temporary
256  rem path is not the same as the source path then it is *removed* after the
257  rem installation is completed.
258  rem
259  rem For legacy OpenSSL the temporary build path must be the source path.
260  rem
261  rem For OpenSSL 1.1.x the temporary paths must be separate not a descendant
262  rem of the other, otherwise pdb files will be lost between builds.
263  rem https://github.com/openssl/openssl/issues/10005
264  rem
265  if "%LEGACY_BUILD%" == "TRUE" (
266    set "TMP_BUILD_PATH=%SOURCE_PATH%"
267    set "TMP_INSTALL_PATH=%SOURCE_PATH%"
268  ) else (
269    set "TMP_BUILD_PATH=%SOURCE_PATH%\build\tmp_build"
270    set "TMP_INSTALL_PATH=%SOURCE_PATH%\build\tmp_install"
271  )
272
273  goto %BUILD_PLATFORM%
274
275:x64
276  rem Calculate our output directory
277  set OUTDIR=build\Win64\%VC_DESC%
278  if not exist %OUTDIR% md %OUTDIR%
279
280  if not "%BUILD_CONFIG%" == "release" (
281    rem Configuring 64-bit Static Library Debug Build
282    call :configure x64 debug static %LEGACY_BUILD%
283
284    rem Perform the build
285    call :build x64 static %LEGACY_BUILD%
286
287    rem Perform the install
288    call :install debug static %LEGACY_BUILD%
289
290    rem Configuring 64-bit Shared Library Debug Build
291    call :configure x64 debug shared %LEGACY_BUILD%
292
293    rem Perform the build
294    call :build x64 shared %LEGACY_BUILD%
295
296    rem Perform the install
297    call :install debug shared %LEGACY_BUILD%
298  )
299
300  if not "%BUILD_CONFIG%" == "debug" (
301    rem Configuring 64-bit Static Library Release Build
302    call :configure x64 release static %LEGACY_BUILD%
303
304    rem Perform the build
305    call :build x64 static %LEGACY_BUILD%
306
307    rem Perform the install
308    call :install release static %LEGACY_BUILD%
309
310    rem Configuring 64-bit Shared Library Release Build
311    call :configure x64 release shared %LEGACY_BUILD%
312
313    rem Perform the build
314    call :build x64 shared %LEGACY_BUILD%
315
316    rem Perform the install
317    call :install release shared %LEGACY_BUILD%
318  )
319
320  goto success
321
322:x86
323  rem Calculate our output directory
324  set OUTDIR=build\Win32\%VC_DESC%
325  if not exist %OUTDIR% md %OUTDIR%
326
327  if not "%BUILD_CONFIG%" == "release" (
328    rem Configuring 32-bit Static Library Debug Build
329    call :configure x86 debug static %LEGACY_BUILD%
330
331    rem Perform the build
332    call :build x86 static %LEGACY_BUILD%
333
334    rem Perform the install
335    call :install debug static %LEGACY_BUILD%
336
337    rem Configuring 32-bit Shared Library Debug Build
338    call :configure x86 debug shared %LEGACY_BUILD%
339
340    rem Perform the build
341    call :build x86 shared %LEGACY_BUILD%
342
343    rem Perform the install
344    call :install debug shared %LEGACY_BUILD%
345  )
346
347  if not "%BUILD_CONFIG%" == "debug" (
348    rem Configuring 32-bit Static Library Release Build
349    call :configure x86 release static %LEGACY_BUILD%
350
351    rem Perform the build
352    call :build x86 static %LEGACY_BUILD%
353
354    rem Perform the install
355    call :install release static %LEGACY_BUILD%
356
357    rem Configuring 32-bit Shared Library Release Build
358    call :configure x86 release shared %LEGACY_BUILD%
359
360    rem Perform the build
361    call :build x86 shared %LEGACY_BUILD%
362
363    rem Perform the install
364    call :install release shared %LEGACY_BUILD%
365  )
366
367  goto success
368
369rem Function to configure the build.
370rem
371rem %1 - Platform (x86 or x64)
372rem %2 - Configuration (release or debug)
373rem %3 - Build Type (static or shared)
374rem %4 - Build type (TRUE for legacy aka pre v1.1.0; otherwise FALSE)
375rem
376:configure
377  setlocal
378
379  if "%1" == "" exit /B 1
380  if "%2" == "" exit /B 1
381  if "%3" == "" exit /B 1
382  if "%4" == "" exit /B 1
383
384  if not exist "%TMP_BUILD_PATH%" mkdir "%TMP_BUILD_PATH%"
385  cd /d "%TMP_BUILD_PATH%" || (echo Error: Failed cd build & exit /B 1)
386
387  if "%4" == "TRUE" (
388    rem Calculate the configure options
389    if "%1" == "x86" (
390      if "%2" == "debug" (
391        set options=debug-VC-WIN32
392      ) else if "%2" == "release" (
393        set options=VC-WIN32
394      ) else (
395        exit /B 1
396      )
397
398      set options=!options! no-asm
399    ) else if "%1" == "x64" (
400      if "%2" == "debug" (
401        set options=debug-VC-WIN64A
402      ) else if "%2" == "release" (
403        set options=VC-WIN64A
404      ) else (
405        exit /B 1
406      )
407    ) else (
408      exit /B 1
409    )
410  ) else if "%4" == "FALSE" (
411    rem Has configure already been ran?
412    if exist makefile (
413      rem Clean up the previous build
414      nmake clean
415
416      rem Remove the old makefile
417      del makefile 1>nul
418    )
419
420    rem Calculate the configure options
421    if "%1" == "x86" (
422      set options=VC-WIN32
423    ) else if "%1" == "x64" (
424      set options=VC-WIN64A
425    ) else (
426      exit /B 1
427    )
428
429    if "%2" == "debug" (
430      set options=!options! --debug
431    ) else if "%2" == "release" (
432      set options=!options! --release
433    ) else (
434      exit /B 1
435    )
436
437    if "%3" == "static" (
438      set options=!options! no-shared
439    ) else if not "%3" == "shared" (
440      exit /B 1
441    )
442
443    set options=!options! no-asm
444  ) else (
445    exit /B 1
446  )
447
448  rem Run the configure
449  perl "%SOURCE_PATH%\Configure" %options% "--prefix=%TMP_INSTALL_PATH%"
450
451  exit /B %ERRORLEVEL%
452
453rem Main build function.
454rem
455rem %1 - Platform (x86 or x64)
456rem %2 - Build Type (static or shared)
457rem %3 - Build type (TRUE for legacy aka pre v1.1.0; otherwise FALSE)
458rem
459:build
460  setlocal
461
462  if "%1" == "" exit /B 1
463  if "%2" == "" exit /B 1
464  if "%3" == "" exit /B 1
465
466  cd /d "%TMP_BUILD_PATH%" || (echo Error: Failed cd build & exit /B 1)
467
468  if "%3" == "TRUE" (
469    if "%1" == "x86" (
470      call ms\do_ms.bat
471    ) else if "%1" == "x64" (
472      call ms\do_win64a.bat
473    ) else (
474      exit /B 1
475    )
476
477    if "%2" == "static" (
478      nmake -f ms\nt.mak
479    ) else if "%2" == "shared" (
480      nmake -f ms\ntdll.mak
481    ) else (
482      exit /B 1
483    )
484  ) else if "%3" == "FALSE" (
485    nmake
486  ) else (
487    exit /B 1
488  )
489
490  exit /B 0
491
492rem Main installation function.
493rem
494rem %1 - Configuration (release or debug)
495rem %2 - Build Type (static or shared)
496rem %3 - Build type (TRUE for legacy aka pre v1.1.0; otherwise FALSE)
497rem
498:install
499  setlocal
500
501  if "%1" == "" exit /B 1
502  if "%2" == "" exit /B 1
503  if "%3" == "" exit /B 1
504
505  rem Copy the generated files to our directory structure
506  if "%3" == "TRUE" (
507    rem There's no actual installation for legacy OpenSSL, the files are copied
508    rem from the build dir (for legacy this is same as source dir) to the final
509    rem location.
510    cd /d "%SOURCE_PATH%" || (echo Error: Failed cd source & exit /B 1)
511    if "%1" == "debug" (
512      if "%2" == "static" (
513        rem Move the output directories
514        if exist "%OUTDIR%\LIB Debug" (
515          copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
516          rd out32.dbg /s /q
517        ) else (
518          move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
519        )
520
521        rem Move the PDB files
522        move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
523
524        rem Remove the intermediate directories
525        rd tmp32.dbg /s /q
526      ) else if "%2" == "shared" (
527        if exist "%OUTDIR%\DLL Debug" (
528          copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
529          rd out32dll.dbg /s /q
530        ) else (
531          move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
532        )
533
534        rem Move the PDB files
535        move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
536
537        rem Remove the intermediate directories
538        rd tmp32dll.dbg /s /q
539      ) else (
540        exit /B 1
541      )
542    ) else if "%1" == "release" (
543      if "%2" == "static" (
544        rem Move the output directories
545        if exist "%OUTDIR%\LIB Release" (
546          copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
547          rd out32 /s /q
548        ) else (
549          move out32 "%OUTDIR%\LIB Release" 1>nul
550        )
551
552        rem Move the PDB files
553        move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
554
555        rem Remove the intermediate directories
556        rd tmp32 /s /q
557      ) else if "%2" == "shared" (
558        if exist "%OUTDIR%\DLL Release" (
559          copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
560          rd out32dll /s /q
561        ) else (
562          move out32dll "%OUTDIR%\DLL Release" 1>nul
563        )
564
565        rem Move the PDB files
566        move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
567
568        rem Remove the intermediate directories
569        rd tmp32dll /s /q
570      ) else (
571        exit /B 1
572      )
573    )
574  ) else if "%3" == "FALSE" (
575    cd /d "%TMP_BUILD_PATH%" || (echo Error: Failed cd build & exit /B 1)
576
577    rem Perform the installation
578    nmake install_sw
579
580    cd /d "%SOURCE_PATH%" || (echo Error: Failed cd source & exit /B 1)
581
582    rem Move the output directories
583    if "%1" == "debug" (
584      if "%2" == "static" (
585        if not exist "%OUTDIR%\LIB Debug" (
586          mkdir "%OUTDIR%\LIB Debug" 1>nul
587        )
588
589        move "%TMP_INSTALL_PATH%\lib\*.lib" "%OUTDIR%\LIB Debug" 1>nul
590        move "%TMP_INSTALL_PATH%\lib\*.pdb" "%OUTDIR%\LIB Debug" 1>nul
591        move "%TMP_INSTALL_PATH%\bin\*.exe" "%OUTDIR%\LIB Debug" 1>nul
592        move "%TMP_INSTALL_PATH%\bin\*.pdb" "%OUTDIR%\LIB Debug" 1>nul
593        xcopy /E /I /Y "%TMP_INSTALL_PATH%\include" "%OUTDIR%\LIB Debug\include" 1>nul
594      ) else if "%2" == "shared" (
595        if not exist "%OUTDIR%\DLL Debug" (
596          mkdir "%OUTDIR%\DLL Debug" 1>nul
597        )
598
599        move "%TMP_INSTALL_PATH%\lib\*.lib" "%OUTDIR%\DLL Debug" 1>nul
600        move "%TMP_INSTALL_PATH%\lib\engines-1_1\*.dll" "%OUTDIR%\DLL Debug" 1>nul
601        move "%TMP_INSTALL_PATH%\lib\engines-1_1\*.pdb" "%OUTDIR%\DLL Debug" 1>nul
602        move "%TMP_INSTALL_PATH%\bin\*.dll" "%OUTDIR%\DLL Debug" 1>nul
603        move "%TMP_INSTALL_PATH%\bin\*.exe" "%OUTDIR%\DLL Debug" 1>nul
604        move "%TMP_INSTALL_PATH%\bin\*.pdb" "%OUTDIR%\DLL Debug" 1>nul
605        xcopy /E /I /Y "%TMP_INSTALL_PATH%\include" "%OUTDIR%\DLL Debug\include" 1>nul
606      ) else (
607        exit /B 1
608      )
609    ) else if "%1" == "release" (
610      if "%2" == "static" (
611        if not exist "%OUTDIR%\LIB Release" (
612          mkdir "%OUTDIR%\LIB Release" 1>nul
613        )
614
615        move "%TMP_INSTALL_PATH%\lib\*.lib" "%OUTDIR%\LIB Release" 1>nul
616        move "%TMP_INSTALL_PATH%\lib\*.pdb" "%OUTDIR%\LIB Release" 1>nul
617        move "%TMP_INSTALL_PATH%\bin\*.exe" "%OUTDIR%\LIB Release" 1>nul
618        move "%TMP_INSTALL_PATH%\bin\*.pdb" "%OUTDIR%\LIB Release" 1>nul
619        xcopy /E /I /Y "%TMP_INSTALL_PATH%\include" "%OUTDIR%\LIB Release\include" 1>nul
620      ) else if "%2" == "shared" (
621        if not exist "%OUTDIR%\DLL Release" (
622          mkdir "%OUTDIR%\DLL Release" 1>nul
623        )
624
625        move "%TMP_INSTALL_PATH%\lib\*.lib" "%OUTDIR%\DLL Release" 1>nul
626        move "%TMP_INSTALL_PATH%\lib\engines-1_1\*.dll" "%OUTDIR%\DLL Release" 1>nul
627        move "%TMP_INSTALL_PATH%\lib\engines-1_1\*.pdb" "%OUTDIR%\DLL Release" 1>nul
628        move "%TMP_INSTALL_PATH%\bin\*.dll" "%OUTDIR%\DLL Release" 1>nul
629        move "%TMP_INSTALL_PATH%\bin\*.exe" "%OUTDIR%\DLL Release" 1>nul
630        move "%TMP_INSTALL_PATH%\bin\*.pdb" "%OUTDIR%\DLL Release" 1>nul
631        xcopy /E /I /Y "%TMP_INSTALL_PATH%\include" "%OUTDIR%\DLL Release\include" 1>nul
632      ) else (
633        exit /B 1
634      )
635    ) else (
636      exit /B 1
637    )
638
639    rem Remove the output directories
640    if not "%SOURCE_PATH%" == "%TMP_BUILD_PATH%" (
641      rd "%TMP_BUILD_PATH%" /s /q
642    )
643    if not "%SOURCE_PATH%" == "%TMP_INSTALL_PATH%" (
644      rd "%TMP_INSTALL_PATH%" /s /q
645    )
646  ) else (
647    exit /B 1
648  )
649
650  exit /B 0
651
652:syntax
653  rem Display the help
654  echo.
655  echo Usage: build-openssl ^<compiler^> [platform] [configuration] [directory] [-VSpath] ["VSpath"] [-perlpath] ["perlpath"]
656  echo.
657  echo Compiler:
658  echo.
659  echo vc6       - Use Visual Studio 6
660  echo vc7       - Use Visual Studio .NET
661  echo vc7.1     - Use Visual Studio .NET 2003
662  echo vc8       - Use Visual Studio 2005
663  echo vc9       - Use Visual Studio 2008
664  echo vc10      - Use Visual Studio 2010
665  echo vc11      - Use Visual Studio 2012
666  echo vc12      - Use Visual Studio 2013
667  echo vc14      - Use Visual Studio 2015
668  echo vc14.1    - Use Visual Studio 2017
669  echo vc14.2    - Use Visual Studio 2019
670  echo.
671  echo Platform:
672  echo.
673  echo x86       - Perform a 32-bit build
674  echo x64       - Perform a 64-bit build
675  echo.
676  echo Configuration:
677  echo.
678  echo debug     - Perform a debug build
679  echo release   - Perform a release build
680  echo.
681  echo Other:
682  echo.
683  echo directory - Specifies the OpenSSL source directory
684  echo.
685  echo -VSpath - Specify the custom VS path if Visual Studio is not located at
686  echo           "C:\<ProgramFiles>\Microsoft Visual Studio <version>"
687  echo           For e.g. -VSpath "C:\apps\MVS14"
688  echo.
689  echo -perlpath - Specify the custom perl root path if perl is not located at
690  echo             "C:\Perl" and it is a portable copy of perl and not
691  echo             installed on the win system.
692  echo             For e.g. -perlpath "D:\strawberry-perl-5.24.3.1-64bit-portable"
693  goto error
694
695:unknown
696  echo.
697  echo Error: Unknown argument '%1'
698  goto error
699
700:nodos
701  echo.
702  echo Error: Only a Windows NT based Operating System is supported
703  goto error
704
705:nopf
706  echo.
707  echo Error: Cannot obtain the directory for Program Files
708  goto error
709
710:novc
711  echo.
712  echo Error: %VC_DESC% is not installed
713  echo Error: Please check whether Visual compiler is installed at the path "%ABS_VC_PATH%"
714  echo Error: Please provide proper VS Path by using -VSpath
715  goto error
716
717:noperl
718  echo.
719  echo Error: Perl is not installed
720  echo Error: Please check whether Perl is installed or it is at location "C:\Perl"
721  echo Error: If Perl is portable please provide perl root path by using -perlpath
722  goto error
723
724:nox64
725  echo.
726  echo Error: %VC_DESC% does not support 64-bit builds
727  goto error
728
729:noopenssl
730  echo.
731  echo Error: Cannot locate OpenSSL source directory
732  goto error
733
734:error
735  if "%OS%" == "Windows_NT" endlocal
736  exit /B 1
737
738:success
739  cd /d "%SAVED_PATH%"
740  endlocal
741  exit /B 0
742