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