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}}"
149 %package -n kmod-${kmodname}-${kernel_uname_r}
150 Summary: ${kmodname} kernel module(s) for ${kernel_uname_r}
151 Group: System Environment/Kernel
152 Provides: kernel-modules-for-kernel = ${kernel_uname_r}
153 Provides: kmod-${kmodname}-uname-r = ${kernel_uname_r}
154 Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
155 Requires: ${kmodname}-kmod-common >= %{?epoch:%{epoch}:}%{version}
156 Requires(post): ${prefix}/sbin/depmod
157 Requires(postun): ${prefix}/sbin/depmod
160 if [[ ${obsolete_name} ]]; then
161 echo "Provides: kmod-${obsolete_name}-${kernel_uname_r} = ${obsolete_version}"
162 echo "Obsoletes: kmod-${obsolete_name}-${kernel_uname_r} < ${obsolete_version}"
166 if [[ ! "${customkernel}" ]]; then
168 Requires: kernel-uname-r = ${kernel_uname_r}
169 BuildRequires: kernel-devel-uname-r = ${kernel_uname_r}
170 %{?KmodsRequires:Requires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
171 %{?KmodsRequires:BuildRequires: %{KmodsRequires}-uname-r = ${kernel_uname_r}}
172 %post -n kmod-${kmodname}-${kernel_uname_r}
173 ${prefix}/sbin/depmod -aeF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} > /dev/null || :
174 %postun -n kmod-${kmodname}-${kernel_uname_r}
175 ${prefix}/sbin/depmod -aF /boot/System.map-${kernel_uname_r} ${kernel_uname_r} &> /dev/null || :
180 %post -n kmod-${kmodname}-${kernel_uname_r}
181 [[ "$(uname -r)" == "${kernel_uname_r}" ]] && ${prefix}/sbin/depmod -a > /dev/null || :
182 %postun -n kmod-${kmodname}-${kernel_uname_r}
183 [[ "$(uname -r)" == "${kernel_uname_r}" ]] && ${prefix}/sbin/depmod -a > /dev/null || :
190 %description -n kmod-${kmodname}-${kernel_uname_r}
191 This package provides the ${kmodname} kernel modules built for the Linux
192 kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.
193 %files -n kmod-${kmodname}-${kernel_uname_r}
194 %defattr(644,root,root,755)
195 %dir $prefix/lib/modules/${kernel_uname_r}/extra
196 ${prefix}/lib/modules/${kernel_uname_r}/extra/${kmodname}/
202 print_rpmtemplate_kmoddevelpkg
()
204 if [[ "${1}" == "--custom" ]]; then
206 local customkernel
=true
207 elif [[ "${1}" == "--redhat" ]]; then
209 local redhatkernel
=true
212 local kernel_uname_r
=${1}
215 %package -n kmod-${kmodname}-devel
216 Summary: ${kmodname} kernel module(s) devel common
217 Group: System Environment/Kernel
218 Provides: ${kmodname}-devel-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
221 if [[ ! ${customkernel} ]] && [[ ! ${redhatkernel} ]]; then
222 echo "Requires: kmod-${kmodname}-devel-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}"
225 if [[ ${obsolete_name} ]]; then
226 echo "Provides: kmod-${obsolete_name}-devel = ${obsolete_version}"
227 echo "Obsoletes: kmod-${obsolete_name}-devel < ${obsolete_version}"
231 %description -n kmod-${kmodname}-devel
232 This package provides the common header files to build kernel modules
233 which depend on the ${kmodname} kernel module. It may optionally require
234 the ${kmodname}-devel-<kernel> objects for the newest kernel.
236 %files -n kmod-${kmodname}-devel
237 %defattr(644,root,root,755)
238 %{_usrsrc}/${kmodname}-%{version}
241 for kernel
in ${1}; do
242 local kernel_uname_r
=${kernel}
243 echo "%exclude %{_usrsrc}/${kmodname}-%{version}/${kernel_uname_r}"
250 print_rpmtemplate_per_kmoddevelpkg
()
252 if [[ "${1}" == "--custom" ]]; then
254 local customkernel
=true
255 elif [[ "${1}" == "--redhat" ]]; then
256 # this is needed for akmods
258 local redhatkernel
=true
261 local kernel_uname_r
=${1}
262 local kernel_variant
="${2:+-${2}}"
266 %package -n kmod-${kmodname}-devel-${kernel_uname_r}
267 Summary: ${kmodname} kernel module(s) devel for ${kernel_uname_r}
268 Group: System Environment/Kernel
269 Provides: kernel-objects-for-kernel = ${kernel_uname_r}
270 Provides: ${kmodname}-devel-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
271 Provides: kmod-${kmodname}-devel-uname-r = ${kernel_uname_r}
274 if [[ ${obsolete_name} ]]; then
275 echo "Provides: kmod-${obsolete_name}-devel-${kernel_uname_r} = ${obsolete_version}"
276 echo "Obsoletes: kmod-${obsolete_name}-devel-${kernel_uname_r} < ${obsolete_version}"
280 if [[ ! "${customkernel}" ]]; then
282 Requires: kernel-devel-uname-r = ${kernel_uname_r}
283 BuildRequires: kernel-devel-uname-r = ${kernel_uname_r}
284 %{?KmodsDevelRequires:Requires: %{KmodsDevelRequires}-uname-r = ${kernel_uname_r}}
285 %{?KmodsDevelRequires:BuildRequires: %{KmodsDevelRequires}-uname-r = ${kernel_uname_r}}
291 %description -n kmod-${kmodname}-devel-${kernel_uname_r}
292 This package provides objects and symbols required to build kernel modules
293 which depend on the ${kmodname} kernel modules built for the Linux
294 kernel ${kernel_uname_r} for the %{_target_cpu} family of processors.
295 %files -n kmod-${kmodname}-devel-${kernel_uname_r}
296 %defattr(644,root,root,755)
297 %{_usrsrc}/${kmodname}-%{version}/${kernel_uname_r}
303 print_rpmtemplate_kmodmetapkg
()
305 local kernel_uname_r
=${1}
306 local kernel_variant
="${2:+-${2}}"
309 %package -n kmod-${kmodname}${kernel_variant}
310 Summary: Metapackage which tracks in ${kmodname} kernel module for newest kernel${kernel_variant}
311 Group: System Environment/Kernel
313 Provides: ${kmodname}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
314 Requires: kmod-${kmodname}-${kernel_uname_r} >= %{?epoch:%{epoch}:}%{version}-%{release}
315 %{?KmodsMetaRequires:Requires: %{?KmodsMetaRequires}}
318 if [[ ${obsolete_name} ]]; then
319 echo "Provides: kmod-${obsolete_name}${kernel_variant} = ${obsolete_version}"
320 echo "Obsoletes: kmod-${obsolete_name}${kernel_variant} < ${obsolete_version}"
325 %description -n kmod-${kmodname}${kernel_variant}
326 This is a meta-package without payload which sole purpose is to require the
327 ${kmodname} kernel module(s) for the newest kernel${kernel_variant}.
328 to make sure you get it together with a new kernel.
330 %files -n kmod-${kmodname}${kernel_variant}
331 %defattr(644,root,root,755)
337 print_customrpmtemplate
()
341 if [[ -e "${buildroot}/usr/src/kernels/${kernel}" ]] ; then
342 # this looks like a Fedora/RH kernel -- print a normal template (which includes the proper BR) and be happy :)
343 kernel_versions
="${kernel_versions}${kernel}___${buildroot}%{_usrsrc}/kernels/${kernel} "
345 # parse kernel versions string and print template
346 local kernel_verrelarch
=${kernel%%${kernels_known_variants}}
347 print_rpmtemplate_per_kmodpkg
--redhat ${kernel} ${kernel##${kernel_verrelarch}}
349 # create development package
350 if [[ "${devel}" ]]; then
351 # create devel package including common headers
352 print_rpmtemplate_kmoddevelpkg
--redhat ${kernel} ${kernel##${kernel_verrelarch}}
354 # create devel package
355 print_rpmtemplate_per_kmoddevelpkg
--redhat ${kernel} ${kernel##${kernel_verrelarch}}
357 elif [[ -e ${prefix}/lib
/modules
/"${kernel}"/build
/Makefile
]] ; then
358 # likely a user-build-kernel with available buildfiles
359 # fixme: we should check if uname from Makefile is the same as ${kernel}
361 kernel_versions
="${kernel_versions}${kernel}___${prefix}/lib/modules/${kernel}/build/ "
362 print_rpmtemplate_per_kmodpkg
--custom "${kernel}"
364 # create development package
365 if [[ "${devel}" ]]; then
366 # create devel package including common headers
367 print_rpmtemplate_kmoddevelpkg
--custom "${kernel}"
369 # create devel package
370 print_rpmtemplate_per_kmoddevelpkg
--custom "${kernel}"
373 error_out
2 "Don't know how to handle ${kernel} -- ${prefix}/lib/modules/${kernel}/build/Makefile not found"
377 # well, it's no header anymore, but who cares ;-)
378 print_rpmtemplate_header
384 # create kernel_versions var
385 for kernel_version
in ${kernel_versions_to_build_for}
387 kernel_versions
="${kernel_versions}${kernel_version}___%{_usrsrc}/kernels/${kernel_version} "
390 # and print it and some other required stuff as macro
391 print_rpmtemplate_header
393 # now print the packages itselfs
394 for kernel
in ${kernel_versions_to_build_for} ; do
396 local kernel_verrelarch
=${kernel%%${kernels_known_variants}}
399 print_rpmtemplate_kmodmetapkg
${kernel} ${kernel##${kernel_verrelarch}}
402 print_rpmtemplate_per_kmodpkg
${kernel} ${kernel##${kernel_verrelarch}}
404 if [[ "${devel}" ]]; then
405 # create devel package including common headers
406 print_rpmtemplate_kmoddevelpkg
${kernel} ${kernel##${kernel_verrelarch}}
408 # create devel package
409 print_rpmtemplate_per_kmoddevelpkg
${kernel} ${kernel##${kernel_verrelarch}}
416 echo "Usage: $(basename ${0}) [OPTIONS]"
417 echo $
'\n'"Creates a template to be used during kmod building"
418 echo $
'\n'"Available options:"
419 echo " --filterfile <file> -- filter the results with grep --file <file>"
420 echo " --for-kernels <list> -- created templates only for these kernels"
421 echo " --kmodname <file> -- name of the kmod (required)"
422 echo " --devel -- make kmod-devel package"
423 echo " --noakmod -- no akmod package"
424 echo " --repo <name> -- use buildsys-build-<name>-kerneldevpkgs"
425 echo " --target <arch> -- target-arch (required)"
426 echo " --buildroot <dir> -- Build root (place to look for build files)"
429 while [ "${1}" ] ; do
433 if [[ ! "${1}" ]] ; then
434 error_out
2 "Please provide path to a filter-file together with --filterfile" >&2
435 elif [[ ! -e "${1}" ]]; then
436 error_out
2 "Filterfile ${1} not found" >&2
443 if [[ ! "${1}" ]] ; then
444 error_out
2 "Please provide the name of the kmod together with --kmodname" >&2
446 # strip pending -kmod
447 kmodname
="${1%%-kmod}"
456 if [[ ! "${1}" ]] ; then
457 error_out
2 "Please provide a prefix with --prefix" >&2
464 if [[ ! "${1}" ]] ; then
465 error_out
2 "Please provide the name of the repo together with --repo" >&2
472 if [[ ! "${1}" ]] ; then
473 error_out
2 "Please provide the name of the kmod together with --kmodname" >&2
484 if [[ ! "${1}" ]] ; then
485 error_out
2 "Please provide the name of the kmod to obsolte together with --obsolete-name" >&2
492 if [[ ! "${1}" ]] ; then
493 error_out
2 "Please provide the version of the kmod to obsolte together with --obsolete-version" >&2
495 obsolete_version
="${1}"
505 build_kernels
="akmod"
509 build_kernels
="newest"
513 build_kernels
="current"
525 echo "${myprog} ${myver}"
529 echo "Error: Unknown option '${1}'." >&2
536 if [[ -e .
/kmodtool-kernel-variants
]]; then
537 kernels_known_variants
="$(cat ./kmodtool-kernel-variants)"
538 elif [[ -e /usr
/share
/kmodtool
/kernel-variants
]] ; then
539 kernels_known_variants
="$(cat /usr/share/kmodtool/kernel-variants)"
541 kernels_known_variants
="@(smp?(-debug)|PAE?(-debug)|debug|kdump|xen|kirkwood|highbank|imx|omap|tegra)"
544 # general sanity checks
545 if [[ ! "${target}" ]]; then
546 error_out
2 "please pass target arch with --target"
547 elif [[ ! "${kmodname}" ]]; then
548 error_out
2 "please pass kmodname with --kmodname"
549 elif [[ ! "${kernels_known_variants}" ]] ; then
550 error_out
2 "could not determine known variants"
551 elif ( [[ "${obsolete_name}" ]] && [[ ! "${obsolete_version}" ]] ) || ( [[ ! "${obsolete_name}" ]] && [[ "${obsolete_version}" ]] ) ; then
552 error_out
2 "you need to provide both --obsolete-name and --obsolete-version"
556 if [[ "${for_kernels}" ]]; then
558 print_customrpmtemplate
"${for_kernels}"
559 elif [[ "${build_kernels}" == "akmod" ]]; then
560 # do only a akmod package
564 # seems we are on out own to decide for which kernels to build
566 # we need more sanity checks in this case
567 if [[ ! "${repo}" ]]; then
568 error_out
2 "please provide repo name with --repo"
569 elif ! $
(which buildsys-build-
${repo}-kerneldevpkgs &> /dev
/null
) ; then
570 error_out
2 "buildsys-build-${repo}-kerneldevpkgs not found"
573 # call buildsys-build-${repo}-kerneldevpkgs to get the list of kernels
574 cmdoptions
="--target ${target}"
576 # filterfile to filter list of kernels?
577 if [[ "${filterfile}" ]] ; then
578 cmdoptions
="${cmdoptions} --filterfile ${filterfile}"
581 kernel_versions_to_build_for
="$(buildsys-build-${repo}-kerneldevpkgs --${build_kernels} ${cmdoptions})"
583 if (( ${returncode} != 0 )); then
584 error_out
2 "buildsys-build-${repo}-kerneldevpkgs failed: $(buildsys-build-${repo}-kerneldevpkgs --${build_kernels} ${cmdoptions})"
587 if [[ "${build_kernels}" == "current" ]] && [[ ! "${noakmod}" ]]; then