File r8168.spec of Package r8168

%define realname r8168
%define realver  8.040.00
%define srcext   tar.bz2

Name:          %{realname}
Version:       %{realver}
Release:       1
License:       GPL-2.0+
Group:         System/Kernel
URL:           http://www.realtek.com.tw/products/productsView.aspx?Langid=1&PNid=13&PFid=5&Level=5&Conn=4
Summary:       Driver for RealTek Gigabit Ethernet controllers with PCI-Express interface

# Build-time parameters
ExclusiveOS:   Linux
BuildRequires: %kernel_module_package_buildreqs
BuildArch:     %{_host_cpu}
# Needed for rpmlint
%if 0%{?opensuse_bs}
BuildRequires: dkms
%endif
BuildRoot:     %{_tmppath}/%{name}-%{version}-build
Source0:       http://12244.wpc.azureedge.net/8012244/drivers/rtdrivers/cn/nic/0002-%{realname}-%{realver}.%{srcext}
Source199:     compiler-gcc5.h

%description
Linux device driver released for RealTek RTL8168B/8111B, RTL8168C/8111C,
RTL8168CP/8111CP, RTL8168D/8111D, RTL8168DP/8111DP, and RTL8168E/8111E
Gigabit Ethernet controllers with PCI-Express interface

%kernel_module_package %{?suse_version:-p %_sourcedir/preamble} -x kdump -x um -x ec2 -x debug

%package KMP
Group:         System/Kernel
Summary:       Driver for RealTek Gigabit Ethernet controllers with PCI-Express interface

%description KMP
Linux device driver released for RealTek RTL8168B/8111B, RTL8168C/8111C,
RTL8168CP/8111CP, RTL8168D/8111D, RTL8168DP/8111DP, and RTL8168E/8111E
Gigabit Ethernet controllers with PCI-Express interface

%package dkms
Summary:       Driver for RealTek Gigabit Ethernet controllers with PCI-Express interface
Group:         System/Kernel
Requires:      dkms kernel-devel
BuildArch:     noarch

%description dkms
Linux device driver released for RealTek RTL8168B/8111B, RTL8168C/8111C,
RTL8168CP/8111CP, RTL8168D/8111D, RTL8168DP/8111DP, and RTL8168E/8111E
Gigabit Ethernet controllers with PCI-Express interface

%prep
%setup -q -n %{realname}-%{realver}
%{__chmod} a-x,g-w README src/*
if [ -f /usr/src/linux/include/linux/compiler-gcc4.h ]; then
  %{__install} -D -m644 /usr/src/linux/include/linux/compiler-gcc4.h src/linux/compiler-gcc5.h
elif [ -f %{kernel_source default}/include/linux/compiler-gcc4.h ]; then
  %{__install} -D -m644 %{kernel_source default}/include/linux/compiler-gcc4.h src/linux/compiler-gcc5.h
else
  %{__install} -D -m644 %{S:199} src/linux/compiler-gcc5.h
fi
sed -ri '/obj-m/ a\\tEXTRA_CFLAGS := -I$(KBUILD_EXTMOD)' src/Makefile

%build
# Build kernel module
%{__mkdir} obj
for flavor in %flavors_to_build; do
  %{__rm} -rf obj/$flavor
  %{__cp} -r src obj/$flavor
  %{__make} -C %{kernel_source $flavor} modules \
    M=$PWD/obj/$flavor
done

%install
# Install kernel module
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=updates
for flavor in %flavors_to_build; do
  %{__make} -C %{kernel_source $flavor} modules_install \
  M=$PWD/obj/$flavor
done
# Install sources for DKMS
%{__install} -d -m755 %{buildroot}/usr/src/%{realname}-%{realver}
%{__cp} -r src/* %{buildroot}/usr/src/%{realname}-%{realver}/
cat > %{buildroot}/usr/src/%{realname}-%{realver}/dkms.conf <<EOF
PACKAGE_NAME=%{realname}
PACKAGE_VERSION=%{realver}
AUTOINSTALL=yes

BUILT_MODULE_NAME=%{realname}

DEST_MODULE_LOCATION=/updates
EOF

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files dkms
%defattr(-,root,root)
%doc README
%dir /usr/src/%{realname}-%{realver}
/usr/src/%{realname}-%{realver}/*

%post dkms
/usr/sbin/dkms add -q -m %{realname} -v %{version} || :

%preun dkms
/usr/sbin/dkms remove -q --all -m %{realname} -v %{version} || :

%changelog