Commit | Line | Data |
---|---|---|
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 |
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 | ||
339db64d MJ |
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 | ||
f3d8604b MJ |
86 | # Use all CPU cores |
87 | NPROC=$(nproc) | |
88 | ||
339db64d MJ |
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 | ;; | |
104 | ||
105 | "x86-64") | |
106 | karch="x86" | |
107 | ;; | |
108 | ||
109 | "armhf") | |
110 | karch="arm" | |
111 | ;; | |
112 | ||
113 | "arm64") | |
114 | karch="arm64" | |
115 | ;; | |
116 | ||
117 | "powerpc") | |
118 | karch="powerpc" | |
119 | ;; | |
120 | ||
121 | "ppc64|ppc64el") | |
122 | karch="powerpc" | |
123 | ;; | |
124 | ||
125 | *) | |
126 | echo "Unsupported arch $arch" | |
127 | exit 1 | |
128 | ;; | |
129 | esac | |
130 | ||
131 | ||
132 | # Create build directories | |
133 | mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" | |
134 | ||
135 | ||
136 | ## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL | |
137 | ||
138 | # Enter linux source dir | |
139 | cd "${LNXSRCDIR}" | |
140 | ||
141 | # Prepare linux sources for headers install | |
142 | make defconfig | |
f3d8604b | 143 | |
339db64d MJ |
144 | # Enable CONFIG_KALLSYMS_ALL |
145 | sed -i "s/# CONFIG_KALLSYMS_ALL is not set/CONFIG_KALLSYMS_ALL=y/g" .config | |
146 | ||
147 | make modules_prepare | |
148 | ||
149 | # first copy everything | |
150 | cp --parents `find -type f -name "Makefile*" -o -name "Kconfig*"` "${LNXHDRDIR}" | |
151 | ||
152 | if [ -s Module.symvers ]; then | |
153 | cp Module.symvers "${LNXHDRDIR}" | |
154 | fi | |
155 | ||
156 | if [ -s System.map ]; then | |
157 | cp System.map "${LNXHDRDIR}" | |
158 | fi | |
159 | ||
160 | if [ -s Module.markers ]; then | |
161 | cp Module.markers "${LNXHDRDIR}" | |
162 | fi | |
163 | ||
164 | # then drop all but the needed Makefiles/Kconfig files | |
165 | rm -rf "${LNXHDRDIR}/Documentation" | |
166 | rm -rf "${LNXHDRDIR}/scripts" | |
167 | rm -rf "${LNXHDRDIR}/include" | |
168 | ||
169 | cp .config "${LNXHDRDIR}" | |
170 | cp -a scripts "${LNXHDRDIR}" | |
171 | ||
172 | if [ -d arch/${karch}/scripts ]; then | |
173 | cp -a arch/${karch}/scripts "${LNXHDRDIR}/arch/${karch}/" || : | |
174 | fi | |
175 | ||
176 | if [ -f arch/${karch}/*lds ]; then | |
177 | cp -a arch/${karch}/*lds "${LNXHDRDIR}/arch/${karch}/" || : | |
178 | fi | |
179 | ||
180 | rm -f "${LNXHDRDIR}/scripts/*.o" | |
181 | rm -f "${LNXHDRDIR}/scripts/*/*.o" | |
182 | ||
183 | if [ "${karch}" = "powerpc" ]; then | |
184 | cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/" | |
185 | fi | |
186 | ||
187 | if [ -d arch/${karch}/include ]; then | |
188 | cp -a --parents arch/${karch}/include "${LNXHDRDIR}/" | |
189 | fi | |
190 | ||
191 | cp -a include "${LNXHDRDIR}/include" | |
192 | ||
193 | # Make sure the Makefile and version.h have a matching timestamp so that | |
194 | # external modules can be built | |
195 | if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then | |
196 | touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h" | |
197 | elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then | |
198 | touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h" | |
199 | else | |
200 | echo "Missing version.h" | |
201 | exit 1 | |
202 | fi | |
203 | touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h" | |
204 | ||
205 | # Copy .config to include/config/auto.conf so "make prepare" is unnecessary. | |
206 | cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf" | |
207 | ||
208 | ||
209 | ||
210 | ||
211 | ## PREPARE FULL LINUX SOURCE TREE | |
f3d8604b MJ |
212 | |
213 | # Enter linux source dir | |
214 | cd "${LNXSRCDIR}" | |
215 | ||
339db64d MJ |
216 | # Make sure linux source dir is clean |
217 | make mrproper | |
218 | ||
f3d8604b MJ |
219 | # Prepare linux sources for modules OOT build |
220 | make O="${LNXBUILDDIR}" defconfig | |
221 | ||
222 | # Enable CONFIG_KALLSYMS_ALL | |
223 | sed -i "s/# CONFIG_KALLSYMS_ALL is not set/CONFIG_KALLSYMS_ALL=y/g" "${LNXBUILDDIR}"/.config | |
224 | ||
339db64d | 225 | # Prepare out of tree dir for modules build |
f3d8604b MJ |
226 | make O="${LNXBUILDDIR}" modules_prepare |
227 | ||
339db64d | 228 | # Version specific tasks |
f3d8604b MJ |
229 | case "$kversion" in |
230 | Ubuntu*) | |
231 | #fakeroot debian/rules clean | |
232 | #fakeroot debian/rules genconfigs | |
233 | #cp CONFIGS/amd64-config.flavour.generic .config | |
234 | ||
235 | # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code | |
236 | ABINUM=$(echo $kversion | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)') | |
237 | echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> ${LNXBUILDDIR}/include/generated/utsrelease.h | |
238 | ;; | |
239 | esac | |
240 | ||
339db64d MJ |
241 | # Build modules against full kernel sources |
242 | build_modules "${LNXBUILDDIR}" "${LTTBUILKSRCDDIR}" | |
f3d8604b | 243 | |
339db64d MJ |
244 | # Build modules against kernel headers |
245 | build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}" | |
f3d8604b MJ |
246 | |
247 | # EOF |