#
# spec file for package libzypp
#
# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#

%define _unpackaged_files_terminate_build 1

Name:           libzypp
Version:        17.28.6
Release:        1%{?_dist_release}
Summary:        Package, Patch, Pattern, and Product Management
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        GPL-2.0+
Url:            https://github.com/openSUSE/libzypp
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Source:         https://github.com/openSUSE/libzypp/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        %{name}-rpmlintrc
Source2:        ChangeLog.suse

# Features we provide (update doc/autoinclude/FeatureTest.doc):
Provides:       libzypp(plugin) = 0
Provides:       libzypp(plugin:appdata) = 0
Provides:       libzypp(plugin:commit) = 1
Provides:       libzypp(plugin:services) = 0
Provides:       libzypp(plugin:system) = 0
Provides:       libzypp(plugin:urlresolver) = 0
Provides:       libzypp(repovarexpand) = 0

Recommends:     logrotate
# lsof is used for 'zypper ps':
Recommends:     lsof
BuildRequires:  cmake
BuildRequires:  openssl-devel
BuildRequires:  libudev-devel
BuildRequires:  libboost-devel
BuildRequires:  libboost-program-options
BuildRequires:  libboost-thread
BuildRequires:  libboost-test
BuildRequires:  dejagnu
BuildRequires:  doxygen
BuildRequires:  gcc-c++
BuildRequires:  gettext-devel
BuildRequires:  graphviz
BuildRequires:  asciidoc
#BuildRequires:  graphviz-gnome
BuildRequires:  libxml2-devel
BuildRequires:  libproxy-devel
BuildRequires:  gpgme-devel
BuildRequires:  pkgconfig(sigc++-2.0)
BuildRequires:  glib2-devel
BuildRequires:  yaml-cpp-devel
BuildConflicts: yaml-cpp-static
BuildRequires:  protobuf-devel
BuildRequires:  protobuf-lite-devel

BuildRequires:  pkgconfig

BuildRequires:  libsolv-devel >= 0.6.7
Requires:       libsolv-tools

# required for testsuite, webrick
BuildRequires:  ruby

BuildRequires:  expat-devel

Requires:       rpm

BuildRequires:  popt-devel
BuildRequires:  rpm-devel

Requires:       gnupg2

%define min_curl_version 7.19.4
BuildRequires:  curl-devel >= %{min_curl_version}
Requires:       curl   >= %{min_curl_version}

%description
Package, Patch, Pattern, and Product Management


%package devel
Summary:        Package, Patch, Pattern, and Product Management - developers files
Group:          programming
Requires:       libboost-devel
Requires:       bzip2
Requires:       glibc-devel
Requires:       libstdc++-devel
Requires:       libxml2-devel
Requires:       libzypp = %{version}
Requires:       openssl-devel
Requires:       popt-devel
Requires:       rpm-devel
Requires:       zlib-devel
Requires:       libzstd-devel
Requires:       libudev-devel
Requires:       cmake
Requires:       curl-devel >= %{min_curl_version}
Requires:       libsolv-devel

%description devel
Package, Patch, Pattern, and Product Management - developers files


%debug_package


%prep
%setup -q


%build
unset TRANSLATION_SET
unset EXTRA_CMAKE_OPTIONS
export YAML_CPP_LIBRARIES=-lyaml-cpp \

%cmake \
      -DCMAKE_INSTALL_PREFIX=%{_prefix} \
      -DDOC_INSTALL_DIR=%{_docdir} \
      -DLIB=%{_lib} \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_SKIP_RPATH=1 \
      -DUSE_TRANSLATION_SET=${TRANSLATION_SET:-zypp} \
      -DENABLE_ZSTD_COMPRESSION=ON \
      -DDISABLE_MEDIABACKEND_TESTS=ON \
      -DDISABLE_AUTODOCS=ON \
      ${EXTRA_CMAKE_OPTIONS}

%cmake_build
#make -C doc/autodoc %{?_smp_mflags}
%make_build -C %{_vpath_builddir}/po


%install
rm -rf "$RPM_BUILD_ROOT"
%cmake_install

%if 0%{?fedora_version} || 0%{?rhel_version} >= 600 || 0%{?centos_version} >= 600
ln -s %{_sysconfdir}/yum.repos.d $RPM_BUILD_ROOT%{_sysconfdir}/zypp/repos.d
%else
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/zypp/repos.d
%endif
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/zypp/services.d
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/zypp/vendors.d
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/zypp/multiversion.d
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp/plugins
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp/plugins/appdata
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp/plugins/commit
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp/plugins/services
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp/plugins/system
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/zypp/plugins/urlresolver
mkdir -p $RPM_BUILD_ROOT%{_var}/lib/zypp
mkdir -p $RPM_BUILD_ROOT%{_var}/log/zypp
mkdir -p $RPM_BUILD_ROOT%{_var}/cache/zypp

%make_install -C %{_vpath_builddir}/po

# Create filelist with translations
%{find_lang} zypp


%post
if [ -f /var/cache/zypp/zypp.db ]; then rm /var/cache/zypp/zypp.db; fi

# convert old lock file to new
# TODO make this a separate file?
# TODO run the sript only when updating form pre-11.0 libzypp versions
LOCKSFILE=%{_sysconfdir}/zypp/locks
OLDLOCKSFILE=%{_sysconfdir}/zypp/locks.old

is_old(){
  # if no such file, exit with false (1 in bash)
  test -f ${LOCKSFILE} || return 1
  TEMP_FILE=`mktemp`
  cat ${LOCKSFILE} | sed '/^\#.*/ d;/.*:.*/d;/^[^[a-zA-Z\*?.0-9]*$/d' > ${TEMP_FILE}
  if [ -s ${TEMP_FILE} ]
  then
    RES=0
  else
    RES=1
  fi
  rm -f ${TEMP_FILE}
  return ${RES}
}

append_new_lock(){
  case "$#" in
    1 )
  echo "
solvable_name: $1
match_type: glob
" >> ${LOCKSFILE}
;;
    2 ) #TODO version
  echo "
solvable_name: $1
match_type: glob
version: $2
" >> ${LOCKSFILE}
;;
    3 ) #TODO version
  echo "
solvable_name: $1
match_type: glob
version: $2 $3
" >> ${LOCKSFILE}
  ;;
esac
}

die() {
  echo $1
  exit 1
}

if is_old ${LOCKSFILE}
  then
  mv -f ${LOCKSFILE} ${OLDLOCKSFILE} || die "cannot backup old locks"
  cat ${OLDLOCKSFILE}| sed "/^\#.*/d"| while read line
  do
    append_new_lock $line
  done
fi


%clean
rm -rf "$RPM_BUILD_ROOT"


%files -f zypp.lang
%defattr(-,root,root)
%dir               %{_sysconfdir}/zypp
%if 0%{?fedora_version} || 0%{?rhel_version} >= 600 || 0%{?centos_version} >= 600
%{_sysconfdir}/zypp/repos.d
%else
%dir               %{_sysconfdir}/zypp/repos.d
%endif
%dir               %{_sysconfdir}/zypp/services.d
%dir               %{_sysconfdir}/zypp/vendors.d
%dir               %{_sysconfdir}/zypp/multiversion.d
%config(noreplace) %{_sysconfdir}/zypp/zypp.conf
%config(noreplace) %{_sysconfdir}/zypp/systemCheck
%config(noreplace) %{_sysconfdir}/zypp/needreboot
%config(noreplace) %{_sysconfdir}/logrotate.d/zypp-history.lr
%dir               %{_var}/lib/zypp
%dir               %{_var}/log/zypp
%dir               %{_var}/cache/zypp
%{_prefix}/lib/zypp
%{_datadir}/zypp
%{_bindir}/*
%{_libdir}/libzypp*so.*
%{_libexecdir}/zypp/zypp-rpm
%doc %{_mandir}/man1/*.1.*
%doc %{_mandir}/man5/*.5.*

%files devel
%defattr(-,root,root)
%license COPYING
%{_libdir}/libzypp.so
%{_includedir}/zypp
%{_includedir}/zypp-core
%{_datadir}/cmake/Modules/*
%{_libdir}/pkgconfig/libzypp.pc


%changelog
* Tue Oct 19 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.28.6-1
- new upstream release.
- built with openssl-3.0.0.

* Thu Sep 09 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.28.3-1
- new upstream release.
- dropped ldconfig scriptlets.

* Mon Feb 22 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.25.7-2
- rebuilt with rpm-4.16.

* Sat Feb 20 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.25.7-1
- new upstream release.
- built with boost-1.75.0.

* Sat Apr 25 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.23.4-1
- new upstream release.
- built with boost-1.72.0.

* Wed Mar 25 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.23.2-1
- new upstream release.

* Tue Sep 03 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.14.0-1
- new upstream release.

* Mon Nov 05 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 17.8.1-1
- new upstream release.

* Tue Jan 09 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 16.17.7-2
- rebuilt with libproxy-0.4.15.

* Wed Jan 03 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 16.17.7-1
- new upstream release.

* Sun Jul 17 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 15.22.2-1
- new upstream release.

* Sun May  8 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 15.22.0-1
- new upstream release.

* Sun Nov 15 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 15.19.6-1
- initial build for Vine Linux.
- new upstream release.
