forked from niyas-sait/libxml2-win-binaries
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.ps1
118 lines (94 loc) · 4.04 KB
/
build.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
<#
This script builds libiconv,libxml2 and libxslt
#>
Param(
[switch]$x64,
[switch]$arm64,
[switch]$vs2008
)
$ErrorActionPreference = "Stop"
Import-Module Pscx
Function Get-BatPath($year, $edition, $vcvarsarch) {
if ($year -eq 2019) {
return "C:\Program Files (x86)\Microsoft Visual Studio\2019\$edition\VC\Auxiliary\Build\vcvars$vcvarsarch.bat"
} elseif ($year -eq 2022) {
return "C:\Program Files\Microsoft Visual Studio\2022\$edition\VC\Auxiliary\Build\vcvars$vcvarsarch.bat"
}
}
$platDir = If($x64) { "\x64" } ElseIf ($arm64) { "\arm64" } Else { "" }
$distname = If($x64) { "win64" } ElseIf($arm64) { "win-arm64" } Else { "win32" }
If($vs2008) { $distname = "vs2008.$distname" }
If($vs2008) {
$vcvarsarch = If($x64) { "amd64" } Else { "x86" }
Import-VisualStudioVars -VisualStudioVersion "90" -Architecture $vcvarsarch
} Else {
$vcvarsarch = If($x64) { "x86_amd64" } ElseIf ($arm64) { "x86_arm64" } Else { "32" }
$community = Get-BatPath 2019 "Community" $vcvarsarch
$enterprise = Get-BatPath 2019 "Enterprise" $vcvarsarch
$bat = ""
if (Test-Path $community) {
$bat = $community
} elseif (Test-Path $enterprise) {
$bat = $enterprise
}
cmd.exe /c "call `"$bat`" && set > %temp%\vcvars$vcvarsarch.txt"
Get-Content "$env:temp\vcvars$vcvarsarch.txt" | Foreach-Object {
if ($_ -match "^(.*?)=(.*)$") {
Set-Content "env:\$($matches[1])" $matches[2]
}
}
}
Set-Location $PSScriptRoot
if($vs2008) {
Set-Location .\libiconv\MSVC9
$vcarch = If($x64) { "x64" } Else {"Win32"}
vcbuild libiconv_static\libiconv_static.vcproj "Release|$vcarch"
$iconvLib = Join-Path (pwd) libiconv_static$platDir\Release
} else {
Set-Location .\libiconv\MSVC16
msbuild libiconv_static\libiconv_static.vcxproj /p:Configuration=Release
$iconvLib = Join-Path (pwd) $platDir\lib
}
$iconvInc = Join-Path $PSScriptRoot libiconv\source\include
Set-Location $PSScriptRoot
Set-Location .\zlib
Start-Process -NoNewWindow -Wait nmake "-f win32/Makefile.msc zlib_a.lib"
$zlibLib = (pwd)
$zlibInc = (pwd)
Move-Item zlib_a.lib zlib.lib -force
Set-Location ..
Set-Location .\libxml2\win32
cscript configure.js lib="$zlibLib;$iconvLib" include="$zlibInc;$iconvInc" vcmanifest=yes zlib=yes
Start-Process -NoNewWindow -Wait nmake libxmla
$xmlLib = Join-Path (pwd) bin.msvc
$xmlInc = Join-Path (pwd) ..\include
Set-Location ..\..
Set-Location .\libxslt\win32
cscript configure.js lib="$zlibLib;$iconvLib;$xmlLib" include="$zlibInc;$iconvInc;$xmlInc" vcmanifest=yes zlib=yes
Start-Process -NoNewWindow -Wait nmake "libxslta libexslta"
Set-Location ..\..
if($vs2008) {
# Pushed by Import-VisualStudioVars
Pop-EnvironmentBlock
}
# Bundle releases
Function BundleRelease($name, $lib, $inc)
{
New-Item -ItemType Directory .\dist\$name
New-Item -ItemType Directory .\dist\$name\lib
Copy-Item -Recurse $lib .\dist\$name\lib
Get-ChildItem -File -Recurse .\dist\$name\lib | Where{$_.Name -NotMatch ".(lib|pdb)$" } | Remove-Item
New-Item -ItemType Directory .\dist\$name\include
Copy-Item -Recurse $inc .\dist\$name\include
Get-ChildItem -File -Recurse .\dist\$name\include | Where{$_.Name -NotMatch ".h$" } | Remove-Item
Write-Zip .\dist\$name .\dist\$name.zip
Remove-Item -Recurse -Path .\dist\$name
}
if (Test-Path .\dist) { Remove-Item .\dist -Recurse }
New-Item -ItemType Directory .\dist
# lxml expects iconv to be called iconv, not libiconv
Dir $iconvLib\libiconv* | Copy-Item -Force -Destination {Join-Path $iconvLib ($_.Name -replace "libiconv","iconv") }
BundleRelease "iconv-1.15.$distname" (dir $iconvLib\iconv_a*) (dir $iconvInc\*)
BundleRelease "libxml2-2.11.8.$distname" (dir $xmlLib\*) (Get-Item $xmlInc\libxml)
BundleRelease "libxslt-1.1.39.$distname" (dir .\libxslt\win32\bin.msvc\*) (Get-Item .\libxslt\libxslt,.\libxslt\libexslt)
BundleRelease "zlib-1.3.1.$distname" (Get-Item .\zlib\*.*) (Get-Item .\zlib\zconf.h,.\zlib\zlib.h)