forked from showp1984/bricked-flo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildme.sh
executable file
·321 lines (292 loc) · 9.99 KB
/
buildme.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
#!/bin/bash
#switches
USEAROMA=0;
USEPREBUILT=1;
USECHKS=1;
USEFTP=0;
#sourcedir
SOURCE_DIR="$(pwd)"
#crosscompile stuff
CROSSARCH="arm"
CROSSCC="$CROSSARCH-eabi-"
TOOLCHAIN_D="$(pwd)/toolch"
TOOLCHAIN="$(pwd)/toolch/android-toolchain-eabi/bin"
#our used directories
PREBUILT="$(pwd)/prebuilt"
OUT_DIR="$(pwd)/out"
#compile neccesities
USERCCDIR="$HOME/.ccache"
CODENAME="flo"
DEFCONFIG="bricked_defconfig"
NRJOBS=$(( $(nproc) * 2 ))
#ftpstuff
RETRY="60s";
MAXCOUNT=30;
HOST="host.com"
USER="user"
PASS='pass'
#if we are not called with an argument, default to branch master
if [ -z "$1" ]; then
BRANCH="master"
echo "[BUILD]: WARNING: Not called with branchname, defaulting to $BRANCH!";
echo "[BUILD]: If this is not what you want, call this script with the branchname.";
else
BRANCH=$1;
fi
echo "[BUILD]: ####################################";
echo "[BUILD]: ####################################";
echo "[BUILD]: Building branch: $BRANCH";
echo "[BUILD]: ####################################";
echo "[BUILD]: ####################################";
#Checking out latest upstream changes
echo "[BUILD]: Checking out branch: $BRANCH...";
git clean -f -d
git checkout $BRANCH
OUT_ENABLED=1;
if [ ! -d "$OUT_DIR" ]; then
echo "[BUILD]: Directory '$OUT_DIR' which is configure as output directory does not exist!";
VALID=0;
while [[ $VALID -eq 0 ]]
do
echo "[Y|y] Create it.";
echo "[N|n] Don't create it, this will disable the output directory.";
echo "Choose an option:";
read DECISION;
case "$DECISION" in
y|Y)
VALID=1;
echo "Creating directory $OUT_DIR...";
mkdir $OUT_DIR
mkdir $OUT_DIR/kernel
mkdir $OUT_DIR/modules
;;
n|N)
VALID=1;
OUT_ENABLED=0;
echo "Disabling output directory...";
;;
*)
echo "Error: Unknown input ($DECISION), try again.";
esac
done
else
if [ ! -d "$OUT_DIR/kernel" ]; then
echo "Creating directory $OUT_DIR/kernel...";
mkdir $OUT_DIR/kernel
fi
if [ ! -d "$OUT_DIR/modules" ]; then
echo "Creating directory $OUT_DIR/modules...";
mkdir $OUT_DIR/modules
fi
fi
###CCACHE CONFIGURATION STARTS HERE, DO NOT MESS WITH IT!!!
TOOLCHAIN_CCACHE="$TOOLCHAIN/../bin-ccache"
gototoolchain() {
echo "[BUILD]: Changing directory to $TOOLCHAIN/../ ...";
cd $TOOLCHAIN/../
}
gototoolchaind() {
echo "[BUILD]: Changing directory to $TOOLCHAIN_D ...";
cd $TOOLCHAIN_D
}
gotocctoolchain() {
echo "[BUILD]: Changing directory to $TOOLCHAIN_CCACHE...";
cd $TOOLCHAIN_CCACHE
}
if [ ! -d "$TOOLCHAIN_D" ]; then
mkdir $TOOLCHAIN_D
fi
if [ ! -d "$TOOLCHAIN_D/android-toolchain-eabi" ]; then
gototoolchaind
# wget http://bricked.de/downloads/android-toolchain-eabi-4.8-2014.03-x86.tar.bz2
wget http://bricked.de/downloads/android-toolchain-eabi.zip
echo "[BUILD]: Extracting...";
unzip android-toolchain-eabi.zip
rm android-toolchain-eabi.zip
# tar jxf android-toolchain-eabi-4.8-2014.03-x86.tar.bz2
# rm -f android-toolchain-eabi-4.8-2014.03-x86.tar.bz2
fi
#check ccache configuration
#if not configured, do that now.
if [ ! -d "$TOOLCHAIN_CCACHE" ]; then
echo "[BUILD]: CCACHE: not configured! Doing it now...";
gototoolchain
mkdir bin-ccache
gotocctoolchain
ln -s $(which ccache) "$CROSSCC""gcc"
ln -s $(which ccache) "$CROSSCC""g++"
ln -s $(which ccache) "$CROSSCC""cpp"
ln -s $(which ccache) "$CROSSCC""c++"
gototoolchain
chmod -R 777 bin-ccache
echo "[BUILD]: CCACHE: Done...";
fi
export CCACHE_DIR=$USERCCDIR
###CCACHE CONFIGURATION ENDS HERE, DO NOT MESS WITH IT!!!
echo "[BUILD]: Setting cross compile env vars...";
SAVEDPATH=$PATH;
SAVEDCROSS_COMPILE=$CROSS_COMPILE;
SAVEDARCH=$ARCH;
export ARCH=$CROSSARCH
export CROSS_COMPILE=$CROSSCC
export PATH=$TOOLCHAIN_CCACHE:${PATH}:$TOOLCHAIN
gotoprebuilt() {
if [ ! -d "$PREBUILT" ]; then
mkdir $PREBUILT
fi
echo "[BUILD]: Changing directory to $PREBUILT...";
cd $PREBUILT
}
gotosource() {
echo "[BUILD]: Changing directory to $SOURCE_DIR...";
cd $SOURCE_DIR
}
gotoout() {
if [[ ! $OUT_ENABLED -eq 0 ]]; then
echo "[BUILD]: Changing directory to $OUT_DIR...";
cd $OUT_DIR;
fi
}
if [ ! $USEPREBUILT -eq 0 ]; then
if [ ! -d "$PREBUILT" ]; then
gotoprebuilt
wget http://bricked.de/downloads/prebuilts/${CODENAME}_prebuilt.zip
unzip ${CODENAME}_prebuilt.zip
rm ${CODENAME}_prebuilt.zip
fi
fi
gotosource
#saving new rev
REV=$(git log --pretty=format:'%h' -n 1)
echo "[BUILD]: Saved current hash as revision: $REV...";
#date of build
DATE=$(date +%Y%m%d_%H%M%S)
echo "[BUILD]: Start of build: $DATE...";
#build the kernel
echo "[BUILD]: Cleaning kernel (make mrproper)...";
make mrproper
echo "[BUILD]: Using defconfig: $DEFCONFIG...";
make $DEFCONFIG
echo "[BUILD]: Changing CONFIG_LOCALVERSION to: -bricked-"$CODENAME"-"$BRANCH" ...";
sed -i "/CONFIG_LOCALVERSION=\"/c\CONFIG_LOCALVERSION=\"-bricked-"$CODENAME"-"$BRANCH"\"" .config
#kcontrol necessities
if [ $(cat .config | grep 'CONFIG_ARCH_MSM=y' | tail -n1) == "CONFIG_ARCH_MSM=y" ]; then
DEVARCH="msm";
elif [ $(cat .config | grep 'CONFIG_ARCH_TEGRA=y' | tail -n1) == "CONFIG_ARCH_TEGRA=y" ]; then
DEVARCH="tegra";
fi
gotokcontrol() {
echo "[BUILD]: Changing directory to $SOURCE_DIR/kcontrol...";
cd $SOURCE_DIR/kcontrol
}
gotokcontrolgpu() {
echo "[BUILD]: Changing directory to $SOURCE_DIR/kcontrol/kcontrol_gpu_$DEVARCH...";
cd $SOURCE_DIR/kcontrol/kcontrol_gpu_$DEVARCH
}
#end kcontrol necessities
echo "[BUILD]: Bulding the kernel...";
time make -j$NRJOBS || { return 1; }
echo "[BUILD]: Done with kernel!...";
# BUILD KCONTROL
#done building, lets build kcontrol modulesa
echo "[BUILD]: Initializing directories for KControl modules...";
rm -rf kcontrol
mkdir kcontrol
gotokcontrol
#gpu
echo "[BUILD]: Cloning KControl msm gpu module source...";
if [ $DEVARCH == "msm" ]; then
git clone https://git.bricked.de/kcontrol/kcontrol_gpu_msm.git
elif [ $DEVARCH == "tegra" ]; then
git clone https://git.bricked.de/kcontrol/kcontrol_gpu_tegra.git
fi
gotokcontrolgpu
echo "[BUILD]: Updating KERNEL_BUILD inside the Makefile...";
sed -i '/KERNEL_BUILD := /c\KERNEL_BUILD := ../../' Makefile
echo "[BUILD]: Building KControl $DEVARCH gpu module...";
make || { return 1; }
echo "[BUILD]: Done with kcontrol's $DEVARCH gpu module!...";
# END BUILD KCONTROL
if [[ ! $OUT_ENABLED -eq 0 ]]; then
gotoout
#prepare our zip structure
echo "[BUILD]: Cleaning out directory...";
find $OUT_DIR/* -maxdepth 0 ! -name '*.zip' ! -name '*.md5' ! -name '*.sha1' ! -name kernel ! -name modules ! -name out -exec rm -rf '{}' ';'
if [ ! $USEPREBUILT -eq 0 ]; then
if [ -d "$PREBUILT" ]; then
echo "[BUILD]: Copying prebuilts to out directory...";
cp -R $PREBUILT/* $OUT_DIR/
fi
fi
if [ ! $USEAROMA -eq 0 ]; then
echo "[BUILD]: Changing aroma version/data/device to: $BRANCH-$REV/$DATE/$CODENAME...";
sed -i "/ini_set(\"rom_version\",/c\ini_set(\"rom_version\", \""$BRANCH-$REV"\");" $OUT_DIR/META-INF/com/google/android/aroma-config
sed -i "/ini_set(\"rom_date\",/c\ini_set(\"rom_date\", \""$DATE"\");" $OUT_DIR/META-INF/com/google/android/aroma-config
sed -i "/ini_set(\"rom_device\",/c\ini_set(\"rom_device\", \""$CODENAME"\");" $OUT_DIR/META-INF/com/google/android/aroma-config
fi
gotosource
#copy stuff for our zip
echo "[BUILD]: Copying kernel (zImage) to $OUT_DIR/kernel/...";
cp arch/arm/boot/zImage $OUT_DIR/kernel/
echo "[BUILD]: Copying modules (*.ko) to $OUT_DIR/modules/...";
find $SOURCE_DIR/ -name \*.ko -exec cp '{}' $OUT_DIR/modules/ ';'
echo "[BUILD]: Done!...";
gotoout
#create zip and clean folder
echo "[BUILD]: Creating zip: bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip ...";
zip -r bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip . -x "*.zip" "*.sha1" "*.md5"
echo "[BUILD]: Cleaning out directory...";
find $OUT_DIR/* -maxdepth 0 ! -name '*.zip' ! -name '*.md5' ! -name '*.sha1' ! -name out -exec rm -rf '{}' ';'
echo "[BUILD]: Done!...";
if [ ! $USECHKS -eq 0 ]; then
echo "[BUILD]: Creating sha1 & md5 sums...";
md5sum bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip > bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip.md5
sha1sum bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip > bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip.sha1
fi
if [ ! $USEFTP -eq 0 ]; then
echo "[BUILD]: Testing connection to $HOST...";
SUCCESS=0;
ZERO=0;
COUNT=0;
while [ $SUCCESS -eq $ZERO ]
do
COUNT=$(($COUNT + 1));
if [ $COUNT -eq $MAXCOUNT ]; then
return 1;
fi
ping -c1 $HOST
case "$?" in
0)
echo "[BUILD]: $HOST is online, continuing...";
SUCCESS=1 ;;
1)
echo "[BUILD]: Packet Loss while pinging $HOST. Retrying in $RETRY!";
sleep $RETRY ;;
2)
echo "[BUILD]: $HOST is unknown (offline). Retrying in $RETRY!";
sleep $RETRY ;;
*)
echo "[BUILD]: Some unknown error occured while trying to connect to $HOST. Retrying in $RETRY seconds!";
sleep $RETRY ;;
esac
done
echo "[BUILD]: Uploading files to $HOST...";
# Uses the ftp command with the -inv switches.
# -i turns off interactive prompting
# -n Restrains FTP from attempting the auto-login feature
# -v enables verbose and progress
ftp -inv $HOST << End-Of-Session
user $USER $PASS
cd /$CODENAME/$BRANCH/
put bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip
put bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip.md5
put bricked_"$CODENAME"_"$DATE"_"$BRANCH"-"$REV".zip.sha1
bye
End-Of-Session
fi
fi
echo "[BUILD]: All done!...";
gotosource
export PATH=$SAVEDPATH
export CROSS_COMPILE=$SAVEDCROSS_COMPILE;
export ARCH=$SAVEDARCH;