File of Package kernel-source

# spec file for package kernel-docs@VARIANT@
# Copyright (c) @YEAR@ SUSE LINUX 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

%define patchversion @PATCHVERSION@
%define variant @VARIANT@%{nil}

%include %_sourcedir/kernel-spec-macros

%define use_fop	1

%if %{?is_opensuse}
%define use_sphinx 1
%define use_sphinx 0

# copy the whole tree to generate some images (sigh...)
%define local_copy 1
%if %local_copy
%define linux_src .
%define linux_src /usr/src/linux%variant
%define make_arg "-C %linux_src"

Name:           kernel-docs@VARIANT@
Summary:        Kernel Documentation (man pages)
License:        GPL-2.0
Group:          Documentation/Man
Version:        @RPMVERSION@
%if 0%{?is_kotd}
Release:        <RELEASE>.g@COMMIT@
Release:        @RELEASE@
BuildRequires:  kernel-source%variant
%if %use_sphinx
BuildRequires:  graphviz
BuildRequires:  python-Sphinx
# rst2pdf is broken with Sphinx 1.3.x, so disabled for now
# BuildRequires:  python-rst2pdf
BuildRequires:  xmlto
%if %use_fop
BuildRequires:  fop
BuildRequires:  docbook-toys
BuildRequires:  docbook-utils
BuildRequires:  texlive-courier
BuildRequires:  texlive-dvips
BuildRequires:  texlive-ec
BuildRequires:  texlive-helvetic
BuildRequires:  texlive-jadetex
BuildRequires:  texlive-times
Provides:       %name = %version-%source_rel
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Source:         kernel-spec-macros

These are the man pages (section 9) built from the current kernel sources.


%package pdf
Summary:        Kernel Documentation (PDF)
Group:          Documentation/Other

%description pdf
These are PDF documents built from the current kernel sources.


%package html
Summary:        Kernel Documentation (HTML)
Group:          Documentation/HTML

%description html
These are HTML documents built from the current kernel sources.


%if !%use_fop
cp -av /etc/texmf/web2c/texmf.cnf .
cat << EOF >> texmf.cnf
main_memory.pdfjadetex = 5000000
hash_extra.pdfjadetex = 140000
max_strings.pdfjadetex = 240000
save_size.pdfjadetex = 20000
%setup -T -c
%if %local_copy
# FIXME: need to copy locally to generate some images...
cp -a /usr/src/linux%variant/* .

%if !%use_fop
# use texmf.cnf from local source
export LANG=en_US
mkdir -p man
make %{?make_arg} O=$PWD/man mandocs %{?jobs:-j%jobs}
mkdir -p html
make %{?make_arg} O=$PWD/html htmldocs
mkdir -p pdf
make \
%if %use_fop
    XMLTOFLAGS="-m %linux_src/Documentation/DocBook/stylesheet.xsl --skip-validation --with-fop" \
  %{?make_arg} O=$PWD/pdf pdfdocs

install -d $RPM_BUILD_ROOT/%{_mandir}/man9
# filter out obscure device drivers - they clutter up the rpm and don't add any real value
find man/Documentation/DocBook/ -name '*.9.gz' | 
grep -E -v 'man/(sis[69]|rio|fsl|struct_rio|RIO|mpc85|set_rx_mode|mdio_(read|write)|mii_ioctl|mca_|z8530|nand|sppp|piix|(read|write)_zs)' |  
while read i ; do
	cp $i $RPM_BUILD_ROOT/%{_mandir}/man9
if [ -d man/Documentation/kdb ] ; then
    for i in man/Documentation/kdb/*.m* ; do
	k=`basename $i`
	cp $i $RPM_BUILD_ROOT/%{_mandir}/man9/$k

ln -s %{_mandir}/man9/request_threaded_irq.9.gz $RPM_BUILD_ROOT%{_mandir}/man9/request_irq.9.gz

install -d $RPM_BUILD_ROOT%{_datadir}/doc/kernel/pdf
cp -a pdf/Documentation/DocBook/*.pdf $RPM_BUILD_ROOT%{_datadir}/doc/kernel/pdf || true
%if %use_sphinx
# copy PDF files generated by sphinx (once when it really works...)
for i in pdf/Documentation/output/*.pdf; do
    test -s $i && cp -a $i $RPM_BUILD_ROOT%{_datadir}/doc/kernel/pdf

install -d $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/DocBook
cp -a html/Documentation/DocBook/* $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/DocBook || true
rm -f $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/DocBook/*.xml
rm -f $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/DocBook/*.db
rm -f $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/DocBook/*.{gif,png}
rm -f $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/DocBook/*/*.proc
install -d $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/rst
%if %use_sphinx
cp -a html/Documentation/output/* $RPM_BUILD_ROOT%{_datadir}/doc/kernel/html/rst || true

%if !%local_copy


%files pdf
%dir %{_datadir}/doc/kernel
%docdir %{_datadir}/doc/kernel/pdf

%files html
%dir %{_datadir}/doc/kernel
%docdir %{_datadir}/doc/kernel/html