forked from codeworkx/buildscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·385 lines (347 loc) · 13.1 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/bin/bash
CMD="$1"
EXTRACMD="$2"
A_TOP=${PWD}
CUR_DIR=`dirname $0`
DATE=$(date +%D)
MACHINE_TYPE=`uname -m`
SLIM_VERSION=4.2
# Common defines (Arch-dependent)
case `uname -s` in
Darwin)
txtrst='\033[0m' # Color off
txtred='\033[0;31m' # Red
txtgrn='\033[0;32m' # Green
txtylw='\033[0;33m' # Yellow
txtblu='\033[0;34m' # Blue
THREADS=`sysctl -an hw.logicalcpu`
;;
*)
txtrst='\e[0m' # Color off
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
THREADS=`cat /proc/cpuinfo | grep processor | wc -l`
;;
esac
check_root() {
if [ ! $( id -u ) -eq 0 ]; then
echo -e "${txtred}Please run this script as root."
echo -e "\r\n ${txtrst}"
exit
fi
}
check_machine_type() {
echo "Checking machine architecture..."
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo -e "${txtgrn}Detected: ${MACHINE_TYPE}. Good!"
echo -e "\r\n ${txtrst}"
else
echo -e "${txtred}Detected: ${MACHINE_TYPE}. Bad!"
echo -e "${txtred}Sorry, we do only support building on 64-bit machines."
echo -e "${txtred}32-bit is soooo 1970, consider a upgrade. ;-)"
echo -e "\r\n ${txtrst}"
exit
fi
}
install_sun_jdk()
{
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get update
apt-get install sun-java6-jdk
}
install_arch_packages()
{
# x86_64
pacman -S jdk7-openjdk jre7-openjdk jre7-openjdk-headless perl git gnupg flex bison gperf zip unzip lzop sdl wxgtk \
squashfs-tools ncurses libpng zlib libusb libusb-compat readline schedtool \
optipng python2 perl-switch lib32-zlib lib32-ncurses lib32-readline \
gcc-libs-multilib gcc-multilib lib32-gcc-libs binutils-multilib libtool-multilib
}
install_ubuntu_packages()
{
# x86_64
apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386 pngcrush
}
prepare_environment()
{
echo "Which 64-bit distribution are you running?"
echo "1) Ubuntu 11.04"
echo "2) Ubuntu 11.10"
echo "3) Ubuntu 12.04"
echo "4) Ubuntu 12.10"
echo "5) Arch Linux"
echo "6) Debian"
read -n1 distribution
echo -e "\r\n"
case $distribution in
"1")
# Ubuntu 11.04
echo "Installing packages for Ubuntu 11.04"
install_sun_jdk
apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc libx11-dev:i386
;;
"2")
# Ubuntu 11.10
echo "Installing packages for Ubuntu 11.10"
install_sun_jdk
apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc libx11-dev:i386
;;
"3")
# Ubuntu 12.04
echo "Installing packages for Ubuntu 12.04"
install_ubuntu_packages
ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
;;
"4")
# Ubuntu 12.10
echo "Installing packages for Ubuntu 12.10"
install_ubuntu_packages
ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
;;
"5")
# Arch Linux
echo "Installing packages for Arch Linux"
install_arch_packages
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/bin/python2 /usr/bin/python
;;
"6")
# Debian
echo "Installing packages for Debian"
apt-get update
apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev lib32ncurses5 libncurses5-dev x11proto-core-dev \
libx11-dev libreadline6-dev lib32readline-gplv2-dev libgl1-mesa-glx \
libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev pngcrush \
libcurl4-gnutls-dev comerr-dev krb5-multidev libcurl4-gnutls-dev \
libgcrypt11-dev libglib2.0-dev libgnutls-dev libgnutls-openssl27 \
libgnutlsxx27 libgpg-error-dev libgssrpc4 libgstreamer-plugins-base0.10-dev \
libgstreamer0.10-dev libidn11-dev libkadm5clnt-mit8 libkadm5srv-mit8 \
libkdb5-6 libkrb5-dev libldap2-dev libp11-kit-dev librtmp-dev libtasn1-3-dev \
libxml2-dev tofrodos python-markdown lib32z-dev ia32-libs
ln -s /usr/lib32/libX11.so.6 /usr/lib32/libX11.so
ln -s /usr/lib32/libGL.so.1 /usr/lib32/libGL.so
;;
*)
# No distribution
echo -e "${txtred}No distribution set. Aborting."
echo -e "\r\n ${txtrst}"
exit
;;
esac
echo "Do you want us to get android sources for you? (y/n)"
read -n1 sources
echo -e "\r\n"
case $sources in
"Y" | "y")
echo "Choose a branch:"
echo "1) jb4.2 (slimbean 4.2)"
read -n1 branch
echo -e "\r\n"
case $branch in
"1")
# cm-7
branch="jb4.2"
;;
*)
# no branch
echo -e "${txtred}No branch choosen. Aborting."
echo -e "\r\n ${txtrst}"
exit
;;
esac
echo "Target Directory (~/android/system):"
read working_directory
if [ ! -n $working_directory ]; then
working_directory="~/android/system"
fi
echo "Installing to $working_directory"
mkdir ~/bin
export PATH=~/bin:$PATH
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
source ~/.profile
repo selfupdate
mkdir -p $working_directory
cd $working_directory
repo init -u git://github.com/slimbean/android.git -b $branch
mkdir -p $working_directory/.repo/local_manifests
touch $working_directory/.repo/local_manifests/my_manifest.xml
curl https://raw.github.com/flinny/buildscripts/$branch/my_manifest.xml > $working_directory/.repo/local_manifests/my_manifest.xml
repo sync -j15
echo "Sources synced to $working_directory"
exit
;;
"N" | "n")
# nothing to do
exit
;;
esac
}
# create kernel zip after successfull build
create_kernel_zip()
{
echo -e "${txtgrn}Creating kernel zip...${txtrst}"
if [ -e ${ANDROID_PRODUCT_OUT}/boot.img ]; then
echo -e "${txtgrn}Bootimage found...${txtrst}"
if [ -e ${A_TOP}/buildscripts/targets/${CMD}/kernel_updater-script ]; then
echo -e "${txtylw}Package KERNELUPDATE:${txtrst} out/target/product/${CMD}/kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}-signed.zip"
cd ${ANDROID_PRODUCT_OUT}
rm -rf kernel_zip
rm kernel-sb-${SLIM_VERSION}-*
mkdir -p kernel_zip/system/lib/modules
mkdir -p kernel_zip/META-INF/com/google/android
echo "Copying boot.img..."
cp boot.img kernel_zip/
echo "Copying kernel modules..."
cp -R system/lib/modules/* kernel_zip/system/lib/modules
echo "Copying update-binary..."
cp obj/EXECUTABLES/updater_intermediates/updater kernel_zip/META-INF/com/google/android/update-binary
echo "Copying updater-script..."
cat ${A_TOP}/buildscripts/targets/${CMD}/kernel_updater-script > kernel_zip/META-INF/com/google/android/updater-script
echo "Zipping package..."
cd kernel_zip
zip -qr ../kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}.zip ./
cd ${ANDROID_PRODUCT_OUT}
echo "Signing package..."
java -jar ${ANDROID_HOST_OUT}/framework/signapk.jar ${A_TOP}/build/target/product/security/testkey.x509.pem ${A_TOP}/build/target/product/security/testkey.pk8 kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}.zip kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}-signed.zip
rm kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}.zip
echo -e "${txtgrn}Package complete:${txtrst} out/target/product/${CMD}/kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}-signed.zip"
md5sum kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}-signed.zip
cd ${A_TOP}
else
echo -e "${txtred}No instructions to create out/target/product/${CMD}/kernel-sb-${SLIM_VERSION}-$(date +%Y%m%d)-${CMD}-signed.zip... skipping."
echo -e "\r\n ${txtrst}"
fi
else
echo -e "${txtred}Bootimage not found... skipping."
echo -e "\r\n ${txtrst}"
fi
}
echo -e "${txtblu} ########################################################################"
echo -e "${txtblu} \r\n"
echo -e "${txtblu} _______ _ _________ _______ ______ _______ _______ _ "
echo -e "${txtblu} ( ____ \( \ \__ __/( )( ___ \ ( ____ \( ___ )( ( /|"
echo -e "${txtblu} | ( \/| ( ) ( | () () || ( ) )| ( \/| ( ) || \ ( |"
echo -e "${txtblu} | (_____ | | | | | || || || (__/ / | (__ | (___) || \ | |"
echo -e "${txtblu} (_____ )| | | | | |(_)| || __ ( | __) | ___ || (\ \) |"
echo -e "${txtblu} ) || | | | | | | || ( \ \ | ( | ( ) || | \ |"
echo -e "${txtblu} /\____) || (____/\___) (___| ) ( || )___) )| (____/\| ) ( || ) \ |"
echo -e "${txtblu} \_______)(_______/\_______/|/ \||/ \___/ (_______/|/ \||/ )_)"
echo -e "${txtblu} \r\n"
echo -e "${txtblu} ########################################################################"
echo -e "\r\n ${txtrst}"
# Check for build target
if [ -z "${CMD}" ]; then
echo -e "${txtred}No build target set."
echo -e "${txtred}Usage: ./build.sh i9300 (complete build)"
echo -e "${txtred} ./build.sh i9300 kernel (bootimage only)"
echo -e "${txtred} ./build.sh clean"
echo -e "${txtred} ./build.sh prepare (prepares the build environment)"
echo -e "\r\n ${txtrst}"
exit
fi
# Starting Timer
START=$(date +%s)
# Device specific settings
case "$CMD" in
prepare)
check_root
check_machine_type
prepare_environment
exit
;;
clean)
make clean
rm -rf ./out/target/product
exit
;;
*)
lunch=slim_${CMD}-userdebug
brunch=${lunch}
;;
esac
# Apply patches
if [ -f $CUR_DIR/patch.sh ]; then
echo -e "${txtylw}Applying patches...${txtrst}"
source $CUR_DIR/patch.sh
echo -e "${txtgrn}Patches applied!${txtrst}"
fi
# Setting up Build Environment
echo -e "${txtgrn}Setting up Build Environment...${txtrst}"
. build/envsetup.sh
lunch ${lunch}
# Allow setting of additional flags
if [ -f $CUR_DIR/env.sh ]; then
source $CUR_DIR/env.sh
fi
# fix module copy for archlinux
mkdir -p ${ANDROID_PRODUCT_OUT}/system/lib
mkdir -p ${ANDROID_PRODUCT_OUT}/system/usr
cd ${ANDROID_PRODUCT_OUT}/system/usr
ln -sf ../lib .
cd -
# Start the Build
case "$EXTRACMD" in
kernel)
echo -e "${txtgrn}Rebuilding bootimage...${txtrst}"
rm -rf ${ANDROID_PRODUCT_OUT}/kernel_zip
rm ${ANDROID_PRODUCT_OUT}/kernel
rm ${ANDROID_PRODUCT_OUT}/boot.img
rm -rf ${ANDROID_PRODUCT_OUT}/root
rm -rf ${ANDROID_PRODUCT_OUT}/ramdisk*
rm -rf ${ANDROID_PRODUCT_OUT}/combined*
mka bootimage
if [ ! -e ${ANDROID_PRODUCT_OUT}/obj/EXECUTABLES/updater_intermediates/updater ]; then
mka updater
fi
if [ ! -e ${ANDROID_HOST_OUT}/framework/signapk.jar ]; then
mka signapk
fi
create_kernel_zip
;;
recovery)
echo -e "${txtgrn}Rebuilding recoveryimage...${txtrst}"
rm -rf ${ANDROID_PRODUCT_OUT}/obj/KERNEL_OBJ
rm ${ANDROID_PRODUCT_OUT}/kernel
rm ${ANDROID_PRODUCT_OUT}/recovery.img
rm ${ANDROID_PRODUCT_OUT}/recovery
rm -rf ${ANDROID_PRODUCT_OUT}/ramdisk*
mka ${ANDROID_PRODUCT_OUT}/recovery.img
;;
*)
echo -e "${txtgrn}Building Android...${txtrst}"
lunch ${brunch}
if [[ ${hostname} = ${slimbuild} ]]; then
echo "Building on slimbuild host using -j4"
BUILDCMD="make -j4 bacon"
else
CPUNUM=$(cat /proc/cpuinfo | grep processor | wc -l)
BUILDCMD="make -j$CPUNUM bacon"
fi
$BUILDCMD
create_kernel_zip
;;
esac
END=$(date +%s)
ELAPSED=$((END - START))
E_MIN=$((ELAPSED / 60))
E_SEC=$((ELAPSED - E_MIN * 60))
printf "${txtgrn}Elapsed: "
[ $E_MIN != 0 ] && printf "%d min(s) " $E_MIN
printf "%d sec(s)\n ${txtrst}" $E_SEC