• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "%VERSION%" == "PRE" goto success
75  if "%VERSION%" == "VC10" goto vc10
76  if "%VERSION%" == "VC11" goto vc11
77  if "%VERSION%" == "VC12" goto vc12
78
79:vc10
80  echo.
81
82  if "%MODE%" == "GENERATE" (
83    echo Generating VC10 project files
84    call :generate vcxproj Windows\VC10\src\curl.tmpl Windows\VC10\src\curl.vcxproj
85    call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
86  ) else (
87    echo Removing VC10 project files
88    call :clean Windows\VC10\src\curl.vcxproj
89    call :clean Windows\VC10\lib\libcurl.vcxproj
90  )
91
92  if not "%VERSION%" == "ALL" goto success
93
94:vc11
95  echo.
96
97  if "%MODE%" == "GENERATE" (
98    echo Generating VC11 project files
99    call :generate vcxproj Windows\VC11\src\curl.tmpl Windows\VC11\src\curl.vcxproj
100    call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
101  ) else (
102    echo Removing VC11 project files
103    call :clean Windows\VC11\src\curl.vcxproj
104    call :clean Windows\VC11\lib\libcurl.vcxproj
105  )
106
107  if not "%VERSION%" == "ALL" goto success
108
109:vc12
110  echo.
111
112  if "%MODE%" == "GENERATE" (
113    echo Generating VC12 project files
114    call :generate vcxproj Windows\VC12\src\curl.tmpl Windows\VC12\src\curl.vcxproj
115    call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
116  ) else (
117    echo Removing VC12 project files
118    call :clean Windows\VC12\src\curl.vcxproj
119    call :clean Windows\VC12\lib\libcurl.vcxproj
120  )
121
122  goto success
123
124rem Main generate function.
125rem
126rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30)
127rem %2 - Input template file
128rem %3 - Output project file
129rem
130:generate
131  if not exist %2 (
132    echo.
133    echo Error: Cannot open %2
134    exit /B
135  )
136
137  if exist %3 (
138    del %3
139  )
140
141  echo * %CD%\%3
142  for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
143    set "var=%%i"
144    setlocal enabledelayedexpansion
145    set "var=!var:*:=!"
146
147    if "!var!" == "CURL_SRC_C_FILES" (
148      for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
149    ) else if "!var!" == "CURL_SRC_H_FILES" (
150      for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
151    ) else if "!var!" == "CURL_SRC_RC_FILES" (
152      for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
153    ) else if "!var!" == "CURL_SRC_X_C_FILES" (
154      call :element %1 lib "strtoofft.c" %3
155      call :element %1 lib "timediff.c" %3
156      call :element %1 lib "nonblock.c" %3
157      call :element %1 lib "warnless.c" %3
158      call :element %1 lib "curl_get_line.c" %3
159      call :element %1 lib "curl_multibyte.c" %3
160      call :element %1 lib "version_win32.c" %3
161      call :element %1 lib "dynbuf.c" %3
162      call :element %1 lib "base64.c" %3
163    ) else if "!var!" == "CURL_SRC_X_H_FILES" (
164      call :element %1 lib "config-win32.h" %3
165      call :element %1 lib "curl_setup.h" %3
166      call :element %1 lib "strtoofft.h" %3
167      call :element %1 lib "timediff.h" %3
168      call :element %1 lib "nonblock.h" %3
169      call :element %1 lib "warnless.h" %3
170      call :element %1 lib "curl_ctype.h" %3
171      call :element %1 lib "curl_get_line.h" %3
172      call :element %1 lib "curl_multibyte.h" %3
173      call :element %1 lib "version_win32.h" %3
174      call :element %1 lib "dynbuf.h" %3
175      call :element %1 lib "curl_base64.h" %3
176    ) else if "!var!" == "CURL_LIB_C_FILES" (
177      for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
178    ) else if "!var!" == "CURL_LIB_H_FILES" (
179      for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3
180      for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
181    ) else if "!var!" == "CURL_LIB_RC_FILES" (
182      for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
183    ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" (
184      for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3
185    ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" (
186      for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3
187    ) else if "!var!" == "CURL_LIB_VQUIC_C_FILES" (
188      for /f "delims=" %%c in ('dir /b ..\lib\vquic\*.c') do call :element %1 lib\vquic "%%c" %3
189    ) else if "!var!" == "CURL_LIB_VQUIC_H_FILES" (
190      for /f "delims=" %%h in ('dir /b ..\lib\vquic\*.h') do call :element %1 lib\vquic "%%h" %3
191    ) else if "!var!" == "CURL_LIB_VSSH_C_FILES" (
192      for /f "delims=" %%c in ('dir /b ..\lib\vssh\*.c') do call :element %1 lib\vssh "%%c" %3
193    ) else if "!var!" == "CURL_LIB_VSSH_H_FILES" (
194      for /f "delims=" %%h in ('dir /b ..\lib\vssh\*.h') do call :element %1 lib\vssh "%%h" %3
195    ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
196      for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
197    ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
198      for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
199    ) else (
200      echo.!var!>> %3
201    )
202
203    endlocal
204  )
205  exit /B
206
207rem Generates a single file xml element.
208rem
209rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30)
210rem %2 - Directory (src, lib, lib\vauth, lib\vquic, lib\vssh, lib\vtls)
211rem %3 - Source filename
212rem %4 - Output project file
213rem
214:element
215  set "SPACES=    "
216  if "%2" == "lib\vauth" (
217    set "TABS=				"
218  ) else if "%2" == "lib\vquic" (
219    set "TABS=				"
220  ) else if "%2" == "lib\vssh" (
221    set "TABS=				"
222  ) else if "%2" == "lib\vtls" (
223    set "TABS=				"
224  ) else (
225    set "TABS=			"
226  )
227
228  call :extension %3 ext
229
230  if "%1" == "dsp" (
231    echo # Begin Source File>> %4
232    echo.>> %4
233    echo SOURCE=..\..\..\..\%2\%~3>> %4
234    echo # End Source File>> %4
235  ) else if "%1" == "vcproj1" (
236    echo %TABS%^<File>> %4
237    echo %TABS%	RelativePath="..\..\..\..\%2\%~3"^>>> %4
238    echo %TABS%^</File^>>> %4
239  ) else if "%1" == "vcproj2" (
240    echo %TABS%^<File>> %4
241    echo %TABS%	RelativePath="..\..\..\..\%2\%~3">> %4
242    echo %TABS%^>>> %4
243    echo %TABS%^</File^>>> %4
244  ) else if "%1" == "vcxproj" (
245    if "%ext%" == "c" (
246      echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
247    ) else if "%ext%" == "h" (
248      echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
249    ) else if "%ext%" == "rc" (
250      echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
251    )
252  )
253
254  exit /B
255
256rem Returns the extension for a given filename.
257rem
258rem %1 - The filename
259rem %2 - The return value
260rem
261:extension
262  set fname=%~1
263  set ename=
264:loop1
265  if "%fname%"=="" (
266    set %2=
267    exit /B
268  )
269
270  if not "%fname:~-1%"=="." (
271    set ename=%fname:~-1%%ename%
272    set fname=%fname:~0,-1%
273    goto loop1
274  )
275
276  set %2=%ename%
277  exit /B
278
279rem Removes the given project file.
280rem
281rem %1 - The filename
282rem
283:clean
284  echo * %CD%\%1
285
286  if exist %1 (
287    del %1
288  )
289
290  exit /B
291
292:syntax
293  rem Display the help
294  echo.
295  echo Usage: generate [what] [-clean]
296  echo.
297  echo What to generate:
298  echo.
299  echo pre       - Prerequisites only
300  echo vc10      - Use Visual Studio 2010
301  echo vc11      - Use Visual Studio 2012
302  echo vc12      - Use Visual Studio 2013
303  echo.
304  echo Only legacy Visual Studio project files can be generated.
305  echo.
306  echo To generate recent versions of Visual Studio project files use cmake.
307  echo Refer to INSTALL-CMAKE.md in the docs directory.
308  echo.
309  echo -clean    - Removes the project files
310  goto error
311
312:unknown
313  echo.
314  echo Error: Unknown argument '%1'
315  goto error
316
317:nodos
318  echo.
319  echo Error: Only a Windows NT based Operating System is supported
320  goto error
321
322:nonetdrv
323  echo.
324  echo Error: This batch file cannot run from a network drive
325  goto error
326
327:norepo
328  echo.
329  echo Error: This batch file should only be used from a curl git repository
330  goto error
331
332:seterr
333  rem Set the caller's errorlevel.
334  rem %1[opt]: Errorlevel as integer.
335  rem If %1 is empty the errorlevel will be set to 0.
336  rem If %1 is not empty and not an integer the errorlevel will be set to 1.
337  setlocal
338  set EXITCODE=%~1
339  if not defined EXITCODE set EXITCODE=0
340  echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1
341  if %ERRORLEVEL% EQU 0 set EXITCODE=1
342  exit /b %EXITCODE%
343
344:error
345  if "%OS%" == "Windows_NT" endlocal
346  exit /B 1
347
348:success
349  endlocal
350  exit /B 0
351