#
-# 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 smp # don't build SMP module
-%bcond_without userspace # don't build userspace module
+%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 pname PACKAGE_NAME
Summary: -
-Summary(pl): -
-Name: -
-Version: -
-%define _rel 0.1
-Release: %{_rel}
-Epoch: 0
+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: -
-Vendor: -
-Icon: -
-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-module-build >= 2.6.7}
-BuildRequires: rpmbuild(macros) >= 1.217
-%endif
+BuildRequires: rpmbuild(macros) >= 1.701
+%{?with_kernel:%{expand:%buildrequires_kernel kernel%%{_alt_kernel}-module-build >= 3:2.6.20.2}}
#BuildRequires: -
-#PreReq: -
+#Requires(postun): -
#Requires(pre,post): -
#Requires(preun): -
-#Requires(postun): -
#Requires: -
#Provides: -
#Obsoletes: -
%description
-%description -l pl
-
-# kernel subpackages.
-
-%package -n kernel-MODULE_DIR-MODULE_NAME
-Summary: Linux driver for MODULE_NAME
-Summary(pl): 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_up
-Requires(postun): %releq_kernel_up
-%endif
-
-%description -n kernel-MODULE_DIR-MODULE_NAME
-This is driver for MODULE_NAME for Linux.
-
-This package contains Linux module.
+%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}}
-%description -n kernel-MODULE_DIR-MODULE_NAME -l pl
-Sterownik dla Linuksa do MODULE_NAME.
-
-Ten pakiet zawiera modu³ j±dra Linuksa.
-
-%package -n kernel-smp-MODULE_DIR-MODULE_NAME
-Summary: Linux SMP driver for MODULE_NAME
-Summary(pl): Sterownik dla Linuksa SMP do MODULE_NAME
-Release: %{_rel}@%{_kernel_ver_str}
-Group: Base/Kernel
-Requires(post,postun): /sbin/depmod
-%if %{with dist_kernel}
-%requires_releq_kernel_smp
-Requires(postun): %releq_kernel_smp
-%endif
+%prep
+%setup -q -n %{pname}-%{version}
-%description -n kernel-smp-MODULE_DIR-MODULE_NAME
-This is driver for MODULE_NAME for Linux.
+# prepare makefile:
+cat > path/to/dir/Makefile << EOF
-This package contains Linux SMP module.
+obj-m += MODULE_NAME.o MODULE2.o
-%description -n kernel-smp-MODULE_DIR-MODULE_NAME -l pl
-Sterownik dla Linuksa do MODULE_NAME.
+MODULE_NAME-objs := file1.o file2.o \
+ file3.o file4.o file5.o
-Ten pakiet zawiera modu³ j±dra Linuksa SMP.
+MODULE2-objs := file6.o file7.o file8.o
-%prep
+CFLAGS += -DCONFIG_MODULE_NAME_SOME_OPTION=1
+%{?debug:CFLAGS += -DCONFIG_MODULE_NAME_DEBUG=1}
+EOF
%build
-%if %{with userspace}
+%{?with_kernel:%{expand:%build_kernel_packages}}
+%if %{with userspace}
%endif
-%if %{with kernel}
-# kernel module(s)
-for cfg in %{?with_dist_kernel:%{?with_smp:smp} up}%{!?with_dist_kernel:nondist}; do
- if [ ! -r "%{_kernelsrcdir}/config-$cfg" ]; then
- exit 1
- fi
- rm -rf include
- install -d include/{linux,config}
- ln -sf %{_kernelsrcdir}/config-$cfg .config
- ln -sf %{_kernelsrcdir}/include/linux/autoconf-$cfg.h include/linux/autoconf.h
- ln -sf %{_kernelsrcdir}/include/asm-%{_target_base_arch} include/asm
- touch include/config/MARKER
-#
-# patching/creating makefile(s) (optional)
-#
- %{__make} -C %{_kernelsrcdir} clean \
- RCS_FIND_IGNORE="-name '*.ko' -o" \
- M=$PWD O=$PWD \
- %{?with_verbose:V=1}
- %{__make} -C %{_kernelsrcdir} modules \
- CC="%{__cc}" CPP="%{__cpp}" \
- M=$PWD O=$PWD \
- %{?with_verbose:V=1}
-
- mv MODULE_NAME{,-$cfg}.ko
-done
-%endif
-
%install
rm -rf $RPM_BUILD_ROOT
-
-%if %{with userspace}
-
-
-%endif
+install -d $RPM_BUILD_ROOT
%if %{with kernel}
-install -d $RPM_BUILD_ROOT/lib/modules/%{_kernel_ver}{,smp}/MODULE_DIR
-install MODULE_NAME-%{?with_dist_kernel:up}%{!?with_dist_kernel:nondist}.ko \
- $RPM_BUILD_ROOT/lib/modules/%{_kernel_ver}/MODULE_DIR/MODULE_NAME.ko
-%if %{with smp} && %{with dist_kernel}
-install MODULE_NAME-smp.ko \
- $RPM_BUILD_ROOT/lib/modules/%{_kernel_ver}smp/MODULE_DIR/MODULE_NAME.ko
+%{expand:%install_kernel_packages}
+cp -a installed/* $RPM_BUILD_ROOT
%endif
+
+%if %{with userspace}
+
%endif
%clean
rm -rf $RPM_BUILD_ROOT
-%post -n kernel-MODULE_DIR-MODULE_NAME
-%depmod %{_kernel_ver}
-
-%postun -n kernel-MODULE_DIR-MODULE_NAME
-%depmod %{_kernel_ver}
-
-%post -n kernel-smp-MODULE_DIR-MODULE_NAME
-%depmod %{_kernel_ver}smp
-
-%postun -n kernel-smp-MODULE_DIR-MODULE_NAME
-%depmod %{_kernel_ver}smp
-
-%if %{with kernel}
-%files -n kernel-MODULE_DIR-MODULE_NAME
-%defattr(644,root,root,755)
-/lib/modules/%{_kernel_ver}/MODULE_DIR/*.ko*
-
-%if %{with smp} && %{with dist_kernel}
-%files -n kernel-smp-MODULE_DIR-MODULE_NAME
-%defattr(644,root,root,755)
-/lib/modules/%{_kernel_ver}smp/MODULE_DIR/*.ko*
-%endif
-%endif
-
%if %{with userspace}
%files
%defattr(644,root,root,755)
-
%endif