%define debug_package %{nil}
%global build_opt /opt/distributed-middleware-build
%global init_path %{build_opt}/openeuler/compiler_gn/base/startup/init
%global openHarmony_source_release OpenHarmony-v3.2-Release

Name:           distributed-beget
Version:        1.0.0
Release:        5
Summary:        openEuler embedded softbus capability support
License:        Apache License 2.0
URL:            https://gitee.com/openeuler/distributed-beget.git
Source1:        distributed-beget.tar.gz
Source2:        startup.bundle.json
Source3:        startup.BUILD.gn
Patch1:         0001-fixbug_fd_leak_for_init.patch
Patch2:         0002-feat-for-embedded-fix-compile-errors.patch
Patch3:         0003-feat-for-embedded-fix-sysroot-hilog-path.patch
Patch4:         0004-refactor-using-the-reactor-framework.patch
Patch5:         0005-feat-for-embedded-fix-compile-errors-after-refactor.patch

BuildRequires:  distributed-build, hilog, commonlibrary_c_utils

Requires:   commonlibrary_c_utils
Requires:   hilog
# Requires:   libatomic

%description
OpenEuler supports param service for distributed softbus capability

%prep
# Create directory structure
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}

# mkdir -p %{_builddir}/base/startup
%setup -q -D -T -a 1 -c -n %{_builddir}/base/startup
%patch -P1 -p1 -d %{_builddir}/base/startup/init
%patch -P2 -p1 -d %{_builddir}/base/startup/init
%patch -P3 -p1 -d %{_builddir}/base/startup/init
%patch -P4 -p1 -d %{_builddir}/base/startup/init
# exit 0

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

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

%install
install -d -m 0755 %{buildroot}/%{_includedir}/init/syspara
install -d -m 0755 %{buildroot}/%{_includedir}/init/param
install -d -m 0755 %{buildroot}/%{_libdir}
install -d -m 0755 %{buildroot}/system/lib64/
install -d -m 0755 %{buildroot}/%{_bindir}
install -d -m 0755 %{buildroot}%{build_opt}/openeuler/compiler_gn/base/startup/init/interfaces/innerkits

%ifarch aarch64
%define module_out_path out/openeuler/linux_clang_arm64
%define so_out_path out/openeuler/linux_clang_arm64/startup/init/
%endif
%ifarch x86_64
%define module_out_path out/openeuler/linux_clang_x86_64
%define so_out_path out/openeuler/linux_clang_x86_64/startup/init/
%endif

# bin
install -m 0755 %{_builddir}/out/openeuler/packages/phone/system/bin/param_service %{buildroot}/%{_bindir}
# shared library
install -m 0755 %{_builddir}/%{so_out_path}/libbeget_proxy.z.so %{buildroot}/%{_libdir}
install -m 0755 %{_builddir}/%{so_out_path}/libbegetutil.z.so %{buildroot}/%{_libdir}
install -m 0755 %{_builddir}/%{so_out_path}/libbeget_proxy.z.so %{buildroot}/system/lib64/
install -m 0755 %{_builddir}/%{so_out_path}/libbegetutil.z.so %{buildroot}/system/lib64/
# header files
%define interface_path base/startup/init/interfaces/innerkits/include
%define service_path base/startup/init/services/include
install -m 0755 %{_builddir}/%{interface_path}/{beget_ext.h,service_watcher.h,service_control.h} %{buildroot}/%{_includedir}/init
install -m 0755 %{_builddir}/%{interface_path}/syspara/* %{buildroot}/%{_includedir}/init/syspara
install -m 0755 %{_builddir}/%{interface_path}/syspara/* %{buildroot}/%{_includedir}/init
install -m 0755 %{_builddir}/%{service_path}/init_utils.h %{buildroot}/%{_includedir}/init
install -m 0755 %{_builddir}/%{service_path}/param/* %{buildroot}/%{_includedir}/init/param
install -m 0755 %{_builddir}/%{service_path}/param/* %{buildroot}/%{_includedir}/init

# cp bundle.json
mkdir -p %{buildroot}%{init_path}
mkdir -p %{buildroot}%{init_path}/interfaces/innerkits/
install -m 0755 %{SOURCE2} %{buildroot}%{init_path}/bundle.json
# cp BUILD.gn
install -m 0755 %{SOURCE3} %{buildroot}%{init_path}/interfaces/innerkits/BUILD.gn
# create soft link
ln -s /usr/include/init %{buildroot}%{build_opt}/openeuler/compiler_gn/%{interface_path} 

%files
%{_bindir}/*
%{_libdir}/*
%{_includedir}/init/*
/system/lib64/*
%{build_opt}/*

%changelog
* Mon Apr 8 2024 s_c_c <shichuchao@huawei.com> - 1.0.0-5
- Fix compile errors and BUILD.gn for embedded after refactor

* Wed Mar 27 2024 peng_langyuan <peng_langyuan@hoperun.com> - 1.0.0-4
- Refactor param service using the reactor framework

* Mon Mar 18 2024 s_c_c <shichuchao@huawei.com> - 1.0.0-3
- Fix compile errors and sysroot hilog path for embedded

* Thu Mar 14 2024 s_c_c <shichuchao@huawei.com> - 1.0.0-2
- Remove unused tar.gz

* Fri Nov 24 2023 muyuying <muyuying1@huawei.com> - 1.0.0-1
- Init and Adapt to Openeule

