generate.bat 12 KB

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