forked from Ylarod/ddk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvsetup.sh
More file actions
93 lines (90 loc) · 2.72 KB
/
Copy pathenvsetup.sh
File metadata and controls
93 lines (90 loc) · 2.72 KB
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
#!/usr/bin/env bash
function setup_clang()
{
local branch=$1
local version=$2
if [ -d /opt/ddk/clang/$version ]; then
echo "[!] $version already exists, skip"
return
fi
local url_prefix=https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads
local url=$url_prefix/$branch/$version.tar.gz
echo "[+] Download from $url"
wget $url
mkdir -p /opt/ddk/clang/$version
tar xzvf $version.tar.gz -C /opt/ddk/clang/$version
}
function setup_source()
{
local name=$1
local branch=$2
if [ -z "$branch" ]; then
branch="$name"
fi
if [ -d /opt/ddk/src/$name ]; then
echo "[!] $name already exists, skip"
return
fi
echo "[+] Clone $name (branch: $branch)"
git clone https://android.googlesource.com/kernel/common -b $branch --depth 1 /opt/ddk/src/$name
pushd /opt/ddk/src/$name
sed -i '/check_exports(mod);/s/^/\/\//' scripts/mod/modpost.c
popd
}
function build_kernel()
{
local clang_version=$1
local branch=$2
if [ -d /opt/ddk/kdir/$branch ]; then
echo "[!] $branch already exists, skip"
return
fi
local cache_path=$PATH
local out_path=$(realpath /opt/ddk/kdir/$branch)
local clang_path=$(realpath /opt/ddk/clang/$clang_version/bin)
echo "[+] Building $branch"
# setup env
set -x
export PATH=$clang_path:$cache_path
export CROSS_COMPILE=aarch64-linux-gnu-
export ARCH=arm64
export LLVM=1
export LLVM_IAS=1
pushd /opt/ddk/src/$branch
make O=$out_path gki_defconfig
if [ "${LTO}" = "none" ]; then
scripts/config --file $out_path/.config \
-d LTO_CLANG \
-e LTO_NONE \
-d LTO_CLANG_THIN \
-d LTO_CLANG_FULL \
-d THINLTO
elif [ "${LTO}" = "thin" ]; then
# This is best-effort; some kernels don't support LTO_THIN mode
# THINLTO was the old name for LTO_THIN, and it was 'default y'
scripts/config --file $out_path/.config \
-e LTO_CLANG \
-d LTO_NONE \
-e LTO_CLANG_THIN \
-d LTO_CLANG_FULL \
-e THINLTO
elif [ "${LTO}" = "full" ]; then
# THINLTO was the old name for LTO_THIN, and it was 'default y'
scripts/config --file $out_path/.config \
-e LTO_CLANG \
-d LTO_NONE \
-d LTO_CLANG_THIN \
-e LTO_CLANG_FULL \
-d THINLTO
fi
if [ "${branch}" = "android16-6.12" ]; then
scripts/config --file $out_path/.config -e CONFIG_CFI_ICALL_NORMALIZE_INTEGERS
fi
# Check and set BUILD_PROC environment variable
local build_proc=${BUILD_PROC:-$(nproc)}
make O=$out_path -j$build_proc
set +x
popd
# restore path
export PATH=$cache_path
}