generate.bat 12 KB

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