fed472e04c24574878aeea7dbeee620831ba4a3f
[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_LIB_C_FILES" (
96       for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
97     ) else if "!var!" == "CURL_LIB_H_FILES" (
98       for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
99     ) else if "!var!" == "CURL_LIB_RC_FILES" (
100       for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
101     ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
102       for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
103     ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
104       for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
105     ) else (
106       echo.!var!>> %3
107     )
108
109     endlocal
110   )
111   exit /B
112
113 rem Generates a single file xml element.
114 rem
115 rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
116 rem      or vcxproj for VC10, VC11 and VC12)
117 rem %2 - Directory (src, lib or lib\vtls)
118 rem %3 - Source filename
119 rem %4 - Output project file
120 rem
121 :element
122   set "SPACES=    "
123   if "%2" == "lib\vtls" (
124     set "TABS=        "
125   ) else (
126     set "TABS=      "
127   )
128
129   if "%1" == "dsp" (
130     echo # Begin Source File>> %4
131     echo.>> %4
132     echo SOURCE=..\..\..\..\%2\%~3>> %4
133     echo # End Source File>> %4
134   ) else if "%1" == "vcproj1" (
135     echo %TABS%^<File>> %4
136     echo %TABS%  RelativePath="..\..\..\..\%2\%~3"^>>> %4
137     echo %TABS%^</File^>>> %4
138   ) else if "%1" == "vcproj2" (
139     echo %TABS%^<File>> %4
140     echo %TABS%  RelativePath="..\..\..\..\%2\%~3">> %4
141     echo %TABS%^>>> %4
142     echo %TABS%^</File^>>> %4
143   ) else if "%1" == "vcxproj" (
144     call :extension %3 ext
145
146     if "%ext%" == "c" (
147       echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
148     ) else if "%ext%" == "h" (
149       echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
150     ) else if "%ext%" == "rc" (
151       echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
152     )
153   )
154
155   exit /B
156
157 rem Returns the extension for a given filename.
158 rem
159 rem %1 - The filename
160 rem %2 - The return value
161 rem
162 :extension
163   set fname=%~1
164   set ename=
165 :loop1
166   if "%fname%"=="" (
167     set %2=
168     exit /B
169   )
170
171   if not "%fname:~-1%"=="." (
172     set ename=%fname:~-1%%ename%
173     set fname=%fname:~0,-1%
174     goto loop1
175   )
176
177   set %2=%ename%
178   exit /B
179
180 :exit
181   echo.
182   pause