-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-openssl.ps1
122 lines (112 loc) · 4.12 KB
/
build-openssl.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
[CmdletBinding()]
Param(
[ValidateSet("amd64", "x86", "arm64", "arm")]
[string[]]$Archs = $Env:PROCESSOR_ARCHITECTURE
)
if ($MyInvocation.InvocationName -eq "&") {
$env:BuildScriptPath = (Get-Item $MyInvocation.PSScriptRoot).FullName
} else {
$env:BuildScriptPath = (Get-Item (Split-Path $MyInvocation.InvocationName)).FullName
}
$env:BuildScriptModulesPath = Join-Path $env:BuildScriptPath "modules"
Import-Module "$env:BuildScriptModulesPath/environment" -DisableNameChecking -Verbose:$false
Import-Module "$env:BuildScriptModulesPath/common" -DisableNameChecking -Verbose:$false
Import-Module "$env:BuildScriptModulesPath/dependent" -DisableNameChecking -Verbose:$false
$TipGroup = "openssl"
function GetSources
{
[CmdletBinding()]
Param()
$opensslSourcesDir = "$SourcesDir/openssl"
Write-TaskTip $TipGroup "Find sources..."
Invoke-CloneGit "https://github.com/openssl/openssl.git" "openssl-$OpensslVersion" $opensslSourcesDir -TipGroup $TipGroup -TipName "openssl" | Out-Host
return $opensslSourcesDir
}
function Build
{
[CmdletBinding()]
Param(
[string]$OpensslSourcesDir,
[ValidateSet("amd64", "x86", "arm64", "arm")]
[string]$Arch,
[switch]$BuildDebug)
$perlPath = Invoke-DownloadDeps "Perl" $TipGroup
$nasmPath = Invoke-DownloadDeps "Nasm" $TipGroup
$vsDevShellPath = Get-VsDevShellPath
$opensslArch = ""
switch($Arch) {
"amd64" {
$opensslArch = "VC-WIN64A"
}
"x86" {
$opensslArch = "VC-WIN32"
}
"arm64" {
$opensslArch = "VC-WIN64-ARM"
}
"arm" {
$opensslArch = "VC-WIN32-ARM"
}
}
$hostArch = "x86"
if (Get-IsAmd64) {
$hostArch = "amd64"
}
$archLower = $Arch.ToLower()
$opensslInstallDir = Join-Path $InstallDir "openssl-$OpensslVersion-$archLower"
if ($BuildDebug) {
$opensslArch = "debug-$opensslArch"
$opensslInstallDir = "$opensslInstallDir-debug"
} else {
$opensslInstallDir = "$opensslInstallDir-release"
}
New-Dictoray $opensslInstallDir -CleanUp | Out-Host
Write-TaskTip $TipGroup "Configuring & Cleaning & Building..."
Invoke-ExecuteCommand "
`$Env:PATH = ""$perlPath/perl/bin;$nasmPath;`$Env:PATH""
&""$vsDevShellPath"" -Arch $Arch -HostArch $hostArch
Set-Location ""$OpensslSourcesDir""
&""$perlPath/perl/bin/perl"" Configure $opensslArch ``
--strict-warnings --prefix=""$opensslInstallDir"" ``
--openssldir=""$opensslInstallDir""
nmake clean /NOLOGO 2> `$null
nmake install_dev /NOLOGO
" -TipGroup $TipGroup | Out-Host
return $opensslInstallDir
}
function CopyToBuildDir
{
[CmdletBinding()]
Param(
[string]$OpensslInstallDir,
[ValidateSet("amd64", "x86", "arm64", "arm")]
[string]$Arch,
[switch]$BuildDebug
)
$dirSuffix = "release"
if ($BuildDebug) {
$dirSuffix = "debug"
}
$buildArchDir = $BuildArchDirs[$Arch] + "-$dirSuffix"
Write-TaskTip $TipGroup "Copying include files..."
New-Dictoray $BuildDir
Copy-Item -Path "$OpensslInstallDir/include" -Recurse -Destination $BuildDir -Force
Write-TaskTip $TipGroup "Copying bin files..."
New-Dictoray $buildArchDir
Copy-Item -Path "$OpensslInstallDir/bin" -Recurse -Destination $buildArchDir -Force
Write-TaskTip $TipGroup "Copying lib files..."
Copy-Item -Path "$OpensslInstallDir/lib" -Recurse -Destination $buildArchDir -Force
}
Write-StepTip $TipGroup "Geting v$OpensslVersion sources..."
$opensslSourcesDir = GetSources
foreach ($arch in $Archs)
{
Write-StepTip $TipGroup "Building v$OpensslVersion $arch-debug..."
$buildDebugArchDir = Build $opensslSourcesDir $arch -BuildDebug
Write-StepTip $TipGroup "Building v$OpensslVersion $arch-release..."
$buildReleaseArchDir = Build $opensslSourcesDir $arch
Write-StepTip $TipGroup "Copying v$OpensslVersion $arch-debug files..."
CopyToBuildDir $buildDebugArchDir $arch -BuildDebug
Write-StepTip $TipGroup "Copying v$OpensslVersion $arch-release files..."
CopyToBuildDir $buildReleaseArchDir $arch
}