%if 0%{?fedora}
%global buildforkernels akmod
%else
%global buildforkernels current
%endif
%global debug_package %{nil}
%global forgeurl https://github.com/atar-axis/xpadneo
%global prjname xpadneo

Name: %{prjname}-kmod
Version: 0.9.6
%forgemeta
Release: 1%{?dist}
Summary: Kernel module (kmod) for %{prjname}

# The license in the repository says GPLv3 but it was autogenerated by Github.
# The module declares its license as GPL, which in a kernel module means GPLv2.
License: GPL-2.0-only
URL: https://atar-axis.github.io/xpadneo
Source0: %{forgesource}

BuildRequires: gcc
BuildRequires: make
BuildRequires: kmodtool

%if 0%{?rhel}
%{!?kernels:BuildRequires: buildsys-build-rpmfusion-kerneldevpkgs-%{?buildforkernels:%{buildforkernels}}%{!?buildforkernels:current}-%{_target_cpu} }
%endif

# kmodtool does its magic here
%{expand:%(kmodtool --target %{_target_cpu} --repo rpmfusion --kmodname %{prjname} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null) }

%description
Advanced Linux Driver for Xbox One Wireless Controller (shipped with Xbox One
S).

  * Supports Bluetooth
  * Supports all Force Feedback/Rumble effects through Linux ff-memless effect
    emulation
  * Supports Trigger Force Feedback in every game by applying a
    pressure-dependent effect intensity to the current rumble effect (not even
    supported in Windows)
  * Supports disabling FF
  * Supports multiple Gamepads at the same time (not even supported in
    Windows)
  * Offers a consistent mapping, even if the Gamepad was paired to
    Windows/Xbox before, and independent of software layers (SDL2, Stadia via
    Chrome Gamepad API, etc)
  * Working Select, Start, Mode buttons
  * Correct Axis Range (signed, important for e.g. RPCS3)
  * Supports Battery Level Indication (including the Play 'n Charge Kit)
    Battery Level Indication
  * Easy Installation
  * Agile Support and Development
  * Supports customization through profiles (work in progress)
  * Optional high-precision mode for Wine/Proton users
  * Share button support on supported controllers
  * Works as a mouse if you're are in couch-mode (press Guide+Select)

This package contains the kmod module for %{prjname}.


%prep
%forgeautosetup

# Error out if there was something wrong with kmodtool.
%{?kmodtool_check}

# Print kmodtool output for debugging purposes:
kmodtool --target %{_target_cpu} --repo rpmfusion --kmodname %{prjname} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null

for kernel_version in %{?kernel_versions} ; do
    cp -a hid-%{prjname} _kmod_build_${kernel_version%%___*}
done

echo %{version} > VERSION


%build
for kernel_version in %{?kernel_versions} ; do
    make V=1 %{?_smp_mflags} -C ${kernel_version##*___} M=${PWD}/_kmod_build_${kernel_version%%___*}/src modules
done


%install
for kernel_version in %{?kernel_versions}; do
    mkdir -p %{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/
    install -D -p -m 0755 _kmod_build_${kernel_version%%___*}/src/*.ko %{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/
    chmod a+x %{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix}/*.ko
done
%{?akmod_install}


%changelog
* Tue Feb 13 2024 Artem Polishchuk <ego.cordatus@gmail.com> - 0.9.6-1
- chore: Update to latest release

* Tue Mar 14 2023 Artem Polishchuk <ego.cordatus@gmail.com> - 0.9.5-2
- build: Fixes per review request

* Sat Sep 17 2022 Artem Polishchuk <ego.cordatus@gmail.com> - 0.9.5-1
- chore(update): 0.9.5

* Thu May 26 2022 Artem Polishchuk <ego.cordatus@gmail.com> - 0.9.2-1
- chore(update): 0.9.2

* Tue Nov 02 2021 Artem Polishchuk <ego.cordatus@gmail.com> - 0.9.1-3
- build: Polish build to conform packaging guidelines

* Fri Jul 16 2021 Dorian Stoll <dorian.stoll@tmsp.io> - 0.9.1-1
- Initial package