build: Added VC9 and VC10 support to the project file generator
[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 setlocal ENABLEDELAYEDEXPANSION
24
25 rem Generate VC8 project files
26 call :generate vc8 Windows\VC8\src\curlsrc.tmpl Windows\VC8\src\curlsrc.vcproj
27 call :generate vc8 Windows\VC8\lib\libcurl.tmpl Windows\VC8\lib\libcurl.vcproj
28
29 rem Generate VC9 project files
30 call :generate vc9 Windows\VC9\src\curlsrc.tmpl Windows\VC9\src\curlsrc.vcproj
31 call :generate vc9 Windows\VC9\lib\libcurl.tmpl Windows\VC9\lib\libcurl.vcproj
32
33 rem Generate VC10 project files
34 call :generate vc10 Windows\VC10\src\curlsrc.tmpl Windows\VC10\src\curlsrc.vcxproj
35 call :generate vc10 Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
36
37 goto exit
38
39 rem Main generate function.
40 rem
41 rem %1 - IDE
42 rem %2 - Input template file
43 rem %3 - Output project file
44 rem
45 :generate
46   echo.
47
48   if not exist %2 (
49     echo Error: Cannot open %CD%\%2
50     exit /B
51   )
52
53   if exist %3 (  
54     echo Deleting %3
55     del %3
56   )
57
58   echo Generating %3
59   for /f "delims=" %%i in (%2) do (
60     if "%%i" == "CURL_SRC_C_FILES" (
61       for /f %%c in ('dir /b ..\src\*.c') do call :element %1 src %%c %3
62     ) else if "%%i" == "CURL_SRC_H_FILES" (
63       for /f %%h in ('dir /b ..\src\*.h') do call :element %1 src %%h %3
64     ) else if "%%i" == "CURL_SRC_RC_FILES" (
65       for /f %%r in ('dir /b ..\src\*.rc') do call :element %1 src %%r %3
66     ) else if "%%i" == "CURL_LIB_C_FILES" (
67       for /f %%c in ('dir /b ..\lib\*.c') do call :element %1 lib %%c %3
68     ) else if "%%i" == "CURL_LIB_H_FILES" (
69       for /f %%h in ('dir /b ..\lib\*.h') do call :element %1 lib %%h %3
70     ) else if "%%i" == "CURL_LIB_RC_FILES" (
71       for /f %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib %%r %3
72     ) else if "%%i" == "CURL_LIB_VTLS_C_FILES" (
73       for /f %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls %%c %3
74     ) else if "%%i" == "CURL_LIB_VTLS_H_FILES" (
75       for /f %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls %%h %3
76     ) else (
77       echo %%i>> %3
78     )
79   )
80   exit /B
81
82 rem Generates a single file xml element.
83 rem
84 rem %1 - IDE
85 rem %2 - Directory (eg src, lib or lib\vtls)
86 rem %3 - Source filename
87 rem %4 - Output project file
88 rem
89 :element
90   set "SPACES=    "
91   if "%2" == "lib\vtls" (
92     set "TABS=        "
93   ) else (
94     set "TABS=      "
95   )
96
97   call :extension %3 ext
98
99   if "%1" == "vc10" (
100     if "%ext%" == "c" (
101       echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%3^" /^>>> %4
102     ) else if "%ext%" == "h" (
103       echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%3^" /^>>> %4
104     ) else if "%ext%" == "rc" (
105       echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%3^" /^>>> %4
106     )
107   ) else (
108     echo %TABS%^<File>> %4
109     echo %TABS%  RelativePath="..\..\..\..\%2\%3">> %4
110     echo %TABS%^>>> %4
111     echo %TABS%^</File^>>> %4
112   )
113
114   exit /B
115
116 rem Returns the extension for a given filename.
117 rem
118 rem %1 - The filename
119 rem %2 - The return value
120 rem
121 :extension
122   set fname=%1
123   set ename=
124 :loop1
125   if "%fname%"=="" (
126     set %2=
127     exit /B
128   )
129
130   if not "%fname:~-1%"=="." (
131     set ename=%fname:~-1%%ename%
132     set fname=%fname:~0,-1%
133     goto loop1
134   )
135
136   set %2=%ename%
137   exit /B
138
139 :exit
140   echo.
141   pause