param([ValidateSet('Debug','Release')][string]$Configuration='Release') $ErrorActionPreference='Stop' $root=$PSScriptRoot $source=Join-Path $root 'openssl-3.5.9' $prefix=Join-Path $root ('openssl/'+$Configuration) if((Test-Path (Join-Path $prefix 'lib/libssl.lib')) -and (Test-Path (Join-Path $prefix 'lib/libcrypto.lib')) -and (Test-Path (Join-Path $prefix 'include/openssl/configuration.h'))) { exit 0 } $perl=(Get-Command perl -ErrorAction SilentlyContinue).Source if(!$perl -and (Test-Path C:/Strawberry/perl/bin/perl.exe)) { $perl='C:/Strawberry/perl/bin/perl.exe' } if(!$perl) { throw 'Strawberry Perl is required to build OpenSSL' } $vs=& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath $build=Join-Path $root ('build/openssl-'+$Configuration) New-Item -ItemType Directory -Force $build | Out-Null $make='nmake /nologo' $mode=if($Configuration -eq 'Debug'){'--debug'}else{'--release'} $batch=Join-Path $build 'build.cmd' @" @echo off call "$vs\VC\Auxiliary\Build\vcvars64.bat" >nul if errorlevel 1 exit /b 1 set "PATH=$(Split-Path $perl);%PATH%" set "CL=/FS" set "LC_ALL=C" set "LANG=C" cd /d "$build" "$perl" "$source\Configure" VC-WIN64A $mode no-shared no-module no-asm no-tests no-apps no-docs no-legacy no-ml-kem no-ml-dsa no-slh-dsa -D_WIN32_WINNT=0x0601 --prefix="$prefix" --openssldir="$prefix\ssl" --libdir=lib if errorlevel 1 exit /b 1 $make if errorlevel 1 exit /b 1 $make install_sw exit /b %ERRORLEVEL% "@ | Set-Content -LiteralPath $batch -Encoding ASCII & cmd /c $batch if($LASTEXITCODE) { throw 'OpenSSL build failed' }