ansible: Replace sudo by become
[lttng-ci.git] / scripts / lttng-modules / param-build.sh
CommitLineData
f3d8604b
MJ
1#!/bin/sh -exu
2#
3# Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
339db64d
MJ
18## FUNCTIONS ##
19
f3d8604b
MJ
20# Kernel version compare functions
21verlte() {
22 [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | head -n1`" ]
23}
24
25verlt() {
26 [ "$1" = "$2" ] && return 1 || verlte $1 $2
27}
28
29vergte() {
30 [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | tail -n1`" ]
31}
32
33vergt() {
34 [ "$1" = "$2" ] && return 1 || vergte $1 $2
35}
36
339db64d 37
7e02032c
MJ
38prepare_lnx_sources() {
39
40 outdir=$1
41
42 if [ "$outdir" = "." ]; then
43 koutput=""
44 else
45 koutput="O=\"${outdir}\""
46 fi
47
48 # Generate kernel configuration
49 case "$kversion" in
50 Ubuntu*)
51 fakeroot debian/rules clean
52 fakeroot debian/rules genconfigs
53 cp CONFIGS/${ubuntu_config} "${outdir}"/.config
54 ;;
55 *)
a822250c 56 # Que sera sera
e6416ee0 57 make ${koutput} allyesconfig CC=$CC
7e02032c
MJ
58 ;;
59 esac
60
61 # GCC 4.8
62 sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
63
64 # Don't try to sign modules
65 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
66
9ef18fa2
MJ
67 # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails
68 sed -i "s/CONFIG_STACK_VALIDATION=y/# CONFIG_STACK_VALIDATION is not set/g" "${outdir}"/.config
69
7e02032c
MJ
70 # Enable CONFIG_KALLSYMS_ALL
71 echo "CONFIG_KPROBES=y" >> "${outdir}"/.config
72 echo "CONFIG_FTRACE=y" >> "${outdir}"/.config
73 echo "CONFIG_BLK_DEV_IO_TRACE=y" >> "${outdir}"/.config
74 echo "CONFIG_TRACEPOINTS=y" >> "${outdir}"/.config
75 echo "CONFIG_KALLSYMS_ALL=y" >> "${outdir}"/.config
76
77
e6416ee0
MJ
78 make ${koutput} silentoldconfig CC=$CC
79 make ${koutput} modules_prepare CC=$CC
7e02032c
MJ
80
81 # Version specific tasks
82 case "$kversion" in
83 Ubuntu*)
84 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
85 ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')
86 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> ${outdir}/include/generated/utsrelease.h
87 ;;
88 esac
89
90 # On powerpc this object is required to link modules
91 if [ "${karch}" = "powerpc" ]; then
e6416ee0 92 make ${koutput} arch/powerpc/lib/crtsavres.o CC=$CC
7e02032c
MJ
93 fi
94}
95
96
97
339db64d
MJ
98build_modules() {
99
100 kdir="$1"
101 bdir="$2"
102
103 # Get kernel version from source tree
104 cd "${kdir}"
105 kversion=$(make kernelversion)
106
107 # Enter lttng-modules source dir
108 cd "${LTTSRCDIR}"
109
110 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
111 # timekeeping subsystem. We want those build to fail.
112 if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \
113 { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then
114
115 set +e
116
117 # Build modules
e6416ee0 118 KERNELDIR="${kdir}" make -j${NPROC} V=1 CC=$CC
339db64d
MJ
119
120 # We expect this build to fail, if it doesn't, fail the job.
121 if [ "$?" -eq 0 ]; then
122 exit 1
123 fi
124
125 # We have to publish at least one file or the build will fail
7e02032c 126 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko"
339db64d
MJ
127
128 set -e
129
e6416ee0 130 KERNELDIR="${kdir}" make clean CC=$CC
7e02032c 131
339db64d
MJ
132 else # Regular build
133
134 # Build modules against full kernel sources
e6416ee0 135 KERNELDIR="${kdir}" make -j${NPROC} V=1 CC=$CC
339db64d
MJ
136
137 # Install modules to build dir
e6416ee0 138 KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install CC=$CC
339db64d
MJ
139
140 # Clean build dir
e6416ee0 141 KERNELDIR="${kdir}" make clean CC=$CC
339db64d
MJ
142 fi
143}
144
145
146## MAIN ##
147
e6416ee0
MJ
148# Use gcc 4.9, older kernel don't build with gcc 5
149export CC=gcc-4.9
150
f3d8604b
MJ
151# Use all CPU cores
152NPROC=$(nproc)
153
339db64d
MJ
154LTTSRCDIR="${WORKSPACE}/src/lttng-modules"
155LNXSRCDIR="${WORKSPACE}/src/linux"
156
157LNXBUILDDIR="${WORKSPACE}/build/linux"
158LNXHDRDIR="${WORKSPACE}/build/linux-headers"
159
a822250c 160LTTBUILDKSRCDIR="${WORKSPACE}/build/lttng-modules-ksrc"
339db64d
MJ
161LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr"
162
163
7e02032c
MJ
164# Setup cross compile env if available
165if [ "x${cross_arch:-}" != "x" ]; then
166
167 case "$cross_arch" in
168 "armhf")
169 karch="arm"
170 cross_compile="arm-linux-gnueabihf-"
171 ubuntu_config="armhf-config.flavour.generic"
172 ;;
173
174 "arm64")
175 karch="arm64"
176 cross_compile="aarch64-linux-gnu-"
177 ubuntu_config="arm64-config.flavour.generic"
178 ;;
179
180 "powerpc")
181 karch="powerpc"
182 cross_compile="powerpc-linux-gnu-"
183 ubuntu_config="powerpc-config.flavour.powerpc-smp"
184 ;;
185
186 "ppc64el")
187 karch="powerpc"
188 cross_compile="powerpc64le-linux-gnu-"
189 ubuntu_config="ppc64el-config.flavour.generic"
190 ;;
191
192 *)
193 echo "Unsupported cross arch $arch"
194 exit 1
195 ;;
196 esac
339db64d 197
7e02032c
MJ
198 # Export variables used by Kbuild for cross compilation
199 export ARCH="${karch}"
200 export CROSS_COMPILE="${cross_compile}"
339db64d 201
339db64d 202
7e02032c
MJ
203# Set arch specific values if we are not cross compiling
204elif [ "x${arch:-}" != "x" ]; then
205 case "$arch" in
206 "x86-32")
207 karch="x86"
208 ubuntu_config="i386-config.flavour.generic"
209 ;;
210
211 "x86-64")
212 karch="x86"
213 ubuntu_config="amd64-config.flavour.generic"
214 ;;
215
216 "armhf")
217 karch="arm"
218 ubuntu_config="armhf-config.flavour.generic"
219 ;;
220
221 "arm64")
222 karch="arm64"
223 ubuntu_config="arm64-config.flavour.generic"
224 ;;
225
226 "powerpc")
227 karch="powerpc"
228 ubuntu_config="powerpc-config.flavour.powerpc-smp"
229 ;;
230
231 "ppc64el")
232 karch="powerpc"
233 ubuntu_config="ppc64el-config.flavour.generic"
234 ;;
235
236 *)
237 echo "Unsupported arch $arch"
238 exit 1
239 ;;
240 esac
241else
242 echo "Not arch or cross_arch specified"
243 exit 1
244fi
339db64d 245
339db64d 246
b214d997 247
339db64d
MJ
248
249# Create build directories
a822250c 250mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}"
7e02032c 251
339db64d
MJ
252
253
254## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
255
256# Enter linux source dir
257cd "${LNXSRCDIR}"
258
7e02032c 259prepare_lnx_sources "."
339db64d 260
b214d997
MJ
261# For RT kernels, copy version file
262if [ -s localversion-rt ]; then
263 cp -a localversion-rt "${LNXHDRDIR}"
339db64d
MJ
264fi
265
b214d997
MJ
266# Copy all Makefile related stuff
267find . -path './include/*' -prune \
268 -o -path './scripts/*' -prune -o -type f \
269 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
270 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
271 -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 272
b214d997
MJ
273# Copy base scripts and include dirs
274cp -a scripts include "${LNXHDRDIR}"
339db64d 275
b214d997
MJ
276# Copy arch includes
277(find arch -name include -type d -print | \
278 xargs -n1 -i: find : -type f) | \
279 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 280
b214d997
MJ
281# Copy arch scripts
282(find arch -name scripts -type d -print | \
283 xargs -n1 -i: find : -type f) | \
284 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 285
b214d997 286# Cleanup scripts
339db64d
MJ
287rm -f "${LNXHDRDIR}/scripts/*.o"
288rm -f "${LNXHDRDIR}/scripts/*/*.o"
289
b214d997 290# On powerpc this object is required to link modules
339db64d
MJ
291if [ "${karch}" = "powerpc" ]; then
292 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
293fi
294
b214d997
MJ
295# Copy modules related stuff, if available
296if [ -s Module.symvers ]; then
297 cp Module.symvers "${LNXHDRDIR}"
298fi
299
300if [ -s System.map ]; then
301 cp System.map "${LNXHDRDIR}"
302fi
303
304if [ -s Module.markers ]; then
305 cp Module.markers "${LNXHDRDIR}"
339db64d
MJ
306fi
307
b214d997
MJ
308# Copy config file
309cp .config "${LNXHDRDIR}"
339db64d
MJ
310
311# Make sure the Makefile and version.h have a matching timestamp so that
312# external modules can be built
313if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
314 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
315elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
316 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
317else
318 echo "Missing version.h"
319 exit 1
320fi
321touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
322
323# Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
324cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
325
326
327
328
329## PREPARE FULL LINUX SOURCE TREE
f3d8604b
MJ
330
331# Enter linux source dir
332cd "${LNXSRCDIR}"
333
339db64d 334# Make sure linux source dir is clean
7e02032c 335git clean -xdf
f3d8604b 336
7e02032c 337prepare_lnx_sources "${LNXBUILDDIR}"
b214d997 338
f3d8604b 339
7e02032c 340## BUILD modules
f3d8604b 341
339db64d 342# Build modules against full kernel sources
a822250c 343build_modules "${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}"
f3d8604b 344
339db64d
MJ
345# Build modules against kernel headers
346build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
f3d8604b 347
b214d997 348# Make sure modules were built
a822250c
MJ
349tree "${LTTBUILDKSRCDIR}"
350if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
7e02032c
MJ
351 echo "No modules built!"
352 exit 1
353fi
354
a822250c
MJ
355tree "${LTTBUILDKHDRDIR}"
356if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
7e02032c
MJ
357 echo "No modules built!"
358 exit 1
359fi
b214d997 360
f3d8604b 361# EOF
This page took 0.037744 seconds and 4 git commands to generate.