3 # kmodtool - Helper script for building kernel module RPMs
4 # Copyright (c) 2003-2012 Ville Skyttä <ville.skytta@iki.fi>,
5 # Thorsten Leemhuis <fedora@leemhuis.info>
6 # Nicolas Chauvet <kwizart@gmail.com>
8 # Permission is hereby granted, free of charge, to any person obtaining
9 # a copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sublicense, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so, subject to
14 # the following conditions:
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 myprog
="kmodtool-${repo}"
33 build_kernels
="current"
34 kernels_known_variants
=
36 kernel_versions_to_build_for
=
47 # the next line is not multi-line safe -- not needed *yet*
48 echo "%global kmodtool_check echo \"kmodtool error: $@\"; exit ${errorlevel};"
52 print_rpmtemplate_header
()
55 echo '%global kmodinstdir_prefix '${prefix}/lib
/modules
/
56 echo '%global kmodinstdir_postfix '/extra
/${kmodname}/
57 echo '%global kernel_versions '${kernel_versions}
61 print_akmodtemplate
()
66 %global akmod_install mkdir -p \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/; \\\
67 LANG=C rpmbuild --define "_sourcedir %{_sourcedir}" \\\
68 --define "_srcrpmdir \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/" \\\
69 -bs --nodeps %{_specdir}/%{name}.spec ; \\\
70 ln -s \$(ls \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/) \$RPM_BUILD_ROOT/%{_usrsrc}/akmods/${kmodname}-kmod.latest
72 %package -n akmod-${kmodname}
73 Summary: Akmod package for ${kmodname} kernel module(s)
74 Group: System Environment/Kernel
77 %{?AkmodsBuildRequires:Requires: %{AkmodsBuildRequires}}
78 # same requires and provides as a kmods package would have
79 Requires: ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}
80 Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
83 if [[ ${obsolete_name} ]]; then
84 echo "Provides: akmod-${obsolete_name} = ${obsolete_version}"
85 echo "Obsoletes: akmod-${obsolete_name} < ${obsolete_version}"
90 %description -n akmod-${kmodname}
91 This package provides the akmod package for the ${kmodname} kernel modules.
93 %posttrans -n akmod-${kmodname}
94 nohup ${prefix}/sbin/akmods --from-akmod-posttrans --akmod ${kmodname} &> /dev/null &
96 %files -n akmod-${kmodname}
97 %defattr(-,root,root,-)
106 %package -n kmod-${kmodname}
107 Summary: Metapackage which tracks in ${kmodname} kernel module for newest kernel${dashvariant}
108 Group: System Environment/Kernel
110 Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
111 Provides: kmod-${kmodname}-xen = %{?epoch:%{epoch}:}%{version}-%{release}
112 Provides: kmod-${kmodname}-smp = %{?epoch:%{epoch}:}%{version}-%{release}
113 Provides: kmod-${kmodname}-PAE = %{?epoch:%{epoch}:}%{version}-%{release}
114 Requires: akmod-${kmodname} = %{?epoch:%{epoch}:}%{version}-%{release}
117 if [[ ${obsolete_name} ]]; then
118 echo "Provides: kmod-${obsolete_name} = ${obsolete_version}"
119 echo "Obsoletes: kmod-${obsolete_name} < ${obsolete_version}"
123 %description -n kmod-${kmodname}${dashvariant}
124 This is a meta-package without payload which sole purpose is to require the
125 ${kmodname} kernel module(s) for the newest kernel${dashvariant},
126 to make sure you get it together with a new kernel.
128 %files -n kmod-${kmodname}${dashvariant}
129 %defattr(644,root,root,755)
133 print_rpmtemplate_per_kmodpkg
()
135 if [[ "${1}" == "--custom" ]]; then
137 local customkernel
=true
138 elif [[ "${1}" == "--redhat" ]]; then
139 # this is needed for akmods
141 local redhatkernel
=true
144 local kernel_uname_r
=${1}
145 local kernel_variant
="${2:+-${2}}"
147 # Detect depmod install location
148 local depmod_path
=/sbin
/depmod
149 if [ ! -f ${depmod_path} ]; then
150 depmod_path
=/usr
/sbin
/depmod
155 %package -n kmod-${kmodname}-${kernel_uname_r}
156 Summary: ${kmodname} kernel module(s) for ${kernel_uname_r}
157 Group: System Environment/Kernel
158 Provides: kernel-modules-for-kernel = ${kernel_uname_r}
159 Provides: kmod-${kmodname}-uname-r = ${kernel_uname_r}
160 Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
161 Requires: ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}
163 %if 0%{?rhel} == 6 || 0%{?centos} == 6
164 Requires(post): module-init-tools
165 Requires(postun): module-init-tools
168 Requires(postun): kmod
172 if [[ ${obsolete_name} ]]; then
173 echo "Provides: kmod-${obsolete_name}-${kernel_uname_r} = ${obsolete_version}"
174 echo "Obsoletes: kmod-${obsolete_name}-${kernel_uname_r} < ${obsolete_version}"
178 if [[ ! "${customkernel}" ]]; then
180 Requires: kernel-uname-r = ${kernel_uname_r}
181 BuildRequires: kernel-devel-uname-r = ${kernel_uname_r}
182 %{?KmodsRequires:Requires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
183 %{?KmodsRequires:BuildRequires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
184 %post -n kmod-${kmodname}-${kernel_uname_r}
185 ${prefix}${depmod_path} -aeF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} > /dev/null || :
186 %postun -n kmod-${kmodname}-${kernel_uname_r}
187 ${prefix}${depmod_path} -aF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} &> /dev/null || :
192 %post -n kmod-${kmodname}-${kernel_uname_r}
193 [[ "\$(uname -r)" == "${kernel_uname_r}" ]] && ${prefix}${depmod_path} -a > /dev/null || :
194 %postun -n kmod-${kmodname}-${kernel_uname_r}
195 [[ "\$(uname -r)" == "${kernel_uname_r}" ]] && ${prefix}${depmod_path} -a > /dev/null || :
202 %description -n kmod-${kmodname}-${kernel_uname_r}
203 This package provides the ${kmodname} kernel modules built for the Linux
204 kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.
205 %files -n kmod-${kmodname}-${kernel_uname_r}
206 %defattr(644,root,root,755)
207 %dir $prefix/lib/modules/${kernel_uname_r}/extra
208 ${prefix}/lib/modules/${kernel_uname_r}/extra/${kmodname}/
214 print_rpmtemplate_kmoddevelpkg
()
216 if [[ "${1}" == "--custom" ]]; then
218 local customkernel
=true
219 elif [[ "${1}" == "--redhat" ]]; then
221 local redhatkernel
=true
224 local kernel_uname_r
=${1}
227 %package -n kmod-${kmodname}-devel
228 Summary: ${kmodname} kernel module(s) devel common
229 Group: System Environment/Kernel
230 Provides: ${kmodname}-devel-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
233 if [[ ! ${customkernel} ]] && [[ ! ${redhatkernel} ]]; then
234 echo "Requires: kmod-${kmodname}-devel-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}"
237 if [[ ${obsolete_name} ]]; then
238 echo "Provides: kmod-${obsolete_name}-devel = ${obsolete_version}"
239 echo "Obsoletes: kmod-${obsolete_name}-devel < ${obsolete_version}"
243 %description -n kmod-${kmodname}-devel
244 This package provides the common header files to build kernel modules
245 which depend on the ${kmodname} kernel module. It may optionally require
246 the ${kmodname}-devel-<kernel> objects for the newest kernel.
248 %files -n kmod-${kmodname}-devel
249 %defattr(644,root,root,755)
250 %{_usrsrc}/${kmodname}-%{version}
252 if [[ ${obsolete_name} ]]; then
253 echo "%{_usrsrc}/${obsolete_name}-%{version}"
256 for kernel
in ${1}; do
257 local kernel_uname_r
=${kernel}
258 echo "%exclude %{_usrsrc}/${kmodname}-%{version}/${kernel_uname_r}"
259 if [[ ${obsolete_name} ]]; then
260 echo "%exclude %{_usrsrc}/${obsolete_name}-%{version}/${kernel_uname_r}"
268 print_rpmtemplate_per_kmoddevelpkg
()
270 if [[ "${1}" == "--custom" ]]; then
272 local customkernel
=true
273 elif [[ "${1}" == "--redhat" ]]; then
274 # this is needed for akmods
276 local redhatkernel
=true
279 local kernel_uname_r
=${1}
280 local kernel_variant
="${2:+-${2}}"
284 %package -n kmod-${kmodname}-devel-${kernel_uname_r}
285 Summary: ${kmodname} kernel module(s) devel for ${kernel_uname_r}
286 Group: System Environment/Kernel
287 Provides: kernel-objects-for-kernel = ${kernel_uname_r}
288 Provides: ${kmodname}-devel-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
289 Provides: kmod-${kmodname}-devel-uname-r = ${kernel_uname_r}
292 if [[ ${obsolete_name} ]]; then
293 echo "Provides: kmod-${obsolete_name}-devel-${kernel_uname_r} = ${obsolete_version}"
294 echo "Obsoletes: kmod-${obsolete_name}-devel-${kernel_uname_r} < ${obsolete_version}"
298 if [[ ! "${customkernel}" ]]; then
300 Requires: kernel-devel-uname-r = ${kernel_uname_r}
301 BuildRequires: kernel-devel-uname-r = ${kernel_uname_r}
302 %{?KmodsDevelRequires:Requires: %{KmodsDevelRequires}-uname-r = ${kernel_uname_r}}
303 %{?KmodsDevelRequires:BuildRequires: %{KmodsDevelRequires}-uname-r = ${kernel_uname_r}}
309 %description -n kmod-${kmodname}-devel-${kernel_uname_r}
310 This package provides objects and symbols required to build kernel modules
311 which depend on the ${kmodname} kernel modules built for the Linux
312 kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.
313 %files -n kmod-${kmodname}-devel-${kernel_uname_r}
314 %defattr(644,root,root,755)
315 %{_usrsrc}/${kmodname}-%{version}/${kernel_uname_r}
317 if [[ ${obsolete_name} ]]; then
318 echo "%{_usrsrc}/${obsolete_name}-%{version}/${kernel_uname_r}"
322 print_rpmtemplate_kmodmetapkg
()
324 local kernel_uname_r
=${1}
325 local kernel_variant
="${2:+-${2}}"
328 %package -n kmod-${kmodname}${kernel_variant}
329 Summary: Metapackage which tracks in ${kmodname} kernel module for newest kernel${kernel_variant}
330 Group: System Environment/Kernel
332 Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
333 Requires: kmod-${kmodname}-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}
334 %{?KmodsMetaRequires:Requires: %{?KmodsMetaRequires}}
337 if [[ ${obsolete_name} ]]; then
338 echo "Provides: kmod-${obsolete_name}${kernel_variant} = ${obsolete_version}"
339 echo "Obsoletes: kmod-${obsolete_name}${kernel_variant} < ${obsolete_version}"
344 %description -n kmod-${kmodname}${kernel_variant}
345 This is a meta-package without payload which sole purpose is to require the
346 ${kmodname} kernel module(s) for the newest kernel${kernel_variant}.
347 to make sure you get it together with a new kernel.
349 %files -n kmod-${kmodname}${kernel_variant}
350 %defattr(644,root,root,755)
356 print_customrpmtemplate
()
360 if [[ -e "${buildroot}/usr/src/kernels/${kernel}" ]] ; then
361 # this looks like a Fedora/RH kernel -- print a normal template (which includes the proper BR) and be happy :)
362 kernel_versions
="${kernel_versions}${kernel}___${buildroot}%{_usrsrc}/kernels/${kernel} "
364 # parse kernel versions string and print template
365 local kernel_verrelarch
=${kernel%%${kernels_known_variants}}
366 print_rpmtemplate_per_kmodpkg
--redhat ${kernel} ${kernel##${kernel_verrelarch}}
368 # create development package
369 if [[ "${devel}" ]]; then
370 # create devel package including common headers
371 print_rpmtemplate_kmoddevelpkg
--redhat ${kernel} ${kernel##${kernel_verrelarch}}
373 # create devel package
374 print_rpmtemplate_per_kmoddevelpkg
--redhat ${kernel} ${kernel##${kernel_verrelarch}}
376 elif [[ -e ${prefix}/lib
/modules
/"${kernel}"/build
/Makefile
]] ; then
377 # likely a user-build-kernel with available buildfiles
378 # fixme: we should check if uname from Makefile is the same as ${kernel}
380 kernel_versions
="${kernel_versions}${kernel}___${prefix}/lib/modules/${kernel}/build/ "
381 print_rpmtemplate_per_kmodpkg
--custom "${kernel}"
383 # create development package
384 if [[ "${devel}" ]]; then
385 # create devel package including common headers
386 print_rpmtemplate_kmoddevelpkg
--custom "${kernel}"
388 # create devel package
389 print_rpmtemplate_per_kmoddevelpkg
--custom "${kernel}"
392 error_out
2 "Don't know how to handle ${kernel} -- ${prefix}/lib/modules/${kernel}/build/Makefile not found"
396 # well, it's no header anymore, but who cares ;-)
397 print_rpmtemplate_header
403 # create kernel_versions var
404 for kernel_version
in ${kernel_versions_to_build_for}
406 kernel_versions
="${kernel_versions}${kernel_version}___%{_usrsrc}/kernels/${kernel_version} "
409 # and print it and some other required stuff as macro
410 print_rpmtemplate_header
412 # now print the packages
413 for kernel
in ${kernel_versions_to_build_for} ; do
415 local kernel_verrelarch
=${kernel%%${kernels_known_variants}}
418 print_rpmtemplate_kmodmetapkg
${kernel} ${kernel##${kernel_verrelarch}}
421 print_rpmtemplate_per_kmodpkg
${kernel} ${kernel##${kernel_verrelarch}}
423 if [[ "${devel}" ]]; then
424 # create devel package including common headers
425 print_rpmtemplate_kmoddevelpkg
${kernel} ${kernel##${kernel_verrelarch}}
427 # create devel package
428 print_rpmtemplate_per_kmoddevelpkg
${kernel} ${kernel##${kernel_verrelarch}}
435 echo "Usage: $(basename ${0}) [OPTIONS]"
436 echo $
'\n'"Creates a template to be used during kmod building"
437 echo $
'\n'"Available options:"
438 echo " --filterfile <file> -- filter the results with grep --file <file>"
439 echo " --for-kernels <list> -- created templates only for these kernels"
440 echo " --kmodname <file> -- name of the kmod (required)"
441 echo " --devel -- make kmod-devel package"
442 echo " --noakmod -- no akmod package"
443 echo " --repo <name> -- use buildsys-build-<name>-kerneldevpkgs"
444 echo " --target <arch> -- target-arch (required)"
445 echo " --buildroot <dir> -- Build root (place to look for build files)"
448 while [ "${1}" ] ; do
452 if [[ ! "${1}" ]] ; then
453 error_out
2 "Please provide path to a filter-file together with --filterfile" >&2
454 elif [[ ! -e "${1}" ]]; then
455 error_out
2 "Filterfile ${1} not found" >&2
462 if [[ ! "${1}" ]] ; then
463 error_out
2 "Please provide the name of the kmod together with --kmodname" >&2
465 # strip pending -kmod
466 kmodname
="${1%%-kmod}"
475 if [[ ! "${1}" ]] ; then
476 error_out
2 "Please provide a prefix with --prefix" >&2
483 if [[ ! "${1}" ]] ; then
484 error_out
2 "Please provide the name of the repo together with --repo" >&2
491 if [[ ! "${1}" ]] ; then
492 error_out
2 "Please provide the name of the kmod together with --kmodname" >&2
503 if [[ ! "${1}" ]] ; then
504 error_out
2 "Please provide the name of the kmod to obsolete together with --obsolete-name" >&2
511 if [[ ! "${1}" ]] ; then
512 error_out
2 "Please provide the version of the kmod to obsolete together with --obsolete-version" >&2
514 obsolete_version
="${1}"
524 build_kernels
="akmod"
528 build_kernels
="newest"
532 build_kernels
="current"
544 echo "${myprog} ${myver}"
548 echo "Error: Unknown option '${1}'." >&2
555 if [[ -e .
/kmodtool-kernel-variants
]]; then
556 kernels_known_variants
="$(cat ./kmodtool-kernel-variants)"
557 elif [[ -e /usr
/share
/kmodtool
/kernel-variants
]] ; then
558 kernels_known_variants
="$(cat /usr/share/kmodtool/kernel-variants)"
560 kernels_known_variants
="@(smp?(-debug)|PAE?(-debug)|debug|kdump|xen|kirkwood|highbank|imx|omap|tegra)"
563 # general sanity checks
564 if [[ ! "${target}" ]]; then
565 error_out
2 "please pass target arch with --target"
566 elif [[ ! "${kmodname}" ]]; then
567 error_out
2 "please pass kmodname with --kmodname"
568 elif [[ ! "${kernels_known_variants}" ]] ; then
569 error_out
2 "could not determine known variants"
570 elif ( [[ "${obsolete_name}" ]] && [[ ! "${obsolete_version}" ]] ) || ( [[ ! "${obsolete_name}" ]] && [[ "${obsolete_version}" ]] ) ; then
571 error_out
2 "you need to provide both --obsolete-name and --obsolete-version"
575 if [[ "${for_kernels}" ]]; then
577 print_customrpmtemplate
"${for_kernels}"
578 elif [[ "${build_kernels}" == "akmod" ]]; then
579 # do only a akmod package
583 # seems we are on out own to decide for which kernels to build
585 # we need more sanity checks in this case
586 if [[ ! "${repo}" ]]; then
587 error_out
2 "please provide repo name with --repo"
588 elif ! $
(which buildsys-build-
${repo}-kerneldevpkgs &> /dev
/null
) ; then
589 error_out
2 "buildsys-build-${repo}-kerneldevpkgs not found"
592 # call buildsys-build-${repo}-kerneldevpkgs to get the list of kernels
593 cmdoptions
="--target ${target}"
595 # filterfile to filter list of kernels?
596 if [[ "${filterfile}" ]] ; then
597 cmdoptions
="${cmdoptions} --filterfile ${filterfile}"
600 kernel_versions_to_build_for
="$(buildsys-build-${repo}-kerneldevpkgs --${build_kernels} ${cmdoptions})"
602 if (( ${returncode} != 0 )); then
603 error_out
2 "buildsys-build-${repo}-kerneldevpkgs failed: $(buildsys-build-${repo}-kerneldevpkgs --${build_kernels} ${cmdoptions})"
606 if [[ "${build_kernels}" == "current" ]] && [[ ! "${noakmod}" ]]; then