102 lines
2.4 KiB
PowerShell
102 lines
2.4 KiB
PowerShell
param(
|
||
[ValidateNotNullOrEmpty()]
|
||
[ValidatePattern('^[0-9A-Za-z._+-]+$')]
|
||
[string]$Version = 'dev'
|
||
)
|
||
|
||
Set-StrictMode -Version Latest
|
||
$ErrorActionPreference = 'Stop'
|
||
|
||
New-Item -ItemType Directory -Force -Path 'build' | Out-Null
|
||
Set-Content -LiteralPath 'build\version.h' -Encoding utf8NoBOM -Value "#define APP_VERSION `"$Version`""
|
||
|
||
& windres -I . resources.rc -O coff -o build\resources.o
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "windres 失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
$common = @(
|
||
'-std=c17'
|
||
'-Os'
|
||
'-Wall'
|
||
'-Wextra'
|
||
'-Wconversion'
|
||
'-Wshadow'
|
||
'-Werror'
|
||
'-DUNICODE'
|
||
'-D_UNICODE'
|
||
'-I', 'src'
|
||
'-I', 'build'
|
||
'-isystem', 'third_party\jsmn'
|
||
'-isystem', 'third_party\miniz'
|
||
)
|
||
& gcc @common -c src\main.c -o build\main.o
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "main.c 编译失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
& gcc @common -c src\qrc.c -o build\qrc.o
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "qrc.c 编译失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
$thirdParty = @(
|
||
'-std=c17'
|
||
'-Os'
|
||
'-Wall'
|
||
'-Wextra'
|
||
'-Wno-sign-conversion'
|
||
'-Wno-type-limits'
|
||
'-Wno-unused-function'
|
||
'-DMINIZ_NO_ARCHIVE_APIS'
|
||
'-DMINIZ_NO_STDIO'
|
||
'-DMINIZ_NO_TIME'
|
||
'-DMINIZ_NO_DEFLATE_APIS'
|
||
'-I', 'third_party\miniz'
|
||
)
|
||
|
||
& gcc @thirdParty -I third_party\jsmn -c src\jsmn.c -o build\jsmn.o
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "jsmn 编译失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
& gcc @thirdParty -c third_party\miniz\miniz.c -o build\miniz.o
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "miniz.c 编译失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
& gcc @thirdParty -c third_party\miniz\miniz_tinfl.c -o build\miniz_tinfl.o
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "miniz_tinfl.c 编译失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
$link = @(
|
||
'build\main.o'
|
||
'build\qrc.o'
|
||
'build\jsmn.o'
|
||
'build\miniz.o'
|
||
'build\miniz_tinfl.o'
|
||
'build\resources.o'
|
||
'-lwinhttp'
|
||
'-lws2_32'
|
||
'-lcrypt32'
|
||
'-lbcrypt'
|
||
'-lshell32'
|
||
'-static-libgcc'
|
||
'-s'
|
||
'-o', 'build\lrc-local-win-x64.exe'
|
||
)
|
||
|
||
& gcc @link
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "链接失败,退出码:$LASTEXITCODE"
|
||
}
|
||
|
||
$artifact = Get-Item -LiteralPath 'build\lrc-local-win-x64.exe'
|
||
$hash = Get-FileHash -Algorithm SHA256 -LiteralPath $artifact.FullName
|
||
|
||
Write-Host "构建完成:$($artifact.FullName)"
|
||
Write-Host "版本:$Version"
|
||
Write-Host "大小:$($artifact.Length) 字节"
|
||
Write-Host "SHA-256:$($hash.Hash)"
|