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