File clamav.spec of Package clamav
%define realname clamav
%define realver 1.2.0
%define srcext tar.gz
%bcond_with system_llvm
%bcond_without system_mspack
%bcond_without systemd
%define so_ver 12
%define fc_so_ver 3
%define ms_so_ver 0
%if 0%{?suse_version}
%define clam_user vscan
%define clam_group vscan
%else
%define clam_user clam
%define clam_group clam
%endif
# turn off the generation of debuginfo rpm (RH9) ??
%global debug_package %{nil}
# Common info
Name: %{realname}
Version: %{realver}
Release: %{?extraver:0.}1%{?dist}
License: GPL-2.0
Group: Productivity/Security
URL: http://www.clamav.net/
Summary: Clam AntiVirus is an open source anti-virus toolkit
# Install-time parameters
Requires: libclamav%{?so_ver} = %{version}
Provides: clamd = %{version}
Obsoletes: clamd < %{version}
# Build-time parameters
BuildRequires: cmake >= 3.14 ninja
BuildRequires: pkg-config gcc-c++
BuildRequires: rust
BuildRequires: openssl-devel
BuildRequires: zlib-devel
%if 0%{?suse_version}
BuildRequires: libbz2-devel
%else
BuildRequires: bzip2-devel
%endif
BuildRequires: libxml2-devel
BuildRequires: pcre2-devel
%if 0%{?suse_version} && ! 0%{?sles_version}
BuildRequires: libjson-c-devel
%endif
%if %{with system_llvm}
BuildRequires: llvm-devel
%endif
%if 0%{?rhel}
BuildRequires: json-c-devel
%endif
BuildRequires: libcurl-devel
BuildRequires: ncurses-devel
BuildRequires: pkgconfig(systemd) pkgconfig(libsystemd)
%if %{with system_mspack}
BuildRequires: pkgconfig(libmspack)
%endif
BuildRoot: %{_tmppath}/%{name}-root
Source0: http://www.clamav.net/downloads/production/%{realname}-%{realver}%{?extraver}.%{srcext}
Source13: systemd-tmpfiles.conf
%description
Clam AntiVirus is an open source (GPL) anti-virus toolkit for UNIX,
designed especially for e-mail scanning on mail gateways. It provides
a number of utilities including a flexible and scalable multi-threaded
daemon, a command line scanner and advanced tool for automatic database
updates. The core of the package is an anti-virus engine available in a
form of shared library.
%package -n libclamav%{?so_ver}
Group: System/Libraries
Summary: Clam AntiVirus library
Provides: libclamav = %{version}
Obsoletes: libclamav < %{version}
%description -n libclamav%{?so_ver}
Clam AntiVirus shared library.
%package -n libfreshclam%{?fc_so_ver}
Group: System/Libraries
Summary: Clam AntiVirus Updater library
Provides: libfreshclam = %{version}
Obsoletes: libfreshclam < %{version}
%description -n libfreshclam%{?fc_so_ver}
Clam AntiVirus Updater shared library.
%if %{without system_mspack}
%package -n libclammspack%{?ms_so_ver}
Group: System/Libraries
License: LGPL-2.1
Summary: Library for handling Microsoft compression formats
%description -n libclammspack%{?ms_so_ver}
The purpose of libmspack is to provide compressors and decompressors,
archivers and dearchivers for Microsoft compression formats: CAB, CHM, WIM,
LIT, HLP, KWAJ and SZDD. It is also designed to be easily embeddable,
stable, robust and resource-efficient.
%files -n libclammspack%{?ms_so_ver}
%defattr(-,root,root)
%{_libdir}/libclammspack.so.%{?ms_so_ver}*
%post -n libclammspack%{?ms_so_ver} -p /sbin/ldconfig
%postun -n libclammspack%{?ms_so_ver} -p /sbin/ldconfig
%endif
%package devel
Group: Development/Languages/C and C++
Summary: Development files for %{name}
Requires: libclamav%{?so_ver} = %{version}
Requires: openssl-devel
Provides: libclamav%{?so_ver}-devel = %{version}
Provides: libclamav-devel = %{version}
Provides: libclammspack-devel = %{version}
%description devel
Development files for %{name}
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
%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_ARGS=(
-G Ninja
-DCMAKE_INSTALL_PREFIX=%{_prefix}
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_FLAGS_RELEASE="$_CFLAGS"
-DCMAKE_CXX_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
)
export RUSTFLAGS_NOT_BOOTSTRAP='-C opt-level=2 -C target-cpu=skylake -C strip=symbols -C lto=yes '
cmake -S . -B build \
"${_CMAKE_ARGS[@]}" \
\
%if %{with system_llvm}
-DBYTECODE_RUNTIME=llvm \
%else
-DBYTECODE_RUNTIME=interpreter \
%endif
%if %{with system_mspack}
-DENABLE_EXTERNAL_MSPACK=YES \
%endif
-DENABLE_JSON_SHARED=YES \
-DENABLE_MILTER=NO \
-DENABLE_MAN_PAGES=YES \
-DENABLE_EXAMPLES=NO \
-DENABLE_TESTS=NO \
-DENABLE_UNRAR=YES \
-DENABLE_SYSTEMD=YES \
-DAPP_CONFIG_DIRECTORY=%{_sysconfdir} \
-DDATABASE_DIRECTORY=/var/lib/clamav
ninja -v -C build %{?_smp_mflags}
%install
DESTDIR=%{buildroot} ninja -v -C build install
%{__install} -d -m755 %{buildroot}/var/lib/clamav
sed -r 's/^(Example)/#\1/' %{buildroot}%{_sysconfdir}/clamd.conf.sample > %{buildroot}%{_sysconfdir}/clamd.conf
sed -r 's/^(Example)/#\1/' %{buildroot}%{_sysconfdir}/freshclam.conf.sample > %{buildroot}%{_sysconfdir}/freshclam.conf
sed -ri \
-e 's|^#(PidFile\s+).+$|\1%{!?_unitdir:/var}/run/clamav/clamd.pid|' \
-e 's|^#(LocalSocket\s+).+$|\1%{!?_unitdir:/var}/run/clamav/clamd.socket|' \
-e 's|^#(LocalSocketGroup\s+).+$|\1%{clam_group}|' \
%{buildroot}%{_sysconfdir}/clamd.conf
sed -ri \
-e 's|^#(PidFile\s+).+$|\1%{!?_unitdir:/var}/run/clamav/freshclam.pid|' \
-e 's|^#(DatabaseOwner\s+).+$|\1%{clam_user}|' \
%{buildroot}%{_sysconfdir}/freshclam.conf
%{__install} -d -m755 %{buildroot}%{_tmpfilesdir}
sed -r \
-e 's/##clam_user##/%{clam_user}/g' \
-e 's/##clam_group##/%{clam_group}/g' \
%{S:13} > %{buildroot}%{_tmpfilesdir}/clamav.conf
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}%{_datadir}/doc/ClamAV
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%defattr(-,root,root)
%license COPYING.txt
%doc docs/html
%{_bindir}/*
%{_sbindir}/clamd
%{_sbindir}/clamonacc
%config(noreplace) %attr(0644, root, root) %{_sysconfdir}/*.conf
%config %{_sysconfdir}/*.sample
%dir %attr(0755, %{clam_user}, %{clam_group}) /var/lib/clamav
%doc %{_mandir}/man1/*
%doc %{_mandir}/man5/*
%doc %{_mandir}/man8/*
%exclude %{_bindir}/clamav-config
%dir %{_unitdir}
%dir %{_tmpfilesdir}
%attr(0644,root,root) %{_unitdir}/*
%attr(0644,root,root) %{_tmpfilesdir}/clamav.conf
# Will be created by systemd-tmpfiles
%ghost /run/clamav
# Shared library(-es)
%files -n libclamav%{?so_ver}
%defattr(-,root,root)
%{_libdir}/libclamav.so.%{?so_ver}*
%{_libdir}/libclamunrar.so.%{?so_ver}*
%{_libdir}/libclamunrar_iface.so.%{?so_ver}*
%files -n libfreshclam%{?fc_so_ver}
%defattr(-,root,root)
%{_libdir}/libfreshclam.so.%{?fc_so_ver}*
# Development stuff
%files devel
%defattr(-,root,root)
%{_bindir}/clamav-config
%{_libdir}/pkgconfig/*.pc
%{_includedir}/clamav.h
%{_includedir}/clamav-types.h
%{_includedir}/clamav-version.h
%{_includedir}/libfreshclam.h
%{_libdir}/*.so
%exclude %{_libdir}/*.la
%pre
/usr/sbin/groupadd -r %{clam_group} 2> /dev/null || :
/usr/sbin/useradd -r -g %{clam_group} -G mail -s /bin/false -c "ClamAV user" \
-d /var/lib/clamav %{clam_user} 2> /dev/null || :
%if 0%{?suse_version}
%{service_add_pre clamav-clamonacc.service}
%{service_add_pre clamav-daemon.service}
%{service_add_pre clamav-daemon.socket}
%{service_add_pre clamav-freshclam.service}
%endif
%if 0%{?suse_version}
%post
%{tmpfiles_create %{_tmpfilesdir}/clamav.conf}
%{service_add_post clamav-clamonacc.service}
%{service_add_post clamav-daemon.service}
%{service_add_post clamav-daemon.socket}
%{service_add_post clamav-freshclam.service}
%preun
test $1 -eq 0 && %{__rm} -f /var/lib/clamav/*
%{service_del_preun clamav-clamonacc.service}
%{service_del_preun clamav-daemon.service}
%{service_del_preun clamav-daemon.socket}
%{service_del_preun clamav-freshclam.service}
%postun
%{service_del_postun clamav-clamonacc.service}
%{service_del_postun clamav-daemon.service}
%{service_del_postun clamav-daemon.socket}
%{service_del_postun clamav-freshclam.service}
%endif
%post -n lib%{name}%{?so_ver} -p /sbin/ldconfig
%postun -n lib%{name}%{?so_ver} -p /sbin/ldconfig
%post -n libfreshclam%{?fc_so_ver} -p /sbin/ldconfig
%postun -n libfreshclam%{?fc_so_ver} -p /sbin/ldconfig
%changelog