File libarchive.spec of Package libarchive

%define realname libarchive
%define realver  3.7.7
%define srcext   tar.gz

%bcond_without cmake

%define so_ver   13

# turn off the generation of debuginfo rpm  (RH9) ??
%global debug_package %{nil}

# Common info
Name:          %{realname}%{so_ver}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       BSD-2-Clause
Group:         Development/Libraries/C and C++
URL:           https://www.libarchive.org/
Summary:       Multi-format archive and compression library

# Build-time parameters
BuildRequires: cmake >= 2.8.12
BuildRequires: ninja
BuildRequires: pkg-config
# Compress libs
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(liblzma)
BuildRequires: lzo-devel
### BuildRequires: libb2-devel
BuildRequires: %{?suse_version:lib}lz4-devel
BuildRequires: libzstd-devel
# Other deps
BuildRequires: libacl-devel
BuildRequires: libattr-devel
BuildRequires: pkgconfig(openssl) >= 3.0
BuildRequires: pkgconfig(expat)
BuildRequires: libxml2%{?suse_version:-tools}
%if 0%{?suse_version}
BuildRequires: libbz2-devel
BuildRequires: libext2fs-devel
%else
BuildRequires: bzip2-devel
BuildRequires: e2fsprogs-devel
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source:        https://www.libarchive.org/downloads/%{realname}-%{realver}.%{srcext}

%description
The libarchive project develops a portable, efficient C library that can read
and write streaming archives in a variety of formats.

%package -n %{realname}-devel
Group:         Development/Languages/C and C++
Summary:       Development files for %{name}
Provides:      %{name}-devel = %{version}-%{release}
Provides:      %{realname}-devel-static = %{version}-%{release}
Requires:      %{name} = %{version}-%{release}
Requires:      pkgconfig(zlib)
Requires:      pkgconfig(liblzma)
Requires:      lzo-devel
### Requires:      libb2-devel
Requires:      %{?suse_version:lib}lz4-devel
Requires:      libzstd-devel
# Other deps
Requires:      libacl-devel
Requires:      pkgconfig(openssl) >= 3.0
Requires:      pkgconfig(expat)
%if 0%{?suse_version}
Requires:      libbz2-devel
%else
Requires:      bzip2-devel
%endif

%description -n %{realname}-devel
The libarchive project develops a portable, efficient C library that can read
and write streaming archives in a variety of formats.

This package provides development stuff for %{name}.

%package -n bsdtar
Group:         Productivity/Archiving/Compression
Summary:       Common tar, cpio, and zcat command-line tools using libarchive
Provides:      bsdcat = %{version}-%{release}
Provides:      bsdcpio = %{version}-%{release}
Provides:      bsdunzip = %{version}-%{release}

%description -n bsdtar
Implementations of the common tar, cpio, and zcat command-line tools that use
the libarchive library.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
# Fix libdir
%{__sed} -i 's|DESTINATION lib|DESTINATION %{_lib}|' libarchive/CMakeLists.txt
%{__sed} -i 's|DESTINATION "lib/pkgconfig"|DESTINATION "%{_lib}/pkgconfig"|' build/cmake/CreatePkgConfigFile.cmake

%build
_CFLAGS="%{optflags} %{?gcc_lto}"
_LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}"
cmake -S . -B tmp_build \
 -G Ninja \
 -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_C_FLAGS_RELEASE="$_CFLAGS" \
 -DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
 -DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
 -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
 -DCMAKE_VERBOSE_MAKEFILE=YES \
 \
 -DENABLE_LZO=YES
ninja -C tmp_build -v %{?_smp_mflags}

%install
DESTDIR=%{buildroot} ninja -C tmp_build -v install

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

%files
%defattr(-,root,root)
%license COPYING
%doc NEWS README.md
%{_libdir}/libarchive.so.%{so_ver}*

# Development stuff
%files -n %{realname}-devel
%defattr(-,root,root)
%license COPYING
%doc NEWS README.md
%{_libdir}/pkgconfig/libarchive.pc
%{_includedir}/archive.h
%{_includedir}/archive_entry.h
%{_libdir}/libarchive.a
%{_libdir}/libarchive.so
%doc %{_mandir}/man3/*

%files -n bsdtar
%defattr(-,root,root)
%license COPYING
%doc NEWS README.md
%{_bindir}/*
%doc %{_mandir}/man1/*
%doc %{_mandir}/man5/*

%post   -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%changelog
openSUSE Build Service is sponsored by