2
0

generate.bat 12 KB

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