generate.bat (10054B)
1 @echo off 2 rem *************************************************************************** 3 rem * _ _ ____ _ 4 rem * Project ___| | | | _ \| | 5 rem * / __| | | | |_) | | 6 rem * | (__| |_| | _ <| |___ 7 rem * \___|\___/|_| \_\_____| 8 rem * 9 rem * Copyright (C) Steve Holme, <steve_holme@hotmail.com>. 10 rem * 11 rem * This software is licensed as described in the file COPYING, which 12 rem * you should have received as part of this distribution. The terms 13 rem * are also available at https://curl.se/docs/copyright.html. 14 rem * 15 rem * You may opt to use, copy, modify, merge, publish, distribute and/or sell 16 rem * copies of the Software, and permit persons to whom the Software is 17 rem * furnished to do so, under the terms of the COPYING file. 18 rem * 19 rem * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 rem * KIND, either express or implied. 21 rem * 22 rem * SPDX-License-Identifier: curl 23 rem * 24 rem *************************************************************************** 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 124 rem Main generate function. 125 rem 126 rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30) 127 rem %2 - Input template file 128 rem %3 - Output project file 129 rem 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 ( 149 if /i "%%c" NEQ "curlinfo.c" call :element %1 src "%%c" %3 150 ) 151 ) else if "!var!" == "CURL_SRC_H_FILES" ( 152 for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3 153 ) else if "!var!" == "CURL_SRC_RC_FILES" ( 154 for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3 155 ) else if "!var!" == "CURL_SRC_X_H_FILES" ( 156 call :element %1 lib "config-win32.h" %3 157 call :element %1 lib "curl_setup.h" %3 158 ) else if "!var!" == "CURL_LIB_C_FILES" ( 159 for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3 160 ) else if "!var!" == "CURL_LIB_H_FILES" ( 161 for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3 162 for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3 163 ) else if "!var!" == "CURL_LIB_RC_FILES" ( 164 for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3 165 ) else if "!var!" == "CURL_LIB_CURLX_C_FILES" ( 166 for /f "delims=" %%c in ('dir /b ..\lib\curlx\*.c') do call :element %1 lib\curlx "%%c" %3 167 ) else if "!var!" == "CURL_LIB_CURLX_H_FILES" ( 168 for /f "delims=" %%h in ('dir /b ..\lib\curlx\*.h') do call :element %1 lib\curlx "%%h" %3 169 ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" ( 170 for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3 171 ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" ( 172 for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3 173 ) else if "!var!" == "CURL_LIB_VQUIC_C_FILES" ( 174 for /f "delims=" %%c in ('dir /b ..\lib\vquic\*.c') do call :element %1 lib\vquic "%%c" %3 175 ) else if "!var!" == "CURL_LIB_VQUIC_H_FILES" ( 176 for /f "delims=" %%h in ('dir /b ..\lib\vquic\*.h') do call :element %1 lib\vquic "%%h" %3 177 ) else if "!var!" == "CURL_LIB_VSSH_C_FILES" ( 178 for /f "delims=" %%c in ('dir /b ..\lib\vssh\*.c') do call :element %1 lib\vssh "%%c" %3 179 ) else if "!var!" == "CURL_LIB_VSSH_H_FILES" ( 180 for /f "delims=" %%h in ('dir /b ..\lib\vssh\*.h') do call :element %1 lib\vssh "%%h" %3 181 ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" ( 182 for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3 183 ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" ( 184 for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3 185 ) else ( 186 echo.!var!>> %3 187 ) 188 189 endlocal 190 ) 191 exit /B 192 193 rem Generates a single file xml element. 194 rem 195 rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30) 196 rem %2 - Directory (src, lib, lib\vauth, lib\vquic, lib\vssh, lib\vtls) 197 rem %3 - Source filename 198 rem %4 - Output project file 199 rem 200 :element 201 set "SPACES= " 202 if "%2" == "lib\vauth" ( 203 set "TABS= " 204 ) else if "%2" == "lib\vquic" ( 205 set "TABS= " 206 ) else if "%2" == "lib\vssh" ( 207 set "TABS= " 208 ) else if "%2" == "lib\vtls" ( 209 set "TABS= " 210 ) else if "%2" == "lib\curlx" ( 211 set "TABS= " 212 ) else ( 213 set "TABS= " 214 ) 215 216 call :extension %3 ext 217 218 if "%1" == "dsp" ( 219 echo # Begin Source File>> %4 220 echo.>> %4 221 echo SOURCE=..\..\..\..\%2\%~3>> %4 222 echo # End Source File>> %4 223 ) else if "%1" == "vcproj1" ( 224 echo %TABS%^<File>> %4 225 echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4 226 echo %TABS%^</File^>>> %4 227 ) else if "%1" == "vcproj2" ( 228 echo %TABS%^<File>> %4 229 echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4 230 echo %TABS%^>>> %4 231 echo %TABS%^</File^>>> %4 232 ) else if "%1" == "vcxproj" ( 233 if "%ext%" == "c" ( 234 echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4 235 ) else if "%ext%" == "h" ( 236 echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4 237 ) else if "%ext%" == "rc" ( 238 echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4 239 ) 240 ) 241 242 exit /B 243 244 rem Returns the extension for a given filename. 245 rem 246 rem %1 - The filename 247 rem %2 - The return value 248 rem 249 :extension 250 set fname=%~1 251 set ename= 252 :loop1 253 if "%fname%"=="" ( 254 set %2= 255 exit /B 256 ) 257 258 if not "%fname:~-1%"=="." ( 259 set ename=%fname:~-1%%ename% 260 set fname=%fname:~0,-1% 261 goto loop1 262 ) 263 264 set %2=%ename% 265 exit /B 266 267 rem Removes the given project file. 268 rem 269 rem %1 - The filename 270 rem 271 :clean 272 echo * %CD%\%1 273 274 if exist %1 ( 275 del %1 276 ) 277 278 exit /B 279 280 :syntax 281 rem Display the help 282 echo. 283 echo Usage: generate [what] [-clean] 284 echo. 285 echo What to generate: 286 echo. 287 echo pre - Prerequisites only 288 echo vc10 - Use Visual Studio 2010 289 echo vc11 - Use Visual Studio 2012 290 echo vc12 - Use Visual Studio 2013 291 echo. 292 echo Only legacy Visual Studio project files can be generated. 293 echo. 294 echo To generate recent versions of Visual Studio project files use cmake. 295 echo Refer to INSTALL-CMAKE.md in the docs directory. 296 echo. 297 echo -clean - Removes the project files 298 goto error 299 300 :unknown 301 echo. 302 echo Error: Unknown argument '%1' 303 goto error 304 305 :nodos 306 echo. 307 echo Error: Only a Windows NT based Operating System is supported 308 goto error 309 310 :nonetdrv 311 echo. 312 echo Error: This batch file cannot run from a network drive 313 goto error 314 315 :norepo 316 echo. 317 echo Error: This batch file should only be used from a curl git repository 318 goto error 319 320 :seterr 321 rem Set the caller's errorlevel. 322 rem %1[opt]: Errorlevel as integer. 323 rem If %1 is empty the errorlevel will be set to 0. 324 rem If %1 is not empty and not an integer the errorlevel will be set to 1. 325 setlocal 326 set EXITCODE=%~1 327 if not defined EXITCODE set EXITCODE=0 328 echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1 329 if %ERRORLEVEL% EQU 0 set EXITCODE=1 330 exit /b %EXITCODE% 331 332 :error 333 if "%OS%" == "Windows_NT" endlocal 334 exit /B 1 335 336 :success 337 endlocal 338 exit /B 0