forked from MotorolaMobilityLLC/kernel-msm
/
build.sh
executable file
·183 lines (160 loc) · 5.4 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
#!/bin/bash
# Variables
sequence=`seq 1 100`;
this="KaminariKernel";
# Set up the cross-compiler (pt. 1)
export ARCH=arm;
export SUBARCH=arm;
export PATH=$HOME/Toolchains/Linaro-4.9/bin:$PATH;
export CROSS_COMPILE=arm-linux-gnueabihf-;
# Clear the screen
clear;
# Variables for bold & normal text
bold=`tput bold`;
normal=`tput sgr0`;
# Let's start...
echo -e "Building KaminariKernel...\n";
devicestr="Which device do you want to build for?
1. Moto G (falcon)
2. Moto G 4G (peregrine)
3. Moto G 2014 (titan) / G 2014 LTE (thea) ";
cleanstr="Do you want to remove everything from the last build? (Y/N)
You ${bold}MUST${normal} do this if you have changed toolchains and/or hotplugs. ";
selstr="Do you want to force SELinux to stay in Permissive mode?
Only say Yes if you're aware of the security risks this may introduce! (Y/N) ";
# Select which device the kernel should be built for
while read -p "$devicestr" dev; do
case $dev in
"1")
echo -e "Selected device: Moto G (falcon)\n"
device="falcon";
break;;
"2")
echo -e "Selected device: Moto G 4G (peregrine)\n"
device="peregrine";
break;;
"3")
echo -e "Selected devices: Moto G 2014 3G/LTE (titan/thea)\n"
device="titan";
break;;
*)
echo -e "\nInvalid option. Try again.\n";;
esac;
done;
# Clean everything via `make clean` or `make mrproper`.
# Recommended if there were extensive changes to the source code.
while read -p "$cleanstr" clean; do
case $clean in
"y" | "Y" | "yes" | "Yes")
echo -e "Cleaning everything...\n";
make --quiet mrproper && echo -e "Done!\n";
break;;
"n" | "N" | "no" | "No" | "" | " ")
echo -e "Not cleaning anything.\n";
break;;
*)
echo -e "\nInvalid option. Try again.\n";;
esac;
done;
# (Optional) Specify a release number.
# A "Testing" label will be used if this is left blank.
while read -p "Do you want to specify a release/version number? (Just press enter if you don't.) " rel; do
if [[ `echo $rel | gawk --re-interval "/^R/"` != "" ]]; then
for i in $sequence; do
if [ `echo $rel | gawk --re-interval "/^R$i/"` ]; then
echo -e "Release number: $rel\n";
export LOCALVERSION="-Kaminari-$rel";
version=$rel;
fi;
done;
elif [[ `echo $rel | gawk --re-interval "/^v/"` ]]; then
echo -e "Version number: $rel\n";
export LOCALVERSION="-Kaminari-$rel";
version=$rel;
else
case $rel in
"" | " " )
echo -e "No release number was specified. Labelling this build as testing/nightly.\n";
export LOCALVERSION="-Kaminari-Testing";
version=`date --utc "+%Y%m%d.%H%M%S"`;
break;;
*)
echo -e "Localversion set as: $rel\n";
export LOCALVERSION="-Kaminari-$rel";
version=$rel;
break;;
esac;
fi;
break;
done;
# Determine if we should force SELinux permissive mode
while read -p "$selstr" forceperm; do
case $forceperm in
"y" | "Y" | "yes" | "Yes")
echo -e "${bold}WARNING: SELinux will stay in Permissive mode at all times. You won't be able to change it to Enforcing.\nBe careful.\n${normal}";
forceperm="Y";
break;;
"n" | "N" | "no" | "No" | "" | " ")
echo -e "SELinux will remain configurable (Android will always default it to Enforcing).\n";
forceperm="N";
break;;
*)
echo -e "\nInvalid option. Try again.\n";;
esac;
done;
# Tell exactly when the build started
echo -e "Build started on:\n`date +"%A, %d %B %Y @ %H:%M:%S %Z (GMT %:z)"`\n`date --utc +"%A, %d %B %Y @ %H:%M:%S %Z"`\n";
starttime=`date +"%s"`;
# Build the kernel
make "$device"_defconfig;
# Permissive selinux? Edit .config
if [[ $forceperm = "Y" ]]; then
sed -i s/"# CONFIG_SECURITY_SELINUX_FORCE_PERMISSIVE is not set"/"CONFIG_SECURITY_SELINUX_FORCE_PERMISSIVE=y"/ .config;
fi;
# 2x no. of CPU cores
make -j$((`nproc --all` * 2));
if [[ -f arch/arm/boot/zImage-dtb ]]; then
echo -e "Code compilation finished on:\n`date +"%A, %d %B %Y @ %H:%M:%S %Z (GMT %:z)"`\n`date --utc +"%A, %d %B %Y @ %H:%M:%S %Z"`\n";
maketime=`date +"%s"`;
makediff=$(($maketime - $starttime));
echo -e "Code compilation took: $(($makediff / 60)) minute(s) and $(($makediff % 60)) second(s).\n";
else
echo -e "zImage not found. Kernel build failed. Aborting.\n";
exit 1;
fi;
# Define directories (zip, out)
maindir=$HOME/Kernel/zip/lineage;
outdir=$HOME/Kernel/out/lineage/$device;
devicedir=$maindir/$device;
# Make the zip and out dirs if they don't exist
if [ ! -d $maindir ] || [ ! -d $outdir ]; then
mkdir -p $maindir && mkdir -p $outdir;
fi;
# Use zImage-dtb since AK officially supports it now
echo -e "Copying zImage-dtb...";
cp -f arch/arm/boot/zImage-dtb $devicedir/;
# Set the zip's name
if [[ $forceperm = "Y" ]]; then
zipname="kaminari_"$version"_"${device}"_forceperm";
else
zipname="kaminari_"$version"_"${device};
fi;
# Zip the stuff we need & finish
echo -e "Creating flashable ZIP...\n";
# Note: titan & thea - unified build
if [[ $device = "titan" ]]; then
echo -e "Unified titan/thea build" > $devicedir/device.txt;
else
echo -e $device > $devicedir/device.txt;
fi;
echo -e "Version: $version" > $devicedir/version.txt;
cd $maindir/common;
zip -r9 $outdir/$zipname.zip . > /dev/null;
cd $devicedir;
zip -r9 $outdir/$zipname.zip * > /dev/null;
echo -e "Done!"
# Tell exactly when the build finished
echo -e "Build finished on:\n`date +"%A, %d %B %Y @ %H:%M:%S %Z (GMT %:z)"`\n`date --utc +"%A, %d %B %Y @ %H:%M:%S %Z"`\n";
finishtime=`date +"%s"`;
finishdiff=$(($finishtime - $starttime));
echo -e "This build took: $(($finishdiff / 60)) minute(s) and $(($finishdiff % 60)) second(s).\n";