File trafficserver.spec of Package trafficserver

%define realname trafficserver
%define realver  8.1.3
%define srcext   tar.bz2

# See doc/ext/plantuml_fetch.sh
%define platinum_ver 1.2018.1

%define runuser  nobody
%define rungroup nobody

%if 0%{?suse_version}
%define perl_pkg perl-%{realname}
%else
%define perl_pkg %{realname}-perl
%endif

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

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       Apache-2.0
Group:         Productivity/Networking/Web/Proxy
URL:           http://trafficserver.apache.org/
Summary:       Fast, scalable and extensible HTTP/1.1 and HTTP/2 compliant caching proxy server

# Build-time parameters
BuildRequires: gcc-c++
BuildRequires: pkg-config
BuildRequires: curl-devel
BuildRequires: pkgconfig(libmemcached) >= 1.0
BuildRequires: python3%{?suse_version:-base} python3-setuptools
BuildRequires: perl-ExtUtils-MakeMaker
BuildRequires: ncurses-devel
BuildRequires: openssl-devel
BuildRequires: zlib-devel xz-devel
BuildRequires: tcl-devel
BuildRequires: %{?suse_version:lib}pcre-devel
BuildRequires: brotli-devel
BuildRequires: luajit-devel
BuildRequires: jansson-devel
BuildRequires: libGeoIP-devel
BuildRequires: jemalloc-devel
BuildRequires: mysql-devel
BuildRequires: readline-devel
BuildRequires: libcap-devel
BuildRequires: systemd-devel
# Docs
### BuildRequires: jre-11-headless
### BuildRequires: python3-Sphinx python3-sphinxcontrib-plantuml
BuildRoot:     %{_tmppath}/%{name}-root
Source:        https://dlcdn.apache.org/trafficserver/%{realname}-%{realver}%{?extraver}.%{srcext}
# Doc
Source11:      https://ci.trafficserver.apache.org/bintray/plantuml-%{platinum_ver}.tar.bz2

%description
Apache Traffic Server

Traffic Server is a high-performance building block for cloud services.
It's more than just a caching proxy server; it also has support for
plugins to build large scale web applications.

%package devel
Group:         Development/Languages/C and C++
Summary:       Development files for %{name}
Requires:      %{name} = %{version}

%description devel
Development files for %{name}

%package -n %{perl_pkg}
Group:         Productivity/Networking/Web/Proxy
Summary:       Set of perl interfaces to manage an Apache Traffic Server instance
Requires:      %{name} = %{version}
Requires:      perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
Provides:      perl-%{realname} = %{version}-%{release}
Provides:      %{realname}-perl = %{version}-%{release}

%description -n %{perl_pkg}
Apache::TS - a set of perl interfaces to manage an Apache Traffic Server
    instance. This includes the following sub-modules

Apache::TS::AdminClient - access the statistics and configuration
    settings stored within Apache Traffic Server

Apache::TS::Config - Manage Apache Traffic Server configs

Apache::TS::Config::Records - Manage records.config settings.

%if 0%{?suse_version} >= 1310 || 0%{?rhel} >= 7
%package memcached-remap
Group:         Productivity/Networking/Web/Proxy
Summary:       Apache Traffic Server Memcached-based remap plugin
Requires:      %{name} = %{version}

%description memcached-remap
This is a plugin which is based on the mysql_remap code that allows us to do
dynamic reverse proxy (dynamic remap) based on the information present in the
memcached database.

memcached is used only as decision making place. All communication happens via
HTTP between above components
%endif

%package mysql-remap
Group:         Productivity/Networking/Web/Proxy
Summary:       Apache Traffic Server MySQL-based remap plugin
Requires:      %{name} = %{version}

%description mysql-remap
This is a basic plugin for doing dynamic "remaps" from a database.
It essentially rewrites the incoming request's Host header / origin server
connection to one retrieved from a database.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a11
PLANTUML_JAR=$(pwd -P)/plantuml-%{platinum_ver}/plantuml.jar
%{__sed} -ri "s|^(\s*PLANTUML_JAR=).+\$|\1$PLANTUML_JAR \\\|" doc/Makefile.am doc/Makefile.in
%{__sed} -ri "/ABSTRACT_FROM/ a\       INSTALLDIRS    => 'vendor'," lib/perl/Makefile.PL
cat >> config.layout <<EOF

<Layout CustomBuild>
  prefix:          %{_prefix}
  exec_prefix:     %{_prefix}
  bindir:          %{_bindir}
  sbindir:         %{_sbindir}
  libdir:          %{_libdir}
  libexecdir:      %{_libexecdir}+
  infodir:         %{_infodir}
  mandir:          %{_mandir}
  sysconfdir:      %{_sysconfdir}+
  datadir:         %{_datadir}+
  installbuilddir: %{_datadir}/build
  includedir:      %{_includedir}+
  localstatedir:   %{_localstatedir}/lib+
  runtimedir:      /run+
  logdir:          /var/log+
  cachedir:        /var/cache+
</Layout>
EOF

%build
export INSTALLDIRS=vendor
PLANTUML_JAR=$(pwd -P)/plantuml-%{platinum_ver}/plantuml.jar
_CFLAGS='%{optflags} %{?gcc_lto} %(pkg-config --cflags-only-I mysqlclient)'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto} %(pkg-config --libs-only-L mysqlclient)'
%configure \
 --sysconfdir=%{_sysconfdir}/%{name} \
 --libexecdir=%{_libexecdir}/%{name} \
 --enable-layout=CustomBuild \
 --disable-diags \
 --disable-tests \
 --enable-wccp \
 --disable-hwloc \
 --enable-hardening \
 --enable-experimental-plugins \
 \
 --with-user=%{runuser} \
 --with-group=%{rungroup} \
 --with-jemalloc \
 \
 CFLAGS="$_CFLAGS" \
 CXXFLAGS="$_CFLAGS" \
 LDFLAGS="$_LDFLAGS"
# Pre-create perl makefiles
cd lib/perl
perl Makefile.PL INSTALLDIRS=vendor
cd -
%{__sed} -i 's/ -o $(pkgsysuser) -g $(pkgsysgroup)//' proxy/Makefile
%{__make} %{?_smp_mflags} INSTALLDIRS=vendor PLANTUML_JAR=$PLANTUML_JAR

%install
%{__make} install DESTDIR=%{buildroot} INSTALLDIRS=vendor
%if 0%{?_unitdir:1}
%{__install} -D -m644 rc/trafficserver.service %{buildroot}%{_unitdir}/trafficserver.service
%endif
%{__rm} -rf %{buildroot}%{_datadir}/doc/trafficserver

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

%files
%defattr(-,root,root)
%license LICENSE
%doc CHANGELOG-%{version} LAYOUT NOTICE README README-EC2 REVIEWERS STATUS
%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/*
%{_unitdir}/trafficserver.service
%{_bindir}/*
%exclude %{_bindir}/traffic_layout
%exclude %{_bindir}/trafficserver
%exclude %{_bindir}/tsxs
%{_libdir}/*.so.*
%dir %{_libexecdir}/%{name}/
### %doc %{_mandir}/man1/*
### %doc %{_mandir}/man5/*
### %doc %{_mandir}/man8/*
%exclude %{_libexecdir}/%{name}/*.la
%exclude %{_libexecdir}/%{name}/memcached_remap.so
%exclude %{_libexecdir}/%{name}/mysql_remap.so
### %exclude %{_mandir}/man1/tsxs.1*
%dir %attr(0755,%{runuser},%{rungroup}) %{_localstatedir}/cache/%{name}
%dir %attr(0755,%{runuser},%{rungroup}) %{_localstatedir}/lib/%{name}
%dir %attr(0755,%{runuser},%{rungroup}) %{_localstatedir}/log/%{name}

# Development stuff
%files devel
%defattr(-,root,root)
%{_libdir}/pkgconfig/trafficserver.pc
%{_bindir}/traffic_layout
%{_bindir}/tsxs
%dir %{_includedir}/trafficserver/atscppapi
%dir %{_includedir}/trafficserver/ts
%dir %{_includedir}/trafficserver
%{_includedir}/trafficserver/atscppapi/*.h
%{_includedir}/trafficserver/ts/*.h
%{_libdir}/*.so
### %doc %{_mandir}/man1/tsxs.1*
%exclude %{_libdir}/*.la

# Perl stuff
%files -n %{perl_pkg}
%defattr(-,root,root)
%doc %{_mandir}/man3/*
%exclude %{perl_archlib}/perllocal.pod
%{perl_vendorlib}/Apache/
%exclude %{perl_vendorarch}/auto/Apache/TS/.packlist

%files memcached-remap
%defattr(-,root,root)
%{_libexecdir}/%{name}/memcached_remap.so

%files mysql-remap
%defattr(-,root,root)
%{_libexecdir}/%{name}/mysql_remap.so

%if 0%{?suse_version}

%if 0%{?_unitdir:1}
%pre
%{service_add_pre %{name}.service}
%endif

%post
%if 0%{?_unitdir:1}
%{fillup_only %{name}}
%{service_add_post %{name}.service}
%else
%{fillup_and_insserv %{name}}
%endif
/sbin/ldconfig
%{__install} -d -m755 -o %{runuser} -g %{rungroup} %{_localstatedir}/run/%{name}

%preun
%if 0%{?_unitdir:1}
%{service_del_preun %{name}.service}
%else
%{stop_on_removal %{name}}
%endif

%postun
%if 0%{?_unitdir:1}
%{service_del_postun %{name}.service}
%else
%{restart_on_update %{name}}
%endif
%{insserv_cleanup}
/sbin/ldconfig
%{__rm} -rf %{_localstatedir}/run/%{name}

%else

%post
/sbin/ldconfig
%{__install} -d -m755 -o %{runuser} -g %{rungroup} %{_localstatedir}/run/%{name}

%postun
/sbin/ldconfig
%{__rm} -rf %{_localstatedir}/run/%{name}

%endif

%changelog
openSUSE Build Service is sponsored by