3 # MODULE_NAME with real module name
4 # MODULE_DIR with required directory name
5 # PACKAGE_NAME with package name
8 %bcond_without kernel # don't build kernel modules
9 %bcond_without userspace # don't build userspace programs
10 %bcond_with verbose # verbose build (V=1)
12 %if 0%{?_pld_builder:1} && %{with kernel} && %{with userspace}
13 %{error:kernel and userspace cannot be built at the same time on PLD builders}
17 %if %{without userspace}
18 # nothing to be placed to debuginfo package
19 %define _enable_debug_packages 0
25 %define pname PACKAGE_NAME
28 Name: %{pname}%{?_pld_builder:%{?with_kernel:-kernel}}%{_alt_kernel}
30 Release: %{rel}%{?_pld_builder:%{?with_kernel:@%{_kernel_ver_str}}}
31 #License: - (enter GPL/LGPL/BSD/BSD-like/other license name here)
33 Source0: %{pname}-%{version}.tar.gz
37 #Patch0: %{pname}-what.patch
39 BuildRequires: rpmbuild(macros) >= 1.701
40 %{?with_kernel:%{expand:%buildrequires_kernel kernel%%{_alt_kernel}-module-build >= 3:2.6.20.2}}
43 #Requires(pre,post): -
49 BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
53 %description -l pl.UTF-8
55 # kernel subpackages definition.
58 %package -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
59 Summary: Linux driver for MODULE_NAME\
60 Summary(pl.UTF-8): Sterownik dla Linuksa do MODULE_NAME\
61 Release: %{rel}@%{_kernel_ver_str}\
63 Requires(post,postun): /sbin/depmod\
64 %requires_releq_kernel\
65 Requires(postun): %releq_kernel\
67 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
68 This is driver for MODULE_NAME for Linux.\
70 This package contains Linux module.\
72 %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME -l pl.UTF-8\
73 Sterownik dla Linuksa do MODULE_NAME.\
75 Ten pakiet zawiera moduł jądra Linuksa.\
78 %files -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
79 %defattr(644,root,root,755)\
80 /lib/modules/%{_kernel_ver}/kernel/MODULE_DIR/*.ko*\
83 %post -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
84 %depmod %{_kernel_ver}\
86 %postun -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\
87 %depmod %{_kernel_ver}\
90 %define build_kernel_pkg()\
91 %build_kernel_modules -m MODULE_NAME\
93 # modules placed in subdirectory:\
94 %build_kernel_modules -C path/to/dir -m MODULE_NAME,MODULE2\
96 # need to pass additional options to make modules:\
97 %build_kernel_modules VAR1=value1 VAR2=value2 -m MODULE_NAME\
100 %build_kernel_modules -m MODULE_NAME <<'EOF'\
102 if grep -q "CONFIG_SOME_OPTION" o/.config; then\
103 sed 's/some/change/' file.c.orig > file.c\
105 cat file.c.orig > file.c\
107 # Don't do it this way unless it depends on kernel options or something\
108 # you can't check before\
111 # install to local directory, this makes building for multiple kernels easy\
112 %install_kernel_modules -D installed -m MODULE_NAME -d kernel/MODULE_DIR\
114 # to avoid conflict with in-kernel modules, and prepare modprobe config:\
115 %install_kernel_modules -D installed -s current -n NAME -m MODULE_NAME -d kernel/MODULE_DIR\
118 %define install_kernel_pkg()\
119 # any additional, per-module, tasks needed at install,\
120 # like blacklisting in-kernel module to always load this one\
121 install -d $RPM_BUILD_ROOT/etc/modprobe.d/%{_kernel_ver}\
122 # blacklist kernel module\
123 cat > $RPM_BUILD_ROOT/etc/modprobe.d/%{_kernel_ver}/MODULE_NAME.conf <<'EOF'\
124 blacklist MODULE_NAME\
125 alias MODULE_NAME MODULE_NAME-current\
129 %{?with_kernel:%{expand:%create_kernel_packages}}
132 %setup -q -n %{pname}-%{version}
135 cat > path/to/dir/Makefile << EOF
137 obj-m += MODULE_NAME.o MODULE2.o
139 MODULE_NAME-objs := file1.o file2.o \
140 file3.o file4.o file5.o
142 MODULE2-objs := file6.o file7.o file8.o
144 CFLAGS += -DCONFIG_MODULE_NAME_SOME_OPTION=1
145 %{?debug:CFLAGS += -DCONFIG_MODULE_NAME_DEBUG=1}
149 %{?with_kernel:%{expand:%build_kernel_packages}}
151 %if %{with userspace}
156 rm -rf $RPM_BUILD_ROOT
157 install -d $RPM_BUILD_ROOT
160 %{expand:%install_kernel_packages}
161 cp -a installed/* $RPM_BUILD_ROOT
164 %if %{with userspace}
169 rm -rf $RPM_BUILD_ROOT
171 %if %{with userspace}
173 %defattr(644,root,root,755)