#
-# Replace MODULE_NAME with real module name and MODULE_DIR
-# with required directory name.
+# Replace:
+# MODULE_NAME with real module name
+# MODULE_DIR with required directory name
+# PACKAGE_NAME with package name
#
# Conditional build:
-%bcond_without dist_kernel # allow non-distribution kernel
%bcond_without kernel # don't build kernel modules
%bcond_without userspace # don't build userspace programs
%bcond_with verbose # verbose build (V=1)
-%if %{without kernel}
-%undefine with_dist_kernel
+%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 rel 0.1
+%define pname PACKAGE_NAME
Summary: -
Summary(pl.UTF-8): -
-Name: -
+Name: %{pname}%{?_pld_builder:%{?with_kernel:-kernel}}%{_alt_kernel}
Version: 0.1
-Release: %{_rel}
-Epoch: 0
+Release: %{rel}%{?_pld_builder:%{?with_kernel:@%{_kernel_ver_str}}}
#License: - (enter GPL/LGPL/BSD/BSD-like/other license name here)
-Group: -
-Source0: %{name}-%{version}.tar.gz
+Group: Base/Kernel
+Source0: %{pname}-%{version}.tar.gz
# Source0-md5: -
#Source1: -
# Source1-md5: -
-#Patch0: %{name}-what.patch
+#Patch0: %{pname}-what.patch
#URL: -
-%if %{with kernel}
-%{?with_dist_kernel:BuildRequires: kernel%{_alt_kernel}-module-build >= 3:2.6.20.2}
-BuildRequires: rpmbuild(macros) >= 1.379
-%endif
+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): -
%description -l pl.UTF-8
-# kernel subpackages.
-
-%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
-%if %{with dist_kernel}
-%requires_releq_kernel
-Requires(postun): %releq_kernel
-%endif
-
-%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.
+# 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
EOF
%build
-%if %{with userspace}
-
-
-%endif
+%{?with_kernel:%{expand:%build_kernel_packages}}
-%if %{with kernel}
-%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
+%if %{with userspace}
%endif
%install
rm -rf $RPM_BUILD_ROOT
+install -d $RPM_BUILD_ROOT
-%if %{with userspace}
-
-
+%if %{with kernel}
+%{expand:%install_kernel_packages}
+cp -a installed/* $RPM_BUILD_ROOT
%endif
-%if %{with kernel}
-%install_kernel_modules -m MODULE_NAME -d MODULE_DIR
+%if %{with userspace}
-# to avoid conflict with in-kernel modules, and prepare modprobe config:
-%install_kernel_modules -s current -n NAME -m MODULE_NAME -d MODULE_DIR
%endif
%clean
rm -rf $RPM_BUILD_ROOT
-%post -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME
-%depmod %{_kernel_ver}
-
-%postun -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME
-%depmod %{_kernel_ver}
-
-%if %{with kernel}
-%files -n kernel%{_alt_kernel}-MODULE_DIR-MODULE_NAME
-%defattr(644,root,root,755)
-/lib/modules/%{_kernel_ver}/MODULE_DIR/*.ko*
-%endif
-
%if %{with userspace}
%files
%defattr(644,root,root,755)
-
%endif