generate.bat 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. :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_multibyte.c" %3
  187. call :element %1 lib "version_win32.c" %3
  188. call :element %1 lib "dynbuf.c" %3
  189. call :element %1 lib "base64.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. call :element %1 lib "curl_base64.h" %3
  202. ) else if "!var!" == "CURL_LIB_C_FILES" (
  203. for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
  204. ) else if "!var!" == "CURL_LIB_H_FILES" (
  205. for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3
  206. for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
  207. ) else if "!var!" == "CURL_LIB_RC_FILES" (
  208. for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
  209. ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" (
  210. for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3
  211. ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" (
  212. for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3
  213. ) else if "!var!" == "CURL_LIB_VQUIC_C_FILES" (
  214. for /f "delims=" %%c in ('dir /b ..\lib\vquic\*.c') do call :element %1 lib\vquic "%%c" %3
  215. ) else if "!var!" == "CURL_LIB_VQUIC_H_FILES" (
  216. for /f "delims=" %%h in ('dir /b ..\lib\vquic\*.h') do call :element %1 lib\vquic "%%h" %3
  217. ) else if "!var!" == "CURL_LIB_VSSH_C_FILES" (
  218. for /f "delims=" %%c in ('dir /b ..\lib\vssh\*.c') do call :element %1 lib\vssh "%%c" %3
  219. ) else if "!var!" == "CURL_LIB_VSSH_H_FILES" (
  220. for /f "delims=" %%h in ('dir /b ..\lib\vssh\*.h') do call :element %1 lib\vssh "%%h" %3
  221. ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
  222. for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
  223. ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
  224. for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
  225. ) else (
  226. echo.!var!>> %3
  227. )
  228. endlocal
  229. )
  230. exit /B
  231. rem Generates a single file xml element.
  232. rem
  233. rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10 and VC14.30)
  234. rem %2 - Directory (src, lib, lib\vauth, lib\vquic, lib\vssh, lib\vtls)
  235. rem %3 - Source filename
  236. rem %4 - Output project file
  237. rem
  238. :element
  239. set "SPACES= "
  240. if "%2" == "lib\vauth" (
  241. set "TABS= "
  242. ) else if "%2" == "lib\vquic" (
  243. set "TABS= "
  244. ) else if "%2" == "lib\vssh" (
  245. set "TABS= "
  246. ) else if "%2" == "lib\vtls" (
  247. set "TABS= "
  248. ) else (
  249. set "TABS= "
  250. )
  251. call :extension %3 ext
  252. if "%1" == "dsp" (
  253. echo # Begin Source File>> %4
  254. echo.>> %4
  255. echo SOURCE=..\..\..\..\%2\%~3>> %4
  256. echo # End Source File>> %4
  257. ) else if "%1" == "vcproj1" (
  258. echo %TABS%^<File>> %4
  259. echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4
  260. echo %TABS%^</File^>>> %4
  261. ) else if "%1" == "vcproj2" (
  262. echo %TABS%^<File>> %4
  263. echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4
  264. echo %TABS%^>>> %4
  265. echo %TABS%^</File^>>> %4
  266. ) else if "%1" == "vcxproj" (
  267. if "%ext%" == "c" (
  268. echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  269. ) else if "%ext%" == "h" (
  270. echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  271. ) else if "%ext%" == "rc" (
  272. echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  273. )
  274. )
  275. exit /B
  276. rem Returns the extension for a given filename.
  277. rem
  278. rem %1 - The filename
  279. rem %2 - The return value
  280. rem
  281. :extension
  282. set fname=%~1
  283. set ename=
  284. :loop1
  285. if "%fname%"=="" (
  286. set %2=
  287. exit /B
  288. )
  289. if not "%fname:~-1%"=="." (
  290. set ename=%fname:~-1%%ename%
  291. set fname=%fname:~0,-1%
  292. goto loop1
  293. )
  294. set %2=%ename%
  295. exit /B
  296. rem Removes the given project file.
  297. rem
  298. rem %1 - The filename
  299. rem
  300. :clean
  301. echo * %CD%\%1
  302. if exist %1 (
  303. del %1
  304. )
  305. exit /B
  306. :syntax
  307. rem Display the help
  308. echo.
  309. echo Usage: generate [what] [-clean]
  310. echo.
  311. echo What to generate:
  312. echo.
  313. echo pre - Prerequisites only
  314. echo vc10 - Use Visual Studio 2010
  315. echo vc11 - Use Visual Studio 2012
  316. echo vc12 - Use Visual Studio 2013
  317. echo vc14 - Use Visual Studio 2015
  318. echo vc14.10 - Use Visual Studio 2017
  319. echo vc14.30 - Use Visual Studio 2022
  320. echo.
  321. echo -clean - Removes the project files
  322. goto error
  323. :unknown
  324. echo.
  325. echo Error: Unknown argument '%1'
  326. goto error
  327. :nodos
  328. echo.
  329. echo Error: Only a Windows NT based Operating System is supported
  330. goto error
  331. :nonetdrv
  332. echo.
  333. echo Error: This batch file cannot run from a network drive
  334. goto error
  335. :norepo
  336. echo.
  337. echo Error: This batch file should only be used from a curl git repository
  338. goto error
  339. :seterr
  340. rem Set the caller's errorlevel.
  341. rem %1[opt]: Errorlevel as integer.
  342. rem If %1 is empty the errorlevel will be set to 0.
  343. rem If %1 is not empty and not an integer the errorlevel will be set to 1.
  344. setlocal
  345. set EXITCODE=%~1
  346. if not defined EXITCODE set EXITCODE=0
  347. echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1
  348. if %ERRORLEVEL% EQU 0 set EXITCODE=1
  349. exit /b %EXITCODE%
  350. :error
  351. if "%OS%" == "Windows_NT" endlocal
  352. exit /B 1
  353. :success
  354. endlocal
  355. exit /B 0