File multichain.spec of Package multichain

#
# spec file for package multichain
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


Name:           multichain
Version:        2.3
Release:        0
Summary:        Platform for private blockchains
License:        GPL-3.0-only
Group:          Productivity/Networking/Other
URL:            https://www.%{name}.com/
Source0:        %{name}-%{version}.tar.xz
Source1:        linux-v8.tar.xz
Source2:        %{name}.template
Source3:        README.SUSE
Patch0:         %{name}-upnp.patch
ExclusiveArch:  x86_64
BuildRequires:  automake
%if 0%{?suse_version} && 0%{?suse_version} > 1500
BuildRequires:  gcc-c++
%endif
%if 0%{?suse_version} && 0%{?suse_version} > 1320
BuildRequires:  libboost_filesystem-devel
BuildRequires:  libboost_program_options-devel
BuildRequires:  libboost_system-devel
BuildRequires:  libboost_test-devel
BuildRequires:  libboost_thread-devel
%else
BuildRequires:  boost_1_62-devel
%endif
BuildRequires:  libdb-4_8-devel
BuildRequires:  libevent-devel
BuildRequires:  libminiupnpc-devel
BuildRequires:  libtool
BuildRequires:  qrencode-devel
%if 0%{?suse_version} && 0%{?suse_version} > 1320
BuildRequires:  libopenssl-1_0_0-devel
%else
BuildRequires:  libopenssl-devel
%endif
BuildRequires:  protobuf-devel
%if 0%{?suse_version} && 0%{?suse_version} <= 1320
BuildRequires:  shadow
%endif

%define display_name MultiChain

# set binary names
%define daemon_name %{name}d
%define cold_name %{daemon_name}-cold
%define cli_name %{name}-cli
%define util_name %{name}-util

# set package names
%define daemon_packname %{name}d

%define description_text MultiChain is an open source platform for private blockchains, which offers a rich set of features including extensive configurability, rapid deployment, permissions management, native assets and data streams. Although it is designed to enable private blockchains, MultiChain provides maximal compatibility with the bitcoin ecosystem, including the peer-to-peer protocol, transaction/block formats and Bitcoin Core APIs/runtime parameters.

%description
%{description_text}

%package utils
Summary:        Utils for the %{display_name} crypto-currency
Group:          Productivity/Networking/Other

%description utils
%{description_text}

This package provides %{display_name} CLI and %{display_name} TX, a command line interface for %{display_name}.

%package -n %{daemon_name}
Summary:        Headless daemon for %{name} crypto-currency
Group:          Productivity/Networking/Other

%description -n %{daemon_name}
%{description_text}

This package provides %{daemon_name}, a headless %{name} daemon.

%prep
%setup -q
%patch -P 0
%{__cp} -a %{S:3} .

# setup systemd service
%{__cp} %{S:2} %{daemon_name}.template
%{__sed} -i 's#<DESCRIPTION>#%{display_name} Daemon#g' %{daemon_name}.template
%{__sed} -i 's#<DAEMON>#%{_bindir}/%{daemon_name}#g' %{daemon_name}.template
%{__sed} -i 's#<PID>#%{_rundir}/%{name}/%{daemon_name}#g' %{daemon_name}.template
%{__sed} -i 's#<CONF>#%{_sysconfdir}/%{name}#g' %{daemon_name}.template
%{__sed} -i 's#<DATA>#%{_localstatedir}/lib/%{name}#g' %{daemon_name}.template
%{__sed} -i 's#<RUN>#%{name}#g' %{daemon_name}.template
%{__sed} -i 's#<USER>#%{name}#g' %{daemon_name}.template
%{__sed} -i 's#<GROUP>#%{name}#g' %{daemon_name}.template

# setup v8 engine
%{__mkdir_p} v8build
cd v8build
%{__tar} -xf %{S:1}

%build
./autogen.sh
%configure --docdir=%{_defaultdocdir}/%{name} --enable-silent-rules --enable-wallet --enable-upnp-default --disable-tests --enable-hardening --enable-reduce-exports --with-miniupnpc --with-qrencode --with-boost --with-utils --without-libs --with-daemon --with-gui=no --with-qtdbus --disable-static CXXFLAGS="${CXXFLAGS} -DBUILD_SUFFIX=%{_host_vendor}"
%{__make} %{?_smp_mflags}
%{__strip} -s src/%{daemon_name}
%{__strip} -s src/%{cold_name}
%{__strip} -s src/%{cli_name}
%{__strip} -s src/%{util_name}

%install
%{__make} %{?_smp_mflags} install DESTDIR=%{buildroot}
%{__install} -d -m 0755 %{buildroot}%{_localstatedir}/lib/%{name}
%{__install} -d -m 0755 %{buildroot}%{_sbindir}
%{__install} -D -m 0644 -p %{daemon_name}.template %{buildroot}%{_unitdir}/%{daemon_name}@.service
%{__ln_s} %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{daemon_name}

%pre -n %{daemon_name}
getent group %{name} > /dev/null || groupadd -r %{name}
getent passwd %{name} > /dev/null || useradd -r -g %{name} -d %{_localstatedir}/lib/%{name} -s /sbin/nologin -c "%{name} daemon" %{name}
%service_add_pre %{daemon_name}@.service

%preun -n %{daemon_name}
%service_del_preun %{daemon_name}@.service

%post -n %{daemon_name}
%service_add_post %{daemon_name}@.service
%if 0%{?suse_version} && ( 0%{?suse_version} > 1320 || ( 0%{?is_opensuse} && 0%{?suse_version} == 1315 && 0%{?sle_version} && 0%{?sle_version} >= 120100 ) )
%tmpfiles_create %{_tmpfilesdir}/%{name}_rundir.conf
%else
systemd-tmpfiles --create %{_tmpfilesdir}/%{name}_rundir.conf >/dev/null 2>&1 || :
%endif

%postun -n %{daemon_name}
%service_del_postun %{daemon_name}@.service

%files utils
%defattr(-,root,root,-)
%attr(755,root,root) %{_bindir}/%{cli_name}
%attr(755,root,root) %{_bindir}/%{util_name}
%doc README.md
%license COPYING

%files -n %{daemon_name}
%defattr(-,root,root,-)
%attr(755,root,root) %{_bindir}/%{daemon_name}
%attr(755,root,root) %{_bindir}/%{cold_name}
%{_sbindir}/rc%{daemon_name}
%{_unitdir}/%{daemon_name}@.service
%dir %attr(700,%{name},%{name}) %{_localstatedir}/lib/%{name}
%doc README.md README.SUSE
%license COPYING

%changelog
openSUSE Build Service is sponsored by