generate.bat 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. @echo off
  2. rem ***************************************************************************
  3. rem * _ _ ____ _
  4. rem * Project ___| | | | _ \| |
  5. rem * / __| | | | |_) | |
  6. rem * | (__| |_| | _ <| |___
  7. rem * \___|\___/|_| \_\_____|
  8. rem *
  9. rem * Copyright (C) 2014, 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 http://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. setlocal
  27. rem Display the help
  28. if /i "%~1" == "-?" goto syntax
  29. if /i "%~1" == "-h" goto syntax
  30. if /i "%~1" == "-help" goto syntax
  31. :parseArgs
  32. if "%~1" == "" goto all
  33. if /i "%~1" == "vc6" (
  34. goto vc6
  35. ) else if /i "%~1" == "vc7" (
  36. goto vc7
  37. ) else if /i "%~1" == "vc7.1" (
  38. goto vc71
  39. ) else if /i "%~1" == "vc8" (
  40. goto vc8
  41. ) else if /i "%~1" == "vc9" (
  42. goto vc9
  43. ) else if /i "%~1" == "vc10" (
  44. goto vc10
  45. ) else if /i "%~1" == "vc11" (
  46. goto vc11
  47. ) else if /i "%~1" == "vc12" (
  48. goto vc12
  49. ) else (
  50. goto unknown
  51. )
  52. :all
  53. set ALL=true
  54. :vc6
  55. echo.
  56. echo Generating VC6 project files
  57. call :generate dsp Windows\VC6\src\curlsrc.tmpl Windows\VC6\src\curlsrc.dsp
  58. call :generate dsp Windows\VC6\lib\libcurl.tmpl Windows\VC6\lib\libcurl.dsp
  59. if not "%ALL%" == "true" goto success
  60. :vc7
  61. echo.
  62. echo Generating VC7 project files
  63. call :generate vcproj1 Windows\VC7\src\curlsrc.tmpl Windows\VC7\src\curlsrc.vcproj
  64. call :generate vcproj1 Windows\VC7\lib\libcurl.tmpl Windows\VC7\lib\libcurl.vcproj
  65. if not "%ALL%" == "true" goto success
  66. :vc71
  67. echo.
  68. echo Generating VC7.1 project files
  69. call :generate vcproj1 Windows\VC7.1\src\curlsrc.tmpl Windows\VC7.1\src\curlsrc.vcproj
  70. call :generate vcproj1 Windows\VC7.1\lib\libcurl.tmpl Windows\VC7.1\lib\libcurl.vcproj
  71. if not "%ALL%" == "true" goto success
  72. :vc8
  73. echo.
  74. echo Generating VC8 project files
  75. call :generate vcproj2 Windows\VC8\src\curlsrc.tmpl Windows\VC8\src\curlsrc.vcproj
  76. call :generate vcproj2 Windows\VC8\lib\libcurl.tmpl Windows\VC8\lib\libcurl.vcproj
  77. if not "%ALL%" == "true" goto success
  78. :vc9
  79. echo.
  80. echo Generating VC9 project files
  81. call :generate vcproj2 Windows\VC9\src\curlsrc.tmpl Windows\VC9\src\curlsrc.vcproj
  82. call :generate vcproj2 Windows\VC9\lib\libcurl.tmpl Windows\VC9\lib\libcurl.vcproj
  83. if not "%ALL%" == "true" goto success
  84. :vc10
  85. echo.
  86. echo Generating VC10 project files
  87. call :generate vcxproj Windows\VC10\src\curlsrc.tmpl Windows\VC10\src\curlsrc.vcxproj
  88. call :generate vcxproj Windows\VC10\lib\libcurl.tmpl Windows\VC10\lib\libcurl.vcxproj
  89. if not "%ALL%" == "true" goto success
  90. :vc11
  91. echo.
  92. echo Generating VC11 project files
  93. call :generate vcxproj Windows\VC11\src\curlsrc.tmpl Windows\VC11\src\curlsrc.vcxproj
  94. call :generate vcxproj Windows\VC11\lib\libcurl.tmpl Windows\VC11\lib\libcurl.vcxproj
  95. if not "%ALL%" == "true" goto success
  96. :vc12
  97. echo.
  98. echo Generating VC12 project files
  99. call :generate vcxproj Windows\VC12\src\curlsrc.tmpl Windows\VC12\src\curlsrc.vcxproj
  100. call :generate vcxproj Windows\VC12\lib\libcurl.tmpl Windows\VC12\lib\libcurl.vcxproj
  101. goto success
  102. rem Main generate function.
  103. rem
  104. rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
  105. rem or vcxproj for VC10, VC11 and VC12)
  106. rem %2 - Input template file
  107. rem %3 - Output project file
  108. rem
  109. :generate
  110. if not exist %2 (
  111. echo.
  112. echo Error: Cannot open %CD%\%2
  113. exit /B
  114. )
  115. if exist %3 (
  116. del %3
  117. )
  118. echo * %CD%\%3
  119. for /f "usebackq delims=" %%i in (`"findstr /n ^^ %2"`) do (
  120. set "var=%%i"
  121. setlocal enabledelayedexpansion
  122. set "var=!var:*:=!"
  123. if "!var!" == "CURL_SRC_C_FILES" (
  124. for /f "delims=" %%c in ('dir /b ..\src\*.c') do call :element %1 src "%%c" %3
  125. ) else if "!var!" == "CURL_SRC_H_FILES" (
  126. for /f "delims=" %%h in ('dir /b ..\src\*.h') do call :element %1 src "%%h" %3
  127. ) else if "!var!" == "CURL_SRC_RC_FILES" (
  128. for /f "delims=" %%r in ('dir /b ..\src\*.rc') do call :element %1 src "%%r" %3
  129. ) else if "!var!" == "CURL_SRC_X_C_FILES" (
  130. call :element %1 lib "strtoofft.c" %3
  131. call :element %1 lib "strdup.c" %3
  132. call :element %1 lib "rawstr.c" %3
  133. call :element %1 lib "nonblock.c" %3
  134. call :element %1 lib "warnless.c" %3
  135. ) else if "!var!" == "CURL_SRC_X_H_FILES" (
  136. call :element %1 lib "config-win32.h" %3
  137. call :element %1 lib "curl_setup.h" %3
  138. call :element %1 lib "strtoofft.h" %3
  139. call :element %1 lib "strdup.h" %3
  140. call :element %1 lib "rawstr.h" %3
  141. call :element %1 lib "nonblock.h" %3
  142. call :element %1 lib "warnless.h" %3
  143. ) else if "!var!" == "CURL_LIB_C_FILES" (
  144. for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
  145. ) else if "!var!" == "CURL_LIB_H_FILES" (
  146. for /f "delims=" %%h in ('dir /b ..\lib\*.h') do call :element %1 lib "%%h" %3
  147. ) else if "!var!" == "CURL_LIB_RC_FILES" (
  148. for /f "delims=" %%r in ('dir /b ..\lib\*.rc') do call :element %1 lib "%%r" %3
  149. ) else if "!var!" == "CURL_LIB_VTLS_C_FILES" (
  150. for /f "delims=" %%c in ('dir /b ..\lib\vtls\*.c') do call :element %1 lib\vtls "%%c" %3
  151. ) else if "!var!" == "CURL_LIB_VTLS_H_FILES" (
  152. for /f "delims=" %%h in ('dir /b ..\lib\vtls\*.h') do call :element %1 lib\vtls "%%h" %3
  153. ) else (
  154. echo.!var!>> %3
  155. )
  156. endlocal
  157. )
  158. exit /B
  159. rem Generates a single file xml element.
  160. rem
  161. rem %1 - Project Type (dsp for VC6, vcproj1 for VC7 and VC7.1, vcproj2 for VC8 and VC9
  162. rem or vcxproj for VC10, VC11 and VC12)
  163. rem %2 - Directory (src, lib or lib\vtls)
  164. rem %3 - Source filename
  165. rem %4 - Output project file
  166. rem
  167. :element
  168. set "SPACES= "
  169. if "%2" == "lib\vtls" (
  170. set "TABS= "
  171. ) else (
  172. set "TABS= "
  173. )
  174. call :extension %3 ext
  175. if "%1" == "dsp" (
  176. echo # Begin Source File>> %4
  177. echo.>> %4
  178. echo SOURCE=..\..\..\..\%2\%~3>> %4
  179. echo # End Source File>> %4
  180. ) else if "%1" == "vcproj1" (
  181. echo %TABS%^<File>> %4
  182. echo %TABS% RelativePath="..\..\..\..\%2\%~3"^>>> %4
  183. echo %TABS%^</File^>>> %4
  184. ) else if "%1" == "vcproj2" (
  185. echo %TABS%^<File>> %4
  186. echo %TABS% RelativePath="..\..\..\..\%2\%~3">> %4
  187. echo %TABS%^>>> %4
  188. echo %TABS%^</File^>>> %4
  189. ) else if "%1" == "vcxproj" (
  190. if "%ext%" == "c" (
  191. echo %SPACES%^<ClCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  192. ) else if "%ext%" == "h" (
  193. echo %SPACES%^<ClInclude Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  194. ) else if "%ext%" == "rc" (
  195. echo %SPACES%^<ResourceCompile Include=^"..\..\..\..\%2\%~3^" /^>>> %4
  196. )
  197. )
  198. exit /B
  199. rem Returns the extension for a given filename.
  200. rem
  201. rem %1 - The filename
  202. rem %2 - The return value
  203. rem
  204. :extension
  205. set fname=%~1
  206. set ename=
  207. :loop1
  208. if "%fname%"=="" (
  209. set %2=
  210. exit /B
  211. )
  212. if not "%fname:~-1%"=="." (
  213. set ename=%fname:~-1%%ename%
  214. set fname=%fname:~0,-1%
  215. goto loop1
  216. )
  217. set %2=%ename%
  218. exit /B
  219. :syntax
  220. rem Display the help
  221. echo.
  222. echo Usage: generate [compiler]
  223. echo.
  224. echo Compiler:
  225. echo.
  226. echo vc6 - Use Visual Studio 6
  227. echo vc7 - Use Visual Studio .NET
  228. echo vc7.1 - Use Visual Studio .NET 2003
  229. echo vc8 - Use Visual Studio 2005
  230. echo vc9 - Use Visual Studio 2008
  231. echo vc10 - Use Visual Studio 2010
  232. echo vc11 - Use Visual Studio 2012
  233. echo vc12 - Use Visual Studio 2013
  234. goto error
  235. :unknown
  236. echo.
  237. echo Error: Unknown argument '%1'
  238. goto error
  239. :nodos
  240. echo.
  241. echo Error: Only a Windows NT based Operating System is supported
  242. goto error
  243. :error
  244. endlocal
  245. exit /B 1
  246. :success
  247. endlocal
  248. exit /B 0