tizen 2.4 release
[external/curl.git] / projects / generate.bat
1 @echo off
2 rem ***************************************************************************
3 rem *                                  _   _ ____  _
4 rem *  Project                     ___| | | |  _ \| |
5 rem *                             / __| | | | |_) | |
6 rem *                            | (__| |_| |  _ <| |___
7 rem *                             \___|\___/|_| \_\_____|
8 rem *
9 rem * Copyright (C) 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" == "-h" goto syntax
32   if /i "%~1" == "-help" goto syntax
33
34 :parseArgs
35   if "%~1" == "" goto all
36
37   if /i "%~1" == "vc6" (
38     goto vc6
39   ) else if /i "%~1" == "vc7" (
40     goto vc7
41   ) else if /i "%~1" == "vc7.1" (
42     goto vc71
43   ) else if /i "%~1" == "vc8" (
44     goto vc8
45   ) else if /i "%~1" == "vc9" (
46     goto vc9
47   ) else if /i "%~1" == "vc10" (
48     goto vc10
49   ) else if /i "%~1" == "vc11" (
50     goto vc11
51   ) else if /i "%~1" == "vc12" (
52     goto vc12
53   ) else (
54     goto unknown
55   )
56
57 :all
58   set ALL=true
59
60 :vc6
61   echo.
62   echo Generating VC6 project files
63   call :generate dsp Windows\VC6\src\curlsrc.tmpl Windows\VC6\src\curlsrc.dsp
64   call :generate dsp Windows\VC6\lib\libcurl.tmpl Windows\VC6\lib\libcurl.dsp
65   if not "%ALL%" == "true" goto success
66
67 :vc7
68   echo.
69   echo Generating VC7 project files
70   call :generate vcproj1 Windows\VC7\src\curlsrc.tmpl Windows\VC7\src\curlsrc.vcproj
71   call :generate vcproj1 Windows\VC7\lib\libcurl.tmpl Windows\VC7\lib\libcurl.vcproj
72   if not "%ALL%" == "true" goto success
73
74 :vc71
75   echo.
76   echo Generating VC7.1 project files
77   call :generate vcproj1 Windows\VC7.1\src\curlsrc.tmpl Windows\VC7.1\src\curlsrc.vcproj
78   call :generate vcproj1 Windows\VC7.1\lib\libcurl.tmpl Windows\VC7.1\lib\libcurl.vcproj
79   if not "%ALL%" == "true" goto success
80
81 :vc8
82   echo.
83   echo Generating VC8 project files
84   call :generate vcproj2 Windows\VC8\src\curlsrc.tmpl Windows\VC8\src\curlsrc.vcproj
85   call :generate vcproj2 Windows\VC8\lib\libcurl.tmpl Windows\VC8\lib\libcurl.vcproj
86   if not "%ALL%" == "true" goto success
87
88 :vc9
89   echo.
90   echo Generating VC9 project files
91   call :generate vcproj2 Windows\VC9\src\curlsrc.tmpl Windows\VC9\src\curlsrc.vcproj
92   call :generate vcproj2 Windows\VC9\lib\libcurl.tmpl Windows\VC9\lib\libcurl.vcproj
93   if not "%ALL%" == "true" goto success
94
95 :vc10
96   echo.
97   echo Generating VC10 project files
98   call :generate vcxproj Windows\VC10\src\curlsrc.tmpl Windows\VC10\src\curlsrc.vcxproj
99   call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
100   if not "%ALL%" == "true" goto success
101
102 :vc11
103   echo.
104   echo Generating VC11 project files
105   call :generate vcxproj Windows\VC11\src\curlsrc.tmpl Windows\VC11\src\curlsrc.vcxproj
106   call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
107   if not "%ALL%" == "true" goto success
108
109 :vc12
110   echo.
111   echo Generating VC12 project files
112   call :generate vcxproj Windows\VC12\src\curlsrc.tmpl Windows\VC12\src\curlsrc.vcxproj
113   call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
114
115   goto success
116
117 rem Main generate function.
118 rem
119 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
120 rem      or vcxproj for VC10, VC11 and VC12)
121 rem %2 - Input template file
122 rem %3 - Output project file
123 rem
124 :generate
125   if not exist %2 (
126     echo.
127     echo Error: Cannot open %CD%\%2
128     exit /B
129   )
130
131   if exist %3 (  
132     del %3
133   )
134
135   echo * %CD%\%3
136   for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
137     set "var=%%i"
138     setlocal enabledelayedexpansion
139     set "var=!var:*:=!"
140
141     if "!var!" == "CURL_SRC_C_FILES" (
142       for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
143     ) else if "!var!" == "CURL_SRC_H_FILES" (
144       for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
145     ) else if "!var!" == "CURL_SRC_RC_FILES" (
146       for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
147     ) else if "!var!" == "CURL_SRC_X_C_FILES" (
148       call :element %1 lib "strtoofft.c" %3
149       call :element %1 lib "rawstr.c" %3
150       call :element %1 lib "nonblock.c" %3
151       call :element %1 lib "warnless.c" %3
152     ) else if "!var!" == "CURL_SRC_X_H_FILES" (
153       call :element %1 lib "config-win32.h" %3
154       call :element %1 lib "curl_setup.h" %3
155       call :element %1 lib "strtoofft.h" %3
156       call :element %1 lib "rawstr.h" %3
157       call :element %1 lib "nonblock.h" %3
158       call :element %1 lib "warnless.h" %3
159     ) else if "!var!" == "CURL_LIB_C_FILES" (
160       for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
161     ) else if "!var!" == "CURL_LIB_H_FILES" (
162       for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
163     ) else if "!var!" == "CURL_LIB_RC_FILES" (
164       for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
165     ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
166       for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
167     ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
168       for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
169     ) else (
170       echo.!var!>> %3
171     )
172
173     endlocal
174   )
175   exit /B
176
177 rem Generates a single file xml element.
178 rem
179 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
180 rem      or vcxproj for VC10, VC11 and VC12)
181 rem %2 - Directory (src, lib or lib\vtls)
182 rem %3 - Source filename
183 rem %4 - Output project file
184 rem
185 :element
186   set "SPACES=    "
187   if "%2" == "lib\vtls" (
188     set "TABS=                          "
189   ) else (
190     set "TABS=                  "
191   )
192
193   call :extension %3 ext
194
195   if "%1" == "dsp" (
196     echo # Begin Source File>> %4
197     echo.>> %4
198     echo SOURCE=..\..\..\..\%2\%~3>> %4
199     echo # End Source File>> %4
200   ) else if "%1" == "vcproj1" (
201     echo %TABS%^<File>> %4
202     echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4
203     echo %TABS%^</File^>>> %4
204   ) else if "%1" == "vcproj2" (
205     echo %TABS%^<File>> %4
206     echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4
207     echo %TABS%^>>> %4
208     echo %TABS%^</File^>>> %4
209   ) else if "%1" == "vcxproj" (
210     if "%ext%" == "c" (
211       echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
212     ) else if "%ext%" == "h" (
213       echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
214     ) else if "%ext%" == "rc" (
215       echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
216     )
217   )
218
219   exit /B
220
221 rem Returns the extension for a given filename.
222 rem
223 rem %1 - The filename
224 rem %2 - The return value
225 rem
226 :extension
227   set fname=%~1
228   set ename=
229 :loop1
230   if "%fname%"=="" (
231     set %2=
232     exit /B
233   )
234
235   if not "%fname:~-1%"=="." (
236     set ename=%fname:~-1%%ename%
237     set fname=%fname:~0,-1%
238     goto loop1
239   )
240
241   set %2=%ename%
242   exit /B
243
244 :syntax
245   rem Display the help
246   echo.
247   echo Usage: generate [compiler]
248   echo.
249   echo Compiler:
250   echo.
251   echo vc6       - Use Visual Studio 6
252   echo vc7       - Use Visual Studio .NET
253   echo vc7.1     - Use Visual Studio .NET 2003
254   echo vc8       - Use Visual Studio 2005
255   echo vc9       - Use Visual Studio 2008
256   echo vc10      - Use Visual Studio 2010
257   echo vc11      - Use Visual Studio 2012
258   echo vc12      - Use Visual Studio 2013
259   goto error
260
261 :unknown
262   echo.
263   echo Error: Unknown argument '%1'
264   goto error
265
266 :nodos
267   echo.
268   echo Error: Only a Windows NT based Operating System is supported
269   goto error
270
271 :error
272   endlocal
273   exit /B 1
274
275 :success
276   endlocal
277   exit /B 0