-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
make.ps1
171 lines (157 loc) · 4.79 KB
/
make.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
param (
[Parameter(Mandatory=$True)] [string[]]$target,
[Parameter(Mandatory=$False)] [string]$prefix = "$pwd/build/windows",
[Parameter(Mandatory=$False)] [string]$EXTRA_FLAGS,
[Parameter(Mandatory=$False)] [string]$BUILD_ID,
[Parameter(Mandatory=$False)] [switch]$auto_setup
)
function make_absolute( [string]$path ) {
if ( -Not( [System.IO.Path]::IsPathRooted( $path ) ) ) {
$path = [IO.Path]::GetFullPath( [IO.Path]::Combine( ( ($pwd).Path ), ( $path ) ) )
}
return $path.Replace( "\", "/" )
}
function purge {
Write-Host -NoNewline "Purging... "
Remove-Item "build" -Recurse -ErrorAction Ignore
Write-Host "done."
}
function build( [string]$config, [string]$extraFlags ) {
New-Item -ItemType Directory -Force -Path "build/$config" > $null
Push-Location "build/$config"
cscript ../../configure.js PROJECT_ROOT=../../ BUILD_TYPE=$config $extraFlags
cmake --build . --config $config
Pop-Location
}
function install( [string]$config ) {
Push-Location "build/$config"
cmake --build . --target install --config $config
Pop-Location
}
function debug( [string]$extraFlags = $EXTRA_FLAGS ) {
build "debug" $extraFlags
}
function release( [string]$extraFlags = $EXTRA_FLAGS ) {
build "release" $extraFlags
}
function install-debug {
debug
install "debug"
}
function install-release {
release
install "release"
}
function package {
debug "BUILD_PACKAGE=1"
release "BUILD_PACKAGE=1"
Remove-Item "build/msi" -Recurse -ErrorAction Ignore
$packagePath = make_absolute( "build/msi" )
Push-Location "build/release"
cpack -B $packagePath
Pop-Location
}
function bundle {
package
$version = ""
Select-String `
-ErrorAction Ignore `
-Path "Makefile.mk.in" `
-Pattern "VERSION\s*=\s*(\d+)" `
| ForEach-Object {
if ( $version -ne "" ) {
$version += "."
}
$version += "$($_.Matches.groups[1])"
}
$bundlePath = "build/msi/yaal-bundle/windows/$version"
Remove-Item "build/msi/yaal-bundle" -Recurse -ErrorAction Ignore
New-Item -ItemType Directory -Force -Path "$bundlePath" > $null
$sys = "win32"
$tag = $version
if ( $BUILD_ID -ne "" ) {
$tag += "-$BUILD_ID"
}
Move-Item `
-Path build/msi/yaal-$version-$sys.msi `
-Destination "$bundlePath/yaal-$tag-$sys.msi" `
-Force
Compress-Archive -Path build/msi/yaal-bundle -DestinationPath build/msi/yaal-$version-windows.zip -Force
Compress-Archive -Path build/msi/yaal-$version-windows.zip -DestinationPath build/msi/yaal-bundle.zip -Force
}
function auto_setup( $parameters ) {
if ( $parameters.ContainsKey( "EXTRA_FLAGS" ) ) {
throw "You cannot specify EXTRA_FLAGS in auto_setup mode!"
}
if ( -Not( Test-Path( "$prefix/bin/pcre.dll" ) ) ) {
$out = "build/cache/windows-dev.zip"
if ( -Not( Test-Path( $out ) ) ) {
New-Item -ItemType Directory -Force -Path "build/cache" > $null
$EXTRA_FLAGS="EXTRA_FLAGS=YAAL_AUTO_SANITY"
$uri = "https://codestation.org/download/windows-dev.zip"
Invoke-WebRequest -Uri $uri -OutFile $out
}
Expand-Archive -LiteralPath $out -DestinationPath "build/cache" -Force
$extract = "build/cache/windows/"
New-Item -ItemType Directory -Force -Path "$prefix" > $null
Copy-Item -Path "$extract/*" -Destination "$prefix/" -Recurse -Force
Remove-Item -Path $extract -Recurse -Force
}
}
foreach ( $t in $target ) {
if (
( $t -ne "debug" ) -and
( $t -ne "release" ) -and
( $t -ne "install-debug" ) -and
( $t -ne "install-release" ) -and
( $t -ne "purge" ) -and
( $t -ne "package" ) -and
( $t -ne "bundle" )
) {
Write-Error "Unknown target: ``$t``"
exit 1
}
}
try {
$global:ProgressPreference = "SilentlyContinue"
$origEnvPath=$env:Path
$stackSize = ( Get-Location -Stack ).Count
Push-Location $PSScriptRoot
if ( Test-Path( "local.js" ) ) {
Select-String -ErrorAction Ignore -Path "local.js" -Pattern "PREFIX\s*=\s*[`"]([^`"]+)[`"]" | ForEach-Object {
$prefix = make_absolute( "$($_.Matches.groups[1])" )
}
} elseif ( $auto_setup ) {
$prefix = make_absolute( $prefix )
$local_js = (
"PREFIX = `"$prefix`";`n" +
"SYSCONFDIR = `"$prefix/etc`";`n" +
"DATADIR = `"$prefix/share`";`n" +
"LOCALSTATEDIR = `"$prefix/var`";`n" +
"EXTRA_INCLUDE_PATH = `"$prefix/include`";`n" +
"EXTRA_LIBRARY_PATH = `"$prefix/lib`";`n" +
"VERBOSE = 1;`n" +
"FAST = 1;`n"
)
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllText( "$pwd/local.js", $local_js, $Utf8NoBomEncoding )
}
if ( $auto_setup ) {
auto_setup $PSBoundParameters
}
$env:Path = ( $env:Path.Split( ';') | Where-Object { -Not( $_.ToLower().Contains( "cygwin" ) ) } ) -join ';'
$env:Path = "$prefix\bin;$env:Path"
$env:OPENSSL_CONF = "$prefix/bin/openssl.cfg"
foreach ( $t in $target ) {
&$t
}
} catch {
Write-Error "$_"
$LASTEXITCODE = 1
} finally {
while ( ( Get-Location -Stack ).Count -gt $stackSize ) {
Pop-Location
}
$env:Path=$origEnvPath
exit $LASTEXITCODE
}