generate.bat 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. @echo off
  2. rem ***************************************************************************
  3. rem * _ _ ____ _
  4. rem * Project ___| | | | _ \| |
  5. rem * / __| | | | |_) | |
  6. rem * | (__| |_| | _ <| |___
  7. rem * \___|\___/|_| \_\_____|
  8. rem *
  9. rem * Copyright (C) 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.md 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" == "-clean" (
  49. set MODE=CLEAN
  50. ) else if /i "%~1" == "-?" (
  51. goto syntax
  52. ) else if /i "%~1" == "/?" (
  53. goto syntax
  54. ) else if /i "%~1" == "-h" (
  55. goto syntax
  56. ) else if /i "%~1" == "-help" (
  57. goto syntax
  58. ) else if /i "%~1" == "--help" (
  59. goto syntax
  60. ) else (
  61. goto unknown
  62. )
  63. shift & goto parseArgs
  64. :start
  65. if exist ..\buildconf.bat (
  66. if "%MODE%" == "GENERATE" (
  67. call ..\buildconf
  68. ) else if "%VERSION%" == "PRE" (
  69. call ..\buildconf -clean
  70. ) else if "%VERSION%" == "ALL" (
  71. call ..\buildconf -clean
  72. )
  73. )
  74. if "%VERSION%" == "PRE" goto success
  75. if "%VERSION%" == "VC10" goto vc10
  76. if "%VERSION%" == "VC11" goto vc11
  77. if "%VERSION%" == "VC12" goto vc12
  78. :vc10
  79. echo.
  80. if "%MODE%" == "GENERATE" (
  81. echo Generating VC10 project files
  82. call :generate vcxproj Windows\VC10\src\curl.tmpl Windows\VC10\src\curl.vcxproj
  83. call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
  84. ) else (
  85. echo Removing VC10 project files
  86. call :clean Windows\VC10\src\curl.vcxproj
  87. call :clean Windows\VC10\lib\libcurl.vcxproj
  88. )
  89. if not "%VERSION%" == "ALL" goto success
  90. :vc11
  91. echo.
  92. if "%MODE%" == "GENERATE" (
  93. echo Generating VC11 project files
  94. call :generate vcxproj Windows\VC11\src\curl.tmpl Windows\VC11\src\curl.vcxproj
  95. call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
  96. ) else (
  97. echo Removing VC11 project files
  98. call :clean Windows\VC11\src\curl.vcxproj
  99. call :clean Windows\VC11\lib\libcurl.vcxproj
  100. )
  101. if not "%VERSION%" == "ALL" goto success
  102. :vc12
  103. echo.
  104. if "%MODE%" == "GENERATE" (
  105. echo Generating VC12 project files
  106. call :generate vcxproj Windows\VC12\src\curl.tmpl Windows\VC12\src\curl.vcxproj
  107. call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
  108. ) else (
  109. echo Removing VC12 project files
  110. call :clean Windows\VC12\src\curl.vcxproj
  111. call :clean Windows\VC12\lib\libcurl.vcxproj
  112. )
  113. goto success
  114. rem Main generate function.
  115. rem
  116. rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30)
  117. rem %2 - Input template file
  118. rem %3 - Output project file
  119. rem
  120. :generate
  121. if not exist %2 (
  122. echo.
  123. echo Error: Cannot open %2
  124. exit /B
  125. )
  126. if exist %3 (
  127. del %3
  128. )
  129. echo * %CD%\%3
  130. for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
  131. set "var=%%i"
  132. setlocal enabledelayedexpansion
  133. set "var=!var:*:=!"
  134. if "!var!" == "CURL_SRC_C_FILES" (
  135. for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
  136. ) else if "!var!" == "CURL_SRC_H_FILES" (
  137. for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
  138. ) else if "!var!" == "CURL_SRC_RC_FILES" (
  139. for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
  140. ) else if "!var!" == "CURL_SRC_X_C_FILES" (
  141. call :element %1 lib "strtoofft.c" %3
  142. call :element %1 lib "timediff.c" %3
  143. call :element %1 lib "nonblock.c" %3
  144. call :element %1 lib "warnless.c" %3
  145. call :element %1 lib "curl_multibyte.c" %3
  146. call :element %1 lib "version_win32.c" %3
  147. call :element %1 lib "dynbuf.c" %3
  148. call :element %1 lib "base64.c" %3
  149. ) else if "!var!" == "CURL_SRC_X_H_FILES" (
  150. call :element %1 lib "config-win32.h" %3
  151. call :element %1 lib "curl_setup.h" %3
  152. call :element %1 lib "strtoofft.h" %3
  153. call :element %1 lib "timediff.h" %3
  154. call :element %1 lib "nonblock.h" %3
  155. call :element %1 lib "warnless.h" %3
  156. call :element %1 lib "curl_ctype.h" %3
  157. call :element %1 lib "curl_multibyte.h" %3
  158. call :element %1 lib "version_win32.h" %3
  159. call :element %1 lib "dynbuf.h" %3
  160. call :element %1 lib "curl_base64.h" %3
  161. ) else if "!var!" == "CURL_LIB_C_FILES" (
  162. for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
  163. ) else if "!var!" == "CURL_LIB_H_FILES" (
  164. for /f "delims=" %%h in ('dir /b ..\include\curl\*.h') do call :element %1 include\curl "%%h" %3
  165. for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
  166. ) else if "!var!" == "CURL_LIB_RC_FILES" (
  167. for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
  168. ) else if "!var!" == "CURL_LIB_VAUTH_C_FILES" (
  169. for /f "delims=" %%c in ('dir /b ..\lib\vauth\*.c') do call :element %1 lib\vauth "%%c" %3
  170. ) else if "!var!" == "CURL_LIB_VAUTH_H_FILES" (
  171. for /f "delims=" %%h in ('dir /b ..\lib\vauth\*.h') do call :element %1 lib\vauth "%%h" %3
  172. ) else if "!var!" == "CURL_LIB_VQUIC_C_FILES" (
  173. for /f "delims=" %%c in ('dir /b ..\lib\vquic\*.c') do call :element %1 lib\vquic "%%c" %3
  174. ) else if "!var!" == "CURL_LIB_VQUIC_H_FILES" (
  175. for /f "delims=" %%h in ('dir /b ..\lib\vquic\*.h') do call :element %1 lib\vquic "%%h" %3
  176. ) else if "!var!" == "CURL_LIB_VSSH_C_FILES" (
  177. for /f "delims=" %%c in ('dir /b ..\lib\vssh\*.c') do call :element %1 lib\vssh "%%c" %3
  178. ) else if "!var!" == "CURL_LIB_VSSH_H_FILES" (
  179. for /f "delims=" %%h in ('dir /b ..\lib\vssh\*.h') do call :element %1 lib\vssh "%%h" %3
  180. ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
  181. for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
  182. ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
  183. for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
  184. ) else (
  185. echo.!var!>> %3
  186. )
  187. endlocal
  188. )
  189. exit /B
  190. rem Generates a single file xml element.
  191. rem
  192. rem %1 - Project Type (vcxproj for VC10, VC11, VC12, VC14, VC14.10, VC14.20 and VC14.30)
  193. rem %2 - Directory (src, lib, lib\vauth, lib\vquic, lib\vssh, lib\vtls)
  194. rem %3 - Source filename
  195. rem %4 - Output project file
  196. rem
  197. :element
  198. set "SPACES= "
  199. if "%2" == "lib\vauth" (
  200. set "TABS= "
  201. ) else if "%2" == "lib\vquic" (
  202. set "TABS= "
  203. ) else if "%2" == "lib\vssh" (
  204. set "TABS= "
  205. ) else if "%2" == "lib\vtls" (
  206. set "TABS= "
  207. ) else (
  208. set "TABS= "
  209. )
  210. call :extension %3 ext
  211. if "%1" == "dsp" (
  212. echo # Begin Source File>> %4
  213. echo.>> %4
  214. echo SOURCE=..\..\..\..\%2\%~3>> %4
  215. echo # End Source File>> %4
  216. ) else if "%1" == "vcproj1" (
  217. echo %TABS%^<File>> %4
  218. echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4
  219. echo %TABS%^</File^>>> %4
  220. ) else if "%1" == "vcproj2" (
  221. echo %TABS%^<File>> %4
  222. echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4
  223. echo %TABS%^>>> %4
  224. echo %TABS%^</File^>>> %4
  225. ) else if "%1" == "vcxproj" (
  226. if "%ext%" == "c" (
  227. echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  228. ) else if "%ext%" == "h" (
  229. echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  230. ) else if "%ext%" == "rc" (
  231. echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  232. )
  233. )
  234. exit /B
  235. rem Returns the extension for a given filename.
  236. rem
  237. rem %1 - The filename
  238. rem %2 - The return value
  239. rem
  240. :extension
  241. set fname=%~1
  242. set ename=
  243. :loop1
  244. if "%fname%"=="" (
  245. set %2=
  246. exit /B
  247. )
  248. if not "%fname:~-1%"=="." (
  249. set ename=%fname:~-1%%ename%
  250. set fname=%fname:~0,-1%
  251. goto loop1
  252. )
  253. set %2=%ename%
  254. exit /B
  255. rem Removes the given project file.
  256. rem
  257. rem %1 - The filename
  258. rem
  259. :clean
  260. echo * %CD%\%1
  261. if exist %1 (
  262. del %1
  263. )
  264. exit /B
  265. :syntax
  266. rem Display the help
  267. echo.
  268. echo Usage: generate [what] [-clean]
  269. echo.
  270. echo What to generate:
  271. echo.
  272. echo pre - Prerequisites only
  273. echo vc10 - Use Visual Studio 2010
  274. echo vc11 - Use Visual Studio 2012
  275. echo vc12 - Use Visual Studio 2013
  276. echo.
  277. echo Only legacy Visual Studio project files can be generated.
  278. echo.
  279. echo To generate recent versions of Visual Studio project files use cmake.
  280. echo Refer to INSTALL-CMAKE in the docs directory.
  281. echo.
  282. echo -clean - Removes the project files
  283. goto error
  284. :unknown
  285. echo.
  286. echo Error: Unknown argument '%1'
  287. goto error
  288. :nodos
  289. echo.
  290. echo Error: Only a Windows NT based Operating System is supported
  291. goto error
  292. :nonetdrv
  293. echo.
  294. echo Error: This batch file cannot run from a network drive
  295. goto error
  296. :norepo
  297. echo.
  298. echo Error: This batch file should only be used from a curl git repository
  299. goto error
  300. :seterr
  301. rem Set the caller's errorlevel.
  302. rem %1[opt]: Errorlevel as integer.
  303. rem If %1 is empty the errorlevel will be set to 0.
  304. rem If %1 is not empty and not an integer the errorlevel will be set to 1.
  305. setlocal
  306. set EXITCODE=%~1
  307. if not defined EXITCODE set EXITCODE=0
  308. echo %EXITCODE%|findstr /r "[^0-9\-]" 1>NUL 2>&1
  309. if %ERRORLEVEL% EQU 0 set EXITCODE=1
  310. exit /b %EXITCODE%
  311. :error
  312. if "%OS%" == "Windows_NT" endlocal
  313. exit /B 1
  314. :success
  315. endlocal
  316. exit /B 0