Update lttng-modules build scripts
[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 *)
56 make ${koutput} defconfig
57 ;;
58 esac
59
60 # GCC 4.8
61 sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
62
63 # Don't try to sign modules
64 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
65
66 # Enable CONFIG_KALLSYMS_ALL
67 echo "CONFIG_KPROBES=y" >> "${outdir}"/.config
68 echo "CONFIG_FTRACE=y" >> "${outdir}"/.config
69 echo "CONFIG_BLK_DEV_IO_TRACE=y" >> "${outdir}"/.config
70 echo "CONFIG_TRACEPOINTS=y" >> "${outdir}"/.config
71 echo "CONFIG_KALLSYMS_ALL=y" >> "${outdir}"/.config
72
73
74 make ${koutput} silentoldconfig
75 make ${koutput} modules_prepare
76
77 # Version specific tasks
78 case "$kversion" in
79 Ubuntu*)
80 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
81 ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')
82 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> ${outdir}/include/generated/utsrelease.h
83 ;;
84 esac
85
86 # On powerpc this object is required to link modules
87 if [ "${karch}" = "powerpc" ]; then
88 make ${koutput} arch/powerpc/lib/crtsavres.o
89 fi
90}
91
92
93
339db64d
MJ
94build_modules() {
95
96 kdir="$1"
97 bdir="$2"
98
99 # Get kernel version from source tree
100 cd "${kdir}"
101 kversion=$(make kernelversion)
102
103 # Enter lttng-modules source dir
104 cd "${LTTSRCDIR}"
105
106 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
107 # timekeeping subsystem. We want those build to fail.
108 if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \
109 { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then
110
111 set +e
112
113 # Build modules
114 KERNELDIR="${kdir}" make -j${NPROC} V=1
115
116 # We expect this build to fail, if it doesn't, fail the job.
117 if [ "$?" -eq 0 ]; then
118 exit 1
119 fi
120
121 # We have to publish at least one file or the build will fail
7e02032c 122 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko"
339db64d
MJ
123
124 set -e
125
7e02032c
MJ
126 KERNELDIR="${kdir}" make clean
127
339db64d
MJ
128 else # Regular build
129
130 # Build modules against full kernel sources
131 KERNELDIR="${kdir}" make -j${NPROC} V=1
132
133 # Install modules to build dir
134 KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install
135
136 # Clean build dir
137 KERNELDIR="${kdir}" make clean
138 fi
139}
140
141
142## MAIN ##
143
f3d8604b
MJ
144# Use all CPU cores
145NPROC=$(nproc)
146
339db64d
MJ
147LTTSRCDIR="${WORKSPACE}/src/lttng-modules"
148LNXSRCDIR="${WORKSPACE}/src/linux"
149
150LNXBUILDDIR="${WORKSPACE}/build/linux"
151LNXHDRDIR="${WORKSPACE}/build/linux-headers"
152
153LTTBUILKSRCDDIR="${WORKSPACE}/build/lttng-modules-ksrc"
154LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr"
155
156
7e02032c
MJ
157# Setup cross compile env if available
158if [ "x${cross_arch:-}" != "x" ]; then
159
160 case "$cross_arch" in
161 "armhf")
162 karch="arm"
163 cross_compile="arm-linux-gnueabihf-"
164 ubuntu_config="armhf-config.flavour.generic"
165 ;;
166
167 "arm64")
168 karch="arm64"
169 cross_compile="aarch64-linux-gnu-"
170 ubuntu_config="arm64-config.flavour.generic"
171 ;;
172
173 "powerpc")
174 karch="powerpc"
175 cross_compile="powerpc-linux-gnu-"
176 ubuntu_config="powerpc-config.flavour.powerpc-smp"
177 ;;
178
179 "ppc64el")
180 karch="powerpc"
181 cross_compile="powerpc64le-linux-gnu-"
182 ubuntu_config="ppc64el-config.flavour.generic"
183 ;;
184
185 *)
186 echo "Unsupported cross arch $arch"
187 exit 1
188 ;;
189 esac
339db64d 190
7e02032c
MJ
191 # Export variables used by Kbuild for cross compilation
192 export ARCH="${karch}"
193 export CROSS_COMPILE="${cross_compile}"
339db64d 194
339db64d 195
7e02032c
MJ
196# Set arch specific values if we are not cross compiling
197elif [ "x${arch:-}" != "x" ]; then
198 case "$arch" in
199 "x86-32")
200 karch="x86"
201 ubuntu_config="i386-config.flavour.generic"
202 ;;
203
204 "x86-64")
205 karch="x86"
206 ubuntu_config="amd64-config.flavour.generic"
207 ;;
208
209 "armhf")
210 karch="arm"
211 ubuntu_config="armhf-config.flavour.generic"
212 ;;
213
214 "arm64")
215 karch="arm64"
216 ubuntu_config="arm64-config.flavour.generic"
217 ;;
218
219 "powerpc")
220 karch="powerpc"
221 ubuntu_config="powerpc-config.flavour.powerpc-smp"
222 ;;
223
224 "ppc64el")
225 karch="powerpc"
226 ubuntu_config="ppc64el-config.flavour.generic"
227 ;;
228
229 *)
230 echo "Unsupported arch $arch"
231 exit 1
232 ;;
233 esac
234else
235 echo "Not arch or cross_arch specified"
236 exit 1
237fi
339db64d 238
339db64d 239
b214d997 240
339db64d
MJ
241
242# Create build directories
7e02032c
MJ
243mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILKSRCDDIR}" "${LTTBUILDKHDRDIR}"
244
339db64d
MJ
245
246
247## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
248
249# Enter linux source dir
250cd "${LNXSRCDIR}"
251
7e02032c 252prepare_lnx_sources "."
339db64d 253
b214d997
MJ
254# For RT kernels, copy version file
255if [ -s localversion-rt ]; then
256 cp -a localversion-rt "${LNXHDRDIR}"
339db64d
MJ
257fi
258
b214d997
MJ
259# Copy all Makefile related stuff
260find . -path './include/*' -prune \
261 -o -path './scripts/*' -prune -o -type f \
262 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
263 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
264 -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 265
b214d997
MJ
266# Copy base scripts and include dirs
267cp -a scripts include "${LNXHDRDIR}"
339db64d 268
b214d997
MJ
269# Copy arch includes
270(find arch -name include -type d -print | \
271 xargs -n1 -i: find : -type f) | \
272 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 273
b214d997
MJ
274# Copy arch scripts
275(find arch -name scripts -type d -print | \
276 xargs -n1 -i: find : -type f) | \
277 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 278
b214d997 279# Cleanup scripts
339db64d
MJ
280rm -f "${LNXHDRDIR}/scripts/*.o"
281rm -f "${LNXHDRDIR}/scripts/*/*.o"
282
b214d997 283# On powerpc this object is required to link modules
339db64d
MJ
284if [ "${karch}" = "powerpc" ]; then
285 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
286fi
287
b214d997
MJ
288# Copy modules related stuff, if available
289if [ -s Module.symvers ]; then
290 cp Module.symvers "${LNXHDRDIR}"
291fi
292
293if [ -s System.map ]; then
294 cp System.map "${LNXHDRDIR}"
295fi
296
297if [ -s Module.markers ]; then
298 cp Module.markers "${LNXHDRDIR}"
339db64d
MJ
299fi
300
b214d997
MJ
301# Copy config file
302cp .config "${LNXHDRDIR}"
339db64d
MJ
303
304# Make sure the Makefile and version.h have a matching timestamp so that
305# external modules can be built
306if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
307 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
308elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
309 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
310else
311 echo "Missing version.h"
312 exit 1
313fi
314touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
315
316# Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
317cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
318
319
320
321
322## PREPARE FULL LINUX SOURCE TREE
f3d8604b
MJ
323
324# Enter linux source dir
325cd "${LNXSRCDIR}"
326
339db64d 327# Make sure linux source dir is clean
7e02032c 328git clean -xdf
f3d8604b 329
7e02032c 330prepare_lnx_sources "${LNXBUILDDIR}"
b214d997 331
f3d8604b 332
7e02032c 333## BUILD modules
f3d8604b 334
339db64d
MJ
335# Build modules against full kernel sources
336build_modules "${LNXBUILDDIR}" "${LTTBUILKSRCDDIR}"
f3d8604b 337
339db64d
MJ
338# Build modules against kernel headers
339build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
f3d8604b 340
b214d997 341# Make sure modules were built
7e02032c
MJ
342if [ "x$(find "${LTTBUILKSRCDDIR}" -name "*.ko" -printf yes -quit)" != "xyes" ]; then
343 echo "No modules built!"
344 exit 1
345fi
346
347if [ "x$(find "${LTTBUILDKHDRDIR}" -name "*.ko" -printf yes -quit)" != "xyes" ]; then
348 echo "No modules built!"
349 exit 1
350fi
b214d997 351
f3d8604b 352# EOF
This page took 0.036374 seconds and 4 git commands to generate.