]>
Commit | Line | Data |
---|---|---|
1c834f14 JR |
1 | # vim:ts=4 sw=4 noet ft=spec |
2 | # Kernel specific macro definitions. | |
3 | # To make use of these macros insert the following line into your spec file: | |
4 | # %{load:%{_usrlibrpm}/macros.d/kernel} | |
5 | ||
6 | %__modinfo /sbin/modinfo | |
7 | ||
8 | # Path to scripts to autogenerate gstreamer package dependencies, | |
9 | # | |
10 | # Note: Used iff _use_internal_dependency_generator is non-zero. The | |
11 | # helpers are also used by %{_rpmhome}/rpmdeps {--provides|--requires}. | |
12 | %__kernel_provides %{_rpmhome}/kmod-deps.sh --provides --modinfo %__modinfo | |
13 | #__kernel_requires %{_rpmhome}/kmod-deps.sh --requires --modinfo %__modinfo | |
14 | ||
15 | # Alternative kernel type/version | |
16 | %_alt_kernel %{nil}%{?alt_kernel:-%{?alt_kernel}} | |
17 | %_build_kernels %{nil}%{?build_kernels:%{?build_kernels}}%{!?build_kernels:%{?alt_kernel}} | |
18 | ||
f1f5d044 JR |
19 | # Macros for building kernel packages for multiple kernels from same spec |
20 | # Usage: | |
21 | # | |
22 | # %{expand:%buildrequires_kernel kernel%%{_alt_kernel}-module-build >= 3:2.6.20.2}} | |
23 | # %{expand:%create_kernel_packages} | |
24 | # %{expand:%build_kernel_packages} | |
25 | # %{expand:%install_kernel_packages} | |
26 | # | |
27 | %buildrequires_kernel() %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ | |
28 | [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ | |
3a27fcef | 29 | echo "BuildRequires: %{*}" \ |
f1f5d044 | 30 | done) |
1c834f14 JR |
31 | |
32 | %create_kernel_packages %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ | |
33 | echo %%undefine alt_kernel \ | |
34 | [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ | |
35 | echo %%kernel_pkg \ | |
36 | done) | |
37 | ||
38 | %build_kernel_packages %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ | |
39 | echo %%undefine alt_kernel \ | |
40 | [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ | |
41 | echo %%build_kernel_pkg \ | |
42 | done) | |
43 | ||
44 | %install_kernel_packages %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ | |
45 | echo %%undefine alt_kernel \ | |
46 | [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ | |
47 | echo %%install_kernel_pkg \ | |
48 | done) | |
49 | ||
50 | # The directory holding Linux kernel sources | |
51 | %_kernelsrcdir /usr/src/linux%{_alt_kernel} | |
52 | ||
53 | # rpm -qf on kernel version.h file | |
54 | %__kernel_qf() %(R=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -q --qf '%*' -f include/linux/version.h 2>/dev/null | grep -v 'is not'); echo ${R:-ERROR}) | |
55 | ||
56 | # kernel %{name} and kernel %{epoch}:%{version}-%{release} macro respecing alt_kernel | |
57 | %kernel_name %(N=%{__kernel_qf %{N}}; echo ${N%%-headers}) | |
58 | %kernel_version %{__kernel_qf %|E?{%{E}:}|%{V}-%{R}} | |
59 | ||
60 | # -n drm to generate kernel%{_alt_kernel}-drm dependency | |
61 | %releq_kernel(n:) %{kernel_name}%{?-n:-%{-n*}} = %{kernel_version} | |
62 | %releq_kernel_up(n:) %{kernel_name}-up%{?-n:-%{-n*}} = %{kernel_version} | |
63 | %releq_kernel_smp(n:) %{kernel_name}-smp%{?-n:-%{-n*}} = %{kernel_version} | |
64 | ||
65 | # -s post to generate Requires(post) dependency | |
66 | %requires_releq_kernel(s:n:) Requires%{-s:(%{-s*})}: %releq_kernel | |
67 | %requires_releq_kernel_up(s:n:) Requires%{-s:(%{-s*})}: %releq_kernel_up | |
68 | %requires_releq_kernel_smp(s:n:) Requires%{-s:(%{-s*})}: %releq_kernel_smp | |
69 | ||
70 | # kernel version-release handling | |
71 | %__kernel_ver %( \\ | |
72 | Z=$([ -f '%{_kernelsrcdir}/include/generated/utsrelease.h' ] && \\ | |
73 | awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/{linux/version,generated/utsrelease}.h 2>/dev/null || \\ | |
74 | awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/linux/{version,utsrelease}.h 2>/dev/null); \\ | |
75 | Z=${Z:-$(awk -F' = ' '/^VERSION/{v=$2} /^PATCHLEVEL/{p=$2} /^SUBLEVEL/{s=$2} /^EXTRAVERSION/{e=$2} END {printf("%d.%d.%d%s", v, p, s, e)}' \\ | |
76 | %{_kernelsrcdir}/Makefile 2>/dev/null)}; \\ | |
77 | echo ${Z:-ERROR}; \\ | |
78 | ) | |
79 | ||
80 | %_kernel_version_code %( \\ | |
81 | Z=$(awk '/LINUX_VERSION_CODE/{print $3}' %{_kernelsrcdir}/include/linux/version.h 2>/dev/null); \\ | |
82 | echo ${Z:-ERROR}; \\ | |
83 | ) | |
84 | ||
85 | %_kernel_version_magic() %(echo $((%{1} * 65536 + %{2} * 256 + %{3}))) | |
86 | ||
87 | # `uname -r` used for building/installing kernel modules | |
88 | %_kernel_ver %{!?_without_dist_kernel:%{__kernel_qf %{V}-%{R}}}%{?_without_dist_kernel:%{__kernel_ver}} | |
89 | # package version OR `uname -r` for non-dist kernel to be used in @release field | |
90 | %_kernel_ver_str %(echo %{!?_without_dist_kernel:%{__kernel_qf %{V}-%{R}}}%{?_without_dist_kernel:%{__kernel_ver}} | tr '-' '_') | |
91 | ||
92 | #----------------------------------------------------------------- | |
93 | # Find and gzip all kernel modules | |
94 | # | |
95 | # Requires: find | |
96 | # | |
97 | #%no_install_post_compress_modules 1 | |
98 | %__spec_install_post_compress_modules { \ | |
99 | %{!?no_install_post_compress_modules: __spec_install_post_compress_modules() { \ | |
100 | %{!?debug:set +x;} \ | |
101 | if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \ | |
102 | q=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \ | |
103 | if [ "$q" ]; then \ | |
104 | printf "Compress %d kernel modules..." $(echo "$q" | wc -l); \ | |
105 | echo "$q" | xargs -r %{__gzip} -9nf; \ | |
106 | echo "DONE"; \ | |
107 | find $RPM_BUILD_ROOT/lib/modules -name '*o' -type l -printf "%p %l\n" | \ | |
108 | while read a b; do ln -sf $b.gz $a.gz; rm -f $a; done; \ | |
109 | fi; \ | |
110 | fi; \ | |
111 | }; __spec_install_post_compress_modules } } | |
112 | ||
113 | # Build modules for kernels 2.6 | |
114 | # Author: Przemyslaw Iskra <sparky@pld-linux.org> | |
115 | # | |
116 | # Usage: | |
117 | # %build_kernel_modules -m <modules> -C <directory> | |
118 | # | |
119 | # remember that proper Makefile is still required | |
120 | # Options: | |
121 | # -m <modules> (required) -- comma-separated list of modules to save, | |
122 | # without .ko extension, may be placed in subdirectory | |
123 | # -C <directory> -- change to <directory> before doing anything | |
124 | # -p <arg>, -P <arg> -- arguments passeed to make scripts | |
125 | # -c -- do not execute make clean | |
126 | # <additional arguments> -- all additional arguments will be passed to | |
127 | # make modules | |
128 | # | |
129 | # Additional patching supported via here document. Try: | |
130 | # %build_kernel_modules -m module <<'EOF' | |
131 | # your patch script here | |
132 | # EOF | |
133 | # Don't use it unless patching depends on config options. | |
134 | ||
135 | # Developer note: don't touch it unless you know how to handle '\'. | |
136 | # - \ in script expands to nothing | |
137 | # - \\\ in script expands to \ | |
138 | # - \\\ inside definition expands to nothing | |
139 | # - \\\\\\\ inside definition expands to \ | |
140 | # - in last line \ has to touch arguments so arguments passing | |
141 | # in new lines (using \) will be supported | |
142 | ||
143 | %build_kernel_modules(p:P:m:C:c) \ | |
144 | %{!?-m:%{error:%{0}: Required module name/list missing} exit 1} \ | |
145 | \ | |
146 | %define Opts \\\\\\\ | |
147 | %if "%{_target_base_arch}" != "%{_host_base_arch}" \\\ | |
148 | %if "%{_host_base_arch}" == "x86_64" && "%{_target_base_arch}" == "i386" \\\ | |
149 | CC="%{__cc}" ARCH=%{_target_base_arch} \\\ | |
150 | %else \\\ | |
151 | ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\ | |
152 | %endif \\\ | |
153 | %else \\\ | |
154 | CC="%{__cc}" \\\ | |
155 | %endif \ | |
156 | %define MakeOpts HOSTCC="%{__cc}" SYSSRC=%{_kernelsrcdir} SYSOUT=$PWD/o \\\\\\\ | |
157 | O=$PWD/o %{?with_verbose:V=1} %{Opts} \ | |
158 | \ | |
159 | %{?-C:cd %{-C*}} \ | |
160 | compile() { \ | |
161 | local L="<" PATCH_SH; \ | |
162 | [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)" \ | |
163 | set -e -x \ | |
164 | \ | |
165 | [ -r "%{_kernelsrcdir}/.config" ] || exit 1 \ | |
166 | rm -rf o \ | |
167 | install -d o/include/linux o/include/generated o/arch/x86/include o/arch/powerpc/lib \ | |
168 | ln -sf %{_kernelsrcdir}/.config o/.config \ | |
169 | ln -sf %{_kernelsrcdir}/Module.symvers o/Module.symvers \ | |
170 | if [ -f %{_kernelsrcdir}/include/generated/autoconf.h ]; then \ | |
171 | ln -sf %{_kernelsrcdir}/include/generated/autoconf.h o/include/generated/autoconf.h \ | |
172 | ln -s ../generated/autoconf.h o/include/linux/autoconf.h \ | |
173 | else \ | |
174 | ln -sf %{_kernelsrcdir}/include/linux/autoconf.h o/include/linux/autoconf.h \ | |
175 | fi \ | |
176 | if [ -d %{_kernelsrcdir}/arch/x86/include/generated ]; then \ | |
177 | ln -s %{_kernelsrcdir}/arch/x86/include/generated o/arch/x86/include \ | |
178 | fi \ | |
179 | \ | |
180 | set +x \ | |
181 | [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell \ | |
182 | set -x \ | |
183 | \ | |
184 | install -d o/include/config \ | |
185 | touch o/include/config/MARKER \ | |
186 | ln -sf %{_kernelsrcdir}/include/config/auto.conf o/include/config/auto.conf \ | |
187 | ln -sf %{_kernelsrcdir}/scripts o/scripts \ | |
188 | \ | |
189 | %{!?-c:%{__make} -C %{_kernelsrcdir} clean \\\ | |
190 | RCS_FIND_IGNORE="-name '*.[ks]o' -o" \\\ | |
191 | ${1+"$@"} \\\ | |
192 | M=$PWD %{MakeOpts}} \ | |
193 | \ | |
194 | %{__make} -C %{_kernelsrcdir} modules \\\ | |
195 | ${1+"$@"} \\\ | |
196 | M=$PWD CONSTIFY_PLUGIN="" %{MakeOpts} \ | |
197 | %{?-C:cd -} \ | |
198 | } \ | |
199 | compile %{*} \ | |
200 | %{nil} | |
201 | ||
202 | %build_kernel_modules_compat(p:P:m:C:c) \ | |
203 | %{!?-m:%{error:%{0}: Required module name/list missing} exit 1} \ | |
204 | \ | |
205 | %define Opts \\\\\\\ | |
206 | %if "%{_target_base_arch}" != "%{_host_base_arch}" \\\ | |
207 | %if "%{_host_base_arch}" == "x86_64" && "%{_target_base_arch}" == "i386" \\\ | |
208 | CC="%{__cc}" ARCH=%{_target_base_arch} \\\ | |
209 | %else \\\ | |
210 | ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\ | |
211 | %endif \\\ | |
212 | %else \\\ | |
213 | CC="%{__cc}" \\\ | |
214 | %endif \ | |
215 | %define MakeOpts HOSTCC="%{__cc}" SYSSRC=%{_kernelsrcdir} SYSOUT=$PWD/o \\\\\\\ | |
216 | O=$PWD/o %{?with_verbose:V=1} %{Opts} \ | |
217 | \ | |
218 | %{?-C:cd %{-C*}} \ | |
219 | compile() { \ | |
220 | local L="<" PATCH_SH; \ | |
221 | [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)" \ | |
222 | set -e -x \ | |
223 | local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \ | |
224 | \ | |
225 | for cfg in ${cfgs:-dist}; do \ | |
226 | [ -r "%{_kernelsrcdir}/config-$cfg" ] || exit 1 \ | |
227 | \ | |
228 | rm -rf o \ | |
229 | install -d o/include/linux o/include/generated o/arch/powerpc/lib \ | |
230 | ln -sf %{_kernelsrcdir}/config-$cfg o/.config \ | |
231 | ln -sf %{_kernelsrcdir}/Module.symvers-$cfg o/Module.symvers \ | |
232 | if [ -f %{_kernelsrcdir}/include/generated/autoconf-$cfg.h ]; then \ | |
233 | ln -sf %{_kernelsrcdir}/include/generated/autoconf-$cfg.h o/include/generated/autoconf.h \ | |
234 | ln -s ../generated/autoconf.h o/include/linux/autoconf.h \ | |
235 | else \ | |
236 | ln -sf %{_kernelsrcdir}/include/linux/autoconf-$cfg.h o/include/linux/autoconf.h \ | |
237 | fi \ | |
238 | \ | |
239 | set +x \ | |
240 | [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell \ | |
241 | set -x \ | |
242 | \ | |
243 | %if %{with dist_kernel} || %(test -f %{_kernelsrcdir}/scripts/bin2c ; echo $?) \ | |
244 | %{__make} -j1 -C %{_kernelsrcdir} prepare scripts \\\ | |
245 | %{-p*} %{-P*} \\\ | |
246 | %{MakeOpts} \ | |
247 | %else \ | |
248 | install -d o/include/config \ | |
249 | touch o/include/config/MARKER \ | |
250 | ln -sf %{_kernelsrcdir}/include/config/auto-$cfg.conf o/include/config/auto.conf \ | |
251 | ln -sf %{_kernelsrcdir}/scripts o/scripts \ | |
252 | %endif \ | |
253 | \ | |
254 | %{!?-c:%{__make} -C %{_kernelsrcdir} clean \\\ | |
255 | RCS_FIND_IGNORE="-name '*.[ks]o' -o" \\\ | |
256 | ${1+"$@"} \\\ | |
257 | M=$PWD %{MakeOpts}} \ | |
258 | \ | |
259 | %{__make} -C %{_kernelsrcdir} modules \\\ | |
260 | ${1+"$@"} \\\ | |
261 | M=$PWD CONSTIFY_PLUGIN="" %{MakeOpts} \ | |
262 | \ | |
263 | for MODULE in {%{-m*},}; do \ | |
264 | [ -z "${MODULE}" ] || mv ${MODULE}{,-$cfg}.ko \ | |
265 | done \ | |
266 | done \ | |
267 | %{?-C:cd -} \ | |
268 | } \ | |
269 | compile %{*} \ | |
270 | %{nil} | |
271 | ||
272 | ||
273 | # Install kernel modules built by %build_kernel_modules | |
274 | # Author: Przemyslaw Iskra <sparky@pld-linux.org> | |
275 | # | |
276 | # Usage: | |
277 | # %install_kernel_modules -m <modules> -d <directory> | |
278 | # | |
279 | # Options: | |
280 | # -m <modules> (required) -- comma-separated list of modules to install, | |
281 | # without .ko extension, may be placed in subdirectory | |
282 | # -d <directory> (required) -- in what subdirectory modules should be | |
283 | # installed (eg. misc, kernel/drivers/net) | |
284 | # -s <suffix> -- suffix to use when installing modules, useful when module | |
285 | # with same name exists in kernel already | |
286 | # -n <file> -- name of modprobe config file to use (without .conf extension) | |
287 | # for defining aliases, only useful with -s | |
288 | # -D <directory> -- DESTDIR, base directory for installed files, | |
289 | # defaults to RPM_BUILD_ROOT | |
290 | ||
291 | %install_kernel_modules(m:d:s:n:D:) \ | |
292 | %{!?-m:%{error:%{0}: Required module name (-m) missing}exit 1} \ | |
293 | %{!?-d:%{error:%{0}: Required module directory missing}exit 1} \ | |
294 | %{?-n:%{!?-s:%{error:%{0}: Modprobe .conf file requires module suffix}exit 1}} \ | |
295 | \ | |
296 | INSTALLROOT=%{-D*} \ | |
297 | [ -n "$INSTALLROOT" ] || INSTALLROOT=$RPM_BUILD_ROOT \ | |
298 | \ | |
299 | %{!?debug:set +x;} \ | |
300 | \ | |
301 | for MODULE in {%{-m*},}; do \ | |
302 | [ -n "${MODULE}" ] || continue \ | |
303 | MNAME=${MODULE##*/} \ | |
304 | install -m 644 -D ${MODULE}.ko $INSTALLROOT/lib/modules/%{_kernel_ver}/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko \ | |
305 | %{?-s:install -d $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \ | |
306 | echo "alias ${MNAME} ${MNAME}-%{-s*}" >> $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver}/%{-n*}.conf} \ | |
307 | done \ | |
308 | unset INSTALLROOT \ | |
309 | %{nil} | |
310 | ||
311 | %install_kernel_modules_compat(m:d:s:n:D:) \ | |
312 | %{!?-m:%{error:%{0}: Required module name (-m) missing}exit 1} \ | |
313 | %{!?-d:%{error:%{0}: Required module directory missing}exit 1} \ | |
314 | %{?-n:%{!?-s:%{error:%{0}: Modprobe .conf file requires module suffix}exit 1}} \ | |
315 | \ | |
316 | INSTALLROOT=%{-D*} \ | |
317 | [ -n "$INSTALLROOT" ] || INSTALLROOT=$RPM_BUILD_ROOT \ | |
318 | \ | |
319 | %{!?debug:set +x;} \ | |
320 | local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \ | |
321 | \ | |
322 | for MODULE in {%{-m*},}; do \ | |
323 | [ -n "${MODULE}" ] || continue \ | |
324 | for cfg in ${cfgs:-dist}; do \ | |
325 | [ "$cfg" = smp ] && suf=smp || suf= \ | |
326 | MNAME=${MODULE##*/} \ | |
327 | install -m 644 -D ${MODULE}-$cfg.ko \\\ | |
328 | $INSTALLROOT/lib/modules/%{_kernel_ver}$suf/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko \ | |
329 | %{?-s:install -d $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver}$suf \ | |
330 | echo "alias ${MNAME} ${MNAME}-%{-s*}" \\\ | |
331 | >> $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} $suf/%{-n*}.conf} \ | |
332 | done \ | |
333 | done \ | |
334 | unset INSTALLROOT \ | |
335 | %{nil} |