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 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)
51 %define pname PACKAGE_NAME
54 Name: %{pname}%{?_pld_builder:%{?with_kernel:-kernel}}%{_alt_kernel}
56 Release: %{rel}%{?_pld_builder:%{?with_kernel:@%{_kernel_ver_str}}}
57 #License: - (enter GPL/LGPL/BSD/BSD-like/other license name here)
59 Source0: %{pname}-%{version}.tar.gz
63 #Patch0: %{pname}-what.patch
65 BuildRequires: rpmbuild(macros) >= 1.678
66 %{?with_dist_kernel:%{expand:%kbrs}}
69 #Requires(pre,post): -
75 BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
79 %description -l pl.UTF-8
81 # kernel subpackages definition.
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}\
89 Requires(post,postun): /sbin/depmod\
90 %if %{with dist_kernel}\
91 %requires_releq_kernel\
92 Requires(postun): %releq_kernel\
95 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
96 This is driver for MODULE_NAME for Linux.\
98 This package contains Linux module.\
100 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME -l pl.UTF-8\
101 Sterownik dla Linuksa do MODULE_NAME.\
103 Ten pakiet zawiera moduł jądra Linuksa.\
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*\
111 %post -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
112 %depmod %{_kernel_ver}\
114 %postun -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
115 %depmod %{_kernel_ver}\
118 %define build_kernel_pkg()\
119 %build_kernel_modules -m MODULE_NAME\
121 # modules placed in subdirectory:\
122 %build_kernel_modules -C path/to/dir -m MODULE_NAME,MODULE2\
124 # need to pass additional options to make modules:\
125 %build_kernel_modules VAR1=value1 VAR2=value2 -m MODULE_NAME\
127 # optional patching:\
128 %build_kernel_modules -m MODULE_NAME <<'EOF'\
130 if grep -q "CONFIG_SOME_OPTION" o/.config; then\
131 sed 's/some/change/' file.c.orig > file.c\
133 cat file.c.orig > file.c\
135 # Don't do it this way unless it depends on kernel options or something\
136 # you can't check before\
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\
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\
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\
157 %{?with_kernel:%{expand:%kpkg}}
160 %setup -q -n %{pname}-%{version}
163 cat > path/to/dir/Makefile << EOF
165 obj-m += MODULE_NAME.o MODULE2.o
167 MODULE_NAME-objs := file1.o file2.o \
168 file3.o file4.o file5.o
170 MODULE2-objs := file6.o file7.o file8.o
172 CFLAGS += -DCONFIG_MODULE_NAME_SOME_OPTION=1
173 %{?debug:CFLAGS += -DCONFIG_MODULE_NAME_DEBUG=1}
177 %if %{with userspace}
181 %{?with_kernel:%{expand:%bkpkg}}
184 rm -rf $RPM_BUILD_ROOT
185 install -d $RPM_BUILD_ROOT
187 %if %{with userspace}
193 cp -a installed/* $RPM_BUILD_ROOT
197 rm -rf $RPM_BUILD_ROOT
199 %if %{with userspace}
201 %defattr(644,root,root,755)