%bcond_with systemd

Summary: a high-performance, distributed memory object caching system
Summary(ja): ハイパフォーマンスな分散メモリオブジェクトキャッシングシステム
Name: memcached
Version: 1.6.18
Release: 1%{?_dist_release}%{?with_systemd:.systemd}
Group: servers
Vendor: Project Vine
Distribution: Vine Linux

License: modified BSD style License
Url: https://memcached.org/
Source0: http://www.memcached.org/files/memcached-%{version}.tar.gz
Source1: memcached.sysconfig
# Patches
Patch1: memcached-unit.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: libevent-devel
BuildRequires: openssl-devel
Requires(pre): shadow-utils
%if %{with systemd}
BuildRequires: systemd
%{?systemd_requires}
%else
Requires(post): chkconfig
Requires(preun): chkconfig
Requires(preun): initscripts
Requires(postun): initscripts
%endif

%description
memcached is a high-performance, distributed memory object caching system, 
generic in nature, but intended for use in speeding up dynamic web 
applications by alleviating database load.


%package devel
Summary:	Files needed for development using memcached protocol
Summary(ja):	memcached プロトコルを使用した開発に必要なファイル
Group:		programming
Requires:	%{name} = %{version}-%{release}

%description devel
Install memcached-devel if you are developing C/C++ applications that require access to the
memcached binary include files.


%debug_package


%prep
%setup -q
%patch1 -p1 -b .unit

%if !%{with systemd}
perl -pi -e 's|/var/run/memcached\.pid|/var/run/memcached/memcached.pid|' scripts/memcached.sysv
%endif


%build
%configure --enable-tls
%__make %{?_smp_mflags}


%install
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
mkdir -p %{buildroot}%{_localstatedir}/run/memcached

make install DESTDIR=%{buildroot} INSTALL="%{__install} -p"
# remove memcached-debug
rm -f %{buildroot}/%{_bindir}/memcached-debug

# Perl script for monitoring memcached
install -Dp -m0755 scripts/memcached-tool %{buildroot}%{_bindir}/memcached-tool
install -Dp -m0644 scripts/memcached-tool.1 \
        %{buildroot}%{_mandir}/man1/memcached-tool.1

%if %{with systemd}
# Unit file
install -Dp -m0644 scripts/memcached.service \
        %{buildroot}%{_unitdir}/memcached.service
%else
mkdir -p %{buildroot}%{_initdir}
install -m755 scripts/memcached.sysv %{buildroot}%{_initdir}/memcached
%endif
# Default configs
install -Dp -m0644 %{SOURCE1} %{buildroot}/%{_sysconfdir}/sysconfig/%{name}


%clean
rm -rf %{buildroot}


%triggerprein -- memcached < 1.5.0
  /sbin/update-alternatives --remove memcached %{_bindir}/memcached.memcached ||:
  /sbin/update-alternatives --remove memcached %{_bindir}/memcached.repcached ||:
rm -f %{_bindir}/memcached

%pre
getent group memcached >/dev/null || groupadd -r memcached
getent passwd memcached >/dev/null || \
useradd -r -g memcached -d %{_sysconfdir}/memcached -s /sbin/nologin \
-c "memcached service" memcached
exit 0

%post
%if %{with systemd}
%systemd_post memcached.service
%else
/sbin/chkconfig --add %{name}
%endif

%preun
%if %{with systemd}
%systemd_preun memcached.service
%else
if [ "$1" -eq 0 -o -x /bin/systemctl ]; then
  /sbin/service %{name} stop >/dev/null 2>&1
  /sbin/chkconfig --del %{name} 
fi
%endif

%postun
%if %{with systemd}
%systemd_postun_with_restart memcached.service
%else
if [ "$1" -ge "1" -a ! -x /bin/systemctl ]; then
  /sbin/service %{name} condrestart ||:
fi
%endif


%files
%defattr(-,root,root)
%license COPYING
%doc AUTHORS* ChangeLog ChangeLog* NEWS README*
%doc doc/CONTRIBUTORS doc/*.txt
%config(noreplace) %{_sysconfdir}/sysconfig/memcached
%{_bindir}/memcached
%{_bindir}/memcached-tool
%{_mandir}/man1/memcached.1*
%{_mandir}/man1/memcached-tool.1*
%if %{with systemd}
%{_unitdir}/memcached.service
%else
%{_initdir}/memcached
%dir %{_localstatedir}/run/memcached
%endif

%files devel
%defattr(-,root,root,0755)
%{_includedir}/memcached/*

%changelog
* Sun Feb 12 2023 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.6.18-1
- new upstream release.

* Tue Oct 05 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.6.12-1
- new upstream release.

* Sat Dec 19 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.6.9-1
- new upstream release.

* Tue Apr 14 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.6.5-1
- new upstream release.
- built with libevent-2.1.11.
- added systemd support (disabled as default).

* Sun Nov 04 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.5.12-1
- new upstream release.
- built with libevent-2.1.8.
- dropped repcached.

* Mon Nov 23 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.25-1
- new upstream release.

* Mon Jul 27 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.24-1
- new upstream release.

* Fri Jan 10 2014 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.17-1
- new upstream release.

* Fri May 11 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.13-2
- fixed missing symlink.

* Sat Apr 28 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.13-1
- new upstream release.
- made be able to choose between memcached and repcached by alternatives.

* Sat Aug 20 2011 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.7.repcached2.3.1-1
- new upstream release.
- updated repcached patch.
- removed %%Patch0. (fixed in upstream)

* Tue Feb 15 2011 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.5.repcached2.3.1-1
- updated repcached patch.

* Mon Feb 14 2011 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.4.5.repcached2.
3-1
- applied the repcached patch.

* Thu Feb 10 2011 Toshiharu Kudoh <toshi.kd2@gmail.com> 1.4.5-1
- new upstream release
- added Patch0 from Fedora
- rebuilt with libevent-2.0.10
- fixed &&files
- splitted -devel package

* Mon Jun 22 2009 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.2.8-1
- new upstream release.
- wrote spec in UTF-8.

* Mon May 19 2008 Tomohiro 'Tomo-p' KATO <tomop@teamgedoh.net> 1.2.5-1
- new upstream release.
- added some scripts.

* Mon Jul 16 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.1.12-0vl2
- rebuilt with libevent-1.3b

* Sun Aug 13 2006 IWAI, Masaharu <iwai@alib.jp> 1.1.12-0vl1
- new package

