generate.bat 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. call :element %1 lib "curl_multibyte.c" %3
  246. ) else if "!var!" == "CURL_SRC_X_H_FILES" (
  247. call :element %1 lib "config-win32.h" %3
  248. call :element %1 lib "curl_setup.h" %3
  249. call :element %1 lib "strtoofft.h" %3
  250. call :element %1 lib "nonblock.h" %3
  251. call :element %1 lib "warnless.h" %3
  252. call :element %1 lib "curl_ctype.h" %3
  253. call :element %1 lib "curl_multibyte.h" %3
  254. ) else if "!var!" == "CURL_LIB_C_FILES" (
  255. for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
  256. ) else if "!var!" == "CURL_LIB_H_FILES" (
  257. for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3
  258. for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
  259. ) else if "!var!" == "CURL_LIB_RC_FILES" (
  260. for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
  261. ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" (
  262. for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3
  263. ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" (
  264. for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3
  265. ) else if "!var!" == "CURL_LIB_VQUIC_C_FILES" (
  266. for /f "delims=" %%c in ('dir /b ..\lib\vquic\*.c') do call :element %1 lib\vquic "%%c" %3
  267. ) else if "!var!" == "CURL_LIB_VQUIC_H_FILES" (
  268. for /f "delims=" %%h in ('dir /b ..\lib\vquic\*.h') do call :element %1 lib\vquic "%%h" %3
  269. ) else if "!var!" == "CURL_LIB_VSSH_C_FILES" (
  270. for /f "delims=" %%c in ('dir /b ..\lib\vssh\*.c') do call :element %1 lib\vssh "%%c" %3
  271. ) else if "!var!" == "CURL_LIB_VSSH_H_FILES" (
  272. for /f "delims=" %%h in ('dir /b ..\lib\vssh\*.h') do call :element %1 lib\vssh "%%h" %3
  273. ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
  274. for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
  275. ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
  276. for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
  277. ) else (
  278. echo.!var!>> %3
  279. )
  280. endlocal
  281. )
  282. exit /B
  283. rem Generates a single file xml element.
  284. rem
  285. rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
  286. rem or vcxproj for VC10, VC11, VC12, VC14 and VC15)
  287. rem %2 - Directory (src, lib, lib\vauth, lib\vquic, lib\vssh, lib\vtls)
  288. rem %3 - Source filename
  289. rem %4 - Output project file
  290. rem
  291. :element
  292. set "SPACES= "
  293. if "%2" == "lib\vauth" (
  294. set "TABS= "
  295. ) else if "%2" == "lib\vquic" (
  296. set "TABS= "
  297. ) else if "%2" == "lib\vssh" (
  298. set "TABS= "
  299. ) else if "%2" == "lib\vtls" (
  300. set "TABS= "
  301. ) else (
  302. set "TABS= "
  303. )
  304. call :extension %3 ext
  305. if "%1" == "dsp" (
  306. echo # Begin Source File>> %4
  307. echo.>> %4
  308. echo SOURCE=..\..\..\..\%2\%~3>> %4
  309. echo # End Source File>> %4
  310. ) else if "%1" == "vcproj1" (
  311. echo %TABS%^<File>> %4
  312. echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4
  313. echo %TABS%^</File^>>> %4
  314. ) else if "%1" == "vcproj2" (
  315. echo %TABS%^<File>> %4
  316. echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4
  317. echo %TABS%^>>> %4
  318. echo %TABS%^</File^>>> %4
  319. ) else if "%1" == "vcxproj" (
  320. if "%ext%" == "c" (
  321. echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  322. ) else if "%ext%" == "h" (
  323. echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  324. ) else if "%ext%" == "rc" (
  325. echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  326. )
  327. )
  328. exit /B
  329. rem Returns the extension for a given filename.
  330. rem
  331. rem %1 - The filename
  332. rem %2 - The return value
  333. rem
  334. :extension
  335. set fname=%~1
  336. set ename=
  337. :loop1
  338. if "%fname%"=="" (
  339. set %2=
  340. exit /B
  341. )
  342. if not "%fname:~-1%"=="." (
  343. set ename=%fname:~-1%%ename%
  344. set fname=%fname:~0,-1%
  345. goto loop1
  346. )
  347. set %2=%ename%
  348. exit /B
  349. rem Removes the given project file.
  350. rem
  351. rem %1 - The filename
  352. rem
  353. :clean
  354. echo * %CD%\%1
  355. if exist %1 (
  356. del %1
  357. )
  358. exit /B
  359. :syntax
  360. rem Display the help
  361. echo.
  362. echo Usage: generate [what] [-clean]
  363. echo.
  364. echo What to generate:
  365. echo.
  366. echo pre - Prerequisites only
  367. echo vc6 - Use Visual Studio 6
  368. echo vc7 - Use Visual Studio .NET
  369. echo vc7.1 - Use Visual Studio .NET 2003
  370. echo vc8 - Use Visual Studio 2005
  371. echo vc9 - Use Visual Studio 2008
  372. echo vc10 - Use Visual Studio 2010
  373. echo vc11 - Use Visual Studio 2012
  374. echo vc12 - Use Visual Studio 2013
  375. echo vc14 - Use Visual Studio 2015
  376. echo vc15 - Use Visual Studio 2017
  377. echo.
  378. echo -clean - Removes the project files
  379. goto error
  380. :unknown
  381. echo.
  382. echo Error: Unknown argument '%1'
  383. goto error
  384. :nodos
  385. echo.
  386. echo Error: Only a Windows NT based Operating System is supported
  387. goto error
  388. :nonetdrv
  389. echo.
  390. echo Error: This batch file cannot run from a network drive
  391. goto error
  392. :norepo
  393. echo.
  394. echo Error: This batch file should only be used from a curl git repository
  395. goto error
  396. :seterr
  397. rem Set the caller's errorlevel.
  398. rem %1[opt]: Errorlevel as integer.
  399. rem If %1 is empty the errorlevel will be set to 0.
  400. rem If %1 is not empty and not an integer the errorlevel will be set to 1.
  401. setlocal
  402. set EXITCODE=%~1
  403. if not defined EXITCODE set EXITCODE=0
  404. echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1
  405. if %ERRORLEVEL% EQU 0 set EXITCODE=1
  406. exit /b %EXITCODE%
  407. :error
  408. if "%OS%" == "Windows_NT" endlocal
  409. exit /B 1
  410. :success
  411. endlocal
  412. exit /B 0