build: Added OpenSSL VC build helper for side-by-side compilations
[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 - 2014, 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   setlocal
28   
29   rem Display the help
30   if /i "%~1" == "" goto syntax
31   if /i "%~1" == "-?" goto syntax
32   if /i "%~1" == "-h" goto syntax
33   if /i "%~1" == "-help" goto syntax
34
35 :parseArgs
36   if "%~1" == "" goto prerequisites
37
38   if /i "%~1" == "vc6" (
39     set VC_VER=6.0
40     set VC_DESC=VC6
41     set "VC_PATH=Microsoft Visual Studio\VC98"
42   ) else if /i "%~1" == "vc7" (
43     set VC_VER=7.0
44     set VC_DESC=VC7
45     set "VC_PATH=Microsoft Visual Studio .NET\Vc7"
46   ) else if /i "%~1" == "vc7.1" (
47     set VC_VER=7.1
48     set VC_DESC=VC7.1
49     set "VC_PATH=Microsoft Visual Studio .NET 2003\Vc7"
50   ) else if /i "%~1" == "vc8" (
51     set VC_VER=8.0
52     set VC_DESC=VC8
53     set "VC_PATH=Microsoft Visual Studio 8\VC"
54   ) else if /i "%~1" == "vc9" (
55     set VC_VER=9.0
56     set VC_DESC=VC9
57     set "VC_PATH=Microsoft Visual Studio 9.0\VC"
58   ) else if /i "%~1" == "vc10" (
59     set VC_VER=10.0
60     set VC_DESC=VC10
61     set "VC_PATH=Microsoft Visual Studio 10.0\VC"
62   ) else if /i "%~1" == "vc11" (
63     set VC_VER=11.0
64     set VC_DESC=VC11
65     set "VC_PATH=Microsoft Visual Studio 11.0\VC"
66   ) else if /i "%~1" == "vc12" (
67     set VC_VER=12.0
68     set VC_DESC=VC12
69     set "VC_PATH=Microsoft Visual Studio 12.0\VC"
70   ) else if /i "%~1%" == "x86" (
71     set BUILD_PLATFORM=x86
72   ) else if /i "%~1%" == "x64" (
73     set BUILD_PLATFORM=x64
74   ) else if /i "%~1%" == "debug" (
75     set BUILD_CONFIG=debug
76   ) else if /i "%~1%" == "release" (
77     set BUILD_CONFIG=release
78   ) else (
79     if not defined START_DIR (
80       set START_DIR=%~1%
81     ) else (
82       goto unknown
83     )
84   )
85
86   shift & goto parseArgs
87
88 :prerequisites
89   rem Calculate the program files directory
90   if defined PROGRAMFILES (
91     set "PF=%PROGRAMFILES%"
92     set OS_PLATFORM=x86
93   )
94   if defined PROGRAMFILES(x86) (
95     set "PF=%PROGRAMFILES(x86)%"
96     set OS_PLATFORM=x64
97   )
98
99   rem Check we have a program files directory
100   if not defined PF goto nopf
101
102   rem Check we have Visual Studio installed
103   if not exist "%PF%\%VC_PATH%" goto novc
104
105 :configure
106   if "%BUILD_PLATFORM%" == "" (
107     if "%VC_VER%" == "6.0" (
108       set BUILD_PLATFORM=x86
109     ) else if "%VC_VER%" == "7.0" (
110       set BUILD_PLATFORM=x86
111     ) else if "%VC_VER%" == "7.1" (
112       set BUILD_PLATFORM=x86
113     ) else (
114       set BUILD_PLATFORM=%OS_PLATFORM%
115     )
116   )
117
118   if "%BUILD_PLATFORM%" == "x86" (
119     set VCVARS_PLATFORM=x86
120   ) else if "%BUILD_PLATFORM%" == "x64" (
121     if "%VC_VER%" == "6.0" goto nox64
122     if "%VC_VER%" == "7.0" goto nox64
123     if "%VC_VER%" == "7.1" goto nox64
124     if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
125     if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
126     if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
127     if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
128     if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
129   )
130
131 :start
132   echo.
133   if "%VC_VER%" == "6.0" (
134     call "%PF%\%VC_PATH%\bin\vcvars32"
135   ) else if "%VC_VER%" == "7.0" (
136     call "%PF%\%VC_PATH%\bin\vcvars32"
137   ) else if "%VC_VER%" == "7.1" (
138     call "%PF%\%VC_PATH%\bin\vcvars32"
139   ) else (
140     call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
141   )
142
143   echo.
144   set SAVED_PATH=%CD%
145   if defined START_DIR CD %START_DIR%
146   goto %BUILD_PLATFORM%
147
148 :x64
149   rem Calculate our output directory
150   set OUTDIR=build\Win64\%VC_DESC%
151   if not exist %OUTDIR% md %OUTDIR%
152
153   if "%BUILD_CONFIG%" == "release" goto x86release
154
155 :x64debug
156   rem Configuring 64-bit Debug Build
157   perl Configure debug-VC-WIN64A --prefix=%CD%
158
159   rem Perform the build
160   call ms\do_win64a
161   nmake -f ms\nt.mak
162   nmake -f ms\ntdll.mak
163
164   rem Move the output directories
165   move out32.dbg "%OUTDIR%\LIB Debug"
166   move out32dll.dbg "%OUTDIR%\DLL Debug"
167
168   rem Move the PDB files
169   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
170   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
171   
172   rem Remove the intermediate directories
173   rd tmp32.dbg /s /q
174   rd tmp32dll.dbg /s /q
175
176   if "%BUILD_CONFIG%" == "debug" goto success
177   
178 :x64release
179   rem Configuring 64-bit Release Build
180   perl Configure VC-WIN64A --prefix=%CD%
181   
182   rem Perform the build
183   call ms\do_win64a
184   nmake -f ms\nt.mak
185   nmake -f ms\ntdll.mak
186   
187   rem Move the output directories
188   move out32 "%OUTDIR%\LIB Release"
189   move out32dll "%OUTDIR%\DLL Release"
190
191   rem Move the PDB files
192   move tmp32\lib.pdb "%OUTDIR%\LIB Release"
193   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
194
195   rem Remove the intermediate directories
196   rd tmp32 /s /q
197   rd tmp32dll /s /q
198
199   goto success
200   
201 :x86
202   rem Calculate our output directory
203   set OUTDIR=build\Win32\%VC_DESC%
204   if not exist %OUTDIR% md %OUTDIR%
205
206   if "%BUILD_CONFIG%" == "release" goto x86release
207   
208 :x86debug
209   rem Configuring 32-bit Debug Build
210   perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
211
212   rem Perform the build
213   call ms\do_ms
214   nmake -f ms\nt.mak
215   nmake -f ms\ntdll.mak
216
217   rem Move the output directories
218   move out32.dbg "%OUTDIR%\LIB Debug"
219   move out32dll.dbg "%OUTDIR%\DLL Debug"
220
221   rem Move the PDB files
222   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
223   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
224
225   rem Remove the intermediate directories
226   rd tmp32.dbg /s /q
227   rd tmp32dll.dbg /s /q
228
229   if "%BUILD_CONFIG%" == "debug" goto success
230   
231 :x86release
232   rem Configuring 32-bit Release Build
233   perl Configure VC-WIN32 no-asm --prefix=%CD%
234
235   rem Perform the build
236   call ms\do_ms
237   nmake -f ms\nt.mak
238   nmake -f ms\ntdll.mak
239   
240   rem Move the output directories
241   move out32 "%OUTDIR%\LIB Release"
242   move out32dll "%OUTDIR%\DLL Release"
243
244   rem Move the PDB files
245   move tmp32\lib.pdb "%OUTDIR%\LIB Release"
246   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
247
248   rem Remove the intermediate directories
249   rd tmp32 /s /q
250   rd tmp32dll /s /q
251
252   goto success
253
254 :syntax
255   rem Display the help
256   echo.
257   echo Usage: build-openssl <compiler> <platform> [configuration] [directory]
258   echo.
259   echo Compiler:
260   echo.
261   echo vc6       - Use Visual Studio 6
262   echo vc7       - Use Visual Studio .NET
263   echo vc7.1     - Use Visual Studio .NET 2003
264   echo vc8       - Use Visual Studio 2005
265   echo vc9       - Use Visual Studio 2008
266   echo vc10      - Use Visual Studio 2010
267   echo vc11      - Use Visual Studio 2012
268   echo vc12      - Use Visual Studio 2013
269   echo.
270   echo Platform:
271   echo.
272   echo x86       - Perform a 32-bit build
273   echo x64       - Perform a 64-bit build
274   echo.
275   echo Configuration:
276   echo.
277   echo debug     - Perform a debug build
278   echo release   - Perform a release build
279   echo.
280   echo Other:
281   echo.
282   echo directory - Specifies the openssl directory
283   goto error
284
285 :unknown
286   echo.
287   echo Error: Unknown argument '%1'
288   goto error
289
290 :nodos
291   echo.
292   echo Error: Only a Windows NT based Operating System is supported
293   goto error
294
295 :nopf
296   echo.
297   echo Error: Cannot obtain the directory for Program Files
298   goto error
299
300 :novc
301   echo.
302   echo Error: %VC_DESC% is not installed
303   goto error
304
305 :nox64
306   echo.
307   echo Error: %VC_DESC% does not support 64-bit builds
308   goto error
309
310 :error
311   if "%OS%" == "Windows_NT" endlocal
312   exit /B 1
313
314 :success
315   cd %SAVED_PATH%
316   endlocal
317   exit /B 0