File squid.spec of Package squid

%define realname squid
%define majorver 4
%define minorver 10
%define realver  %{majorver}.%{minorver}
%define srcext   tar.xz

%if 0%{?suse_version} >= 1230 || 0%{?rhel} >= 7
%bcond_without systemd
%else
%bcond_with systemd
%endif

%if 0%{?suse_version} < 1500
%define cxx11abi -D_GLIBCXX_USE_CXX11_ABI=0
%endif

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
%if 0%{?rhel}
Epoch:         10
%endif
License:       GPL-2.0
Group:         Productivity/Networking/Web/Proxy
URL:           http://www.squid-cache.org/
Summary:       High-performance proxy caching server for web clients

# Install-time parameters
Provides:      http_proxy
Requires:      logrotate
%if 0%{?suse_version}
PreReq:        permissions
Suggests:      perl-base
%else
Requires:      perl
%endif


# Packages needed to define _unitdir
%if %{with systemd}
BuildRequires: systemd-devel
Requires:      systemd
%endif

# Build-time parameters
BuildRequires: xz
BuildRequires: gcc-c++ pkgconfig perl
BuildRequires: libaio-devel
BuildRequires: libxml2-devel
BuildRequires: net-snmp-devel
BuildRequires: libnettle-devel
BuildRequires: openssl-devel
BuildRequires: krb5-devel libcom_err-devel
BuildRequires: openldap2-devel
BuildRequires: libnetfilter_conntrack-devel
BuildRequires: cyrus-sasl-devel
BuildRequires: libcap-devel
BuildRequires: pkgconfig(libecap) >= 1.0 pkgconfig(libecap) < 1.1
%if 0%{?suse_version}
BuildRequires: fdupes
BuildRequires: db-devel
%else
%if 0%{?rhel} >= 7
BuildRequires: libdb-devel
%else
BuildRequires: db4-devel
%endif
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       http://www.squid-cache.org/Versions/v%{majorver}/%{realname}-%{realver}%{?extraver}.%{srcext}
Source2:       sysconfig.squid
Source3:       squid.logrotate
Source11:      squid.init.suse
Source12:      squid.init.rh
Source21:      squid.service
# !Comm::MonitorsRead assertion in HttpStateData::maybeReadVirginBody()
Patch11:       SQUID-385-Comm_MonitorRead-assertion-simple-v4-t2.patch

%description
squid is a high-performance proxy caching server for web clients, supporting
FTP, gopher, ICAP, ICP, HTCP and HTTP data objects. Unlike traditional caching
software, squid handles all requests in a single, non-blocking process.

squid keeps meta data and especially hot objects cached in RAM, caches DNS
lookups, supports non-blocking DNS lookups, and implements negative caching of
failed requests.

squid supports SSL, extensive access controls, and full request logging.
By using the lightweight Internet Cache Protocols ICP, HTCP or CARP, squid
caches can be arranged in a hierarchy or mesh for additional bandwidth savings.

squid is derived from the ARPA-funded Harvest Project
http://harvest.cs.colorado.edu/

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
%patch11 -p1
# Fix error:
#   cc1plus: error: unrecognized command line option '-Wno-deprecated-register' [-Werror]
%{__sed} -ri 's/\s*-Wno-deprecated-register//' configure

%build
%define NFNETLINK_INC %(pkg-config --cflags libnfnetlink)
_CFLAGS='%{optflags} -fpie -fPIC %{NFNETLINK_INC}'
_CFLAGS+=' -Wno-error=format-truncation= -Wno-error=unused-variable -Wno-error=shadow'
%ifarch %ix86
_CFLAGS+=' -march=i686'
%endif
%configure \
 --libexecdir=%{_libdir}/squid \
 --sysconfdir=%{_sysconfdir}/squid \
 --libdir=%{_libdir}/squid \
 --datadir=%{_datadir}/squid \
 \
 --disable-arch-native \
 --disable-static \
 \
 --enable-build-info \
 --enable-storeio="aufs,rock,ufs" \
 --enable-removal-policies="heap,lru" \
 --enable-delay-pools \
 --enable-icap-client \
 --enable-ecap \
 --enable-cachemgr-hostname=squid \
 --enable-forw-via-db \
%ifos linux
 --enable-linux-netfilter \
 --with-netfilter-conntrack \
%endif
 --enable-follow-x-forwarded-for \
 --disable-ident-lookups \
 --enable-ssl-crtd \
 --enable-auth \
 --enable-auth-basic="DB,LDAP,NCSA,RADIUS,SASL" \
 --enable-external-acl-helpers="LDAP_group,kerberos_ldap_group,session,time_quota,wbinfo_group" \
 --enable-x-accelerator-vary \
 --enable-zph-qos \
 \
 --with-default-user=squid \
 --with-dl \
 --with-openssl \
 --with-large-files \
 \
 LDFLAGS='-Wl,--as-needed -Wl,--strip-all -pie' \
 CFLAGS="$_CFLAGS" \
 CXXFLAGS="$_CFLAGS %{?cxx11abi}" \
 LIBS="$(pkg-config --libs libnetfilter_conntrack)" \
 krb5confpath="%{_bindir}"
%{__make} %{?_smp_mflags}

%install
%{__make} install DESTDIR=%{buildroot}
%{__install} -m755 contrib/url-normalizer.pl %{buildroot}%{_libdir}/squid/
%{__install} -D -m644 %{S:3} %{buildroot}%{_sysconfdir}/logrotate.d/squid
%{__install} -d -m750 %{buildroot}/var/cache/squid
%{__install} -d -m750 %{buildroot}/var/log/squid
%if %{with systemd}
%{__install} -D -m644 %{S:21} %{buildroot}%{_unitdir}/squid.service
%else
%if "%{expand:%_vendor}" == "suse"
%{__ln_s} -f %{_initddir}/squid %{buildroot}%{_sbindir}/rcsquid
%{__install} -D -m644 %{S:2} %{buildroot}/var/adm/fillup-templates/sysconfig.squid
%{__install} -D -m755 %{S:11} %{buildroot}%{_initrddir}/squid
%else
%{__install} -D -m644 %{S:2} %{buildroot}%{_sysconfdir}/sysconfig/squid
%{__install} -D -m755 %{S:12} %{buildroot}%{_initrddir}/squid
%endif
%endif
for script in %{buildroot}%{_libdir}/squid/*.pl
do
  sed -ri '1 s|^.+$|#!/usr/bin/env perl|' $script
done
%if 0%{?suse_version}
%fdupes %{buildroot}%{_datadir}/squid/
%endif

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

%files
%defattr(-,root,root)
%doc CONTRIBUTORS COPYING CREDITS QUICKSTART README RELEASENOTES.html
%doc SPONSORS doc/debug-sections.txt
%dir %{_sysconfdir}/squid/
%config(noreplace) %{_sysconfdir}/squid/*
%config(noreplace) %{_sysconfdir}/logrotate.d/squid
%{_bindir}/purge
%{_bindir}/squidclient
%{_sbindir}/squid
%if %{with systemd}
%{_unitdir}/squid.service
%else
%{_initrddir}/squid
%if "%{expand:%_vendor}" == "suse"
%{_sbindir}/rcsquid
/var/adm/fillup-templates/sysconfig.squid
%else
%{_sysconfdir}/sysconfig/squid
%endif
%endif
%{_libdir}/squid/
%{_datadir}/squid/
%doc %{_mandir}/man1/*
%doc %{_mandir}/man8/*
%dir %attr(0750,squid,root) /var/cache/squid
%dir %attr(0750,squid,root) /var/log/squid

%pre
/usr/sbin/useradd -r -o -g nobody -u 31 -s /bin/false -c "WWW-proxy squid" \
  -d /var/cache/squid squid 2> /dev/null || :
%if 0%{?suse_version} && %{with systemd}
%{service_add_pre %{name}.service}
%endif

%if 0%{?suse_version}

%post
%set_permissions /var/cache/squid/
%set_permissions /var/log/squid/
%if %{with systemd}
%{fillup_only %{name}}
%{service_add_post %{name}.service}
%else
%{fillup_and_insserv %{name}}
%endif

%preun
%if %{with systemd}
%{service_del_preun %{name}.service}
%else
%{stop_on_removal %{name}}
%endif

%postun
%if %{with systemd}
%{service_del_postun %{name}.service}
%else
%{restart_on_update %{name}}
%endif
%{insserv_cleanup}

%verifyscript
%verify_permissions -e /var/cache/squid/
%verify_permissions -e /var/log/squid/

%endif

%changelog
openSUSE Build Service is sponsored by