#needsrootforbuild
%global __cargo_skip_build 0
%global __cargo_common_opts %{?__cargo_common_opts} --all
Name:           sysboost
Version:        1.0.0
Release:        3
Summary:        Numa Aware Scheduling
License:        Mulan PSL v2
URL:            https://gitee.com/openeuler/native-turbo

Source0:        %{name}.tar.xz

BuildRequires: meson >= 0.49.2, clang >= 12.0.1
BuildRequires: make >= 4.0, bison >= 2.7, binutils >= 2.30-17, gcc >= 10.3.1
BuildRequires: ncurses-devel
BuildRequires: rust rust-packaging cargo

%description
sysboost can merge ELF files to improve performance.

# Add devel subpackage
%package devel
Summary: Development files for %{name}
Requires: %{name} = %{version}-%{release}
BuildRequires: binutils

%description devel
The %{name}-devel package contains some tools of sysboost.

%prep
export RPM_BUILD_DIR=%_topdir/BUILD
export RPM_BUILD_SOURCE=%_topdir/SOURCES

tar -Jxf $RPM_BUILD_SOURCE/%{name}.tar.xz

cp $RPM_BUILD_SOURCE/objreloc.sh $RPM_BUILD_DIR/objreloc
cp $RPM_BUILD_DIR/native-turbo/sysboost/Cargo.toml $RPM_BUILD_DIR/

%cargo_prep

%cargo_generate_buildrequires

%build
cd $RPM_BUILD_DIR/native-turbo/sysboost
%cargo_build -a

cd $RPM_BUILD_DIR/native-turbo
make release
make

%install
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system

pushd native-turbo/build
install -D -p -m 750 ./sysboost/sysboost $RPM_BUILD_ROOT/%{_bindir}/sysboost
install -D -p -m 750 ./sysboost/src/static_template/sysboost_static_template $RPM_BUILD_ROOT/%{_bindir}/sysboost_static_template
install -D -p -m 750 ./sysboost/src/libhook/libhook.so $RPM_BUILD_ROOT/%{_bindir}/libhook.so
popd

pushd native-turbo/sysboost
install -D -p -m 640 %{name}.service $RPM_BUILD_ROOT/usr/lib/systemd/system/%{name}.service
install -D -p -m 750 ./target/debug/sysboostd $RPM_BUILD_ROOT%{_bindir}/
popd

install -m 755 $RPM_BUILD_DIR/objreloc $RPM_BUILD_ROOT%{_bindir}/

mkdir -p %{buildroot}/etc/sysboost.d/
mkdir -p %{buildroot}/var/lib/sysboost/

%check

%files
%defattr(-,root,root,-)
%dir /etc/sysboost.d/
%dir /var/lib/sysboost/
%{_bindir}/sysboost
%{_bindir}/sysboost_static_template
%{_bindir}/libhook.so
%{_bindir}/sysboostd
/usr/lib/systemd/system/%{name}.service

%files devel
%defattr(0755,root,root)
%{_bindir}/objreloc

%doc

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

%changelog
* Tue May 16 2023 liutie <liutie4@huawei.com> - 1.0.0-3
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: Add sysboostd service for sysboost

* Mon May 8 2023 liutie <liutie4@huawei.com> - 1.0.0-2
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: Independently generate the objreloc tool

* Mon May 8 2023 liutie <liutie4@huawei.com> - 1.0.0-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: Independently generate the objreloc tool

* Thu Apr 6 2023 liutie <liutie4@huawei.com> - 1.0.0-0
