forked from teamacid/android_kernel_galaxys4gmtd
/
build.sh
executable file
·146 lines (98 loc) · 3.29 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
#!/bin/bash
# AntonX
# Before building, create kernel config by executing command:
# $./build.sh -config
# Use "$./build.sh -clean" to kill old .o
# you can modify these to your locations of tooolchain and initramfs
DEFAULT_CROSS_COMPILE=/home/anton/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-
DEFAULT_INITRAMFS=/home/anton/SGS4G/initramfsGB
# check the toolchain
if [ ! -e ${CROSS_COMPILE}gcc ] ; then # export variable is not set; try our own
CROSS_COMPILE=$DEFAULT_CROSS_COMPILE
fi
if [ ! -e ${CROSS_COMPILE}gcc ] ; then
echo "!!! Toolchain not found. Use:"
echo "!!! \$git clone https://android.googlesource.com/platform/prebuilt"
echo "!!! \$export CROSS_COMPILE=\"Your_Toolchain_Location/bin/arm-eabi-\""
exit 0
fi
# check initramfs
if [ ! -e ${INITRAMFS}/init_samsung ] ; then
INITRAMFS=$DEFAULT_INITRAMFS
fi
if [ ! -e ${INITRAMFS}/init_samsung ] ; then
echo "!!! initramfs not found. Make sure you have the directory and use command to set:"
echo "!!! \$export INITRAMFS=\"Your_initramfs_Location\""
exit 0
fi
#
CPU_NUMBER=`grep 'processor' /proc/cpuinfo | wc -l`
TMP_INITRAMFS=/tmp/sgs4g_initramfs
BUILD_DIR="./"
##############################################################################
if [ "$1" == "-config" ] ; then
KCONFIG=vibrantplus_antsvx_defconfig
echo Creating $KCONFIG config...
make $KCONFIG
exit 0
fi
if [ "$1" == "-config2" ] ; then
KCONFIG=vibrantplus_antsvx_noocuv_defconfig
echo Creating $KCONFIG config...
make $KCONFIG
exit 0
fi
if [ "$1" == "-clean" ] ; then
echo Cleaning project...
rm $(find $BUILD_DIR -name '*.ko') > /dev/null 2>&1
rm $(find $BUILD_DIR -name '*.o') > /dev/null 2>&1
rm $(find $BUILD_DIR -name '*.bak') > /dev/null 2>&1
rm $(find $BUILD_DIR -name '*.old') > /dev/null 2>&1
rm $(find $BUILD_DIR -name '*.tmp') > /dev/null 2>&1
exit 0
fi
COMPILEONLY=0
PACKONLY=0
if [ "$1" == "-co" ] ; then # compile only
echo Compilinig only, no initramfs.
COMPILEONLY=1
fi
if [ "$1" == "-pack" ] ; then # compile only
echo Packing zImage with initramfs.
PACKONLY=1
COMPILEONLY=0
fi
#
if [ ! -e ${TMP_INITRAMFS} ] ; then
mkdir ${TMP_INITRAMFS} > /dev/null 2>&1
fi
# some cleanup
if [ $COMPILEONLY == 0 ] && [ $PACKONLY == 0 ] ; then
echo Cleaning previous build...
rm $(find $BUILD_DIR -name '*.ko') > /dev/null 2>&1
fi
if [ $PACKONLY == 0 ] ; then
# run the build
echo Building...
make -j$CPU_NUMBER CROSS_COMPILE=$CROSS_COMPILE
fi
#
if [ $COMPILEONLY == 0 ] ; then
# replace kernel objects with newly build files
echo Preparing initramfs...
rm -rf ${TMP_INITRAMFS} > /dev/null 2>&1
cp -rf ${INITRAMFS} ${TMP_INITRAMFS}
find ${TMP_INITRAMFS} -name '\.git' -o -name '\.gitignore' -o -name 'EMPTY_DIRECTORY' | xargs rm -rf
if [ $PACKONLY == 0 ] ; then
echo Populating initramfs with updated kernel objects...
cp $(find $BUILD_DIR -name '*.ko') ${TMP_INITRAMFS}/lib/modules/
cp $(find $BUILD_DIR -name '*.ko') ${INITRAMFS}/lib/modules/
fi
rm -rf $BUILD_DIR/usr/{built-in.o,initramfs_data.{o,cpio*}} > /dev/null 2>&1
rm $BUILD_DIR/arch/arm/boot/Image > /dev/null 2>&1
rm $BUILD_DIR/arch/arm/boot/zImage > /dev/null 2>&1
# run make again to build zImage with latest kernel objects
echo Rebuilding zImage...
make -j$CPU_NUMBER CROSS_COMPILE=$CROSS_COMPILE
fi
echo Done.