generate.bat 12 KB

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