%define debug_package %{nil}
%global openHarmony_source_release OpenHarmony-v3.2-Release
%global security_dir %{_builddir}/base/security
%global build_opt /opt/distributed-middleware-build

Name: security_device_auth
Version: 1.0.0
Release: 2
Summary: System ability manager
License: Apache License 2.0
Url: https://gitee.com/openharmony/security_device_auth
Source1: https://gitee.com/openharmony/security_device_auth/repository/archive/%{openHarmony_source_release}.tar.gz #/security_device_auth-%{openHarmony_source_release}.tar.gz
Source2: device_auth.bundle.json
Source3: device_auth.BUILD.gn

Patch1: 0001-security_device_auth.patch

BuildRequires:  gcc, make, hilog
BuildRequires:  distributed-build, distributed-beget
BuildRequires:  commonlibrary_c_utils
BuildRequires:  notification_eventhandler
BuildRequires:  communication_ipc
BuildRequires:  security_huks
BuildRequires:  systemabilitymgr_safwk, systemabilitymgr_samgr
BuildRequires:  cjson-devel, compat-openssl11-devel


Requires:  distributed-beget
Requires:  commonlibrary_c_utils
Requires:  notification_eventhandler
Requires:  communication_ipc
Requires:  security_huks
Requires:  systemabilitymgr_safwk, systemabilitymgr_samgr
Requires:  libboundscheck

%description
OpenEuler supports device auth for distributed softbus capability

%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 -D -T -a 1 -c -n %{security_dir}
%patch -P1 -p1 -d %{security_dir}/device_auth
%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}/%{_includedir}/device_auth
install -d -m 0755 %{buildroot}/%{_libdir}
install -d -m 0755 %{buildroot}/usr/bin/
install -d -m 0755 %{buildroot}/system/bin/
install -d -m 0755 %{buildroot}%{build_opt}/openeuler/compiler_gn/base/security/device_auth/services
install -d -m 0755 %{buildroot}%{build_opt}/openeuler/compiler_gn/base/security/device_auth/interfaces

%ifarch aarch64
%define header_out_path out/openeuler/innerkits/linux-arm64/device_auth
%define module_out_path out/openeuler/linux_clang_arm64
%endif
%ifarch x86_64
%define header_out_path out/openeuler/innerkits/linux-x86_64/device_auth
%define module_out_path out/openeuler/linux_clang_x86_64
%endif
# prepare head files
find %{_builddir}/%{header_out_path} -name *.h -print0 | xargs -0 -i cp -rf {} %{buildroot}/%{_includedir}/device_auth/

# copy executable file.
install -m 0755 %{_builddir}/out/openeuler/packages/phone/system/bin/deviceauth_service %{buildroot}/system/bin/
install -m 0755 %{_builddir}/out/openeuler/packages/phone/system/bin/deviceauth_service %{buildroot}/usr/bin/

# prepare so
install -m 0755 %{_builddir}/%{module_out_path}/security/device_auth/*.so %{buildroot}/%{_libdir}


# cp json file
install -m 0755 %{SOURCE2} %{buildroot}/%{build_opt}/openeuler/compiler_gn/base/security/device_auth/bundle.json

# cp gn file
install -m 0755 %{SOURCE3} %{buildroot}/%{build_opt}/openeuler/compiler_gn/base/security/device_auth/services/BUILD.gn

# create soft link
ln -s  /usr/include/device_auth  %{buildroot}%{build_opt}/openeuler/compiler_gn/base/security/device_auth/interfaces/innerkits

%files
%{_includedir}/device_auth/*
%{_libdir}/*.so
/usr/bin/deviceauth_service
/system/bin/deviceauth_service
%{build_opt}/*

%changelog
* Wed Apr 3 2024 s_c_c <shichuchao@huawei.com> - 1.0.0-2
- Fix device_auth.BUILD.gn include_dirs for embedded

* Thu Oct 12 2023 YuYing Mu <muyuying1@huawei.com> - 1.0.0-1
* Tue Nov 21 2023 JiaQi Zhao <zhaojiaqi18@huawei.com> - 1.0.0-1
- Init and adapt device auth to openEuler

