forked from pershoot/android_kernel_google_msm
-
Notifications
You must be signed in to change notification settings - Fork 10
/
glitch
executable file
·262 lines (210 loc) · 7.61 KB
/
glitch
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
#!/bin/bash
# Glitch kernel build-script (Aroma Edition) #
# #
# Options : #
# #
# cm : build cm variant #
# clean : clean the build directory #
# cleank : clean the built kernel packages #
# cleanc : clean the compiler cache #
#################################################
# Device options :
target_name="flo" #defines the device name/codename for config
target_config=$target_name"_defconfig" #defines the device name/codename for config
target_device="N7-2013" #defines the name of device-related folders (can be the same as $target_name)
# Toolchain selection :
# (default path is "kernel_tree_folder/../toolchains")
# -------linux-x86
#export CROSS_PREFIX="arm-cortex_a15-linux-gnueabihf-linaro_4.9.3-2015.03/bin/arm-cortex_a15-linux-gnueabihf-"
#export CROSS_PREFIX="Linaro-arm-eabi-5.1.0/bin/arm-eabi-"
export CROSS_PREFIX="Linaro-arm-eabi-5.2.0/bin/arm-eabi-"
#export CROSS_PREFIX="arm-eabi-5.1.sm/bin/arm-eabi-"
#export CROSS_PREFIX="arm-eabi-6.0.sm/bin/arm-eabi-"
# -------darwin-x86
#export CROSS_PREFIX=""
setup ()
{
if [ ! -f arch/arm/configs/Glitch_$target_name"_defconfig" ] ; then
echo "Glitch defconfig missing. Creating one for regular build and another for CM......"
cp arch/arm/configs/$target_name"_defconfig" arch/arm/configs/Glitch_$target_name"_defconfig"
cp arch/arm/configs/$target_name"_defconfig" arch/arm/configs/Glitch_CM_$target_name"_defconfig"
echo "done"
fi
function mka() {
case `uname -s` in
Darwin)
make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
;;
*)
schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
;;
esac
};
# Arch-dependent definitions
case `uname -s` in
Darwin)
KERNEL_DIR="$(dirname "$(greadlink -f "$0")")"
CROSS_PREFIX="$KERNEL_DIR/../toolchains/$CROSS_PREFIX"
;;
*)
KERNEL_DIR="$(dirname "$(readlink -f "$0")")"
CROSS_PREFIX="$KERNEL_DIR/../toolchains/$CROSS_PREFIX"
;;
esac
BUILD_DIR="../glitch-build/kernel"
if [ x = "x$NO_CCACHE" ] && ccache -V &>/dev/null ; then
CCACHE=ccache
CCACHE_BASEDIR="$KERNEL_DIR"
CCACHE_COMPRESS=1
CCACHE_DIR="$KERNEL_DIR/../.ccache"
export CCACHE_DIR CCACHE_COMPRESS CCACHE_BASEDIR
else
CCACHE=""
fi
}
build ()
{
if [ "$type" = cm ] ; then
target_variant="-CM" #defines the flashable zip additional name (CM)
target_defconfig="Glitch_CM_$target_config" #defines the config to use for the build (CM)
else
target_variant="" #defines the flashable zip additional name
target_defconfig="Glitch_$target_config" #defines the config to use for the build
fi
export ARCH="arm"
local target=$target_device
echo "-----------------------------------------"
if [ "$type" = cm ] ; then
echo "Building for $target_device CM using $target_defconfig"
else
echo "Building for $target_device AOSP using $target_defconfig"
fi
local target_dir="$BUILD_DIR/$target_device"
local module
rm -fr "$target_dir"
rm -f $KERNEL_DIR/tmp_$target_defconfig
rm -f $KERNEL_DIR/arch/arm/configs/release_$target_defconfig
mkdir -p "$target_dir"
. $KERNEL_DIR/../rev
if [ "$type" = cm ] ; then
echo "Using same version number as regular build"
else
counter=$((counter + 1))
fi
echo "-----------------------------------------"
echo "Write release number in config (r"$counter")"
if [ "$type" = cm ] ; then
releasenumber='CONFIG_LOCALVERSION="-Glitch-N7-CM-r'$counter'"'
else
releasenumber='CONFIG_LOCALVERSION="-Glitch-N7-AOSP-r'$counter'"'
fi
cp arch/arm/configs/$target_defconfig tmp_$target_defconfig;
sed "43s/.*/$releasenumber/g" tmp_$target_defconfig > release_$target_defconfig;
mv release_$target_defconfig arch/arm/configs/release_$target_defconfig
rm -f $KERNEL_DIR/tmp_$target_defconfig
mka -C "$KERNEL_DIR" O="$target_dir" release_$target_defconfig HOSTCC="$CCACHE gcc -w -s -pipe -O2"
mka -C "$KERNEL_DIR" O="$target_dir" HOSTCC="$CCACHE gcc -w -s -pipe -O2" CROSS_COMPILE="$CCACHE $CROSS_PREFIX" zImage modules
[[ -d release ]] || {
echo "-----------------------------------------"
echo "must be in kernel root dir"
exit 1;
}
echo "-----------------------------------------"
echo "copying zImage"
#echo "copying modules and zImage"
#Aroma
#mkdir -p $KERNEL_DIR/release/aroma/system/lib/modules/
#Restore
#mkdir -p $KERNEL_DIR/release/restore/system/lib/modules/
#cd $target_dir
#Aroma
#find -name '*.ko' -exec cp -av {} $KERNEL_DIR/release/aroma/system/lib/modules/ \;
#"$CROSS_PREFIX"strip --strip-unneeded $KERNEL_DIR/release/aroma/system/lib/modules/*
#Restore
#find -name '*.ko' -exec cp -av {} $KERNEL_DIR/release/restore/system/lib/modules/ \;
#"$CROSS_PREFIX"strip --strip-unneeded $KERNEL_DIR/release/restore/system/lib/modules/*
cd $KERNEL_DIR
#Aroma
cp $target_dir/arch/arm/boot/zImage $KERNEL_DIR/release/aroma/boot/glitch.zImage
#Restore
cp $target_dir/arch/arm/boot/zImage $KERNEL_DIR/release/restore/boot/glitch.zImage
#Aroma
cd $KERNEL_DIR
rm -f arch/arm/configs/release_$target_defconfig
echo "-----------------------------------------"
echo "Setting date & version in Aroma conf ("$(date +%B)" "$(date +%e)" "$(date +%Y)")"
if [ "$type" = cm ] ; then
AromaVersionReplace='ini_set("rom_version", "N7-CM");'
else
AromaVersionReplace='ini_set("rom_version", "N7-AOSP");'
fi
AromaDateReplace='ini_set("rom_date", "'$(date +%B)' '$(date +%e)' '$(date +%Y)'");'
sed "34s/.*/$AromaVersionReplace/g" ./release/aroma/META-INF/com/google/android/aroma-config > ./aroma-config.tmp;
mv ./aroma-config.tmp ./release/aroma/META-INF/com/google/android/aroma-config
sed "37s/.*/$AromaDateReplace/g" ./release/aroma/META-INF/com/google/android/aroma-config > ./aroma-config.tmp;
mv ./aroma-config.tmp ./release/aroma/META-INF/com/google/android/aroma-config
echo "-----------------------------------------"
echo "packaging it up"
mkdir -p $KERNEL_DIR/release/$target_device
#Aroma
cd $KERNEL_DIR/release/aroma
REL=Glitch-$target_name-r$counter$target_variant-full.zip
zip -q -r ${REL} boot config META-INF system
#sha256sum ${REL} > ${REL}.sha256sum
mv ${REL}* $KERNEL_DIR/release/$target_device/
rm boot/glitch.zImage
rm -fr system/lib/modules/*
#Restore
cd $KERNEL_DIR/release/restore
REL2=Glitch-$target_name-r$counter$target_variant-restore.zip
zip -q -r ${REL2} boot config libs META-INF system
#sha256sum ${REL} > ${REL}.sha256sum
mv ${REL2}* $KERNEL_DIR/release/$target_device/
rm boot/glitch.zImage
rm -fr system/lib/modules/*
if [ "$type" = cm ] ; then
echo "Using same version number as regular build"
else
echo counter=$counter > $KERNEL_DIR/../rev;
fi
echo "-----------------------------------------"
echo ${REL}
echo ${REL2}
}
setup
if [ "$1" = clean ] ; then
rm -fr "$BUILD_DIR"/*
cd release
rm `find ./ -name '*.*~'` -rf
rm `find ./ -name '*~'` -rf
cd $KERNEL_DIR
rm -f $KERNEL_DIR/tmp_$target_defconfig
rm -f arch/arm/configs/release_$target_defconfig
echo "-----------------------------"
echo "Previous build folder cleaned"
echo "-----------------------------"
else
if [ "$1" = cleank ] ; then
rm -fr "$KERNEL_DIR"/release/$target_device/*
echo "---------------------"
echo "Built kernels cleaned"
echo "---------------------"
else
if [ "$1" = cleanc ] ; then
rm -fr "$KERNEL_DIR"/release/$target_device/*
rm -rf ../.ccache
echo "----------------------"
echo "Compiler cache cleaned"
echo "----------------------"
else
time {
if [ "$1" = cm ] ; then
export type="cm"
else
export type="regular"
fi
build $target_device
}
fi
fi
fi