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