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