Add asciidoc dep to lttng-tools
[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
MJ
37
38build_modules() {
39
40 kdir="$1"
41 bdir="$2"
42
43 # Get kernel version from source tree
44 cd "${kdir}"
45 kversion=$(make kernelversion)
46
47 # Enter lttng-modules source dir
48 cd "${LTTSRCDIR}"
49
50 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
51 # timekeeping subsystem. We want those build to fail.
52 if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \
53 { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then
54
55 set +e
56
57 # Build modules
58 KERNELDIR="${kdir}" make -j${NPROC} V=1
59
60 # We expect this build to fail, if it doesn't, fail the job.
61 if [ "$?" -eq 0 ]; then
62 exit 1
63 fi
64
65 # We have to publish at least one file or the build will fail
66 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt"
67
68 set -e
69
70 else # Regular build
71
72 # Build modules against full kernel sources
73 KERNELDIR="${kdir}" make -j${NPROC} V=1
74
75 # Install modules to build dir
76 KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install
77
78 # Clean build dir
79 KERNELDIR="${kdir}" make clean
80 fi
81}
82
83
84## MAIN ##
85
f3d8604b
MJ
86# Use all CPU cores
87NPROC=$(nproc)
88
339db64d
MJ
89LTTSRCDIR="${WORKSPACE}/src/lttng-modules"
90LNXSRCDIR="${WORKSPACE}/src/linux"
91
92LNXBUILDDIR="${WORKSPACE}/build/linux"
93LNXHDRDIR="${WORKSPACE}/build/linux-headers"
94
95LTTBUILKSRCDDIR="${WORKSPACE}/build/lttng-modules-ksrc"
96LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr"
97
98
99# Set arch specific values
100case "$arch" in
101 "x86-32")
102 karch="x86"
b214d997 103 cross_compile=""
339db64d
MJ
104 ;;
105
106 "x86-64")
107 karch="x86"
b214d997 108 cross_compile=""
339db64d
MJ
109 ;;
110
111 "armhf")
112 karch="arm"
b214d997 113 cross_compile="arm-linux-gnueabihf-"
339db64d
MJ
114 ;;
115
116 "arm64")
117 karch="arm64"
b214d997 118 cross_compile="aarch64-linux-gnu-"
339db64d
MJ
119 ;;
120
121 "powerpc")
122 karch="powerpc"
b214d997 123 cross_compile="powerpc-linux-gnu-"
339db64d
MJ
124 ;;
125
b214d997 126 "ppc64el")
339db64d 127 karch="powerpc"
b214d997 128 cross_compile="powerpc64le-linux-gnu-"
339db64d
MJ
129 ;;
130
131 *)
132 echo "Unsupported arch $arch"
133 exit 1
134 ;;
135esac
136
b214d997
MJ
137# Setup cross compile env if required
138if [ "${cross_build:-}" = "true" ]; then
139 export ARCH="${karch}"
140 export CROSS_COMPILE="${cross_compile}"
141fi
142
339db64d
MJ
143
144# Create build directories
145mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}"
146
147
148## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
149
150# Enter linux source dir
151cd "${LNXSRCDIR}"
152
153# Prepare linux sources for headers install
b214d997
MJ
154make allyesconfig
155sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" .config
156make silentoldconfig
339db64d
MJ
157make modules_prepare
158
b214d997
MJ
159# Version specific tasks
160case "$kversion" in
161 Ubuntu*)
162 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
163 ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')
164 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> include/generated/utsrelease.h
165 ;;
166esac
339db64d 167
b214d997
MJ
168# For RT kernels, copy version file
169if [ -s localversion-rt ]; then
170 cp -a localversion-rt "${LNXHDRDIR}"
339db64d
MJ
171fi
172
b214d997
MJ
173# Copy all Makefile related stuff
174find . -path './include/*' -prune \
175 -o -path './scripts/*' -prune -o -type f \
176 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
177 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
178 -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 179
b214d997
MJ
180# Copy base scripts and include dirs
181cp -a scripts include "${LNXHDRDIR}"
339db64d 182
b214d997
MJ
183# Copy arch includes
184(find arch -name include -type d -print | \
185 xargs -n1 -i: find : -type f) | \
186 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 187
b214d997
MJ
188# Copy arch scripts
189(find arch -name scripts -type d -print | \
190 xargs -n1 -i: find : -type f) | \
191 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
339db64d 192
b214d997 193# Cleanup scripts
339db64d
MJ
194rm -f "${LNXHDRDIR}/scripts/*.o"
195rm -f "${LNXHDRDIR}/scripts/*/*.o"
196
b214d997 197# On powerpc this object is required to link modules
339db64d 198if [ "${karch}" = "powerpc" ]; then
b214d997 199 make arch/powerpc/lib/crtsavres.o
339db64d
MJ
200 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
201fi
202
b214d997
MJ
203# Copy modules related stuff, if available
204if [ -s Module.symvers ]; then
205 cp Module.symvers "${LNXHDRDIR}"
206fi
207
208if [ -s System.map ]; then
209 cp System.map "${LNXHDRDIR}"
210fi
211
212if [ -s Module.markers ]; then
213 cp Module.markers "${LNXHDRDIR}"
339db64d
MJ
214fi
215
b214d997
MJ
216# Copy config file
217cp .config "${LNXHDRDIR}"
339db64d
MJ
218
219# Make sure the Makefile and version.h have a matching timestamp so that
220# external modules can be built
221if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
222 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
223elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
224 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
225else
226 echo "Missing version.h"
227 exit 1
228fi
229touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
230
231# Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
232cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
233
234
235
236
237## PREPARE FULL LINUX SOURCE TREE
f3d8604b
MJ
238
239# Enter linux source dir
240cd "${LNXSRCDIR}"
241
339db64d
MJ
242# Make sure linux source dir is clean
243make mrproper
244
f3d8604b 245# Prepare linux sources for modules OOT build
b214d997
MJ
246make O="${LNXBUILDDIR}" allyesconfig
247sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${LNXBUILDDIR}"/.config
248make O="${LNXBUILDDIR}" silentoldconfig
f3d8604b
MJ
249make O="${LNXBUILDDIR}" modules_prepare
250
b214d997
MJ
251# On powerpc this object is required to link modules
252if [ "${karch}" = "powerpc" ]; then
253 make O="${LNXBUILDDIR}" arch/powerpc/lib/crtsavres.o
254fi
255
339db64d 256# Version specific tasks
f3d8604b
MJ
257case "$kversion" in
258 Ubuntu*)
259 #fakeroot debian/rules clean
260 #fakeroot debian/rules genconfigs
261 #cp CONFIGS/amd64-config.flavour.generic .config
262
263 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
264 ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')
265 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> ${LNXBUILDDIR}/include/generated/utsrelease.h
266 ;;
267esac
268
339db64d
MJ
269# Build modules against full kernel sources
270build_modules "${LNXBUILDDIR}" "${LTTBUILKSRCDDIR}"
f3d8604b 271
339db64d
MJ
272# Build modules against kernel headers
273build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
f3d8604b 274
b214d997
MJ
275# Make sure modules were built
276find "${LNXBUILDDIR}" -name "*.ko"
277find "${LNXHDRDIR}" -name "*.ko"
278
f3d8604b 279# EOF
This page took 0.034738 seconds and 4 git commands to generate.