#needsrootforbuild
%global __cargo_skip_build 0
%global _debugsource_packages 1
%global _debuginfo_subpackages 1
%define _unpackaged_files_terminate_build 0
%global sysmaster_install_source target/release
%global sysmaster_install_target %{buildroot}/usr/lib/process1
%global __cargo_common_opts %{?__cargo_common_opts} --all

Name:           sysmaster 
Version:        0.2.1
Release:        2
Summary:        redesign and reimplement process1.

License:        Mulan PSL v2
URL:            https://gitee.com/openeuler/sysmaster
Source0:        %{name}-%{version}.tar.gz

Patch0001:      backport-replaced-argv0-with-the-absolute-path.patch
Patch0002:      backport-fix-dropin-get-real-file-name.patch
Patch0003:      backport-if-Type-item-is-not-configured-set-it-to-default-Sim.patch
Patch0004:      backport-fix-start-and-stop-repeatly-if-the-unit-is-already-i.patch
Patch0005:      backport-rename-to-sysmaster.patch

ExclusiveArch:  x86_64 aarch64

BuildRequires:  rust
BuildRequires:  cargo
BuildRequires:  rust-packaging
BuildRequires:  gcc

%description
redesign and reimplement process1.

Summary:        %{summary}

%files
/usr/bin/pctrl
/usr/lib/process1/*

%prep
%autosetup -p1

%cargo_prep

%cargo_generate_buildrequires

%build

sed -i '/\[source.crates-io\]/{n;d}' ./.cargo/config
sed -i '/\[source.local-registry\]/{n;d}' ./.cargo/config
sed -i '/\[source.local-registry\]/a directory = "vendor"' ./.cargo/config
%ifarch aarch64
sed -i 's/rustflags = \[/rustflags = \["-Clink-arg=-lgcc", /g' ./.cargo/config
%endif

%cargo_build -a

%install
install -Dm0755 -t %{buildroot}/usr/bin %{sysmaster_install_source}/pctrl
install -Dm0755 -t %{sysmaster_install_target} %{sysmaster_install_source}/init
install -Dm0755 -t %{sysmaster_install_target} %{sysmaster_install_source}/sysmaster
install -Dm0755 -t %{sysmaster_install_target} %{sysmaster_install_source}/fstab
install -Dm0755 -t %{sysmaster_install_target} %{sysmaster_install_source}/sysmonitor
install -Dm0755 -t %{sysmaster_install_target} %{sysmaster_install_source}/random_seed
install -Dm0755 -t %{sysmaster_install_target} %{sysmaster_install_source}/rc-local-generator

strip %{sysmaster_install_source}/lib*.so

install -Dm0644 -t %{sysmaster_install_target}/plugin %{sysmaster_install_source}/libmount.so
install -Dm0644 -t %{sysmaster_install_target}/plugin %{sysmaster_install_source}/libservice.so
install -Dm0644 -t %{sysmaster_install_target}/plugin %{sysmaster_install_source}/libsocket.so
install -Dm0644 -t %{sysmaster_install_target}/plugin %{sysmaster_install_source}/libtarget.so
install -Dm0644 -t %{sysmaster_install_target}/plugin config/plugin.conf


%changelog
* Tue Sep 20 2022 licunlong<licunlong1@huawei.com> - 0.2.1-2
- rename process1 to sysmaster, and remove pctrl to /usr/bin

* Tue Sep 13 2022 licunlong<licunlong1@huawei.com> - 0.2.1-1
- sync patches from upstream

* Mon Aug 22 2022 He Xiaowen <hexiaowen@huawei.com> - 0.2.0-2
- strip the libraries

* Mon Aug 22 2022 He Xiaowen <hexiaowen@huawei.com> - 0.2.0-1
- initial package

