File zypper.spec of Package zypper

%define realname zypper
%define realver  1.14.91
%define srcext   tar.gz

%define gh_repo  openSUSE/zypper

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       GPL-2.0+
Group:         System/Packages
URL:           http://en.opensuse.org/Portal:Zypper
Summary:       Command-line interface to ZYpp system management library

# Install-time parameters
Requires:      logrotate
%if 0%{?rhel} >= 8
Requires:      yum-utils
%endif

# Build-time parameters
BuildRequires: cmake >= 3.10 pkg-config
BuildRequires: gcc-c++
BuildRequires: ninja
BuildRequires: libzypp-devel
BuildRequires: gettext-devel
BuildRequires: readline-devel
BuildRequires: augeas-devel
# !!! There is no explicit boost dependency !!!
BuildRequires: boost-devel
# !!! ... and the same about rpm !!!
BuildRequires: rpm-devel
# Documentation
BuildRequires: rubygem(asciidoctor)
BuildRoot:     %{_tmppath}/%{name}-root
Source:        https://codeload.github.com/%{gh_repo}/%{srcext}/refs/tags/%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}

%description
zypper is a command-line interface to ZYpp system management library. It can be
used to install, update, remove software, manage repositories, perform various
queries, and more.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
# Fix diff invocation
%{__sed} -ri 's/-u0/-U 0/' po/PotfileDiff.sh
# Fix paths for augeas lense
%{__sed} -ri 's|/usr/share/zypper|%{_datadir}/augeas/lenses|' src/utils/Augeas.cc
%{__sed} -ri '/zypper\.aug/,/^\)/ s|\$\{PACKAGE\}|augeas/lenses|' src/CMakeLists.txt

%build
export GEM_PATH=%{_datadir}/gems
_CFLAGS='%{optflags} %{?gcc_lto}'
%if 0%{?rhel} >= 7
# Disable Control-flow Enforcement Technology (CET)
_CFLAGS+=' -fcf-protection=none'
%endif
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
cmake -S . -B build \
 -Wno-dev \
 -G Ninja \
 -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 -DCMAKE_C_FLAGS="$_CFLAGS" \
 -DCMAKE_CXX_FLAGS="$_CFLAGS" \
 -DCMAKE_EXE_LINKER_FLAGS="$_LDFLAGS" \
 -DCMAKE_MODULE_LINKER_FLAGS="$_LDFLAGS" \
 -DCMAKE_SHARED_LINKER_FLAGS="$_LDFLAGS -shared" \
 -DCMAKE_VERBOSE_MAKEFILE=YES \
 \
 -DCMAKE_MODULE_PATH=%{_datadir}/cmake/Modules
ninja -v -C build %{?_smp_mflags}

%install
DESTDIR=%{buildroot} ninja -v -C build install
# Remove .lr extension from logrotate config files
for f in %{buildroot}%{_sysconfdir}/logrotate.d/*; do
  %{__mv} -f ${f} ${f%.lr}
done
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}%{_datadir}/doc
%find_lang %{name}

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files -f %{name}.lang
%defattr(-,root,root)
%license COPYING
%dir %{_sysconfdir}/zypp/apt-packagemap.d
%dir %{_sysconfdir}/zypp
%config(noreplace) %{_sysconfdir}/zypp/apt-packagemap.d/*.pm
%config(noreplace) %{_sysconfdir}/zypp/zypper.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/*
%{_bindir}/*
%{_sbindir}/*
%dir %{_datadir}/bash-completion/completions
%dir %{_datadir}/bash-completion
%{_datadir}/bash-completion/completions/zypper
%dir %{_datadir}/zypper/xml
%dir %{_datadir}/zypper
%{_datadir}/zypper/xml/xmlout.rnc
%dir %{_datadir}/augeas/lenses
%dir %{_datadir}/augeas
%{_datadir}/augeas/lenses/zypper.aug
%doc %{_mandir}/man1/*
%doc %{_mandir}/man8/*
%if 0%{?rhel} >= 8
%exclude %{_bindir}/needs-restarting
%exclude %{_mandir}/man1/needs-restarting.1*
%endif

%changelog
openSUSE Build Service is sponsored by