File zcash.spec of Package zcash

#
# spec file for package zcash
#
# 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:           zcash
Version:        5.0.0
Release:        0
Summary:        P2P digital currency
License:        MIT
Group:          Productivity/Networking/Other
URL:            https://z.cash/
Source0:        %{name}-%{version}.tar.xz
Source1:        vendor.tar.xz
Source2:        cargo_config
Source3:        bitcoind.service
Source4:        %{name}-rpmlintrc
Patch0:         %{name}-return.patch
Patch1:         %{name}-utf8.patch
ExclusiveArch:  x86_64
BuildRequires:  automake
BuildRequires:  cargo
%if 0%{?suse_version} && ( 0%{?suse_version} > 1500 || ( 0%{?is_opensuse} && 0%{?suse_version} == 1500 && 0%{?sle_version} && 0%{?sle_version} > 150200 ) )
BuildRequires:  libboost_filesystem-devel
BuildRequires:  libboost_program_options-devel
BuildRequires:  libboost_system-devel
BuildRequires:  libboost_thread-devel
%else
BuildRequires:  libboost_filesystem1_74_0-devel
BuildRequires:  libboost_program_options1_74_0-devel
BuildRequires:  libboost_system1_74_0-devel
BuildRequires:  libboost_thread1_74_0-devel
%endif
BuildRequires:  fdupes
BuildRequires:  git
BuildRequires:  libdb-6_2-devel
BuildRequires:  libevent-devel
BuildRequires:  libopenssl-devel
BuildRequires:  libsodium-devel
BuildRequires:  libtool
BuildRequires:  protobuf-devel
BuildRequires:  rust >= 1.26.0
BuildRequires:  rust-std
%if 0%{?suse_version} && 0%{?is_opensuse} && 0%{?suse_version} == 1315 && 0%{?sle_version} && 0%{?sle_version} >= 120100
BuildRequires:  shadow
%endif
BuildRequires:  utfcpp-devel
BuildRequires:  zeromq-devel
Requires:       rust >= 1.26.0

%if ! %{defined _rundir}
%define _rundir %{_localstatedir}/run
%endif

%define soname 0

# set binary names
%define daemon_name %{name}d
%define display_name ZCash
%define fparams_name %{name}-fetch-params
%define cli_name %{name}-cli
%define lib_name lib%{name}_script%{soname}
%define tx_name %{name}-tx
%define wallet_name %{name}d-wallet-tool

# set legacy binary names
%define lib_name_legacy lib%{name}consensus%{soname}

# set ports
%define p2p_port 8233
%define rpc_port 8232

%define description_text_1 ZCash is a decentralized and open-source cryptocurrency that offers privacy and selective transparency of transactions. ZCash payments are published on a public blockchain, but the sender, recipient, and amount of a transaction remain private.
%define description_text_3 ZCash is based on peer-reviewed cryptographic research, and built by a security-specialized engineering team on an open source platform based on Bitcoin Core's battle-tested codebase. Our improvement over Bitcoin is the addition of privacy. ZCash uses advanced cryptographic techniques, namely zero-knowledge proofs, to guarantee the validity of transactions without revealing additional information about them.

%description
%{description_text_1}

%{description_text_3}

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

%description utils
%{description_text_1}

%{description_text_3}

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
Recommends:     ca-certificates

%description -n %{daemon_name}
%{description_text_1}

%{description_text_3}

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

%package -n %{lib_name}
Summary:        Implementation of getblocktemplate protocol
Group:          System/Libraries
Obsoletes:      %{lib_name_legacy} < %{version}

%description -n %{lib_name}
%{description_text_1}

%{description_text_3}

This package provides shared libraries for %{name}.

%package -n %{lib_name}-devel
Summary:        Development files for %{lib_name}
Group:          Development/Libraries/C and C++
Requires:       %{lib_name} = %{version}
Obsoletes:      %{lib_name_legacy}-devel < %{version}

%description -n %{lib_name}-devel
%{description_text_1}

%{description_text_3}

The %{lib_name}-devel package contains libraries and header files for developing applications that use %{lib_name}.

%package doc
Summary:        Documentation for %{name}
Group:          Documentation/Man
BuildArch:      noarch

%description doc
%{description_text_1}

%{description_text_3}

This package contains the documentation for %{name}.

%prep
%setup -q
%patch0
%if 0%{?suse_version} && ( 0%{?suse_version} > 1500 || ( 0%{?is_opensuse} && 0%{?suse_version} == 1500 && 0%{?sle_version} && 0%{?sle_version} > 150200 ) )
%patch1
%endif

# setup systemd service
%{__mkdir_p} contrib/init
%{__cp} -a %{S:3} contrib/init/%{daemon_name}.service
%{__sed} -i 's#^Description=Bitcoin.s distributed currency daemon$#Description=%{display_name} Daemon#g' contrib/init/%{daemon_name}.service
%{__sed} -i 's#^PIDFile=/var/lib/bitcoind/bitcoind.pid$#PIDFile=%{_rundir}/%{name}/%{daemon_name}.pid#g' contrib/init/%{daemon_name}.service
%{__sed} -i 's#^ExecStart=/usr/bin/bitcoind -daemon -pid=/var/lib/bitcoind/bitcoind.pid \\$#ExecStartPre=%{_bindir}/%{fparams_name}\nExecStart=%{_bindir}/%{daemon_name} -daemon -pid=%{_rundir}/%{name}/%{daemon_name}.pid -conf=%{_sysconfdir}/%{name}.conf -datadir=%{_localstatedir}/lib/%{name} -disablewallet#g' contrib/init/%{daemon_name}.service
%{__sed} -i 's#^-conf=/etc/bitcoin/bitcoin.conf -datadir=/var/lib/bitcoind -disablewallet$#ExecReload=/bin/kill -HUP \$MAINPID#g' contrib/init/%{daemon_name}.service
%{__sed} -i 's#^User=bitcoin$#User=%{name}#g' contrib/init/%{daemon_name}.service
%{__sed} -i 's#^Group=bitcoin$#Group=%{name}#g' contrib/init/%{daemon_name}.service
%{__sed} -i 's#^TimeoutStartSec=2s$#TimeoutStartSec=5m#g' contrib/init/%{daemon_name}.service

# setup firewall config
%if 0%{?suse_version} && ( 0%{?suse_version} < 1500 || ( 0%{?is_opensuse} && 0%{?suse_version} == 1500 && 0%{?sle_version} && 0%{?sle_version} <= 150200 ) )
echo "## Name: %{display_name} Daemon" > %{name}.firewall
echo "## Description: Opens ports for %{daemon_name} in order to allow remote connections." >> %{name}.firewall
echo -e "\nTCP=\"%{rpc_port}:%{p2p_port}\"" >> %{name}.firewall
%endif

# setup run folder
echo "d %{_rundir}/%{name} 0770 root %{name}" > rundir.conf

# cleanup source
%{__rm} doc/book/.gitignore

# setup rust vendored sources
%setup -q -D -T -a 1
%{__cat} %{S:2} | %{_bindir}/head -n-1 > .cargo/config.offline

%build
./autogen.sh
%configure --docdir=%{_defaultdocdir}/%{name} --enable-silent-rules --enable-hardening --enable-reduce-exports --disable-static --disable-online-rust --enable-wallet --enable-mining --with-boost --with-utils --with-libs --with-daemon --with-gui=no --disable-bench --disable-tests --enable-man --enable-zmq --disable-online-rust CXXFLAGS="${CXXFLAGS} -DBUILD_SUFFIX=%{_host_vendor} -DUTF_CPP_CPLUSPLUS=201103L -I${PWD}/src/rust/include" RUST_TARGET="%{_build_arch}-unknown-%{_build_os}-gnu" RUST_VENDORED_SOURCES="./vendor"
%make_build
%{__strip} -s src/%{cli_name}
%{__strip} -s src/%{tx_name}
%{__strip} -s src/%{daemon_name}
%{__strip} -s src/%{wallet_name}

%install
%make_install

# install daemon supplementary files
%{__install} -D -m 0644 contrib/debian/examples/%{name}.conf  %{buildroot}%{_sysconfdir}/%{name}.conf
%{__install} -D -m 0644 contrib/init/%{daemon_name}.service %{buildroot}%{_unitdir}/%{daemon_name}.service
%{__mkdir_p} %{buildroot}%{_localstatedir}/lib/%{name}
%{__install} -d -m 0755 %{buildroot}%{_sbindir}
%{__ln_s} %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{daemon_name}

# install firewall config file
%if 0%{?suse_version} && ( 0%{?suse_version} < 1500 || ( 0%{?is_opensuse} && 0%{?suse_version} == 1500 && 0%{?sle_version} && 0%{?sle_version} <= 150200 ) )
%{__install} -D -m 644 %{name}.firewall %{buildroot}%{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{daemon_name}
%endif

# install run folder configuration
%{__install} -D -m 0644 rundir.conf %{buildroot}/%{_tmpfilesdir}/%{name}_rundir.conf

# compress man pages
%{__gzip} %{buildroot}%{_mandir}/man1/%{cli_name}.1
%{__gzip} %{buildroot}%{_mandir}/man1/%{daemon_name}.1
%{__gzip} %{buildroot}%{_mandir}/man1/%{fparams_name}.1
%{__gzip} %{buildroot}%{_mandir}/man1/%{tx_name}.1

# install documentation
%{__install} -d -m 0755 %{buildroot}%{_defaultdocdir}/%{name}
%{__install} -m 0644 -p -t %{buildroot}%{_defaultdocdir}/%{name} code_of_conduct.md CONTRIBUTING.md README.md SECURITY.md
%{__install} -d -m 0755 %{buildroot}%{_defaultlicensedir}/%{name}
%{__install} -m 0644 -p -t %{buildroot}%{_defaultlicensedir}/%{name} COPYING
%{__mv} doc/man .
%{__cp} -a doc %{buildroot}%{_defaultdocdir}/%{name}/
%{__mv} man doc/
%fdupes %{buildroot}%{_defaultdocdir}/%{name}

# eliminate files that do not go into the package
find %{buildroot} -name '*.la' -exec %{__rm} -f {} ';'

%check
%{__make} %{?_smp_mflags} check

%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 ) )
%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

%post -n %{lib_name}
/sbin/ldconfig

%postun -n %{lib_name}
/sbin/ldconfig

%files utils
%defattr(-,root,root,-)
%attr(755,root,root) %{_bindir}/%{cli_name}
%attr(755,root,root) %{_bindir}/%{tx_name}
%{_mandir}/man1/%{cli_name}.1%{?ext_man}
%{_mandir}/man1/%{tx_name}.1%{?ext_man}

%files -n %{daemon_name}
%defattr(-,root,root,-)
%attr(755,root,root) %{_bindir}/%{daemon_name}
%attr(755,root,root) %{_bindir}/%{fparams_name}
%attr(755,root,root) %{_bindir}/%{wallet_name}
%{_sbindir}/rc%{daemon_name}
%{_unitdir}/%{daemon_name}.service
%config(noreplace) %{_sysconfdir}/%{name}.conf
%if 0%{?suse_version} && ( 0%{?suse_version} < 1500 || ( 0%{?is_opensuse} && 0%{?suse_version} == 1500 && 0%{?sle_version} && 0%{?sle_version} <= 150200 ) )
%config %{_sysconfdir}/sysconfig/SuSEfirewall2.d/services/%{daemon_name}
%endif
%dir %attr(700,%{name},%{name}) %{_localstatedir}/lib/%{name}
%ghost %{_rundir}/%{name}
%dir %{_tmpfilesdir}
%{_tmpfilesdir}/%{name}_rundir.conf
%{_mandir}/man1/%{daemon_name}.1%{?ext_man}
%{_mandir}/man1/%{fparams_name}.1%{?ext_man}

%files -n %{lib_name}
%defattr(-,root,root,-)
%{_libdir}/*.so.*

%files -n %{lib_name}-devel
%defattr(-,root,root,-)
%{_includedir}/*.h
%{_libdir}/pkgconfig/
%{_libdir}/*.so

%files doc
%defattr(-,root,root,-)
%{_defaultdocdir}/%{name}/
%{_defaultlicensedir}/%{name}/

%changelog
openSUSE Build Service is sponsored by