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