-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.ps1
74 lines (61 loc) · 1.99 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
$ErrorActionPreference = 'Stop'
function log {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true, Position = 0)]
[string]$LogMessage
)
Write-Output ("[{0}] {1}" -f (Get-Date), $LogMessage)
}
if ( (Test-Path build) -ne "True" ) {
mkdir build
}
log "Building..."
$id = Get-Content magiskModule/module.prop | Where-Object { $_ -match "id=" }
$id = $id.split('=')[1]
$version = Get-Content magiskModule/module.prop | Where-Object { $_ -match "version=" }
$version = $version.split('=')[1]
$versionCode = Get-Content magiskModule/module.prop | Where-Object { $_ -match "versionCode=" }
$versionCode = $versionCode.split('=')[1]
$zipFile = "${id}_${version}.zip"
# 下载最新工具链
# https://developer.android.com/ndk/downloads
# https://github.com/android/ndk/wiki
# 将 NDK 与其他构建系统配合使用
# https://developer.android.com/ndk/guides/other_build_systems
# https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md
$NDK_PATH = "E:\NDK\android-ndk-r27"
$clang = "${NDK_PATH}/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe"
# Android 10+ Q+ SDK29+ (如果最低支持SDK是28或以下,则需要进行align_fix)
& $clang --target=aarch64-linux-android29 -std=c++20 -static -s -O2 -Wall -Iinclude src/*.cc -o build/$id
if ( -not $? ) {
log "Compile fail"
exit
}
log "Compile success"
# (如果最低支持SDK是28或以下,则需要进行align_fix)
# $res=./align_fix.exe build/$id
# if ( -not $? ) {
# log "align_fix失败"
# exit
# }
# log $res
# log "align_fix完成"
log "Packing zip..."
Copy-Item build/$id magiskModule/$id -force
& ./7za.exe a $zipFile ./magiskModule/* | Out-Null
if ( -not $? ) {
log "Pack fail"
exit
}
log "Packed: $zipFile"
# 从压缩包中删除 webroot/ksu.js 文件
& ./7za.exe d $zipFile webroot/ksu.js | Out-Null
if ( -not $? ) {
log "Remove origin js from zip fail"
exit
}
log "Removed webroot/ksu.js from $zipFile"
Remove-Item magiskModule/$id -Force
log "Done"