]> git.pld-linux.org Git - projects/template-specs.git/blob - kernel-module.spec
- switch to macro driven module build for multiple kernel versions
[projects/template-specs.git] / kernel-module.spec
1 #
2 # Replace:
3 # MODULE_NAME with real module name
4 # MODULE_DIR with required directory name
5 # PACKAGE_NAME with package name
6 #
7 # Conditional build:
8 %bcond_without  dist_kernel     # allow non-distribution kernel
9 %bcond_without  kernel          # don't build kernel modules
10 %bcond_without  userspace       # don't build userspace programs
11 %bcond_with     verbose         # verbose build (V=1)
12
13 %if %{without kernel}
14 %undefine       with_dist_kernel
15 %endif
16
17 # The goal here is to have main, userspace, package built once with
18 # simple release number, and only rebuild kernel packages with kernel
19 # version as part of release number, without the need to bump release
20 # with every kernel change.
21 %if 0%{?_pld_builder:1} && %{with kernel} && %{with userspace}
22 %{error:kernel and userspace cannot be built at the same time on PLD builders}
23 exit 1
24 %endif
25
26 %if "%{_alt_kernel}" != "%{nil}"
27 %if 0%{?build_kernels:1}
28 %{error:alt_kernel and build_kernels are mutually exclusive}
29 exit 1
30 %endif
31 %undefine       with_userspace
32 %global         _build_kernels          %{alt_kernel}
33 %else
34 %global         _build_kernels          %{?build_kernels:,%{?build_kernels}}
35 %endif
36
37 %if %{without userspace}
38 # nothing to be placed to debuginfo package
39 %define         _enable_debug_packages  0
40 %endif
41
42 %define         kpkg    %(echo %{_build_kernels} | tr , '\\n' | while read n ; do echo %%undefine alt_kernel ; [ -z "$n" ] || echo %%define alt_kernel $n ; echo %%kernel_pkg ; done)
43 %define         bkpkg   %(echo %{_build_kernels} | tr , '\\n' | while read n ; do echo %%undefine alt_kernel ; [ -z "$n" ] || echo %%define alt_kernel $n ; echo %%build_kernel_pkg ; done)
44 %define         ikpkg   %(echo %{_build_kernels} | tr , '\\n' | while read n ; do echo %%undefine alt_kernel ; [ -z "$n" ] || echo %%define alt_kernel $n ; echo %%install_kernel_pkg ; done)
45
46 #
47 # main package.
48 #
49 %define         rel     0.1
50 %define         pname   PACKAGE_NAME
51 Summary:        -
52 Summary(pl.UTF-8):      -
53 Name:           %{pname}%{_alt_kernel}
54 Version:        0.1
55 Release:        %{rel}%{?with_kernel:@%{_kernel_ver_str}}
56 #License:       - (enter GPL/LGPL/BSD/BSD-like/other license name here)
57 Group:          Base/Kernel
58 Source0:        %{pname}-%{version}.tar.gz
59 # Source0-md5:  -
60 #Source1:       -
61 # Source1-md5:  -
62 #Patch0:        %{pname}-what.patch
63 #URL:           -
64 BuildRequires:  rpmbuild(macros) >= 1.678
65 %{?with_dist_kernel:BuildRequires:      kernel%{_alt_kernel}-module-build >= 3:2.6.20.2}
66 #BuildRequires: -
67 #Requires(postun):      -
68 #Requires(pre,post):    -
69 #Requires(preun):       -
70 #Requires:      -
71 #Provides:      -
72 #Obsoletes:     -
73 #Conflicts:     -
74 BuildRoot:      %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
75
76 %description
77
78 %description -l pl.UTF-8
79
80 # kernel subpackages definition.
81
82 %define kernel_pkg()\
83 %package -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
84 Summary:        Linux driver for MODULE_NAME\
85 Summary(pl.UTF-8):      Sterownik dla Linuksa do MODULE_NAME\
86 Release:        %{rel}@%{_kernel_ver_str}\
87 Group:          Base/Kernel\
88 Requires(post,postun):  /sbin/depmod\
89 %if %{with dist_kernel}\
90 %requires_releq_kernel\
91 Requires(postun):       %releq_kernel\
92 %endif\
93 \
94 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
95 This is driver for MODULE_NAME for Linux.\
96 \
97 This package contains Linux module.\
98 \
99 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME -l pl.UTF-8\
100 Sterownik dla Linuksa do MODULE_NAME.\
101 \
102 Ten pakiet zawiera moduł jądra Linuksa.\
103 \
104 %if %{with kernel}\
105 %files -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
106 %defattr(644,root,root,755)\
107 /lib/modules/%{_kernel_ver}/kernel/MODULE_DIR/*.ko*\
108 %endif\
109 \
110 %post   -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
111 %depmod %{_kernel_ver}\
112 \
113 %postun -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
114 %depmod %{_kernel_ver}\
115 %{nil}
116
117 %define build_kernel_pkg()\
118 %build_kernel_modules -m MODULE_NAME\
119 \
120 # modules placed in subdirectory:\
121 %build_kernel_modules -C path/to/dir -m MODULE_NAME,MODULE2\
122 \
123 # need to pass additional options to make modules:\
124 %build_kernel_modules VAR1=value1 VAR2=value2 -m MODULE_NAME\
125 \
126 # optional patching:\
127 %build_kernel_modules -m MODULE_NAME <<'EOF'\
128 # Your script here:\
129 if grep -q "CONFIG_SOME_OPTION" o/.config; then\
130         sed 's/some/change/' file.c.orig > file.c\
131 else\
132         cat file.c.orig > file.c\
133 fi\
134 # Don't do it this way unless it depends on kernel options or something\
135 # you can't check before\
136 EOF\
137 \
138 # install to local directory, this makes building for multiple kernels easy\
139 %install_kernel_modules -D installed -m MODULE_NAME -d kernel/MODULE_DIR\
140 \
141 # to avoid conflict with in-kernel modules, and prepare modprobe config:\
142 %install_kernel_modules -D installed -s current -n NAME -m MODULE_NAME -d kernel/MODULE_DIR\
143 %{nil}
144
145 %define install_kernel_pkg()\
146 # any additional, per-module, tasks needed at install,\
147 # like blacklisting in-kernel module to always load this one\
148 install -d $RPM_BUILD_ROOT/etc/modprobe.d/%{_kernel_ver}\
149 # blacklist kernel module\
150 cat > $RPM_BUILD_ROOT/etc/modprobe.d/%{_kernel_ver}/MODULE_NAME.conf <<'EOF'\
151 blacklist MODULE_NAME\
152 alias MODULE_NAME MODULE_NAME-current\
153 EOF\
154 %{nil}
155
156 %{?with_kernel:%{expand:%kpkg}}
157
158 %prep
159 %setup -q -n %{pname}-%{version}
160
161 # prepare makefile:
162 cat > path/to/dir/Makefile << EOF
163
164 obj-m += MODULE_NAME.o MODULE2.o
165
166 MODULE_NAME-objs := file1.o file2.o \
167         file3.o file4.o file5.o
168
169 MODULE2-objs := file6.o file7.o file8.o
170
171 CFLAGS += -DCONFIG_MODULE_NAME_SOME_OPTION=1
172 %{?debug:CFLAGS += -DCONFIG_MODULE_NAME_DEBUG=1}
173 EOF
174
175 %build
176 %if %{with userspace}
177
178 %endif
179
180 %{?with_kernel:%{expand:%bkpkg}}
181
182 %install
183 rm -rf $RPM_BUILD_ROOT
184 install -d $RPM_BUILD_ROOT
185
186 %if %{with userspace}
187
188 %endif
189
190 %if %{with kernel}
191 %{expand:%ikpkg}
192 cp -a installed/* $RPM_BUILD_ROOT
193 %endif
194
195 %clean
196 rm -rf $RPM_BUILD_ROOT
197
198 %if %{with userspace}
199 %files
200 %defattr(644,root,root,755)
201 %endif
This page took 0.314256 seconds and 4 git commands to generate.