-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sh
executable file
·173 lines (153 loc) · 3.9 KB
/
build.sh
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
171
172
173
#!/bin/bash
# Stock kernel for LG Electronics msm8996 devices build script by jcadduono
################### BEFORE STARTING ################
#
# download a working toolchain and extract it somewhere and configure this
# file to point to the toolchain's root directory.
#
# once you've set up the config section how you like it, you can simply run
# ./build.sh [VARIANT]
#
##################### VARIANTS #####################
#
# h820 = AT&T (US)
# LGH820 (LG G5)
#
# h830 = T-Mobile (US)
# LGH830 (LG G5)
#
# ls992 = Sprint (US)
# LGLS992 (LG G5)
#
# us992 = US Cellular (US)
# LGUS992 (LG G5)
#
# vs987 = Verizon (US)
# LGVS987 (LG G5)
#
# rs987 = LTE Rural America (US)
# LGRS987 (LG G5)
#
# rs988 = Unlocked (US)
# LGRS988 (LG G5)
#
# h831 = Canada
# LGH831 (LG G5)
#
# h850 = International (Global)
# LGH850 (LG G5)
#
# h860n = Dual Sim (China / Hong Kong)
# LGH860N (LG G5)
#
# f700k = KT Corporation (Korea)
# LGF700K (LG G5)
#
# f700l = LG Uplus (Korea)
# LGF700L (LG G5)
#
# f700s = SK Telecom (Korea)
# LGF700S (LG G5)
#
# ************************
#
# h910 = AT&T (US)
# LGH910 (LG V20)
#
# h918 = T-Mobile (US)
# LGH918 (LG V20)
#
# ls997 = Sprint (US)
# LGLS997 (LG V20)
#
# us996 = US Cellular & Unlocked (US)
# LGUS996 (LG V20)
#
# vs995 = Verizon (US)
# LGVS995 (LG V20)
#
# h915 = Canada
# LGH915 (LG V20)
#
# h990 = International (Global)
# LGH990 (LG V20)
#
# h990tr = Dual Sim (China / Hong Kong)
# LGH990TR (LG V20)
#
# f800k = KT Corporation (Korea)
# LGF800K (LG V20)
#
# f800l = LG Uplus (Korea)
# LGF800L (LG V20)
#
# f800s = SK Telecom (Korea)
# LGF800S (LG V20)
#
###################### CONFIG ######################
# root directory of LGE msm8996 git repo (default is this script's location)
RDIR=$(pwd)
[ "$VER" ] ||
# version number
VER=$(cat "$RDIR/VERSION")
# directory containing cross-compile arm64 toolchain
TOOLCHAIN=$HOME/build/toolchain/aarch64-linux-android-6.x
CPU_THREADS=$(grep -c "processor" /proc/cpuinfo)
# amount of cpu threads to use in kernel make process
THREADS=$((CPU_THREADS + 1))
############## SCARY NO-TOUCHY STUFF ###############
ABORT() {
[ "$1" ] && echo "Error: $*"
exit 1
}
export ARCH=arm64
export CROSS_COMPILE=$TOOLCHAIN/bin/aarch64-linux-android-
[ -x "${CROSS_COMPILE}gcc" ] ||
ABORT "Unable to find gcc cross-compiler at location: ${CROSS_COMPILE}gcc"
[ "$TARGET" ] || TARGET=lge
[ "$1" ] && DEVICE=$1
[ "$DEVICE" ] || DEVICE=h830
DEFCONFIG=${TARGET}_defconfig
DEVICE_DEFCONFIG=device_lge_${DEVICE}
[ -f "$RDIR/arch/$ARCH/configs/${DEFCONFIG}" ] ||
ABORT "Config $DEFCONFIG not found in $ARCH configs!"
[ -f "$RDIR/arch/$ARCH/configs/${DEVICE_DEFCONFIG}" ] ||
ABORT "Device config $DEVICE_DEFCONFIG not found in $ARCH configs!"
KDIR="$RDIR/build/arch/$ARCH/boot"
export LOCALVERSION=$TARGET-$DEVICE-$VER
CLEAN_BUILD() {
echo "Cleaning build..."
rm -rf build
}
SETUP_BUILD() {
echo "Creating kernel config for $LOCALVERSION..."
mkdir -p build
make -C "$RDIR" O=build "$DEFCONFIG" \
DEVICE_DEFCONFIG="$DEVICE_DEFCONFIG" \
|| ABORT "Failed to set up build"
}
BUILD_KERNEL() {
echo "Starting build for $LOCALVERSION..."
while ! make -C "$RDIR" O=build -j"$THREADS"; do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) return 1 ;;
esac
done
}
INSTALL_MODULES() {
grep -q 'CONFIG_MODULES=y' build/.config || return 0
echo "Installing kernel modules to build/lib/modules..."
make -C "$RDIR" O=build \
INSTALL_MOD_PATH="." \
INSTALL_MOD_STRIP=1 \
modules_install
rm build/lib/modules/*/build build/lib/modules/*/source
}
cd "$RDIR" || ABORT "Failed to enter $RDIR!"
CLEAN_BUILD &&
SETUP_BUILD &&
BUILD_KERNEL &&
INSTALL_MODULES &&
echo "Finished building $LOCALVERSION!"