generate.bat 12 KB

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