Name:           sysboost
Version:        1.0.0
Release:        0
Summary:        Numa Aware Scheduling
License:        Mulan PSL v2
URL:            https://gitee.com/openeuler/native-turbo

Source0:        %{name}.tar.xz
Source1:        sysboost.service
Source2:        sysboost.sysconfig

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

%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
rm -rf src
mkdir -p bin
mkdir -p pkg
mkdir -p src/gitee.com

export RPM_BUILD_DIR=%_topdir/BUILD
export RPM_BUILD_SOURCE=%_topdir/SOURCES
export SYSBOOST_DIR=$RPM_BUILD_DIR/src/gitee.com/%{name}

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

cp $RPM_BUILD_SOURCE/%{name}.service $RPM_BUILD_DIR/
cp $RPM_BUILD_SOURCE/%{name}.sysconfig $RPM_BUILD_DIR/

mv $RPM_BUILD_DIR/native-turbo/sysboost/src/objreloc/objreloc.sh $RPM_BUILD_DIR/native-turbo/sysboost/src/objreloc/objreloc

cd $RPM_BUILD_DIR/

%build
cd native-turbo
make release
make

%install
cd native-turbo/build
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/system
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
install -D -p -m 640 %{SOURCE1} $RPM_BUILD_ROOT/usr/lib/systemd/system/%{name}.service
install -D -p -m 640 %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/%{name}

install -m 755 $RPM_BUILD_DIR/native-turbo/sysboost/src/objreloc/objreloc $RPM_BUILD_ROOT%{_bindir}/

%check

%files
%doc
%{_bindir}/sysboost
%{_bindir}/sysboost_static_template
%{_bindir}/libhook.so
/usr/lib/systemd/system/%{name}.service
%config(noreplace) /etc/sysconfig/%{name}

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

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

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