File scrollkeeper.spec of Package scrollkeeper

#
# spec file for package scrollkeeper
#
# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           scrollkeeper
%define xmlcatalog	%{_sysconfdir}/xml/catalog
%define my_localstatedir /var
Summary:        Cataloging System for Documentation
License:        LGPL-2.1+
Group:          Development/Libraries/C and C++
Version:        0.3.14
Release:        0
Source0:        scrollkeeper-%{version}.tar.bz2
Source1:        logrotate.%{name}
# PATCH-FIX-OPENSUSE scrollkeeper-0.3.14-rebuilddb.diff bnc96609 ke@suse.de
Patch:          scrollkeeper-0.3.14-rebuilddb.diff
# PATCH-FIX-UPSTREAM scrollkeeper-0.3.14-createdbdir.diff bnc230786 prusnak@suse.cz
Patch1:         scrollkeeper-0.3.14-createdbdir.diff
BuildRequires:  docbook_4
BuildRequires:  fdupes
BuildRequires:  intltool
BuildRequires:  libxml2-tools
BuildRequires:  libxslt-devel
BuildRequires:  perl-XML-Parser
BuildRequires:  sgml-skel
Requires:       %{name}-lang = %{version}
Requires:       docbook_4
Requires:       libxml2-tools >= 2.4.19
Requires:       libxslt
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Url:            http://scrollkeeper.sourceforge.net/
PreReq:         sgml-skel
Requires(post): update-alternatives
Requires(postun): update-alternatives
# The build service fails to build the package because it doesn't really
# understand Requires(post), so use PreReq too (see bnc#439232).
%if %defined suse_version
PreReq:         update-alternatives
%endif
Suggests:       logrotate

%description 
ScrollKeeper is a cataloging system for documentation. It manages
documentation metadata (as specified by the Open Source Metadata
Framework (OMF)) and provides a simple API to allow help browsers to
find, sort, and search the document catalog.

It will also be able to communicate with catalog servers on the net to
search for documents which are not on the local system.

%lang_package
%prep
%setup -q
%patch -p1 -b .rebuilddb
%patch1

%build
%configure \
  --localstatedir=%{my_localstatedir} \
  --with-omfdirs=/usr/share/omf:/usr/local/share/omf
%{__make} %{?jobs:-j%jobs}
xmlcatbin=/usr/bin/xmlcatalog
CATALOG=scrollkeeper.xml
$xmlcatbin --noout --create $CATALOG
$xmlcatbin --noout --add "public" \
  "-//OMF//DTD Scrollkeeper OMF Variant V1.0//EN" \
  "file://%{_datadir}/xml/scrollkeeper/dtds/scrollkeeper-omf.dtd" $CATALOG
# $xmlcatbin --noout --add "system" \
#   "http://..."
#   "file://%{_datadir}/xml/scrollkeeper/dtds/scrollkeeper-omf.dtd" $CATALOG
%define FOR_ROOT_CAT for-catalog-%{name}-%{version}.xml
CATALOG=etc/xml/$CATALOG
rm -f %{FOR_ROOT_CAT}.tmp
$xmlcatbin --noout --create %{FOR_ROOT_CAT}.tmp
# $xmlcatbin --noout --add "delegateSystem" \
#   "http://www.oasis-open.org/docbook/xml/simple/" \
#   "file:///$CATALOG" %{FOR_ROOT_CAT}.tmp
$xmlcatbin --noout --add "delegatePublic" \
  "-//OMF//DTD Scrollkeeper OMF Variant V1.0//EN" \
  "file:///$CATALOG" %{FOR_ROOT_CAT}.tmp
# Create tag
sed '/<catalog/a\
  <group id="%{name}-%{version}">
/<\/catalog/i\
  </group>' \
  %{FOR_ROOT_CAT}.tmp > %{FOR_ROOT_CAT}

%install
%makeinstall
# scrollkeepr does not export headers or a .pc,
# so it can't be used outside of scrollkeeper
rm $RPM_BUILD_ROOT%{_prefix}/%_lib/libscrollkeeper.*a
rm $RPM_BUILD_ROOT%{_prefix}/%_lib/libscrollkeeper.so
# Unwanted doc stuff
rm -fr $RPM_BUILD_ROOT/var/log/scrollkeeper.log \
  $RPM_BUILD_ROOT%{_datadir}/doc \
  $RPM_BUILD_ROOT%{_localstatedir}/lib
#
# Change sr@Latn to sr@latin
mv %{buildroot}%{_datadir}/locale/sr@Latn %{buildroot}%{_datadir}/locale/sr@latin
# Change no to nb
mv %{buildroot}%{_datadir}/locale/no %{buildroot}%{_datadir}/locale/nb
%find_lang %{name}
# Logrotate
install -d $RPM_BUILD_ROOT/etc/logrotate.d
install -m 644 %{S:1} $RPM_BUILD_ROOT/etc/logrotate.d/%{name}
# xml catalog
cat_dir=%{buildroot}/etc/xml
install -d -m755 $cat_dir
# install -m644 %{name}.xml $RPM_BUILD_ROOT/etc/xml/%{name}.xml
install -m644 %{FOR_ROOT_CAT} %{name}.xml $cat_dir
for binary in %{buildroot}/%{_bindir}/*; do
	mv $binary $binary.sk
done
%fdupes $RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT
# %pre
# # rm -rf %{_datadir}/scrollkeeper/Templates || true

%post
/sbin/ldconfig
localstated_r=$(echo %{my_localstatedir}|sed 's:^/::')
# rm -rf /var/lib/scrollkeeper
# mkdir -p var/lib/scrollkeeper
# scrollkeeper-update -p var/lib/scrollkeeper
edit-xml-catalog --group --catalog /etc/xml/suse-catalog.xml \
  --add /etc/xml/%{FOR_ROOT_CAT}
# If the scrollkeeper-config group is in automatic mode, then this
# will also switch all symlinks automatically
update-alternatives \
	--install %{_bindir}/scrollkeeper-config scrollkeeper-config %{_bindir}/scrollkeeper-config.sk 20 \
	--slave %{_bindir}/scrollkeeper-extract scrollkeeper-extract %{_bindir}/scrollkeeper-extract.sk \
	--slave %{_bindir}/scrollkeeper-gen-seriesid scrollkeeper-gen-seriesid %{_bindir}/scrollkeeper-gen-seriesid.sk \
	--slave %{_bindir}/scrollkeeper-get-cl scrollkeeper-get-cl %{_bindir}/scrollkeeper-get-cl.sk \
	--slave %{_bindir}/scrollkeeper-get-content-list scrollkeeper-get-content-list %{_bindir}/scrollkeeper-get-content-list.sk \
	--slave %{_bindir}/scrollkeeper-get-extended-content-list scrollkeeper-get-extended-content-list %{_bindir}/scrollkeeper-get-extended-content-list.sk \
	--slave %{_bindir}/scrollkeeper-get-index-from-docpath scrollkeeper-get-index-from-docpath %{_bindir}/scrollkeeper-get-index-from-docpath.sk \
	--slave %{_bindir}/scrollkeeper-get-toc-from-docpath scrollkeeper-get-toc-from-docpath %{_bindir}/scrollkeeper-get-toc-from-docpath.sk \
	--slave %{_bindir}/scrollkeeper-get-toc-from-id scrollkeeper-get-toc-from-id %{_bindir}/scrollkeeper-get-toc-from-id.sk \
	--slave %{_bindir}/scrollkeeper-install scrollkeeper-install %{_bindir}/scrollkeeper-install.sk \
	--slave %{_bindir}/scrollkeeper-preinstall scrollkeeper-preinstall %{_bindir}/scrollkeeper-preinstall.sk \
	--slave %{_bindir}/scrollkeeper-rebuilddb scrollkeeper-rebuilddb %{_bindir}/scrollkeeper-rebuilddb.sk \
	--slave %{_bindir}/scrollkeeper-uninstall scrollkeeper-uninstall %{_bindir}/scrollkeeper-uninstall.sk \
	--slave %{_bindir}/scrollkeeper-update scrollkeeper-update %{_bindir}/scrollkeeper-update.sk

%postun
localstated_r=$(echo %{my_localstatedir}|sed 's:^/::')
# remove entries only on removal of file
if [ ! -f %{xml_sysconf_dir}/%{FOR_ROOT_CAT} -a -x /usr/bin/edit-xml-catalog ] ; then
  edit-xml-catalog --group --catalog /etc/xml/suse-catalog.xml \
    --del %{name}-%{version}
fi
### if [ $1 = 0 ]; then
###   # SK is being removed, not upgraded.
###   # Remove all generated files
###   rm -rf $localstated_r/lib/scrollkeeper
###   rm -f $localstated_r/log/scrollkeeper.log
###   rm -f $localstated_r/log/scrollkeeper.log.1
###   [ -x $r/$xmlcatbin ] || {
###     echo "$r/$xmlcatbin is missing"
###     echo "Cleanup $xmlcatal_g manually"
###     exit 0
###   }
### fi
#rm -rf %{_datadir}/scrollkeeper/templates
/sbin/ldconfig
# Note: we don't use "$1 -eq 0", to avoid issues if the package gets renamed
if [ ! -f %{_bindir}/scrollkeeper-config.sk ]; then
  update-alternatives --remove scrollkeeper-config %{_bindir}/scrollkeeper-config.sk
fi

%posttrans
# Workaround old bug in 11.1/11.2 packages that always removed the symlinks in
# %postun. Can be removed during 12.2 development.
if [ ! -f %{_bindir}/scrollkeeper-config -a -f %{_bindir}/scrollkeeper-config.sk ]; then
  update-alternatives \
          --install %{_bindir}/scrollkeeper-config scrollkeeper-config %{_bindir}/scrollkeeper-config.sk 20 \
          --slave %{_bindir}/scrollkeeper-extract scrollkeeper-extract %{_bindir}/scrollkeeper-extract.sk \
          --slave %{_bindir}/scrollkeeper-gen-seriesid scrollkeeper-gen-seriesid %{_bindir}/scrollkeeper-gen-seriesid.sk \
          --slave %{_bindir}/scrollkeeper-get-cl scrollkeeper-get-cl %{_bindir}/scrollkeeper-get-cl.sk \
          --slave %{_bindir}/scrollkeeper-get-content-list scrollkeeper-get-content-list %{_bindir}/scrollkeeper-get-content-list.sk \
          --slave %{_bindir}/scrollkeeper-get-extended-content-list scrollkeeper-get-extended-content-list %{_bindir}/scrollkeeper-get-extended-content-list.sk \
          --slave %{_bindir}/scrollkeeper-get-index-from-docpath scrollkeeper-get-index-from-docpath %{_bindir}/scrollkeeper-get-index-from-docpath.sk \
          --slave %{_bindir}/scrollkeeper-get-toc-from-docpath scrollkeeper-get-toc-from-docpath %{_bindir}/scrollkeeper-get-toc-from-docpath.sk \
          --slave %{_bindir}/scrollkeeper-get-toc-from-id scrollkeeper-get-toc-from-id %{_bindir}/scrollkeeper-get-toc-from-id.sk \
          --slave %{_bindir}/scrollkeeper-install scrollkeeper-install %{_bindir}/scrollkeeper-install.sk \
          --slave %{_bindir}/scrollkeeper-preinstall scrollkeeper-preinstall %{_bindir}/scrollkeeper-preinstall.sk \
          --slave %{_bindir}/scrollkeeper-rebuilddb scrollkeeper-rebuilddb %{_bindir}/scrollkeeper-rebuilddb.sk \
          --slave %{_bindir}/scrollkeeper-uninstall scrollkeeper-uninstall %{_bindir}/scrollkeeper-uninstall.sk \
          --slave %{_bindir}/scrollkeeper-update scrollkeeper-update %{_bindir}/scrollkeeper-update.sk
fi

%files
%defattr(-,root,root)
%doc COPYING AUTHORS README NEWS INSTALL
%config(noreplace) /etc/logrotate.d/%{name}
%config %{_sysconfdir}/%{name}.conf
%config %{_sysconfdir}/xml
%{_datadir}/omf
%{_bindir}/*.sk
%{_libdir}/lib*
%{_mandir}/*/*
%{_datadir}/xml/scrollkeeper
%{_datadir}/scrollkeeper

%files lang -f %{name}.lang

%changelog