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