# # Replace: # MODULE_NAME with real module name # MODULE_DIR with required directory name # PACKAGE_NAME with package name # # Conditional build: %bcond_without kernel # don't build kernel modules %bcond_without userspace # don't build userspace programs %bcond_with verbose # verbose build (V=1) %if 0%{?_pld_builder:1} && %{with kernel} && %{with userspace} %{error:kernel and userspace cannot be built at the same time on PLD builders} exit 1 %endif %if %{without userspace} # nothing to be placed to debuginfo package %define _enable_debug_packages 0 %endif # # main package. # %define rel 0.1 %define pname PACKAGE_NAME Summary: - Summary(pl.UTF-8): - Name: %{pname}%{?_pld_builder:%{?with_kernel:-kernel}}%{_alt_kernel} Version: 0.1 Release: %{rel}%{?_pld_builder:%{?with_kernel:@%{_kernel_ver_str}}} #License: - (enter GPL/LGPL/BSD/BSD-like/other license name here) Group: Base/Kernel Source0: %{pname}-%{version}.tar.gz # Source0-md5: - #Source1: - # Source1-md5: - #Patch0: %{pname}-what.patch #URL: - BuildRequires: rpmbuild(macros) >= 1.701 %{?with_kernel:%{expand:%buildrequires_kernel kernel%%{_alt_kernel}-module-build >= 3:2.6.20.2}} #BuildRequires: - #Requires(postun): - #Requires(pre,post): - #Requires(preun): - #Requires: - #Provides: - #Obsoletes: - #Conflicts: - BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) %description %description -l pl.UTF-8 # kernel subpackages definition. %define kernel_pkg()\ %package -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\ Summary: Linux driver for MODULE_NAME\ Summary(pl.UTF-8): Sterownik dla Linuksa do MODULE_NAME\ Release: %{rel}@%{_kernel_ver_str}\ Group: Base/Kernel\ Requires(post,postun): /sbin/depmod\ %requires_releq_kernel\ Requires(postun): %releq_kernel\ \ %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\ This is driver for MODULE_NAME for Linux.\ \ This package contains Linux module.\ \ %description -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME -l pl.UTF-8\ Sterownik dla Linuksa do MODULE_NAME.\ \ Ten pakiet zawiera moduł jądra Linuksa.\ \ %if %{with kernel}\ %files -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\ %defattr(644,root,root,755)\ /lib/modules/%{_kernel_ver}/kernel/MODULE_DIR/*.ko*\ %endif\ \ %post -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\ %depmod %{_kernel_ver}\ \ %postun -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME\ %depmod %{_kernel_ver}\ %{nil} %define build_kernel_pkg()\ %build_kernel_modules -m MODULE_NAME\ \ # modules placed in subdirectory:\ %build_kernel_modules -C path/to/dir -m MODULE_NAME,MODULE2\ \ # need to pass additional options to make modules:\ %build_kernel_modules VAR1=value1 VAR2=value2 -m MODULE_NAME\ \ # optional patching:\ %build_kernel_modules -m MODULE_NAME <<'EOF'\ # Your script here:\ if grep -q "CONFIG_SOME_OPTION" o/.config; then\ sed 's/some/change/' file.c.orig > file.c\ else\ cat file.c.orig > file.c\ fi\ # Don't do it this way unless it depends on kernel options or something\ # you can't check before\ EOF\ \ # install to local directory, this makes building for multiple kernels easy\ %install_kernel_modules -D installed -m MODULE_NAME -d kernel/MODULE_DIR\ \ # to avoid conflict with in-kernel modules, and prepare modprobe config:\ %install_kernel_modules -D installed -s current -n NAME -m MODULE_NAME -d kernel/MODULE_DIR\ %{nil} %define install_kernel_pkg()\ # any additional, per-module, tasks needed at install,\ # like blacklisting in-kernel module to always load this one\ install -d $RPM_BUILD_ROOT/etc/modprobe.d/%{_kernel_ver}\ # blacklist kernel module\ cat > $RPM_BUILD_ROOT/etc/modprobe.d/%{_kernel_ver}/MODULE_NAME.conf <<'EOF'\ blacklist MODULE_NAME\ alias MODULE_NAME MODULE_NAME-current\ EOF\ %{nil} %{?with_kernel:%{expand:%create_kernel_packages}} %prep %setup -q -n %{pname}-%{version} # prepare makefile: cat > path/to/dir/Makefile << EOF obj-m += MODULE_NAME.o MODULE2.o MODULE_NAME-objs := file1.o file2.o \ file3.o file4.o file5.o MODULE2-objs := file6.o file7.o file8.o CFLAGS += -DCONFIG_MODULE_NAME_SOME_OPTION=1 %{?debug:CFLAGS += -DCONFIG_MODULE_NAME_DEBUG=1} EOF %build %{?with_kernel:%{expand:%build_kernel_packages}} %if %{with userspace} %endif %install rm -rf $RPM_BUILD_ROOT install -d $RPM_BUILD_ROOT %if %{with kernel} %{expand:%install_kernel_packages} cp -a installed/* $RPM_BUILD_ROOT %endif %if %{with userspace} %endif %clean rm -rf $RPM_BUILD_ROOT %if %{with userspace} %files %defattr(644,root,root,755) %endif