xref: /curl/projects/generate.bat (revision 6389ba87)
1@echo off
2rem ***************************************************************************
3rem *                                  _   _ ____  _
4rem *  Project                     ___| | | |  _ \| |
5rem *                             / __| | | | |_) | |
6rem *                            | (__| |_| |  _ <| |___
7rem *                             \___|\___/|_| \_\_____|
8rem *
9rem * Copyright (C) Steve Holme, <steve_holme@hotmail.com>.
10rem *
11rem * This software is licensed as described in the file COPYING, which
12rem * you should have received as part of this distribution. The terms
13rem * are also available at https://curl.se/docs/copyright.html.
14rem *
15rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16rem * copies of the Software, and permit persons to whom the Software is
17rem * furnished to do so, under the terms of the COPYING file.
18rem *
19rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20rem * KIND, either express or implied.
21rem *
22rem * SPDX-License-Identifier: curl
23rem *
24rem ***************************************************************************
25
26:begin
27  rem Check we are running on a Windows NT derived OS
28  if not "%OS%" == "Windows_NT" goto nodos
29
30  rem Set our variables
31  setlocal ENABLEEXTENSIONS
32  set VERSION=ALL
33  set MODE=GENERATE
34
35  rem Check we are not running on a network drive
36  if "%~d0."=="\\." goto nonetdrv
37
38  rem Switch to this batch file's directory
39  cd /d "%~0\.." 1>NUL 2>&1
40
41  rem Check we are running from a curl git repository
42  if not exist ..\GIT-INFO.md goto norepo
43
44:parseArgs
45  if "%~1" == "" goto start
46
47  if /i "%~1" == "pre" (
48    set VERSION=PRE
49  ) else if /i "%~1" == "vc10" (
50    set VERSION=VC10
51  ) else if /i "%~1" == "vc11" (
52    set VERSION=VC11
53  ) else if /i "%~1" == "vc12" (
54    set VERSION=VC12
55  ) else if /i "%~1" == "-clean" (
56    set MODE=CLEAN
57  ) else if /i "%~1" == "-?" (
58    goto syntax
59  ) else if /i "%~1" == "/?" (
60    goto syntax
61  ) else if /i "%~1" == "-h" (
62    goto syntax
63  ) else if /i "%~1" == "-help" (
64    goto syntax
65  ) else if /i "%~1" == "--help" (
66    goto syntax
67  ) else (
68    goto unknown
69  )
70
71  shift & goto parseArgs
72
73:start
74  if exist ..\buildconf.bat (
75    if "%MODE%" == "GENERATE" (
76      call ..\buildconf
77    ) else if "%VERSION%" == "PRE" (
78      call ..\buildconf -clean
79    ) else if "%VERSION%" == "ALL" (
80      call ..\buildconf -clean
81    )
82  )
83  if "%VERSION%" == "PRE" goto success
84  if "%VERSION%" == "VC10" goto vc10
85  if "%VERSION%" == "VC11" goto vc11
86  if "%VERSION%" == "VC12" goto vc12
87
88:vc10
89  echo.
90
91  if "%MODE%" == "GENERATE" (
92    echo Generating VC10 project files
93    call :generate vcxproj Windows\VC10\src\curl.tmpl Windows\VC10\src\curl.vcxproj
94    call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
95  ) else (
96    echo Removing VC10 project files
97    call :clean Windows\VC10\src\curl.vcxproj
98    call :clean Windows\VC10\lib\libcurl.vcxproj
99  )
100
101  if not "%VERSION%" == "ALL" goto success
102
103:vc11
104  echo.
105
106  if "%MODE%" == "GENERATE" (
107    echo Generating VC11 project files
108    call :generate vcxproj Windows\VC11\src\curl.tmpl Windows\VC11\src\curl.vcxproj
109    call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
110  ) else (
111    echo Removing VC11 project files
112    call :clean Windows\VC11\src\curl.vcxproj
113    call :clean Windows\VC11\lib\libcurl.vcxproj
114  )
115
116  if not "%VERSION%" == "ALL" goto success
117
118:vc12
119  echo.
120
121  if "%MODE%" == "GENERATE" (
122    echo Generating VC12 project files
123    call :generate vcxproj Windows\VC12\src\curl.tmpl Windows\VC12\src\curl.vcxproj
124    call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
125  ) else (
126    echo Removing VC12 project files
127    call :clean Windows\VC12\src\curl.vcxproj
128    call :clean Windows\VC12\lib\libcurl.vcxproj
129  )
130
131  goto success
132
133rem Main generate function.
134rem
135rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30)
136rem %2 - Input template file
137rem %3 - Output project file
138rem
139:generate
140  if not exist %2 (
141    echo.
142    echo Error: Cannot open %2
143    exit /B
144  )
145
146  if exist %3 (
147    del %3
148  )
149
150  echo * %CD%\%3
151  for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
152    set "var=%%i"
153    setlocal enabledelayedexpansion
154    set "var=!var:*:=!"
155
156    if "!var!" == "CURL_SRC_C_FILES" (
157      for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
158    ) else if "!var!" == "CURL_SRC_H_FILES" (
159      for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
160    ) else if "!var!" == "CURL_SRC_RC_FILES" (
161      for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
162    ) else if "!var!" == "CURL_SRC_X_C_FILES" (
163      call :element %1 lib "strtoofft.c" %3
164      call :element %1 lib "timediff.c" %3
165      call :element %1 lib "nonblock.c" %3
166      call :element %1 lib "warnless.c" %3
167      call :element %1 lib "curl_multibyte.c" %3
168      call :element %1 lib "version_win32.c" %3
169      call :element %1 lib "dynbuf.c" %3
170      call :element %1 lib "base64.c" %3
171    ) else if "!var!" == "CURL_SRC_X_H_FILES" (
172      call :element %1 lib "config-win32.h" %3
173      call :element %1 lib "curl_setup.h" %3
174      call :element %1 lib "strtoofft.h" %3
175      call :element %1 lib "timediff.h" %3
176      call :element %1 lib "nonblock.h" %3
177      call :element %1 lib "warnless.h" %3
178      call :element %1 lib "curl_ctype.h" %3
179      call :element %1 lib "curl_multibyte.h" %3
180      call :element %1 lib "version_win32.h" %3
181      call :element %1 lib "dynbuf.h" %3
182      call :element %1 lib "curl_base64.h" %3
183    ) else if "!var!" == "CURL_LIB_C_FILES" (
184      for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
185    ) else if "!var!" == "CURL_LIB_H_FILES" (
186      for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3
187      for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
188    ) else if "!var!" == "CURL_LIB_RC_FILES" (
189      for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
190    ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" (
191      for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3
192    ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" (
193      for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3
194    ) else if "!var!" == "CURL_LIB_VQUIC_C_FILES" (
195      for /f "delims=" %%c in ('dir /b ..\lib\vquic\*.c') do call :element %1 lib\vquic "%%c" %3
196    ) else if "!var!" == "CURL_LIB_VQUIC_H_FILES" (
197      for /f "delims=" %%h in ('dir /b ..\lib\vquic\*.h') do call :element %1 lib\vquic "%%h" %3
198    ) else if "!var!" == "CURL_LIB_VSSH_C_FILES" (
199      for /f "delims=" %%c in ('dir /b ..\lib\vssh\*.c') do call :element %1 lib\vssh "%%c" %3
200    ) else if "!var!" == "CURL_LIB_VSSH_H_FILES" (
201      for /f "delims=" %%h in ('dir /b ..\lib\vssh\*.h') do call :element %1 lib\vssh "%%h" %3
202    ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
203      for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
204    ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
205      for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
206    ) else (
207      echo.!var!>> %3
208    )
209
210    endlocal
211  )
212  exit /B
213
214rem Generates a single file xml element.
215rem
216rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30)
217rem %2 - Directory (src, lib, lib\vauth, lib\vquic, lib\vssh, lib\vtls)
218rem %3 - Source filename
219rem %4 - Output project file
220rem
221:element
222  set "SPACES=    "
223  if "%2" == "lib\vauth" (
224    set "TABS=				"
225  ) else if "%2" == "lib\vquic" (
226    set "TABS=				"
227  ) else if "%2" == "lib\vssh" (
228    set "TABS=				"
229  ) else if "%2" == "lib\vtls" (
230    set "TABS=				"
231  ) else (
232    set "TABS=			"
233  )
234
235  call :extension %3 ext
236
237  if "%1" == "dsp" (
238    echo # Begin Source File>> %4
239    echo.>> %4
240    echo SOURCE=..\..\..\..\%2\%~3>> %4
241    echo # End Source File>> %4
242  ) else if "%1" == "vcproj1" (
243    echo %TABS%^<File>> %4
244    echo %TABS%	RelativePath="..\..\..\..\%2\%~3"^>>> %4
245    echo %TABS%^</File^>>> %4
246  ) else if "%1" == "vcproj2" (
247    echo %TABS%^<File>> %4
248    echo %TABS%	RelativePath="..\..\..\..\%2\%~3">> %4
249    echo %TABS%^>>> %4
250    echo %TABS%^</File^>>> %4
251  ) else if "%1" == "vcxproj" (
252    if "%ext%" == "c" (
253      echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
254    ) else if "%ext%" == "h" (
255      echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
256    ) else if "%ext%" == "rc" (
257      echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
258    )
259  )
260
261  exit /B
262
263rem Returns the extension for a given filename.
264rem
265rem %1 - The filename
266rem %2 - The return value
267rem
268:extension
269  set fname=%~1
270  set ename=
271:loop1
272  if "%fname%"=="" (
273    set %2=
274    exit /B
275  )
276
277  if not "%fname:~-1%"=="." (
278    set ename=%fname:~-1%%ename%
279    set fname=%fname:~0,-1%
280    goto loop1
281  )
282
283  set %2=%ename%
284  exit /B
285
286rem Removes the given project file.
287rem
288rem %1 - The filename
289rem
290:clean
291  echo * %CD%\%1
292
293  if exist %1 (
294    del %1
295  )
296
297  exit /B
298
299:syntax
300  rem Display the help
301  echo.
302  echo Usage: generate [what] [-clean]
303  echo.
304  echo What to generate:
305  echo.
306  echo pre       - Prerequisites only
307  echo vc10      - Use Visual Studio 2010
308  echo vc11      - Use Visual Studio 2012
309  echo vc12      - Use Visual Studio 2013
310  echo.
311  echo Only legacy Visual Studio project files can be generated.
312  echo.
313  echo To generate recent versions of Visual Studio project files use cmake.
314  echo Refer to INSTALL-CMAKE in the docs directory.
315  echo.
316  echo -clean    - Removes the project files
317  goto error
318
319:unknown
320  echo.
321  echo Error: Unknown argument '%1'
322  goto error
323
324:nodos
325  echo.
326  echo Error: Only a Windows NT based Operating System is supported
327  goto error
328
329:nonetdrv
330  echo.
331  echo Error: This batch file cannot run from a network drive
332  goto error
333
334:norepo
335  echo.
336  echo Error: This batch file should only be used from a curl git repository
337  goto error
338
339:seterr
340  rem Set the caller's errorlevel.
341  rem %1[opt]: Errorlevel as integer.
342  rem If %1 is empty the errorlevel will be set to 0.
343  rem If %1 is not empty and not an integer the errorlevel will be set to 1.
344  setlocal
345  set EXITCODE=%~1
346  if not defined EXITCODE set EXITCODE=0
347  echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1
348  if %ERRORLEVEL% EQU 0 set EXITCODE=1
349  exit /b %EXITCODE%
350
351:error
352  if "%OS%" == "Windows_NT" endlocal
353  exit /B 1
354
355:success
356  endlocal
357  exit /B 0
358