%global PREFIX /usr/
%global DOMAIN github.com
%global ORG kata-containers
%global PROJECT ksm-throttler
%global IMPORTNAME %{DOMAIN}/%{ORG}/%{PROJECT}
%global GO_VERSION @GO_VERSION@
%global GO_ARCH @GO_ARCH@

%if 0%{?suse_version}
%define LIBEXECDIR %{_libdir}
%else
%define LIBEXECDIR %{_libexecdir}
%endif

%undefine _missing_build_ids_terminate_build
%define  debug_package %{nil}

Name:      kata-ksm-throttler
Version:   @VERSION@
Release:   @RELEASE@
Source0:   %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Summary  : No detailed summary available
Group    : Development/Tools
License  : Apache-2.0

BuildRequires: git
BuildRequires: systemd

# Patches
@RPM_PATCH_LIST@

%description
.. contents::
.. sectnum::
``kata-ksm-throttler``
===================
Overview
--------

%prep
mkdir local
tar -C local -xzf ../SOURCES/go%{GO_VERSION}.linux-%{GO_ARCH}.tar.gz

%setup -q
%autosetup -S git
@RPM_APPLY_PATCHES@

%build
export GOROOT=$HOME/rpmbuild/BUILD/local/go
export PATH=$PATH:$HOME/rpmbuild/BUILD/local/go/bin
export GOPATH=$HOME/rpmbuild/BUILD/go/

mkdir -p $HOME/rpmbuild/BUILD/go/src/%{DOMAIN}/%{ORG}
ln -s $HOME/rpmbuild/BUILD/kata-ksm-throttler-%{version} $HOME/rpmbuild/BUILD/go/src/%{IMPORTNAME}
cd $HOME/rpmbuild/BUILD/go/src/%{IMPORTNAME}
make \
    COMMIT=@HASH@ \
    TARGET=kata-ksm-throttler \
    LIBEXECDIR=%{LIBEXECDIR}

%install
export GOROOT=$HOME/rpmbuild/BUILD/local/go
export PATH=$PATH:$HOME/rpmbuild/BUILD/local/go/bin
export GOPATH=$HOME/rpmbuild/BUILD/go/

cd $HOME/rpmbuild/BUILD/go/src/%{IMPORTNAME}
make install \
    COMMIT=@HASH@ \
    TARGET=kata-ksm-throttler \
    DESTDIR=%{buildroot} \
    LIBEXECDIR=%{LIBEXECDIR}

%files
%defattr(-,root,root,-)
%{LIBEXECDIR}/kata-ksm-throttler
%{LIBEXECDIR}/kata-ksm-throttler/kata-ksm-throttler
%{LIBEXECDIR}/kata-ksm-throttler/trigger
%{LIBEXECDIR}/kata-ksm-throttler/trigger/virtcontainers
%{LIBEXECDIR}/kata-ksm-throttler/trigger/virtcontainers/vc
/usr/lib/systemd/system/kata-ksm-throttler.service
/usr/lib/systemd/system/kata-vc-throttler.service
