build-openssl.bat 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. @echo off
  2. rem ***************************************************************************
  3. rem * _ _ ____ _
  4. rem * Project ___| | | | _ \| |
  5. rem * / __| | | | |_) | |
  6. rem * | (__| |_| | _ <| |___
  7. rem * \___|\___/|_| \_\_____|
  8. rem *
  9. rem * Copyright (C) 2012 - 2016, 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
  28. set VC_VER=
  29. set BUILD_PLATFORM=
  30. rem Ensure we have the required arguments
  31. if /i "%~1" == "" goto syntax
  32. :parseArgs
  33. if "%~1" == "" goto prerequisites
  34. if /i "%~1" == "vc6" (
  35. set VC_VER=6.0
  36. set VC_DESC=VC6
  37. set "VC_PATH=Microsoft Visual Studio\VC98"
  38. ) else if /i "%~1" == "vc7" (
  39. set VC_VER=7.0
  40. set VC_DESC=VC7
  41. set "VC_PATH=Microsoft Visual Studio .NET\Vc7"
  42. ) else if /i "%~1" == "vc7.1" (
  43. set VC_VER=7.1
  44. set VC_DESC=VC7.1
  45. set "VC_PATH=Microsoft Visual Studio .NET 2003\Vc7"
  46. ) else if /i "%~1" == "vc8" (
  47. set VC_VER=8.0
  48. set VC_DESC=VC8
  49. set "VC_PATH=Microsoft Visual Studio 8\VC"
  50. ) else if /i "%~1" == "vc9" (
  51. set VC_VER=9.0
  52. set VC_DESC=VC9
  53. set "VC_PATH=Microsoft Visual Studio 9.0\VC"
  54. ) else if /i "%~1" == "vc10" (
  55. set VC_VER=10.0
  56. set VC_DESC=VC10
  57. set "VC_PATH=Microsoft Visual Studio 10.0\VC"
  58. ) else if /i "%~1" == "vc11" (
  59. set VC_VER=11.0
  60. set VC_DESC=VC11
  61. set "VC_PATH=Microsoft Visual Studio 11.0\VC"
  62. ) else if /i "%~1" == "vc12" (
  63. set VC_VER=12.0
  64. set VC_DESC=VC12
  65. set "VC_PATH=Microsoft Visual Studio 12.0\VC"
  66. ) else if /i "%~1" == "vc14" (
  67. set VC_VER=14.0
  68. set VC_DESC=VC14
  69. set "VC_PATH=Microsoft Visual Studio 14.0\VC"
  70. ) else if /i "%~1%" == "x86" (
  71. set BUILD_PLATFORM=x86
  72. ) else if /i "%~1%" == "x64" (
  73. set BUILD_PLATFORM=x64
  74. ) else if /i "%~1%" == "debug" (
  75. set BUILD_CONFIG=debug
  76. ) else if /i "%~1%" == "release" (
  77. set BUILD_CONFIG=release
  78. ) else if /i "%~1" == "-?" (
  79. goto syntax
  80. ) else if /i "%~1" == "-h" (
  81. goto syntax
  82. ) else if /i "%~1" == "-help" (
  83. goto syntax
  84. ) else (
  85. if not defined START_DIR (
  86. set START_DIR=%~1%
  87. ) else (
  88. goto unknown
  89. )
  90. )
  91. shift & goto parseArgs
  92. :prerequisites
  93. rem Compiler and platform are required parameters.
  94. if not defined VC_VER goto syntax
  95. if not defined BUILD_PLATFORM goto syntax
  96. rem Default the start directory if one isn't specified
  97. if not defined START_DIR set START_DIR=..\..\openssl
  98. rem Calculate the program files directory
  99. if defined PROGRAMFILES (
  100. set "PF=%PROGRAMFILES%"
  101. set OS_PLATFORM=x86
  102. )
  103. if defined PROGRAMFILES(x86) (
  104. set "PF=%PROGRAMFILES(x86)%"
  105. set OS_PLATFORM=x64
  106. )
  107. rem Check we have a program files directory
  108. if not defined PF goto nopf
  109. rem Check we have Visual Studio installed
  110. if not exist "%PF%\%VC_PATH%" goto novc
  111. rem Check we have Perl in our path
  112. echo %PATH% | findstr /I /C:"\Perl" 1>nul
  113. if errorlevel 1 (
  114. rem It isn't so check we have it installed and set the path if it is
  115. if exist "%SystemDrive%\Perl" (
  116. set "PATH=%SystemDrive%\Perl\bin;%PATH%"
  117. ) else (
  118. if exist "%SystemDrive%\Perl64" (
  119. set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
  120. ) else (
  121. goto noperl
  122. )
  123. )
  124. )
  125. rem Check the start directory exists
  126. if not exist "%START_DIR%" goto noopenssl
  127. :configure
  128. if "%BUILD_PLATFORM%" == "" (
  129. if "%VC_VER%" == "6.0" (
  130. set BUILD_PLATFORM=x86
  131. ) else if "%VC_VER%" == "7.0" (
  132. set BUILD_PLATFORM=x86
  133. ) else if "%VC_VER%" == "7.1" (
  134. set BUILD_PLATFORM=x86
  135. ) else (
  136. set BUILD_PLATFORM=%OS_PLATFORM%
  137. )
  138. )
  139. if "%BUILD_PLATFORM%" == "x86" (
  140. set VCVARS_PLATFORM=x86
  141. ) else if "%BUILD_PLATFORM%" == "x64" (
  142. if "%VC_VER%" == "6.0" goto nox64
  143. if "%VC_VER%" == "7.0" goto nox64
  144. if "%VC_VER%" == "7.1" goto nox64
  145. if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
  146. if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  147. if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  148. if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
  149. if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
  150. if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
  151. )
  152. :start
  153. echo.
  154. if "%VC_VER%" == "6.0" (
  155. call "%PF%\%VC_PATH%\bin\vcvars32"
  156. ) else if "%VC_VER%" == "7.0" (
  157. call "%PF%\%VC_PATH%\bin\vcvars32"
  158. ) else if "%VC_VER%" == "7.1" (
  159. call "%PF%\%VC_PATH%\bin\vcvars32"
  160. ) else (
  161. call "%PF%\%VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
  162. )
  163. echo.
  164. set SAVED_PATH=%CD%
  165. if defined START_DIR CD %START_DIR%
  166. goto %BUILD_PLATFORM%
  167. :x64
  168. rem Calculate our output directory
  169. set OUTDIR=build\Win64\%VC_DESC%
  170. if not exist %OUTDIR% md %OUTDIR%
  171. if "%BUILD_CONFIG%" == "release" goto x64release
  172. :x64debug
  173. rem Configuring 64-bit Debug Build
  174. perl Configure debug-VC-WIN64A --prefix=%CD%
  175. rem Perform the build
  176. call ms\do_win64a
  177. nmake -f ms\nt.mak
  178. nmake -f ms\ntdll.mak
  179. rem Move the output directories
  180. move out32.dbg "%OUTDIR%\LIB Debug"
  181. move out32dll.dbg "%OUTDIR%\DLL Debug"
  182. rem Move the PDB files
  183. move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
  184. move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
  185. rem Remove the intermediate directories
  186. rd tmp32.dbg /s /q
  187. rd tmp32dll.dbg /s /q
  188. if "%BUILD_CONFIG%" == "debug" goto success
  189. :x64release
  190. rem Configuring 64-bit Release Build
  191. perl Configure VC-WIN64A --prefix=%CD%
  192. rem Perform the build
  193. call ms\do_win64a
  194. nmake -f ms\nt.mak
  195. nmake -f ms\ntdll.mak
  196. rem Move the output directories
  197. move out32 "%OUTDIR%\LIB Release"
  198. move out32dll "%OUTDIR%\DLL Release"
  199. rem Move the PDB files
  200. move tmp32\lib.pdb "%OUTDIR%\LIB Release"
  201. move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
  202. rem Remove the intermediate directories
  203. rd tmp32 /s /q
  204. rd tmp32dll /s /q
  205. goto success
  206. :x86
  207. rem Calculate our output directory
  208. set OUTDIR=build\Win32\%VC_DESC%
  209. if not exist %OUTDIR% md %OUTDIR%
  210. if "%BUILD_CONFIG%" == "release" goto x86release
  211. :x86debug
  212. rem Configuring 32-bit Debug Build
  213. perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
  214. rem Perform the build
  215. call ms\do_ms
  216. nmake -f ms\nt.mak
  217. nmake -f ms\ntdll.mak
  218. rem Move the output directories
  219. move out32.dbg "%OUTDIR%\LIB Debug"
  220. move out32dll.dbg "%OUTDIR%\DLL Debug"
  221. rem Move the PDB files
  222. move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug"
  223. move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug"
  224. rem Remove the intermediate directories
  225. rd tmp32.dbg /s /q
  226. rd tmp32dll.dbg /s /q
  227. if "%BUILD_CONFIG%" == "debug" goto success
  228. :x86release
  229. rem Configuring 32-bit Release Build
  230. perl Configure VC-WIN32 no-asm --prefix=%CD%
  231. rem Perform the build
  232. call ms\do_ms
  233. nmake -f ms\nt.mak
  234. nmake -f ms\ntdll.mak
  235. rem Move the output directories
  236. move out32 "%OUTDIR%\LIB Release"
  237. move out32dll "%OUTDIR%\DLL Release"
  238. rem Move the PDB files
  239. move tmp32\lib.pdb "%OUTDIR%\LIB Release"
  240. move tmp32dll\lib.pdb "%OUTDIR%\DLL Release"
  241. rem Remove the intermediate directories
  242. rd tmp32 /s /q
  243. rd tmp32dll /s /q
  244. goto success
  245. :syntax
  246. rem Display the help
  247. echo.
  248. echo Usage: build-openssl ^<compiler^> ^<platform^> [configuration] [directory]
  249. echo.
  250. echo Compiler:
  251. echo.
  252. echo vc6 - Use Visual Studio 6
  253. echo vc7 - Use Visual Studio .NET
  254. echo vc7.1 - Use Visual Studio .NET 2003
  255. echo vc8 - Use Visual Studio 2005
  256. echo vc9 - Use Visual Studio 2008
  257. echo vc10 - Use Visual Studio 2010
  258. echo vc11 - Use Visual Studio 2012
  259. echo vc12 - Use Visual Studio 2013
  260. echo vc14 - Use Visual Studio 2015
  261. echo.
  262. echo Platform:
  263. echo.
  264. echo x86 - Perform a 32-bit build
  265. echo x64 - Perform a 64-bit build
  266. echo.
  267. echo Configuration:
  268. echo.
  269. echo debug - Perform a debug build
  270. echo release - Perform a release build
  271. echo.
  272. echo Other:
  273. echo.
  274. echo directory - Specifies the OpenSSL source directory
  275. goto error
  276. :unknown
  277. echo.
  278. echo Error: Unknown argument '%1'
  279. goto error
  280. :nodos
  281. echo.
  282. echo Error: Only a Windows NT based Operating System is supported
  283. goto error
  284. :nopf
  285. echo.
  286. echo Error: Cannot obtain the directory for Program Files
  287. goto error
  288. :novc
  289. echo.
  290. echo Error: %VC_DESC% is not installed
  291. goto error
  292. :noperl
  293. echo.
  294. echo Error: Perl is not installed
  295. goto error
  296. :nox64
  297. echo.
  298. echo Error: %VC_DESC% does not support 64-bit builds
  299. goto error
  300. :noopenssl
  301. echo.
  302. echo Error: Cannot locate OpenSSL source directory
  303. goto error
  304. :error
  305. if "%OS%" == "Windows_NT" endlocal
  306. exit /B 1
  307. :success
  308. cd %SAVED_PATH%
  309. endlocal
  310. exit /B 0