3 # MODULE_NAME with real module name
4 # MODULE_DIR with required directory name
5 # PACKAGE_NAME with package name
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)
14 %undefine with_dist_kernel
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}
26 %if "%{_alt_kernel}" != "%{nil}"
27 %if 0%{?build_kernels:1}
28 %{error:alt_kernel and build_kernels are mutually exclusive}
31 %undefine with_userspace
32 %global _build_kernels %{alt_kernel}
34 %global _build_kernels %{?build_kernels:,%{?build_kernels}}
37 %if %{without userspace}
38 # nothing to be placed to debuginfo package
39 %define _enable_debug_packages 0
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)
50 %define pname PACKAGE_NAME
53 Name: %{pname}%{_alt_kernel}
55 Release: %{rel}%{?with_kernel:@%{_kernel_ver_str}}
56 #License: - (enter GPL/LGPL/BSD/BSD-like/other license name here)
58 Source0: %{pname}-%{version}.tar.gz
62 #Patch0: %{pname}-what.patch
64 BuildRequires: rpmbuild(macros) >= 1.678
65 %{?with_dist_kernel:BuildRequires: kernel%{_alt_kernel}-module-build >= 3:2.6.20.2}
68 #Requires(pre,post): -
74 BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
78 %description -l pl.UTF-8
80 # kernel subpackages definition.
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}\
88 Requires(post,postun): /sbin/depmod\
89 %if %{with dist_kernel}\
90 %requires_releq_kernel\
91 Requires(postun): %releq_kernel\
94 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
95 This is driver for MODULE_NAME for Linux.\
97 This package contains Linux module.\
99 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME -l pl.UTF-8\
100 Sterownik dla Linuksa do MODULE_NAME.\
102 Ten pakiet zawiera moduł jądra Linuksa.\
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*\
110 %post -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
111 %depmod %{_kernel_ver}\
113 %postun -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
114 %depmod %{_kernel_ver}\
117 %define build_kernel_pkg()\
118 %build_kernel_modules -m MODULE_NAME\
120 # modules placed in subdirectory:\
121 %build_kernel_modules -C path/to/dir -m MODULE_NAME,MODULE2\
123 # need to pass additional options to make modules:\
124 %build_kernel_modules VAR1=value1 VAR2=value2 -m MODULE_NAME\
126 # optional patching:\
127 %build_kernel_modules -m MODULE_NAME <<'EOF'\
129 if grep -q "CONFIG_SOME_OPTION" o/.config; then\
130 sed 's/some/change/' file.c.orig > file.c\
132 cat file.c.orig > file.c\
134 # Don't do it this way unless it depends on kernel options or something\
135 # you can't check before\
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\
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\
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\
156 %{?with_kernel:%{expand:%kpkg}}
159 %setup -q -n %{pname}-%{version}
162 cat > path/to/dir/Makefile << EOF
164 obj-m += MODULE_NAME.o MODULE2.o
166 MODULE_NAME-objs := file1.o file2.o \
167 file3.o file4.o file5.o
169 MODULE2-objs := file6.o file7.o file8.o
171 CFLAGS += -DCONFIG_MODULE_NAME_SOME_OPTION=1
172 %{?debug:CFLAGS += -DCONFIG_MODULE_NAME_DEBUG=1}
176 %if %{with userspace}
180 %{?with_kernel:%{expand:%bkpkg}}
183 rm -rf $RPM_BUILD_ROOT
184 install -d $RPM_BUILD_ROOT
186 %if %{with userspace}
192 cp -a installed/* $RPM_BUILD_ROOT
196 rm -rf $RPM_BUILD_ROOT
198 %if %{with userspace}
200 %defattr(644,root,root,755)