%define debug_package %{nil}
%global oh_version OpenHarmony-v3.2-Release
%global dfs_service_dir %{_builddir}/foundation/filemanagement
%global build_opt /opt/distributed-middleware-build 

Name: filemanagement_dfs_service
Version: 1.0.0
Release: 4
Summary: The distributed file service from OpenHarmony
License: Apache-2.0
Url: https://gitee.com/openharmony/filemanagement_dfs_service
Source1: https://gitee.com/openharmony/filemanagement_dfs_service/repository/archive/%{oh_version}.tar.gz #/filemanagement_dfs_service-%{oh_version}.tar.gz
Source2: distributedfiledaemon.xml

Patch1: 0001-cut-access_token-common_event-ability.patch
Patch2: 0002-change-default-devsl-from-0-to-4.patch

BuildRequires: libboundscheck
BuildRequires: distributed-build
BuildRequires: distributed-beget, hilog, commonlibrary_c_utils
BuildRequires: communication_ipc, communication_dsoftbus
BuildRequires: systemabilitymgr_safwk, systemabilitymgr_samgr
BuildRequires: security_dataclassification, security_device_auth
BuildRequires: distributedhardware_device_manager

Requires: libboundscheck
Requires: distributed-beget, hilog, commonlibrary_c_utils
Requires: communication_ipc, communication_dsoftbus
Requires: systemabilitymgr_safwk, systemabilitymgr_samgr
Requires: security_dataclassification, security_device_auth
Requires: distributedhardware_device_manager, hmdfs

%description
The distributed file service provides cross-device access capabilities that meet the POSIX specifications.

%prep
rm -rf %{_builddir}/*
cp -rf %{build_opt} %{_builddir}/build
[ ! -L "%{_builddir}/build.sh" ] && ln -s %{_builddir}/build/build_scripts/build.sh %{_builddir}/build.sh
[ ! -L "%{_builddir}/.gn" ] && ln -s %{_builddir}/build/core/gn/dotfile.gn %{_builddir}/.gn
[ ! -L "%{_builddir}/build.py" ] && ln -s %{_builddir}/build/lite/build.py %{_builddir}/build.py
cp -rf %{_builddir}/build/openeuler/vendor %{_builddir}/
cp -rf %{_builddir}/build/openeuler/compiler_gn/* %{_builddir}

%setup -q -T -a 1 -c -n %{dfs_service_dir}
%patch -P1 -p1 -d %{dfs_service_dir}/dfs_service
%patch -P2 -p1 -d %{dfs_service_dir}/dfs_service

%build
%ifarch x86_64
%{_builddir}/build.sh --product-name openeuler --target-cpu x86_64
%endif

%ifarch aarch64
%{_builddir}/build.sh --product-name openeuler --target-cpu arm64
%endif

%install
install -d -m 0755 %{buildroot}/%{_libdir}
install -d -m 0755 %{buildroot}/system/lib64
install -d -m 0755 %{buildroot}/system/profile

%ifarch x86_64
%define lib_path out/openeuler/linux_clang_x86_64/filemanagement/dfs_service
%endif

%ifarch aarch64
%define lib_path out/openeuler/linux_clang_arm64/filemanagement/dfs_service
%endif

# prepare so
install -m 0755 %{_builddir}/%{lib_path}/*.so %{buildroot}/%{_libdir}
install -m 0755 %{_builddir}/%{lib_path}/*.so %{buildroot}/system/lib64

# prepare sa profile
install -m 0755 %{SOURCE2} %{buildroot}/system/profile

%files
%{_libdir}/*.so
/system/*

%changelog
* Fri Dec 15 2023 heppen <hepeng68@huawei.com> - 1.0.0-4
- Add SA profile

* Tue Nov 14 2023 Peng He <hepeng68@huawei.com> - 1.0.0-3
- Update requires and buildrequires.

* Sat Jun 24 2023 Peng He <hepeng68@huawei.com> - 1.0.0-2
- Change default devsl from 0 to 4.

* Sun Jun 18 2023 Peng He <hepeng68@huawei.com> - 1.0.0-1
- Cut access_token, common_event, ability.
