%define debug_package %{nil}
%global build_opt /opt/distributed-middleware-build
%global oh_version OpenHarmony-v3.2-Release
%global third_party_path %{_builddir}/third_party
%global communication_path %{_builddir}/foundation/communication

Name:           communication_dsoftbus
Version:        1.0.0
Release:        7
Summary:        Inter-process Remote Procedure Call (RPC)
License:        Apache License 2.0
Url:            https://gitee.com/openharmony/communication_dsoftbus
Source1:        https://gitee.com/openharmony/communication_dsoftbus/repository/archive/OpenHarmony-v3.2-Release.tar.gz #/communication_dsoftbus-OpenHarmony-v3.2-Release.tar.gz
Source2:        https://gitee.com/openharmony/third_party_sqlite/repository/archive/OpenHarmony-v3.2-Release.tar.gz #/third_party_sqlite-OpenHarmony-v3.2-Release.tar.gz
Source3:        https://gitee.com/openharmony/third_party_libcoap/repository/archive/OpenHarmony-v3.2-Release.tar.gz #/third_party_libcoap-OpenHarmony-v3.2-Release.tar.gz
Source4:        sqlite.BUILD.gn
Source5:        softbus_server.xml

Patch1:         0001-remove-dependency-and-adapt-for-openeuler-dsoftbus.patch
Patch2:         0002-increase-the-pthread-stack-size-of-x86-and-other-env-dsoftbus.patch
Patch3:         0003-open-udp-stream-switch-dsoftbus.patch

BuildRequires:  gcc, make, hilog, kernel-devel, uname-build-checks
BuildRequires:  distributed-build, distributed-beget
BuildRequires:  commonlibrary_c_utils
BuildRequires:  notification_eventhandler
BuildRequires:  communication_ipc
BuildRequires:  security_device_auth, security_huks
BuildRequires:  systemabilitymgr_safwk, systemabilitymgr_samgr
BuildRequires:  cjson-devel, openssl-devel


Requires:  distributed-beget
Requires:  commonlibrary_c_utils
Requires:  notification_eventhandler
Requires:  communication_ipc
Requires:  security_device_auth, security_huks
Requires:  systemabilitymgr_safwk, systemabilitymgr_samgr
Requires:  cjson-devel, openssl-devel

%description
The inter-process remote procedure call (RPC) mechanisms are used to implement cross-process communication.

# Decompress source code package, make patches to the source code.
%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 %{communication_path}

%patch -P1 -p1 -d %{communication_path}/dsoftbus
%patch -P2 -p1 -d %{communication_path}/dsoftbus
%patch -P3 -p1 -d %{communication_path}/dsoftbus


%setup -q -D -T -a 2 -c -n %{third_party_path}
mv %{third_party_path}/third_party_sqlite-%{oh_version} %{third_party_path}/sqlite

%setup -q -D -T -a 3 -c -n %{third_party_path}
mv %{third_party_path}/third_party_libcoap-%{oh_version} %{third_party_path}/libcoap

%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}/dsoftbus
install -d -m 0755 %{buildroot}/%{_includedir}/sqlite
install -d -m 0755 %{buildroot}/%{_libdir}
install -d -m 0755 %{buildroot}/system/lib64
install -d -m 0755 %{buildroot}/system/profile
install -d -m 0755 %{buildroot}/%{build_opt}/openeuler/compiler_gn/third_party/sqlite/

%ifarch aarch64
%define header_out_path out/openeuler/innerkits/linux-arm64/dsoftbus
%define module_out_path out/openeuler/linux_clang_arm64
%endif
%ifarch x86_64
%define header_out_path out/openeuler/innerkits/linux-x86_64/dsoftbus
%define module_out_path out/openeuler/linux_clang_x86_64
%endif

# install libs and headers from dsoftbus
rm -rf %{_builddir}/%{header_out_path}/softbus_client/inner_kits/transport/inner_session.h
find %{_builddir}/%{header_out_path} -name *.h -print0 | xargs -0 -i cp -rf {} %{buildroot}/%{_includedir}/dsoftbus/

# install libs and headers from dsoftbus
rm -rf %{_builddir}/%{header_out_path}/softbus_client/inner_kits/transport/inner_session.h
find %{_builddir}/%{header_out_path} -name *.h -print0 | xargs -0 -i cp -rf {} %{buildroot}/%{_includedir}/dsoftbus/


# install libs and headers from dsoftbus
%define dsoftbus_module_path %{module_out_path}/communication/dsoftbus
install -m 0755 %{_builddir}/%{dsoftbus_module_path}/libsoftbus_server.z.so %{buildroot}/%{_libdir}
install -m 0755 %{_builddir}/%{dsoftbus_module_path}/libsoftbus_server.z.so %{buildroot}/system/lib64

# install headers and BUILD.gn from third party sqlite
install -m 0755 %{_builddir}/third_party/sqlite/include/*.h %{buildroot}/%{_includedir}/sqlite
install -m 0755 %{_builddir}/%{module_out_path}/common/common/libsqlite.z.so %{buildroot}/%{_libdir}
install -m 0755 %{_builddir}/%{module_out_path}/common/common/libsqlite.z.so %{buildroot}/system/lib64
install -m 0755 %{SOURCE4} %{buildroot}/%{build_opt}/openeuler/compiler_gn/third_party/sqlite/BUILD.gn
install -m 0755 %{SOURCE5} %{buildroot}/system/profile

%files
%{_libdir}/*.so
%{_includedir}/dsoftbus/*
%{_includedir}/sqlite/*
/system/*
%{build_opt}

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

* Tue Oct 19 2023 Yuying Mu <muyuying1@huawei.com> - 1.0.0-6
* Tue Nov 20 2023 Jiaqi Zhao <zhaojiaqi18@huawei.com> - 1.0.0-6
- Update dsoftbus from 3.1.2 to 3.2
- Rename package name from dsoftbus to communication_dsoftbus

* Mon Sep 25 2023 heppen <hepeng68@huawei.com> - 1.0.0-5
- fix CVE-2023-30364 for libcoap

* Wed Sep 20 2023 heppen <hepeng68@huawei.com> - 1.0.0-4
- open udp stream and file feature for dsoftbus

* Wed Nov 30 2022 liheavy <lihaiwei8@huawei.com> - 1.0.0-3
- Disassemble yocto-embedded-tools and replace cjson, ninja, gn, openssl, libboundscheck
- with openEuler software package 

* Wed Nov 23 2022 xuchongyu <xuchongyu@huawei.com> - 1.0.0-2
- add URL,change branch of libboundscheck to 22.03-LTS-SP1

