This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuild.sh
executable file
·339 lines (307 loc) · 9.51 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#!/bin/bash
#
# Stock kernel for LG Electronics msm8996 devices build script by jcadduono
# -(heavily)modified by stendro
#
############################# 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 ################################
#
# H850 = International (Global)
# LGH850 (LG G5)
#
# H830 = T-Mobile (US)
# LGH830 (LG G5)
#
# RS988 = Unlocked (US)
# LGRS988 (LG G5)
#
# *************************
#
# H910 = AT&T (US)
# LGH910 (LG V20)
#
# H915 = Canada (CA)
# LGH915 (LG V20)
#
# H918 = T-Mobile (US)
# LGH918 (LG V20)
#
# US996 = US Cellular & Unlocked (US)
# LGUS996 (LG V20)
#
# US996D = US Cellular & Unlocked (US)
# LGUS996 (LG V20) (Unlocked with Engineering Bootloader)
#
# VS995 = Verizon (US)
# LGVS995 (LG V20)
#
# H990DS = International (Global)
# LGH990 (LG V20)
#
# H990TR = Turkey (TR)
# LGH990 (LG V20)
#
# LS997 = Sprint (US)
# LGLS997 (LG V20)
#
# F800K/L/S = Korea (KR)
# LGF800 (LG V20)
#
# *************************
#
# H870 = International (Global)
# LGH870 (LG G6)
#
# US997 = US Cellular & Unlocked (US)
# US997 (LG G6)
#
# H872 = T-Mobile (US)
# LGH872 (LG G6)
#
################################# CONFIG #################################
# Assume build_all is not being used, will be automatically changed if it is
SINGLEBUILD="yes"
# root directory of this kernel (this script's location)
RDIR=$(pwd)
# build dir
BDIR=build
# version file
VFIL=VERSION
# expand version
VER=$(cat $RDIR/$VFIL)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ------------------------- BUILD CONFIG OPTIONS -------------------------
#
# "user"@"host"
KBUSER=stendro_+_AShiningRay
KBHOST=github
# ccache: yes or no
USE_CCACHE=no
# select cpu threads
THREADS=$(grep -c "processor" /proc/cpuinfo)
# directory containing cross-compiler
# a newer toolchain (gcc8+) is recommended due to changes made
# to the kernel.
GCC_COMP=$HOME/toolchains/aarch64-elf/bin/aarch64-elf-
# directory containing 32bit cross-compiler for CONFIG_COMPAT_VDSO
GCC_COMP_32=$HOME/toolchains/arm-eabi/bin/arm-eabi-
# -------------------------------- END -----------------------------------
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# compiler version
# gnu gcc or newer arm (linaro) gcc
if $(${GCC_COMP}gcc --version | grep -q '(GCC)') ||
$(${GCC_COMP}gcc --version | grep -q '(Eva GCC)'); then
GCC_STRING=$(${GCC_COMP}gcc --version | head -n1 | cut -f2 -d')')
GCC_VER="GCC$GCC_STRING"
else # old linaro gcc
GCC_VER="$(${GCC_COMP}gcc --version | head -n1 | cut -f1 -d')' | \
cut -f2 -d'(')"
if $(echo $GCC_VER | grep -q '~dev'); then
GCC_VER="$(echo $GCC_VER | cut -f1 -d'~')+"
fi
fi
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# --------------------------- RIGID PORTION ------------------------------
#
# color codes
COLOR_N="\033[0m"
COLOR_R="\033[0;31m"
COLOR_G="\033[1;32m"
COLOR_Y="\033[1;33m"
COLOR_P="\033[1;35m"
ABORT() {
echo -e $COLOR_R"Error: $*"
exit 1
}
export ARCH=arm64
export KBUILD_BUILD_USER=$KBUSER
export KBUILD_BUILD_HOST=$KBHOST
export LOCALVERSION="-${VER}"
if [ "$USE_CCACHE" = "yes" ]; then
export CROSS_COMPILE="ccache $GCC_COMP"
export CROSS_COMPILE_ARM32="ccache $GCC_COMP_32"
else
export CROSS_COMPILE=$GCC_COMP
export CROSS_COMPILE_ARM32=$GCC_COMP_32
fi
# In case a model isn't passed as an argument, this block acts as a fallback
MODEL_ARRAY=("H850" "H830" "RS988" "H870" "US997" "H872" "H910" "H918" "H990" "LS997" "US996" "US996D" "VS995")
FALLBACK_GET_VARIANT() {
if [[ ${SELECTED_MODEL} = "" ]]; then
echo -e "List of available variants:"
echo -e "G5 -> [$COLOR_C H850, H830, RS988 $COLOR_N]"
echo -e "G6 -> [$COLOR_C H870, US997, H872 $COLOR_N]"
echo -e "V20 -> [$COLOR_C H910, H918, H990, LS997, US996, US996D (Dirtysanta), VS995 $COLOR_N]"
read -p "Please select your model:" DEVICE
fi
# This checks if the user's model is supported by the kernel.
if [[ " ${MODEL_ARRAY[*]} " != *" ${DEVICE} "* ]]; then
echo -e "${COLOR_R}Your model wasn't found. Please check for errors (such as lower-case).${COLOR_N} \n"
FALLBACK_GET_VARIANT
fi
}
# selected device
[ "$1" ] && DEVICE=$1
[ "$DEVICE" ] || FALLBACK_GET_VARIANT
# Checks if the build_all script isn't being used
if [ "$2" = "build_all" ]; then
SINGLEBUILD="no"
else
SINGLEBUILD="yes"
fi
# link device name to lg config files
if [ "$DEVICE" = "H850" ]; then
DEVICE_DEFCONFIG=lineageos_h850_defconfig
elif [ "$DEVICE" = "H830" ]; then
DEVICE_DEFCONFIG=lineageos_h830_defconfig
elif [ "$DEVICE" = "RS988" ]; then
DEVICE_DEFCONFIG=lineageos_rs988_defconfig
elif [ "$DEVICE" = "H870" ]; then
DEVICE_DEFCONFIG=lineageos_h870_defconfig
elif [ "$DEVICE" = "H872" ]; then
DEVICE_DEFCONFIG=lineageos_h872_defconfig
elif [ "$DEVICE" = "US997" ]; then
DEVICE_DEFCONFIG=lineageos_us997_defconfig
elif [ "$DEVICE" = "H918" ]; then
DEVICE_DEFCONFIG=lineageos_h918_defconfig
elif [ "$DEVICE" = "H910" ]; then
DEVICE_DEFCONFIG=lineageos_h910_defconfig
elif [ "$DEVICE" = "H990" ]; then
DEVICE_DEFCONFIG=lineageos_h990_defconfig
elif [ "$DEVICE" = "US996" ]; then
DEVICE_DEFCONFIG=lineageos_us996_defconfig
elif [ "$DEVICE" = "US996D" ]; then
DEVICE_DEFCONFIG=lineageos_us996d_defconfig
elif [ "$DEVICE" = "VS995" ]; then
DEVICE_DEFCONFIG=lineageos_vs995_defconfig
elif [ "$DEVICE" = "LS997" ]; then
DEVICE_DEFCONFIG=lineageos_ls997_defconfig
else
ABORT "Invalid device '${DEVICE}' specified! Make sure to use upper-case."
fi
# check for stuff
[ -f "$RDIR/arch/$ARCH/configs/${DEVICE_DEFCONFIG}" ] \
|| ABORT "$DEVICE_DEFCONFIG not found in $ARCH configs!"
[ -x "${GCC_COMP}gcc" ] \
|| ABORT "Cross-compiler not found at: ${GCC_COMP}gcc"
[ -x "${GCC_COMP_32}gcc" ] \
|| echo -e $COLOR_R"32-bit compiler not found, required for COMPAT_VDSO (VDSO32)."
if [ "$USE_CCACHE" = "yes" ]; then
command -v ccache >/dev/null 2>&1 \
|| ABORT "Do you have ccache installed?"
fi
if [ -f "$BDIR/DEVICE" ] && \
[ "$(cat $BDIR/DEVICE)" = "$DEVICE" ]; then
ASK_CLEAN=yes
fi
# build commands
CLEAN_BUILD() {
echo -e $COLOR_G"Cleaning build folder..."$COLOR_N
rm -rf $BDIR && sleep 5
}
SETUP_BUILD() {
echo -e $COLOR_G"Creating kernel config..."$COLOR_N
mkdir -p $BDIR
echo "$DEVICE" > $BDIR/DEVICE \
|| echo -e $COLOR_R"Failed to reflect device!"
if [ $SINGLEBUILD = "yes" ]; then
make -C "$RDIR" O=$BDIR "$DEVICE_DEFCONFIG" \
|| ABORT "Failed to set up the kernel build."
else # build_all will send make output to a file
make -C "$RDIR" O=$BDIR "$DEVICE_DEFCONFIG" &> zBuild_all.log \
|| ABORT "Failed to set up the kernel build."
fi
}
BUILD_KERNEL() {
echo -e $COLOR_G"Compiling kernel for ${DEVICE}..."$COLOR_N
TIMESTAMP1=$(date +%s)
if [ $SINGLEBUILD = "yes" ]; then
while ! make -C "$RDIR" O=$BDIR -j"$THREADS"; do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) ABORT "Compilation aborted." ;;
esac
done
else # build_all will send compile logs to a file
while ! make -C "$RDIR" O=$BDIR -j"$THREADS" &> zBuild_all.log; do
read -rp "Build failed. Retry? " do_retry
case $do_retry in
Y|y) continue ;;
*) ABORT "Compilation aborted." ;;
esac
done
fi
TIMESTAMP2=$(date +%s)
BSEC=$((TIMESTAMP2-TIMESTAMP1))
BTIME=$(printf '%02dm:%02ds' $(($BSEC/60)) $(($BSEC%60)))
}
INSTALL_MODULES() {
grep -q 'CONFIG_MODULES=y' $BDIR/.config || return 0
echo -e $COLOR_G"Installing kernel modules..."$COLOR_N
if [ $SINGLEBUILD = "yes" ]; then
make -C "$RDIR" O=$BDIR \
INSTALL_MOD_PATH="." \
INSTALL_MOD_STRIP=1 \
modules_install
else # build_all will send module logs to a file
make -C "$RDIR" O=$BDIR \
INSTALL_MOD_PATH="." \
INSTALL_MOD_STRIP=1 \
modules_install &> zBuild_all.log
fi
rm $BDIR/lib/modules/*/build $BDIR/lib/modules/*/source
}
PREPARE_NEXT() {
if grep -q 'CONFIG_KERNEL_LZ4=y' $BDIR/.config; then
echo lz4 > $BDIR/COMPRESSION \
|| echo -e $COLOR_R"Failed to reflect compression method!"
else
echo gz > $BDIR/COMPRESSION \
|| echo -e $COLOR_R"Failed to reflect compression method!"
fi
git log --oneline -50 > $BDIR/GITCOMMITS \
|| echo -e $COLOR_R"Failed to reflect commit log!"
}
cd "$RDIR" || ABORT "Failed to enter $RDIR!"
echo -e $COLOR_G"Building ${DEVICE} ${VER}..."
echo -e $COLOR_P"Using $GCC_VER..."
if [ "$USE_CCACHE" = "yes" ]; then
echo -e $COLOR_P"Using CCACHE..."
fi
# ask before cleaning if device
# is the same as previous build
if [ $SINGLEBUILD = "yes" ]; then
if [ "$ASK_CLEAN" = "yes" ]; then
while true; do
echo -e $COLOR_Y
read -p "Same device as the last build. Do you wish to clean the build directory?" yn
echo -e $COLOR_N
case $yn in
[Yy]* ) CLEAN_BUILD && break ;;
[Nn]* ) break ;;
* ) echo -e $COLOR_R"Please answer 'y' or 'n'"$COLOR_N ;;
esac
done
else
CLEAN_BUILD
fi
else # Always clean build folder for next build on build_all
CLEAN_BUILD
fi
SETUP_BUILD
BUILD_KERNEL
INSTALL_MODULES
PREPARE_NEXT
echo -e $COLOR_G"Finished building ${DEVICE} ${VER} -- Kernel compilation took"$COLOR_R $BTIME
if [ $SINGLEBUILD = "yes" ]; then
echo -e $COLOR_P"Run './copy_finished.sh' to create the flashable AnyKernel zip."
fi