3 # kmodtool - Helper script for building kernel module RPMs
4 # Copyright (c) 2003-2008 Ville Skyttä <ville.skytta@iki.fi>,
5 # Thorsten Leemhuis <fedora@leemhuis.info>
6 # Jon Masters <jcm@redhat.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.
31 knownvariants=@(BOOT|PAE|@(big|huge)mem|debug|enterprise|kdump|?(large)smp|uml|xen[0U]?(-PAE)|xen)
40 verrel=${1:-$(uname -r)}
41 verrel=${verrel%%$knownvariants}
53 variant=${1:-$(uname -r)}
54 variant=${variant##$verrel}
55 variant=${variant:-'""'}
67 local dashvariant="${variant:+-${variant}}"
69 *.el*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
70 *.EL*) kdep="kernel${dashvariant}-%{_target_cpu} = ${verrel}" ;;
71 *) kdep="kernel-%{_target_cpu} = ${verrel}${variant}" ;;
74 echo "%package -n kmod-${kmod_name}${dashvariant}"
76 if [ -z "$kmp_provides_summary" ]; then
77 echo "Summary: ${kmod_name} kernel module(s)"
80 if [ -z "$kmp_provides_group" ]; then
81 echo "Group: System Environment/Kernel"
84 if [ ! -z "$kmp_version" ]; then
85 echo "Version: %{kmp_version}"
88 if [ ! -z "$kmp_release" ]; then
89 echo "Release: %{kmp_release}"
92 if [ ! -z "$kmp" ]; then
93 echo "%global _use_internal_dependency_generator 0"
97 Provides: kernel-modules = ${verrel}${variant}
98 Provides: ${kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
101 if [ -z "$kmp" ]; then
102 echo "Requires: ${kdep}"
106 # RHEL5 - Remove common package requirement on general kmod packages.
107 # Requires: ${kmod_name}-kmod-common >= %{?epoch:%{epoch}:}%{version}
111 Requires(post): /sbin/depmod
112 Requires(postun): /sbin/depmod
115 if [ "no" != "$kmp_nobuildreqs" ]
117 echo "BuildRequires: kernel${dashvariant}-devel-%{_target_cpu} = ${verrel}"
120 if [ "" != "$kmp_override_preamble" ]
122 cat "$kmp_override_preamble"
126 %description -n kmod-${kmod_name}${dashvariant}
127 This package provides the ${kmod_name} kernel modules built for the Linux
128 kernel ${verrel}${variant} for the %{_target_cpu} family of processors.
129 %post -n kmod-${kmod_name}${dashvariant}
130 if [ -e "/boot/System.map-${verrel}${variant}" ]; then
131 /sbin/depmod -aeF "/boot/System.map-${verrel}${variant}" "${verrel}${variant}" > /dev/null || :
135 if [ ! -z "$kmp" ]; then
138 #modules=( \$(rpm -ql kmod-${kmod_name}${dashvariant} | grep '\.ko$') )
139 modules=( \$(find /lib/modules/${verrel}${variant}/extra/${kmod_name} \
141 if [ -x "/sbin/weak-modules" ]; then
142 printf '%s\n' "\${modules[@]}" \
143 | /sbin/weak-modules --add-modules
145 %preun -n kmod-${kmod_name}${dashvariant}
146 rpm -ql kmod-${kmod_name}${dashvariant} | grep '\.ko$' \
147 > /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
153 %postun -n kmod-${kmod_name}${dashvariant}
154 /sbin/depmod -aF /boot/System.map-${verrel}${variant} ${verrel}${variant} &> /dev/null || :
157 if [ ! -z "$kmp" ]; then
159 modules=( \$(cat /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules) )
160 #rm /var/run/rpm-kmod-${kmod_name}${dashvariant}-modules
161 if [ -x "/sbin/weak-modules" ]; then
162 printf '%s\n' "\${modules[@]}" \
163 | /sbin/weak-modules --remove-modules
168 echo "%files -n kmod-${kmod_name}${dashvariant}"
170 if [ "" == "$kmp_override_filelist" ];
172 echo "%defattr(644,root,root,755)"
173 echo "/lib/modules/${verrel}${variant}/"
174 echo "%config /etc/depmod.d/kmod-${kmod_name}.conf"
175 #BZ252188 - I've commented this out for the moment since RHEL5 doesn't
176 # really support external firmware e.g. at install time. If
177 # you really want it, use an override filelist solution.
178 #echo "/lib/firmware/"
180 cat "$kmp_override_filelist"
191 if [ -z "${kmod_name}" ] ; then
192 echo "Please provide the kmodule-name as first parameter." >&2
194 elif [ -z "${kver}" ] ; then
195 echo "Please provide the kver as second parameter." >&2
197 elif [ -z "${verrel}" ] ; then
198 echo "Couldn't find out the verrel." >&2
202 for variant in "$@" ; do
203 if [ "default" == "$variant" ];
207 get_rpmtemplate "${variant}"
215 You called: ${invocation}
217 Usage: ${myprog} <command> <option>+
220 - Get "base" version-release.
222 - Get variant from uname.
223 rpmtemplate <mainpgkname> <uname> <variants>
224 - Return a template for use in a source RPM
225 rpmtemplate_kmp <mainpgkname> <uname> <variants>
226 - Return a template for use in a source RPM with KMP dependencies
228 - Output version number and exit.
232 invocation="$(basename ${0}) $@"
233 while [ "${1}" ] ; do
247 print_rpmtemplate "$@"
253 print_rpmtemplate "$@"
257 echo "${myprog} ${myver}"
261 echo "Error: Unknown option '${1}'." >&2
271 # indent-tabs-mode: nil