generate.bat 14 KB

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