-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-lz4.ps1
115 lines (105 loc) · 4.05 KB
/
build-lz4.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
[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 = "lz4"
function GetSources
{
[CmdletBinding()]
Param()
$lz4SourcesDir = "$SourcesDir/lz4"
Write-TaskTip $TipGroup "Find sources..."
Invoke-CloneGit "https://github.com/lz4/lz4.git" "v$Lz4Version" $Lz4SourcesDir -TipGroup $TipGroup -TipName "lz4" | Out-Host
return $lz4SourcesDir
}
function Build
{
[CmdletBinding()]
Param(
[string]$Lz4SourcesDir,
[ValidateSet("amd64", "x86", "arm64", "arm")]
[string]$Arch,
[switch]$BuildDebug)
$cmakePath = Invoke-DownloadDeps "CMake" $TipGroup
$cmakeArch = ""
switch($Arch) {
"amd64" {
$cmakeArch = "x64"
}
"x86" {
$cmakeArch = "Win32"
}
"arm64" {
$cmakeArch = "ARM64"
}
"arm" {
$cmakeArch = "arm"
}
}
$archLower = $Arch.ToLower()
$cmakeConfig = "RelWithDebInfo"
if ($BuildDebug) {
$cmakeConfig = "Debug"
}
$lz4BuildDir = Join-Path $Lz4SourcesDir "cmake-build/$archLower"
$lz4CmakeDir = Join-Path $Lz4SourcesDir "build/cmake"
New-Dictoray $lz4BuildDir | Out-Host
Write-TaskTip $TipGroup "Configuring..."
Start-CliProcess "$cmakePath/bin/cmake.exe" -WorkingDirectory $lz4BuildDir `
-ArgumentList "-DCMAKE_GENERATOR_PLATFORM=""$cmakeArch""", `
"-DLZ4_BUILD_CLI=OFF", "-DLZ4_BUILD_LEGACY_LZ4C=OFF", `
"-DBUILD_SHARED_LIBS=OFF", "-DBUILD_STATIC_LIBS=ON", "-S", $lz4CmakeDir -TipGroup $TipGroup | Out-Host
Write-TaskTip $TipGroup "Building..."
Start-CliProcess "$cmakePath/bin/cmake.exe" -WorkingDirectory $lz4BuildDir `
-ArgumentList "--build", ".", "--config", $cmakeConfig, "--target", "lz4_static" -TipGroup $TipGroup | Out-Host
return (Join-Path $lz4BuildDir $cmakeConfig)
}
function CopyToBuildDir
{
[CmdletBinding()]
Param(
[string]$Lz4SourcesDir,
[string]$Lz4BuildDir,
[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..."
$buildIncludeDir = "$BuildDir/include"
New-Dictoray $buildIncludeDir
Copy-Item -Path "$Lz4SourcesDir/lib/lz4.h" -Recurse -Destination $buildIncludeDir -Force
Copy-Item -Path "$Lz4SourcesDir/lib/lz4file.h" -Recurse -Destination $buildIncludeDir -Force
Copy-Item -Path "$Lz4SourcesDir/lib/lz4hc.h" -Recurse -Destination $buildIncludeDir -Force
Write-TaskTip $TipGroup "Copying lib files..."
$buildLibDir = "$buildArchDir/lib"
New-Dictoray $buildLibDir
Copy-Item -Path "$Lz4BuildDir/*" -Recurse -Destination $buildLibDir -Force
}
Write-StepTip $TipGroup "Geting v$Lz4Version sources..."
$lz4SourcesDir = GetSources
foreach ($arch in $Archs)
{
Write-StepTip $TipGroup "Building v$Lz4Version $arch-debug..."
$buildDebugArchDir = Build $lz4SourcesDir $arch -BuildDebug
Write-StepTip $TipGroup "Building v$Lz4Version $arch-release..."
$buildReleaseArchDir = Build $lz4SourcesDir $arch
Write-StepTip $TipGroup "Copying v$Lz4Version $arch-debug files..."
CopyToBuildDir $lz4SourcesDir $buildDebugArchDir $arch -BuildDebug
Write-StepTip $TipGroup "Copying v$Lz4Version $arch-release files..."
CopyToBuildDir $lz4SourcesDir $buildReleaseArchDir $arch
}