2
0

generate.bat 13 KB

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