build-openssl.bat 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. @echo off
  2. rem ***************************************************************************
  3. rem * _ _ ____ _
  4. rem * Project ___| | | | _ \| |
  5. rem * / __| | | | |_) | |
  6. rem * | (__| |_| | _ <| |___
  7. rem * \___|\___/|_| \_\_____|
  8. rem *
  9. rem * Copyright (C) 2012 - 2018, 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. rem Calculate the program files directory
  33. if defined PROGRAMFILES (
  34. set "PF=%PROGRAMFILES%"
  35. set OS_PLATFORM=x86
  36. )
  37. if defined PROGRAMFILES(x86) (
  38. set "PF=%PROGRAMFILES(x86)%"
  39. set OS_PLATFORM=x64
  40. )
  41. :parseArgs
  42. if "%~1" == "" goto prerequisites
  43. if /i "%~1" == "vc6" (
  44. set VC_VER=6.0
  45. set VC_DESC=VC6
  46. set "VC_PATH=Microsoft Visual Studio\VC98"
  47. ) else if /i "%~1" == "vc7" (
  48. set VC_VER=7.0
  49. set VC_DESC=VC7
  50. set "VC_PATH=Microsoft Visual Studio .NET\Vc7"
  51. ) else if /i "%~1" == "vc7.1" (
  52. set VC_VER=7.1
  53. set VC_DESC=VC7.1
  54. set "VC_PATH=Microsoft Visual Studio .NET 2003\Vc7"
  55. ) else if /i "%~1" == "vc8" (
  56. set VC_VER=8.0
  57. set VC_DESC=VC8
  58. set "VC_PATH=Microsoft Visual Studio 8\VC"
  59. ) else if /i "%~1" == "vc9" (
  60. set VC_VER=9.0
  61. set VC_DESC=VC9
  62. set "VC_PATH=Microsoft Visual Studio 9.0\VC"
  63. ) else if /i "%~1" == "vc10" (
  64. set VC_VER=10.0
  65. set VC_DESC=VC10
  66. set "VC_PATH=Microsoft Visual Studio 10.0\VC"
  67. ) else if /i "%~1" == "vc11" (
  68. set VC_VER=11.0
  69. set VC_DESC=VC11
  70. set "VC_PATH=Microsoft Visual Studio 11.0\VC"
  71. ) else if /i "%~1" == "vc12" (
  72. set VC_VER=12.0
  73. set VC_DESC=VC12
  74. set "VC_PATH=Microsoft Visual Studio 12.0\VC"
  75. ) else if /i "%~1" == "vc14" (
  76. set VC_VER=14.0
  77. set VC_DESC=VC14
  78. set "VC_PATH=Microsoft Visual Studio 14.0\VC"
  79. ) else if /i "%~1" == "vc14.1" (
  80. set VC_VER=14.1
  81. set VC_DESC=VC14.1
  82. rem Determine the VC14.1 path based on the installed edition in descending
  83. rem order (Enterprise, then Professional and finally Community)
  84. if exist "%PF%\Microsoft Visual Studio\2017\Enterprise\VC" (
  85. set "VC_PATH=Microsoft Visual Studio\2017\Enterprise\VC"
  86. ) else if exist "%PF%\Microsoft Visual Studio\2017\Professional\VC" (
  87. set "VC_PATH=Microsoft Visual Studio\2017\Professional\VC"
  88. ) else (
  89. set "VC_PATH=Microsoft Visual Studio\2017\Community\VC"
  90. )
  91. ) else if /i "%~1%" == "x86" (
  92. set BUILD_PLATFORM=x86
  93. ) else if /i "%~1%" == "x64" (
  94. set BUILD_PLATFORM=x64
  95. ) else if /i "%~1%" == "debug" (
  96. set BUILD_CONFIG=debug
  97. ) else if /i "%~1%" == "release" (
  98. set BUILD_CONFIG=release
  99. ) else if /i "%~1" == "-?" (
  100. goto syntax
  101. ) else if /i "%~1" == "-h" (
  102. goto syntax
  103. ) else if /i "%~1" == "-help" (
  104. goto syntax
  105. ) else if /i "%~1" == "-VSpath" (
  106. if "%~2" == "" (
  107. echo.
  108. echo Error. Please provide VS Path.
  109. goto error
  110. ) else (
  111. set "ABS_VC_PATH=%~2\VC"
  112. shift
  113. )
  114. ) else if /i "%~1" == "-perlpath" (
  115. if "%~2" == "" (
  116. echo.
  117. echo Error. Please provide Perl root Path.
  118. goto error
  119. ) else (
  120. set "PERL_PATH=%~2"
  121. shift
  122. )
  123. ) else (
  124. if not defined START_DIR (
  125. set START_DIR=%~1%
  126. ) else (
  127. goto unknown
  128. )
  129. )
  130. shift & goto parseArgs
  131. :prerequisites
  132. rem Compiler is a required parameter
  133. if not defined VC_VER goto syntax
  134. rem Default the start directory if one isn't specified
  135. if not defined START_DIR set START_DIR=..\..\openssl
  136. if not defined ABS_VC_PATH (
  137. rem Check we have a program files directory
  138. if not defined PF goto nopf
  139. set "ABS_VC_PATH=%PF%\%VC_PATH%"
  140. )
  141. rem Check we have Visual Studio installed
  142. if not exist "%ABS_VC_PATH%" goto novc
  143. if not defined PERL_PATH (
  144. rem Check we have Perl in our path
  145. perl --version <NUL 1>NUL 2>&1
  146. if errorlevel 1 (
  147. rem It isn't so check we have it installed and set the path if it is
  148. if exist "%SystemDrive%\Perl" (
  149. set "PATH=%SystemDrive%\Perl\bin;%PATH%"
  150. ) else (
  151. if exist "%SystemDrive%\Perl64" (
  152. set "PATH=%SystemDrive%\Perl64\bin;%PATH%"
  153. ) else (
  154. goto noperl
  155. )
  156. )
  157. )
  158. ) else (
  159. set "PATH=%PERL_PATH%\Perl\bin;%PATH%"
  160. )
  161. rem Check the start directory exists
  162. if not exist "%START_DIR%" goto noopenssl
  163. rem Check that OpenSSL is not unsupported version 1.1.0
  164. if not exist "%START_DIR%\ms\do_ms.bat" goto unsupported
  165. :configure
  166. if "%BUILD_PLATFORM%" == "" (
  167. if "%VC_VER%" == "6.0" (
  168. set BUILD_PLATFORM=x86
  169. ) else if "%VC_VER%" == "7.0" (
  170. set BUILD_PLATFORM=x86
  171. ) else if "%VC_VER%" == "7.1" (
  172. set BUILD_PLATFORM=x86
  173. ) else (
  174. set BUILD_PLATFORM=%OS_PLATFORM%
  175. )
  176. )
  177. if "%BUILD_PLATFORM%" == "x86" (
  178. set VCVARS_PLATFORM=x86
  179. ) else if "%BUILD_PLATFORM%" == "x64" (
  180. if "%VC_VER%" == "6.0" goto nox64
  181. if "%VC_VER%" == "7.0" goto nox64
  182. if "%VC_VER%" == "7.1" goto nox64
  183. if "%VC_VER%" == "8.0" set VCVARS_PLATFORM=x86_amd64
  184. if "%VC_VER%" == "9.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  185. if "%VC_VER%" == "10.0" set VCVARS_PLATFORM=%BUILD_PLATFORM%
  186. if "%VC_VER%" == "11.0" set VCVARS_PLATFORM=amd64
  187. if "%VC_VER%" == "12.0" set VCVARS_PLATFORM=amd64
  188. if "%VC_VER%" == "14.0" set VCVARS_PLATFORM=amd64
  189. if "%VC_VER%" == "14.1" set VCVARS_PLATFORM=amd64
  190. )
  191. :start
  192. echo.
  193. set SAVED_PATH=%CD%
  194. if "%VC_VER%" == "6.0" (
  195. call "%ABS_VC_PATH%\bin\vcvars32"
  196. ) else if "%VC_VER%" == "7.0" (
  197. call "%ABS_VC_PATH%\bin\vcvars32"
  198. ) else if "%VC_VER%" == "7.1" (
  199. call "%ABS_VC_PATH%\bin\vcvars32"
  200. ) else if "%VC_VER%" == "14.1" (
  201. call "%ABS_VC_PATH%\Auxiliary\Build\vcvarsall" %VCVARS_PLATFORM%
  202. ) else (
  203. call "%ABS_VC_PATH%\vcvarsall" %VCVARS_PLATFORM%
  204. )
  205. echo.
  206. cd /d %SAVED_PATH%
  207. if defined START_DIR cd /d %START_DIR%
  208. goto %BUILD_PLATFORM%
  209. :x64
  210. rem Calculate our output directory
  211. set OUTDIR=build\Win64\%VC_DESC%
  212. if not exist %OUTDIR% md %OUTDIR%
  213. if "%BUILD_CONFIG%" == "release" goto x64release
  214. :x64debug
  215. rem Configuring 64-bit Debug Build
  216. perl Configure debug-VC-WIN64A --prefix=%CD%
  217. rem Perform the build
  218. call ms\do_win64a
  219. nmake -f ms\nt.mak
  220. nmake -f ms\ntdll.mak
  221. rem Move the output directories
  222. if exist "%OUTDIR%\LIB Debug" (
  223. copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
  224. rd out32.dbg /s /q
  225. ) else (
  226. move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
  227. )
  228. if exist "%OUTDIR%\DLL Debug" (
  229. copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
  230. rd out32dll.dbg /s /q
  231. ) else (
  232. move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
  233. )
  234. rem Move the PDB files
  235. move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
  236. move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
  237. rem Remove the intermediate directories
  238. rd tmp32.dbg /s /q
  239. rd tmp32dll.dbg /s /q
  240. if "%BUILD_CONFIG%" == "debug" goto success
  241. :x64release
  242. rem Configuring 64-bit Release Build
  243. perl Configure VC-WIN64A --prefix=%CD%
  244. rem Perform the build
  245. call ms\do_win64a
  246. nmake -f ms\nt.mak
  247. nmake -f ms\ntdll.mak
  248. rem Move the output directories
  249. if exist "%OUTDIR%\LIB Release" (
  250. copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
  251. rd out32 /s /q
  252. ) else (
  253. move out32 "%OUTDIR%\LIB Release" 1>nul
  254. )
  255. if exist "%OUTDIR%\DLL Release" (
  256. copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
  257. rd out32dll /s /q
  258. ) else (
  259. move out32dll "%OUTDIR%\DLL Release" 1>nul
  260. )
  261. rem Move the PDB files
  262. move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
  263. move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
  264. rem Remove the intermediate directories
  265. rd tmp32 /s /q
  266. rd tmp32dll /s /q
  267. goto success
  268. :x86
  269. rem Calculate our output directory
  270. set OUTDIR=build\Win32\%VC_DESC%
  271. if not exist %OUTDIR% md %OUTDIR%
  272. if "%BUILD_CONFIG%" == "release" goto x86release
  273. :x86debug
  274. rem Configuring 32-bit Debug Build
  275. perl Configure debug-VC-WIN32 no-asm --prefix=%CD%
  276. rem Perform the build
  277. call ms\do_ms
  278. nmake -f ms\nt.mak
  279. nmake -f ms\ntdll.mak
  280. rem Move the output directories
  281. if exist "%OUTDIR%\LIB Debug" (
  282. copy /y out32.dbg\* "%OUTDIR%\LIB Debug" 1>nul
  283. rd out32.dbg /s /q
  284. ) else (
  285. move out32.dbg "%OUTDIR%\LIB Debug" 1>nul
  286. )
  287. if exist "%OUTDIR%\DLL Debug" (
  288. copy /y out32dll.dbg\* "%OUTDIR%\DLL Debug" 1>nul
  289. rd out32dll.dbg /s /q
  290. ) else (
  291. move out32dll.dbg "%OUTDIR%\DLL Debug" 1>nul
  292. )
  293. rem Move the PDB files
  294. move tmp32.dbg\lib.pdb "%OUTDIR%\LIB Debug" 1>nul
  295. move tmp32dll.dbg\lib.pdb "%OUTDIR%\DLL Debug" 1>nul
  296. rem Remove the intermediate directories
  297. rd tmp32.dbg /s /q
  298. rd tmp32dll.dbg /s /q
  299. if "%BUILD_CONFIG%" == "debug" goto success
  300. :x86release
  301. rem Configuring 32-bit Release Build
  302. perl Configure VC-WIN32 no-asm --prefix=%CD%
  303. rem Perform the build
  304. call ms\do_ms
  305. nmake -f ms\nt.mak
  306. nmake -f ms\ntdll.mak
  307. rem Move the output directories
  308. if exist "%OUTDIR%\LIB Release" (
  309. copy /y out32\* "%OUTDIR%\LIB Release" 1>nul
  310. rd out32 /s /q
  311. ) else (
  312. move out32 "%OUTDIR%\LIB Release" 1>nul
  313. )
  314. if exist "%OUTDIR%\DLL Release" (
  315. copy /y out32dll\* "%OUTDIR%\DLL Release" 1>nul
  316. rd out32dll /s /q
  317. ) else (
  318. move out32dll "%OUTDIR%\DLL Release" 1>nul
  319. )
  320. rem Move the PDB files
  321. move tmp32\lib.pdb "%OUTDIR%\LIB Release" 1>nul
  322. move tmp32dll\lib.pdb "%OUTDIR%\DLL Release" 1>nul
  323. rem Remove the intermediate directories
  324. rd tmp32 /s /q
  325. rd tmp32dll /s /q
  326. goto success
  327. :syntax
  328. rem Display the help
  329. echo.
  330. echo Usage: build-openssl ^<compiler^> [platform] [configuration] [directory] [-VSpath] ["VSpath"] [-perlpath] ["perlpath"]
  331. echo.
  332. echo Compiler:
  333. echo.
  334. echo vc6 - Use Visual Studio 6
  335. echo vc7 - Use Visual Studio .NET
  336. echo vc7.1 - Use Visual Studio .NET 2003
  337. echo vc8 - Use Visual Studio 2005
  338. echo vc9 - Use Visual Studio 2008
  339. echo vc10 - Use Visual Studio 2010
  340. echo vc11 - Use Visual Studio 2012
  341. echo vc12 - Use Visual Studio 2013
  342. echo vc14 - Use Visual Studio 2015
  343. echo vc14.1 - Use Visual Studio 2017
  344. echo.
  345. echo Platform:
  346. echo.
  347. echo x86 - Perform a 32-bit build
  348. echo x64 - Perform a 64-bit build
  349. echo.
  350. echo Configuration:
  351. echo.
  352. echo debug - Perform a debug build
  353. echo release - Perform a release build
  354. echo.
  355. echo Other:
  356. echo.
  357. echo directory - Specifies the OpenSSL source directory
  358. echo.
  359. echo -VSpath - Specify the custom VS path if Visual Studio is installed at other location
  360. echo then "C:/<ProgramFiles>/Microsoft Visual Studio[version]
  361. echo For e.g. -VSpath "C:\apps\MVS14"
  362. echo.
  363. echo -perlpath - Specify the custom perl root path if perl is not located at "C:\Perl" and it is a
  364. echo portable copy of perl and not installed on the win system
  365. echo For e.g. -perlpath "D:\strawberry-perl-5.24.3.1-64bit-portable"
  366. goto error
  367. :unknown
  368. echo.
  369. echo Error: Unknown argument '%1'
  370. goto error
  371. :nodos
  372. echo.
  373. echo Error: Only a Windows NT based Operating System is supported
  374. goto error
  375. :nopf
  376. echo.
  377. echo Error: Cannot obtain the directory for Program Files
  378. goto error
  379. :novc
  380. echo.
  381. echo Error: %VC_DESC% is not installed
  382. echo Error: Please check whether Visual compiler is installed at the path "%ABS_VC_PATH%"
  383. echo Error: Please provide proper VS Path by using -VSpath
  384. goto error
  385. :noperl
  386. echo.
  387. echo Error: Perl is not installed
  388. echo Error: Please check whether Perl is installed or it is at location "C:\Perl"
  389. echo Error: If Perl is portable please provide perl root path by using -perlpath
  390. goto error
  391. :nox64
  392. echo.
  393. echo Error: %VC_DESC% does not support 64-bit builds
  394. goto error
  395. :noopenssl
  396. echo.
  397. echo Error: Cannot locate OpenSSL source directory
  398. goto error
  399. :unsupported
  400. echo.
  401. echo Error: Unsupported OpenSSL version.
  402. echo The pre-generated project files and this build script only support the
  403. echo LTS version of OpenSSL ^(v1.0.2^). The next version of this build script
  404. echo will support OpenSSL v1.1.0.
  405. goto error
  406. :error
  407. if "%OS%" == "Windows_NT" endlocal
  408. exit /B 1
  409. :success
  410. cd /d %SAVED_PATH%
  411. endlocal
  412. exit /B 0