Added new nodes
[lttng-ci.git] / scripts / lttng-modules / param-build.sh
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
18 ## FUNCTIONS ##
19
20 # Kernel version compare functions
21 verlte() {
22 [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | head -n1`" ]
23 }
24
25 verlt() {
26 [ "$1" = "$2" ] && return 1 || verlte $1 $2
27 }
28
29 vergte() {
30 [ "$1" = "`printf '%s\n%s' $1 $2 | sort -V | tail -n1`" ]
31 }
32
33 vergt() {
34 [ "$1" = "$2" ] && return 1 || vergte $1 $2
35 }
36
37
38 build_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
86 # Use all CPU cores
87 NPROC=$(nproc)
88
89 LTTSRCDIR="${WORKSPACE}/src/lttng-modules"
90 LNXSRCDIR="${WORKSPACE}/src/linux"
91
92 LNXBUILDDIR="${WORKSPACE}/build/linux"
93 LNXHDRDIR="${WORKSPACE}/build/linux-headers"
94
95 LTTBUILKSRCDDIR="${WORKSPACE}/build/lttng-modules-ksrc"
96 LTTBUILDKHDRDIR="${WORKSPACE}/build/lttng-modules-khdr"
97
98
99 # Set arch specific values
100 case "$arch" in
101 "x86-32")
102 karch="x86"
103 cross_compile=""
104 ;;
105
106 "x86-64")
107 karch="x86"
108 cross_compile=""
109 ;;
110
111 "armhf")
112 karch="arm"
113 cross_compile="arm-linux-gnueabihf-"
114 ;;
115
116 "arm64")
117 karch="arm64"
118 cross_compile="aarch64-linux-gnu-"
119 ;;
120
121 "powerpc")
122 karch="powerpc"
123 cross_compile="powerpc-linux-gnu-"
124 ;;
125
126 "ppc64el")
127 karch="powerpc"
128 cross_compile="powerpc64le-linux-gnu-"
129 ;;
130
131 *)
132 echo "Unsupported arch $arch"
133 exit 1
134 ;;
135 esac
136
137 # Setup cross compile env if required
138 if [ "${cross_build:-}" = "true" ]; then
139 export ARCH="${karch}"
140 export CROSS_COMPILE="${cross_compile}"
141 fi
142
143
144 # Create build directories
145 mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}"
146
147
148 ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
149
150 # Enter linux source dir
151 cd "${LNXSRCDIR}"
152
153 # Prepare linux sources for headers install
154 make allyesconfig
155 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" .config
156 make silentoldconfig
157 make modules_prepare
158
159 # Version specific tasks
160 case "$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 ;;
166 esac
167
168 # For RT kernels, copy version file
169 if [ -s localversion-rt ]; then
170 cp -a localversion-rt "${LNXHDRDIR}"
171 fi
172
173 # Copy all Makefile related stuff
174 find . -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}"
179
180 # Copy base scripts and include dirs
181 cp -a scripts include "${LNXHDRDIR}"
182
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}"
187
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}"
192
193 # Cleanup scripts
194 rm -f "${LNXHDRDIR}/scripts/*.o"
195 rm -f "${LNXHDRDIR}/scripts/*/*.o"
196
197 # On powerpc this object is required to link modules
198 if [ "${karch}" = "powerpc" ]; then
199 make arch/powerpc/lib/crtsavres.o
200 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
201 fi
202
203 # Copy modules related stuff, if available
204 if [ -s Module.symvers ]; then
205 cp Module.symvers "${LNXHDRDIR}"
206 fi
207
208 if [ -s System.map ]; then
209 cp System.map "${LNXHDRDIR}"
210 fi
211
212 if [ -s Module.markers ]; then
213 cp Module.markers "${LNXHDRDIR}"
214 fi
215
216 # Copy config file
217 cp .config "${LNXHDRDIR}"
218
219 # Make sure the Makefile and version.h have a matching timestamp so that
220 # external modules can be built
221 if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
222 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
223 elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
224 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
225 else
226 echo "Missing version.h"
227 exit 1
228 fi
229 touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
230
231 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
232 cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
233
234
235
236
237 ## PREPARE FULL LINUX SOURCE TREE
238
239 # Enter linux source dir
240 cd "${LNXSRCDIR}"
241
242 # Make sure linux source dir is clean
243 make mrproper
244
245 # Prepare linux sources for modules OOT build
246 make O="${LNXBUILDDIR}" allyesconfig
247 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${LNXBUILDDIR}"/.config
248 make O="${LNXBUILDDIR}" silentoldconfig
249 make O="${LNXBUILDDIR}" modules_prepare
250
251 # On powerpc this object is required to link modules
252 if [ "${karch}" = "powerpc" ]; then
253 make O="${LNXBUILDDIR}" arch/powerpc/lib/crtsavres.o
254 fi
255
256 # Version specific tasks
257 case "$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 ;;
267 esac
268
269 # Build modules against full kernel sources
270 build_modules "${LNXBUILDDIR}" "${LTTBUILKSRCDDIR}"
271
272 # Build modules against kernel headers
273 build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
274
275 # Make sure modules were built
276 find "${LNXBUILDDIR}" -name "*.ko"
277 find "${LNXHDRDIR}" -name "*.ko"
278
279 # EOF
This page took 0.036619 seconds and 5 git commands to generate.