4ac5fe29693a872672a125df1cef976dd00405b5
[platform/upstream/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 echo Generating VC6 project files
25 call :generate dsp Windows\VC6\src\curlsrc.tmpl Windows\VC6\src\curlsrc.dsp
26 call :generate dsp Windows\VC6\lib\libcurl.tmpl Windows\VC6\lib\libcurl.dsp
27
28 echo.
29 echo Generating VC7 project files
30 call :generate vcproj1 Windows\VC7\src\curlsrc.tmpl Windows\VC7\src\curlsrc.vcproj
31 call :generate vcproj1 Windows\VC7\lib\libcurl.tmpl Windows\VC7\lib\libcurl.vcproj
32
33 echo.
34 echo Generating VC7.1 project files
35 call :generate vcproj1 Windows\VC7.1\src\curlsrc.tmpl Windows\VC7.1\src\curlsrc.vcproj
36 call :generate vcproj1 Windows\VC7.1\lib\libcurl.tmpl Windows\VC7.1\lib\libcurl.vcproj
37
38 echo.
39 echo Generating VC8 project files
40 call :generate vcproj2 Windows\VC8\src\curlsrc.tmpl Windows\VC8\src\curlsrc.vcproj
41 call :generate vcproj2 Windows\VC8\lib\libcurl.tmpl Windows\VC8\lib\libcurl.vcproj
42
43 echo.
44 echo Generating VC9 project files
45 call :generate vcproj2 Windows\VC9\src\curlsrc.tmpl Windows\VC9\src\curlsrc.vcproj
46 call :generate vcproj2 Windows\VC9\lib\libcurl.tmpl Windows\VC9\lib\libcurl.vcproj
47
48 echo.
49 echo Generating VC10 project files
50 call :generate vcxproj Windows\VC10\src\curlsrc.tmpl Windows\VC10\src\curlsrc.vcxproj
51 call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
52
53 echo.
54 echo Generating VC11 project files
55 call :generate vcxproj Windows\VC11\src\curlsrc.tmpl Windows\VC11\src\curlsrc.vcxproj
56 call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
57
58 echo.
59 echo Generating VC12 project files
60 call :generate vcxproj Windows\VC12\src\curlsrc.tmpl Windows\VC12\src\curlsrc.vcxproj
61 call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
62
63 goto exit
64
65 rem Main generate function.
66 rem
67 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
68 rem      or vcxproj for VC10, VC11 and VC12)
69 rem %2 - Input template file
70 rem %3 - Output project file
71 rem
72 :generate
73   if not exist %2 (
74     echo.
75     echo Error: Cannot open %CD%\%2
76     exit /B
77   )
78
79   if exist %3 (  
80     del %3
81   )
82
83   echo * %CD%\%3
84   for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
85     set "var=%%i"
86     setlocal enabledelayedexpansion
87     set "var=!var:*:=!"
88
89     if "!var!" == "CURL_SRC_C_FILES" (
90       for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
91     ) else if "!var!" == "CURL_SRC_H_FILES" (
92       for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
93     ) else if "!var!" == "CURL_SRC_RC_FILES" (
94       for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
95     ) else if "!var!" == "CURL_SRC_X_C_FILES" (
96       call :element %1 lib "strtoofft.c" %3
97       call :element %1 lib "strdup.c" %3
98       call :element %1 lib "rawstr.c" %3
99       call :element %1 lib "nonblock.c" %3
100       call :element %1 lib "warnless.c" %3
101     ) else if "!var!" == "CURL_SRC_X_H_FILES" (
102       call :element %1 lib "config-win32.h" %3
103       call :element %1 lib "curl_setup.h" %3
104       call :element %1 lib "strtoofft.h" %3
105       call :element %1 lib "strdup.h" %3
106       call :element %1 lib "rawstr.h" %3
107       call :element %1 lib "nonblock.h" %3
108       call :element %1 lib "warnless.h" %3
109     ) else if "!var!" == "CURL_LIB_C_FILES" (
110       for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
111     ) else if "!var!" == "CURL_LIB_H_FILES" (
112       for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
113     ) else if "!var!" == "CURL_LIB_RC_FILES" (
114       for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
115     ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
116       for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
117     ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
118       for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
119     ) else (
120       echo.!var!>> %3
121     )
122
123     endlocal
124   )
125   exit /B
126
127 rem Generates a single file xml element.
128 rem
129 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
130 rem      or vcxproj for VC10, VC11 and VC12)
131 rem %2 - Directory (src, lib or lib\vtls)
132 rem %3 - Source filename
133 rem %4 - Output project file
134 rem
135 :element
136   set "SPACES=    "
137   if "%2" == "lib\vtls" (
138     set "TABS=                          "
139   ) else (
140     set "TABS=                  "
141   )
142
143   call :extension %3 ext
144
145   if "%1" == "dsp" (
146     echo # Begin Source File>> %4
147     echo.>> %4
148     echo SOURCE=..\..\..\..\%2\%~3>> %4
149     echo # End Source File>> %4
150   ) else if "%1" == "vcproj1" (
151     echo %TABS%^<File>> %4
152     echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4
153     echo %TABS%^</File^>>> %4
154   ) else if "%1" == "vcproj2" (
155     echo %TABS%^<File>> %4
156     echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4
157     echo %TABS%^>>> %4
158     echo %TABS%^</File^>>> %4
159   ) else if "%1" == "vcxproj" (
160     if "%ext%" == "c" (
161       echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
162     ) else if "%ext%" == "h" (
163       echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
164     ) else if "%ext%" == "rc" (
165       echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
166     )
167   )
168
169   exit /B
170
171 rem Returns the extension for a given filename.
172 rem
173 rem %1 - The filename
174 rem %2 - The return value
175 rem
176 :extension
177   set fname=%~1
178   set ename=
179 :loop1
180   if "%fname%"=="" (
181     set %2=
182     exit /B
183   )
184
185   if not "%fname:~-1%"=="." (
186     set ename=%fname:~-1%%ename%
187     set fname=%fname:~0,-1%
188     goto loop1
189   )
190
191   set %2=%ename%
192   exit /B
193
194 :exit
195   echo.
196   pause