This repository has been archived by the owner on Aug 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.sh
executable file
·256 lines (224 loc) · 9.63 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
#!/bin/bash
# _ _ _ _ __ _
# / \ _ __ ___| |__ (_) |/ /___ _ __ _ __ ___| |
# / _ \ | '__/ __| '_ \| | ' // _ \ '__| '_ \ / _ \ |
# / ___ \| | | (__| | | | | . \ __/ | | | | | __/ |
# /_/ \_\_| \___|_| |_|_|_|\_\___|_| |_| |_|\___|_|
#
# Copyright 2014 Łukasz "JustArchi" Domeradzki
# Contact: [email protected]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Usage:
# build.sh <option1> <option2> <option3> yourconfig
# NOTICE: yourconfig must exist in arch/arm/configs
# Examples:
# ./build.sh aosp_ak_defconfig -> Build ArchiKernel for default AOSP variant
# ./build.sh samsung_ak_defconfig -> Build ArchiKernel for Samsung variant
# ./build.sh aosp_ak_defconfig samsung_ak_defconfig -> Build ArchiKernel for both AOSP and Samsung variant
# ./build.sh --all -> Build ArchiKernel for all currently supported variants. Same as ./build.sh every possible variant
# ./build.sh --version=2.0 aosp_ak_defconfig -> Build ArchiKernel for default AOSP variant and specify that version is V2.0
# ./build.sh --configtest -> Use currently available .config instead of predefined configs. Useful for config tests
# ./build.sh --dirty -> Don't clean, use currentnly available .config and build. Perfect for testing if new commit compiles
# source build.sh --source -> Append proper variables to current shell, so you can use i.e. make clean/menuconfig/all standalone
# Release:
# ./build.sh --all --version=X.Y.Z
SOURCE=0 # --source -> This will prepare environment for cross compiling (only). Use only in conjuction with "source" command, i.e. source build.sh --source
REGEN=0 # --regen/--regenerate -> This will regenerate ArchiKernel configs according to current Kconfig
CLEAN=0 # --clean -> This will clean build directory, same as make clean && make mrproper
DIRTY=0 # --dirty -> This will not call make clean && make mrproper. Implies --configtest
CONFIGTEST=0 # --configtest -> This will call only make clean (without make mrproper) and use .config file instead of $TARGETCONFIG. Useful for config tests
BARE=0 # --bare -> This will finish the script as soon as the kernel is compiled, so no modules stripping or copying files will be done
ALL=0 # --all -> This will build every currently supported ArchiKernel variant, from arch/arm/configs/*_ak_defconfig
# Detect HOME properly
# This workaround is required because arm-eabi-nm has problems following ~. Don't change it
if [[ "$(dirname ~)" = "/" ]]; then
HOME="$(dirname ~)$(basename ~)" # Root
else
HOME="$(dirname ~)/$(basename ~)" # User
fi
# You may need to change these variables
TOOLCHAIN="$HOME/TC" # This is where your toolchain is located. Current default ArchiKernel toolchain: https://github.com/ArchiDroid/Toolchain/tree/linaro-4.9-arm-linux-gnueabihf
TARGETZIPDIR="$HOME/shared/kernel/m0" # If valid, output zip will be moved there from default TARGETDIR location
BEEP=1 # This will beep three times on finish to wake me up :). Works even through SSH!
# Above settings should be enough, changing below things shouldn't be required
TARGETDIR="archikernel/flasher" # This is the general output path. Don't change it, change TARGETZIPDIR above instead
TARGETDIRKERNEL="$TARGETDIR/prebuilt" # This is where zImage is put, this shouldn't be changed
TARGETDIRMODULES="$TARGETDIRKERNEL/system/lib/modules" # Similar to above, but for modules
TARGETZIPNAME="ArchiKernel_$(date '+%y%m%d_%H%M%S')" # Name of output zip. By keeping a date here we can be sure that all zips will be unique
JOBS="$(grep -c "processor" "/proc/cpuinfo")" # Maximum number of jobs, can be declared statically if needed, default to number of threads of the CPU
SUGGESTED_PREFIX="arm-architoolchain-linux-gnueabihf"
SUGGESTED_TOOLCHAIN="https://github.com/ArchiDroid/Toolchain/tree/architoolchain-5.1-arm-linux-gnueabihf-cortex_a9_neon" # Suggested toolchain for this variant of AK
# This is where magic starts
for ARG in "$@"; do
case "$ARG" in
--source|source) SOURCE=1 ;;
--regen|regen|--regenerate|regenerate) REGEN=1 ;;
--clean|clean) CLEAN=1 ;;
--dirty|dirty) DIRTY=1 ;;
--configtest|configtest) CONFIGTEST=1 ;;
--bare|bare) BARE=1 ;;
--all|all) ALL=1 ;;
--version=*) TARGETZIPNAME="ArchiKernel_V$(echo "$ARG" | cut -d '=' -f2)" ;;
*) TARGETCONFIGS+=("$ARG") ;;
esac
done
PREFIXES="$SUGGESTED_PREFIX arm-architoolchain-linux-gnueabihf arm-linux-gnueabihf arm-eabi" # Valid prefixes used by ArchiToolchain, Linaro and Google
for PREFIX in $PREFIXES; do
if [[ -x "$TOOLCHAIN/bin/${PREFIX}-gcc" ]]; then
CROSS_COMPILE="$TOOLCHAIN/bin/${PREFIX}-"
echo "Found ${PREFIX} toolchain!"
echo
if [[ "$PREFIX" != "$SUGGESTED_PREFIX" ]]; then
echo "NOTICE: Your compiler looks good, but ArchiKernel suggests of using $SUGGESTED_PREFIX"
echo "Recommended toolchain mentioned above can be found here: $SUGGESTED_TOOLCHAIN"
echo "You can safely ignore this notice if you know what you're doing"
echo "Just keep in mind that outdated or buggy toolchains can cause compilation issues"
echo
fi
break
fi
done
if [[ -z "$CROSS_COMPILE" ]]; then
echo "ERROR: Could not find any valid toolchain prefix!"
echo "Make sure that $TOOLCHAIN/bin/PREFIX-gcc exists"
echo "Where PREFIX must be one of the following: $PREFIXES"
exit 1
fi
export ARCH=arm
export CROSS_COMPILE="$CROSS_COMPILE"
if [[ "$SOURCE" -eq 1 ]]; then
return
exit 0 # If we're in fact sourcing this file, this won't execute
fi
set -e
SCRIPTDIR="$(dirname "$0")"
# We may have build.sh symlinked e.g. to /bin/adkernel
# In such case, navigating to script's dir is not a way
if [[ -f "$SCRIPTDIR/Kconfig" ]]; then
cd "$SCRIPTDIR" # Navigate to proper dir
elif [[ ! -f "Kconfig" ]]; then
echo "ERROR: Couldn't find Kconfig"
echo "Make sure you're in proper dir!"
exit 1
fi
if [[ "$REGEN" -eq 1 ]]; then
find "arch/$ARCH/configs" -type f -iname "*_ak_defconfig" | while read TOREGEN; do
TOREGENSHORT="$(basename "$TOREGEN")"
echo "Regenerating $TOREGENSHORT"
make -j "$JOBS" "$TOREGENSHORT"
mv .config "$TOREGEN"
done
make -j "$JOBS" clean
make -j "$JOBS" mrproper
echo "All configs are regenerated!"
exit 0
fi
if [[ "$ALL" -eq 1 ]]; then
while read TARGETCONFIG; do
TARGETCONFIGS+=("$(basename "$TARGETCONFIG")")
done < <(find "arch/$ARCH/configs" -type f -iname "*_ak_defconfig")
fi
if [[ -z "$TARGETCONFIGS" ]]; then
if [[ "$CLEAN" -eq 0 && "$CONFIGTEST" -eq 0 && "$DIRTY" -eq 0 ]]; then
echo "ERROR: You didn't specify any config!"
echo
echo "If you want to use locally generated .config, try --configtest"
echo "If you want to build AK for all currently supported variants, try --all"
echo
echo "Otherwise, try invoking this script with argument which matches one of these:"
echo "-=-=-=-=-=-="
find "arch/$ARCH/configs" -type f -iname "*_ak_defconfig" | while read line; do
basename "$line"
done
echo "-=-=-=-=-=-="
echo
exit 1
else
TARGETCONFIGS+=("NULLCONFIG");
fi
fi
for TARGETCONFIG in "${TARGETCONFIGS[@]}"; do
(
if [[ "$DIRTY" -eq 0 ]]; then
make -j "$JOBS" clean
if [[ "$CONFIGTEST" -eq 1 && -f ".config" ]]; then
mv ".config" ".configBackup"
else
rm -f ".configBackup"
fi
make -j "$JOBS" mrproper
if [[ "$CLEAN" -eq 1 ]]; then
rm -f ".configBackup" # Just in case if somebody would call configtest with clean...
exit 0
fi
if [[ "$CONFIGTEST" -eq 1 && -f ".configBackup" ]]; then
mv ".configBackup" ".config"
elif [[ -f "arch/$ARCH/configs/$TARGETCONFIG" ]]; then
make -j "$JOBS" "$TARGETCONFIG"
APPLIEDCONFIG="$(echo $TARGETCONFIG | rev | cut -d'_' -f3- | rev)"
APPLIEDCONFIG="${APPLIEDCONFIG^^}" # To uppercase
else
echo "ERROR: Could not find specified config: arch/$ARCH/configs/$TARGETCONFIG"
continue
fi
fi
# Try to detect applied config if no config has been specified (e.g. --dirty)
if [[ -z "$APPLIEDCONFIG" ]]; then
APPLIEDCONFIG="Unknown"
CONFIGMD5="$(md5sum .config | awk '{print $1}')"
while read TOCHECK; do
if [[ "$(md5sum "$TOCHECK" | awk '{print $1}')" = "$CONFIGMD5" ]]; then
APPLIEDCONFIG="$(basename "$TOCHECK" | rev | cut -d'_' -f3- | rev)"
APPLIEDCONFIG="${APPLIEDCONFIG^^}" # To uppercase
break
fi
done < <(find "arch/$ARCH/configs" -type f -iname "*_ak_defconfig")
fi
make -j "$JOBS" all
if [[ "$BARE" -eq 1 ]]; then
continue
elif [[ -z "$(which zip)" ]]; then
echo "ERROR: Zip binary could not be found!"
echo "You can either install missing zip binary or build in --bare mode"
echo "For debian try: apt-get install zip"
exit 1
fi
mkdir -p "$TARGETDIRKERNEL" "$TARGETDIRMODULES"
cp "arch/$ARCH/boot/zImage" "$TARGETDIRKERNEL"
find "$TARGETDIRMODULES" -type f -iname "*.ko" | while read KO; do
rm -f "$KO"
done
find . -type f -iname "*.ko" | while read KO; do
echo "Including module: $(basename "$KO")"
${CROSS_COMPILE}strip --strip-unneeded "$KO"
cp "$KO" "$TARGETDIRMODULES"
done
THISZIPNAME="$TARGETZIPNAME-$APPLIEDCONFIG"
cd "$TARGETDIR"
zip -qry -9 "$THISZIPNAME.zip" . -x "*.zip"
if [[ ! -z "$TARGETZIPDIR" && -d "$TARGETZIPDIR" ]]; then
mv "$THISZIPNAME.zip" "$TARGETZIPDIR"
fi
echo "Done! Output zip: $THISZIPNAME.zip"
)
done
if [[ "$BEEP" -eq 1 ]]; then
echo -e "\a"
sleep 0.2
echo -e "\a"
sleep 0.2
echo -e "\a"
fi
echo "All tasks done! :)"
exit 0