3703a3f2d3050280382e78984d43ea593aa1ce89
[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 Default the start directory if one isn't specified
90   if not defined START_DIR set START_DIR=..\..\openssl
91
92   rem Calculate the program files directory
93   if defined PROGRAMFILES (
94     set "PF=%PROGRAMFILES%"
95     set OS_PLATFORM=x86
96   )
97   if defined PROGRAMFILES(x86) (
98     set "PF=%PROGRAMFILES(x86)%"
99     set OS_PLATFORM=x64
100   )
101
102   rem Check we have a program files directory
103   if not defined PF goto nopf
104
105   rem Check we have Visual Studio installed
106   if not exist "%PF%\%VC_PATH%" goto novc
107
108   rem Check the start directory exists
109   if not exist "%START_DIR%" goto noopenssl
110
111 :configure
112   if "%BUILD_PLATFORM%" == "" (
113     if "%VC_VER%" == "6.0" (
114       set BUILD_PLATFORM=x86
115     ) else if "%VC_VER%" == "7.0" (
116       set BUILD_PLATFORM=x86
117     ) else if "%VC_VER%" == "7.1" (
118       set BUILD_PLATFORM=x86
119     ) else (
120       set BUILD_PLATFORM=%OS_PLATFORM%
121     )
122   )
123
124   if "%BUILD_PLATFORM%" == "x86" (
125     set VCVARS_PLATFORM=x86
126   ) else if "%BUILD_PLATFORM%" == "x64" (
127     if "%VC_VER%" == "6.0" goto nox64
128     if "%VC_VER%" == "7.0" goto nox64
129     if "%VC_VER%" == "7.1" goto nox64
130     if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
131     if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
132     if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
133     if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
134     if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
135   )
136
137 :start
138   echo.
139   if "%VC_VER%" == "6.0" (
140     call "%PF%\%VC_PATH%\bin\vcvars32"
141   ) else if "%VC_VER%" == "7.0" (
142     call "%PF%\%VC_PATH%\bin\vcvars32"
143   ) else if "%VC_VER%" == "7.1" (
144     call "%PF%\%VC_PATH%\bin\vcvars32"
145   ) else (
146     call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
147   )
148
149   echo.
150   set SAVED_PATH=%CD%
151   if defined START_DIR CD %START_DIR%
152   goto %BUILD_PLATFORM%
153
154 :x64
155   rem Calculate our output directory
156   set OUTDIR=build\Win64\%VC_DESC%
157   if not exist %OUTDIR% md %OUTDIR%
158
159   if "%BUILD_CONFIG%" == "release" goto x64release\r
160
161 :x64debug
162   rem Configuring 64-bit Debug Build
163   perl Configure debug-VC-WIN64A --prefix=%CD%
164
165   rem Perform the build
166   call ms\do_win64a
167   nmake -f ms\nt.mak
168   nmake -f ms\ntdll.mak
169
170   rem Move the output directories
171   move out32.dbg "%OUTDIR%\LIB Debug"
172   move out32dll.dbg "%OUTDIR%\DLL Debug"
173
174   rem Move the PDB files
175   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
176   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
177   
178   rem Remove the intermediate directories
179   rd tmp32.dbg /s /q
180   rd tmp32dll.dbg /s /q
181
182   if "%BUILD_CONFIG%" == "debug" goto success
183   
184 :x64release
185   rem Configuring 64-bit Release Build
186   perl Configure VC-WIN64A --prefix=%CD%
187   
188   rem Perform the build
189   call ms\do_win64a
190   nmake -f ms\nt.mak
191   nmake -f ms\ntdll.mak
192   
193   rem Move the output directories
194   move out32 "%OUTDIR%\LIB Release"
195   move out32dll "%OUTDIR%\DLL Release"
196
197   rem Move the PDB files
198   move tmp32\lib.pdb "%OUTDIR%\LIB Release"
199   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
200
201   rem Remove the intermediate directories
202   rd tmp32 /s /q
203   rd tmp32dll /s /q
204
205   goto success
206   
207 :x86
208   rem Calculate our output directory
209   set OUTDIR=build\Win32\%VC_DESC%
210   if not exist %OUTDIR% md %OUTDIR%
211
212   if "%BUILD_CONFIG%" == "release" goto x86release
213   
214 :x86debug
215   rem Configuring 32-bit Debug Build
216   perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
217
218   rem Perform the build
219   call ms\do_ms
220   nmake -f ms\nt.mak
221   nmake -f ms\ntdll.mak
222
223   rem Move the output directories
224   move out32.dbg "%OUTDIR%\LIB Debug"
225   move out32dll.dbg "%OUTDIR%\DLL Debug"
226
227   rem Move the PDB files
228   move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
229   move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
230
231   rem Remove the intermediate directories
232   rd tmp32.dbg /s /q
233   rd tmp32dll.dbg /s /q
234
235   if "%BUILD_CONFIG%" == "debug" goto success
236   
237 :x86release
238   rem Configuring 32-bit Release Build
239   perl Configure VC-WIN32 no-asm --prefix=%CD%
240
241   rem Perform the build
242   call ms\do_ms
243   nmake -f ms\nt.mak
244   nmake -f ms\ntdll.mak
245   
246   rem Move the output directories
247   move out32 "%OUTDIR%\LIB Release"
248   move out32dll "%OUTDIR%\DLL Release"
249
250   rem Move the PDB files
251   move tmp32\lib.pdb "%OUTDIR%\LIB Release"
252   move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
253
254   rem Remove the intermediate directories
255   rd tmp32 /s /q
256   rd tmp32dll /s /q
257
258   goto success
259
260 :syntax
261   rem Display the help
262   echo.
263   echo Usage: build-openssl ^<compiler^> ^<platform^> [configuration] [directory]
264   echo.
265   echo Compiler:
266   echo.
267   echo vc6       - Use Visual Studio 6
268   echo vc7       - Use Visual Studio .NET
269   echo vc7.1     - Use Visual Studio .NET 2003
270   echo vc8       - Use Visual Studio 2005
271   echo vc9       - Use Visual Studio 2008
272   echo vc10      - Use Visual Studio 2010
273   echo vc11      - Use Visual Studio 2012
274   echo vc12      - Use Visual Studio 2013
275   echo.
276   echo Platform:
277   echo.
278   echo x86       - Perform a 32-bit build
279   echo x64       - Perform a 64-bit build
280   echo.
281   echo Configuration:
282   echo.
283   echo debug     - Perform a debug build
284   echo release   - Perform a release build
285   echo.
286   echo Other:
287   echo.
288   echo directory - Specifies the OpenSSL source directory
289   goto error
290
291 :unknown
292   echo.
293   echo Error: Unknown argument '%1'
294   goto error
295
296 :nodos
297   echo.
298   echo Error: Only a Windows NT based Operating System is supported
299   goto error
300
301 :nopf
302   echo.
303   echo Error: Cannot obtain the directory for Program Files
304   goto error
305
306 :novc
307   echo.
308   echo Error: %VC_DESC% is not installed
309   goto error
310
311 :nox64
312   echo.
313   echo Error: %VC_DESC% does not support 64-bit builds
314   goto error
315
316 :noopenssl
317   echo.
318   echo Error: Cannot locate OpenSSL source directory
319   goto error
320
321 :error
322   if "%OS%" == "Windows_NT" endlocal
323   exit /B 1
324
325 :success
326   cd %SAVED_PATH%
327   endlocal
328   exit /B 0