xref: /freebsd/sys/contrib/openzfs/rpm/generic/zfs-kmod.spec.in (revision c203bd70b5957f85616424b6fa374479372d06e3)
1%define module  @PACKAGE@
2
3%if !%{defined ksrc}
4%if 0%{?rhel}%{?fedora}
5%define ksrc    ${kernel_version##*___}
6%else
7%define ksrc    "$( \
8        if [ -e "/usr/src/linux-${kernel_version%%___*}" ]; then \
9            echo "/usr/src/linux-${kernel_version%%___*}"; \
10        elif [ -e "/lib/modules/${kernel_version%%___*}/source" ]; then \
11            echo "/lib/modules/${kernel_version%%___*}/source"; \
12        else \
13            echo "/lib/modules/${kernel_version%%___*}/build"; \
14        fi)"
15%endif
16%endif
17
18%if !%{defined kobj}
19%if 0%{?rhel}%{?fedora}
20%define kobj    ${kernel_version##*___}
21%else
22%define kobj    "$( \
23        if [ -e "/usr/src/linux-${kernel_version%%___*}" ]; then \
24            echo "/usr/src/linux-${kernel_version%%___*}"; \
25        else \
26            echo "/lib/modules/${kernel_version%%___*}/build"; \
27        fi)"
28%endif
29%endif
30
31#define repo    rpmfusion
32#define repo    chaos
33
34# (un)define the next line to either build for the newest or all current kernels
35%define buildforkernels newest
36#define buildforkernels current
37#define buildforkernels akmod
38
39%bcond_with     debug
40%bcond_with     debuginfo
41
42
43Name:           %{module}-kmod
44
45Version:        @VERSION@
46Release:        @RELEASE@%{?dist}
47Summary:        Kernel module(s)
48
49Group:          System Environment/Kernel
50License:        @ZFS_META_LICENSE@
51URL:            https://github.com/openzfs/zfs
52Source0:        %{module}-%{version}.tar.gz
53Source10:       kmodtool
54BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id} -u -n)
55%if 0%{?rhel}%{?fedora}
56BuildRequires:  gcc, make
57BuildRequires:  elfutils-libelf-devel
58%endif
59
60# The developments headers will conflict with the dkms packages.
61Conflicts:      %{module}-dkms
62
63%if %{defined repo}
64
65# Building for a repository use the proper build-sysbuild package
66# to determine which kernel-devel packages should be installed.
67BuildRequires:  %{_bindir}/kmodtool
68%{!?kernels:BuildRequires: buildsys-build-%{repo}-kerneldevpkgs-%{?buildforkernels:%{buildforkernels}}%{!?buildforkernels:current}-%{_target_cpu}}
69
70%else
71
72# Building local packages attempt to to use the installed kernel.
73%{?rhel:BuildRequires: kernel-devel}
74%{?fedora:BuildRequires: kernel-devel}
75%{?suse_version:BuildRequires: kernel-source}
76
77%if !%{defined kernels} && !%{defined build_src_rpm}
78    %if 0%{?rhel}%{?fedora}%{?suse_version}
79        %define kernels %(ls -1 /usr/src/kernels)
80    %else
81        %define kernels %(ls -1 /lib/modules)
82    %endif
83%endif
84%endif
85
86# LDFLAGS are not sanitized by arch/*/Makefile for these architectures.
87%ifarch ppc ppc64 ppc64le aarch64
88%global __global_ldflags %{nil}
89%endif
90
91# Kmodtool does its magic here.  A patched version of kmodtool is shipped
92# with the source rpm until kmod development packages are supported upstream.
93# https://bugzilla.rpmfusion.org/show_bug.cgi?id=2714
94%{expand:%(bash %{SOURCE10} --target %{_target_cpu} %{?repo:--repo %{?repo}} --kmodname %{name} %{?buildforkernels:--%{buildforkernels}} --devel %{?prefix:--prefix "%{?prefix}"} %{?kernels:--for-kernels "%{?kernels}"} %{?kernelbuildroot:--buildroot "%{?kernelbuildroot}"} --obsolete-name spl --obsolete-version 0.8 2>/dev/null) }
95
96
97%description
98This package contains the ZFS kernel modules.
99
100%prep
101# Error out if there was something wrong with kmodtool.
102%{?kmodtool_check}
103
104# Print kmodtool output for debugging purposes:
105bash %{SOURCE10}  --target %{_target_cpu} %{?repo:--repo %{?repo}} --kmodname %{name} %{?buildforkernels:--%{buildforkernels}} --devel %{?prefix:--prefix "%{?prefix}"} %{?kernels:--for-kernels "%{?kernels}"} %{?kernelbuildroot:--buildroot "%{?kernelbuildroot}"} --obsolete-name spl --obsolete-version 0.8 2>/dev/null
106
107%if %{with debug}
108    %define debug --enable-debug
109%else
110    %define debug --disable-debug
111%endif
112
113%if %{with debuginfo}
114    %define debuginfo --enable-debuginfo
115%else
116    %define debuginfo --disable-debuginfo
117%endif
118
119# Leverage VPATH from configure to avoid making multiple copies.
120%define _configure ../%{module}-%{version}/configure
121
122%setup -q -c -T -a 0
123
124for kernel_version in %{?kernel_versions}; do
125    %{__mkdir} _kmod_build_${kernel_version%%___*}
126done
127
128%build
129for kernel_version in %{?kernel_versions}; do
130    cd _kmod_build_${kernel_version%%___*}
131    %configure \
132        --with-config=kernel \
133        --with-linux=%{ksrc} \
134        --with-linux-obj=%{kobj} \
135        %{debug} \
136        %{debuginfo}
137    make %{?_smp_mflags}
138    cd ..
139done
140
141
142%install
143rm -rf ${RPM_BUILD_ROOT}
144
145# Relies on the kernel 'modules_install' make target.
146for kernel_version in %{?kernel_versions}; do
147    cd _kmod_build_${kernel_version%%___*}
148    make install \
149        DESTDIR=${RPM_BUILD_ROOT} \
150        %{?prefix:INSTALL_MOD_PATH=%{?prefix}} \
151        INSTALL_MOD_DIR=%{kmodinstdir_postfix}
152    cd ..
153done
154# find-debuginfo.sh only considers executables
155chmod u+x ${RPM_BUILD_ROOT}%{kmodinstdir_prefix}/*/extra/*/*/*
156%{?akmod_install}
157
158
159%clean
160rm -rf $RPM_BUILD_ROOT
161