-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild-kernel.sh
executable file
·178 lines (155 loc) · 4.14 KB
/
build-kernel.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
#!/bin/sh
set -e
# for catching make failing but hidden by tee
set -o pipefail
NBCPU=$(getconf _NPROCESSORS_ONLN)
MAKEOPTS="-j$(( $NBCPU + 1 ))"
#get script direcotory
SCRIPT_DIR=$(cd "$(dirname "$0")"|| exit;pwd)
if [ $# -lt 1 ]; then
echo "Usage: $(basename $0) arch BUILDER_NAME BUILD_NUMBER [build|modules]"
exit 1
fi
is_kernel() {
cd kernel-sources/linux-*/ || exit $?
}
# get into kernel directory
is_kernel
ARCH=$1
# make cannot handle ":" in a path, so we need to replace it
BUILDER_NAME=$(echo $2 | sed 's,:,_,g')
BUILD_NUMBER=$3
ACTION=$4
TOOLCHAIN_TODO=$(echo $2 | cut -d: -f3)
if [ -z "$TOOLCHAIN_TODO" ];then
echo "ERROR: I do not find the toolchain to use"
exit 1
else
echo "DEBUG: build use toolchain $TOOLCHAIN_TODO"
fi
# hacks before Gbuildbot has all args
if [ "$2" = 'modules' ];then
ACTION='modules'
fi
if [ -z "$ACTION" ];then
ACTION=build
fi
MAKEFUNC=do_make
if [ "$TOOLCHAIN_TODO" = 'gentoo' ];then
MAKEFUNC=do_native_make
fi
do_make() {
echo "DOMAKE $*"
make $*
}
do_native_make() {
echo "DOMAKE native $*"
docker run --privileged \
-v gdocker_worker_data:/buildbot \
docker-stage3-$ARCH:latest /gentoo/builder.sh $ARCH $(id -u) $(pwd) $FDIR $NBCPU $*
}
# renice itself
renice -n 19 -p $$
build() {
local defconfig="$1"
local toolchain="$2"
TOOLCHAIN_DIR="$TCONFIG/$HOST_ARCH/$ARCH/$toolchain"
echo "DEBUG: found toolchain $toolchain in $TOOLCHAIN_DIR"
if [ -e "$TOOLCHAIN_DIR/opts" ];then
TC_OPTS="$(cat $TOOLCHAIN_DIR/opts)"
MAKEOPTS="$TC_OPTS $MAKEOPTS"
fi
if [ -e "$TOOLCHAIN_DIR/version" ];then
echo "=== version of $toolchain ==="
$TOOLCHAIN_DIR/version
echo "============================="
fi
LINUX_ARCH=$ARCH
# insert ARCH hack for name here
case $ARCH in
amd64)
LINUX_ARCH=x86_64
;;
ppc64)
LINUX_ARCH=powerpc
;;
esac
FDIR="${SCRIPT_DIR}/linux-$ARCH-build/$BUILDER_NAME/$BUILD_NUMBER/$defconfig/$toolchain"
echo "DEBUG: $ACTION for $ARCH/$defconfig to $FDIR"
MAKEOPTS="$MAKEOPTS ARCH=$LINUX_ARCH O=$FDIR"
case $ACTION in
build)
echo "DO: mrproper"
$MAKEFUNC $MAKEOPTS mrproper
echo "DO: generate config from defconfig"
$MAKEFUNC $MAKEOPTS $defconfig | tee --append $FDIR/build.log
if [ -e "$BCDIR/config" ];then
cp $FDIR/.config $FDIR/.config.old
echo "DEBUG: config hacks"
for config in $(ls $BCDIR/config)
do
echo "DEBUG: add config $config"
cat $BCDIR/config/$config >> $FDIR/.config
done
$MAKEFUNC $MAKEOPTS olddefconfig >> $FDIR/build.log
diff -u $FDIR/.config.old $FDIR/.config || true
fi
echo "DO: build"
$MAKEFUNC $MAKEOPTS | tee --append $FDIR/build.log
;;
modules)
rm -f $FDIR/nomodule
grep -q 'CONFIG_MODULES=y' $FDIR/.config || touch $FDIR/nomodule
if [ -e $FDIR/nomodule ];then
echo "INFO: modules are disabled, skipping"
return 0
fi
echo "DO: build modules"
$MAKEFUNC $MAKEOPTS modules | tee --append $FDIR/build.log
echo "DO: install modules"
mkdir $FDIR/modules
$MAKEFUNC $MAKEOPTS modules_install INSTALL_MOD_PATH="$FDIR/modules/" | tee --append $FDIR/build.log
CPWD=$(pwd)
cd $FDIR/modules
echo "DO: targz modules"
tar czf ../modules.tar.gz lib
cd $CPWD
rm -r "$FDIR/modules/"
;;
*)
echo "ERROR: unknow action: $ACTION"
exit 1
;;
esac
}
BCONFIG="${SCRIPT_DIR}/build-config/"
if [ ! -e "$BCONFIG/$ARCH" ];then
echo "ERROR: $ARCH is unsupported"
exit 1
fi
TCONFIG=${SCRIPT_DIR}/toolchains
HOST_ARCH=$(uname -m)
if [ ! -e "$TCONFIG/$HOST_ARCH" ];then
echo "ERROR: build not handled for host arch $HOST_ARCH"
exit 1
fi
if [ ! -e "$TCONFIG/$HOST_ARCH/$ARCH" ];then
echo "ERROR: no toolchain for $ARCH"
exit 1
fi
if [ ! -e "$TCONFIG/$HOST_ARCH/$ARCH/$TOOLCHAIN_TODO" ];then
echo "ERROR: no toolchain $TOOLCHAIN_TODO for $ARCH"
exit 1
fi
for defconfigdir in $(ls $BCONFIG/$ARCH)
do
echo "INFO: $ARCH $defconfigdir"
BCDIR=$BCONFIG/$ARCH/$defconfigdir
if [ -e $BCDIR/defconfig ];then
defconfig="$(cat $BCDIR/defconfig)"
else
echo "ERROR: no defconfig in $BCDIR, defaulting to defconfig"
defconfig="defconfig"
fi
build $defconfig $TOOLCHAIN_TODO
done