%define emacsen_pkg	1
%{?without_emacsen: %define emacsen_pkg	0}

%if %{emacsen_pkg}
%undefine without_emacsen
%else
%define without_emacsen	1
%endif
%define rdmode		rd-mode
%define rdmode_el	rd-mode

Summary: RD document formatter
Name: rdtool
Version: 0.6.22
Release: 2%{?_dist_release}
License: distributable
Group: Development/Tools
Source0: http://www.moonwolf.com/ruby/archive/rdtool-%{version}.tar.gz
Source1: %{rdmode_el}-install.sh
Source2: %{rdmode_el}-remove.sh
Source3: vine-default-%{rdmode_el}.el
Source4: %{rdmode_el}-init.el
URL: http://rubyforge.org/projects/rdtool/
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: ruby, ruby-devel >= 1.8.0
Requires: libruby >= 1.8.0, ruby, sh-utils
Summary(ja): RDドキュメントのフォーマッタ

%description
RD is Ruby's POD. RDtool is formatter for RD.

%description -l ja
RD は Ruby においての POD です．RDtool は RD ドキュメントを
様々な形式に変換するためのツールです．

Vendor: Project Vine
Distribution: Vine Linux
Packager: iwaim

%if %{emacsen_pkg}
%package -n %{rdmode_el}
Summary: Emacsen major-mode for RD documents
Summary: RDドキュメントのためのEmacsen用メジャーモード
Group: Applications/Editors/Emacs
PreReq: emacsen, emacsen-common >= 0.1

%description -n %{rdmode_el}
Emacsen major mode rd-mode for the RD documents

%description -n %{rdmode_el} -l ja
RDドキュメントのためのEmacsen用メジャーモード: rd-mode

%endif

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
%{__ruby} setup.rb all --bindir=%{buildroot}%{rbindir} \
                     --rbdir=%{buildroot}%{rlibdir}
# fix missing rd/dot.rd2rc
install -m 0644 lib/rd/dot.rd2rc %{buildroot}%{rlibdir}/rd

%if %{emacsen_pkg}
mkdir -p $RPM_BUILD_ROOT/%{_datadir}/emacs/site-lisp/%{rdmode}
mkdir -p $RPM_BUILD_ROOT/%{_libdir}/emacsen-common/packages/install
mkdir -p $RPM_BUILD_ROOT/%{_libdir}/emacsen-common/packages/remove
%endif

# fixing `#!' paths
for f in `find . -type f`
do
  sed -e 's,^#![        ]*\([^  ]*\)/\(ruby\|with\|perl\|env\),#!/usr/bin/\2,' < $f > $f.n
  mv -f $f.n $f
done

# installing rd-mode
%if %{emacsen_pkg}
cp utils/*.el %{SOURCE3} %{SOURCE4} $RPM_BUILD_ROOT/%{_datadir}/emacs/site-lisp/%{rdmode}

%_installemacsenscript %{rdmode} %{SOURCE1}

%_removeemacsenscript  %{rdmode} %{SOURCE2}

%endif

%if %{emacsen_pkg}
%post -n %{rdmode_el}
if [ "$1" = 2 ]; then
  %_emacsenPackageRemove %{rdmode}

fi

%_addemacsenlist %{rdmode}

%_emacsenPackageInstall %{rdmode}


%preun -n %{rdmode_el}
if [ "$1" = 0 ]; then
%_emacsenPackageRemove %{rdmode}

%_removeemacsenlist %{rdmode}

fi
%endif

%clean
rm -rf ${RPM_BUILD_ROOT}

%files
%defattr(-, root, root)
%{_bindir}/*
%{rlibdir}/rd
%doc HISTORY
%doc README.rd
%doc README.rd.ja
%doc README.html
%doc README.ja.html
%doc doc/rd-draft.rd
%doc doc/rd-draft.rd.ja
%doc utils

%if %{emacsen_pkg}
%files -n %{rdmode_el}
%defattr(-, root, root)
%{_datadir}/emacs/site-lisp/%{rdmode}
%{emacsen_pkgdir}/install/%{rdmode}
%{emacsen_pkgdir}/remove/%{rdmode}
%endif

%changelog
* Fri Mar 19 2010 IWAI, Masaharu <iwai@alib.jp> 0.6.22-2
- apply vine-default
  - update rd-mode-{install,remove}.sh
  - add vine-default-rd-mode.el (Source3)
  - add rd-mode-init.el (Source4)
- using emacsen_pkgdir macro
- update Summary and description for rd-mode package
- update URL
- add Tags: Vendor, Distribution and Packager
- drop unnecessary defined variable: ruby, rbindir
- drop unnecessary if routine: Source1,2
- drop unnecessary Prefix tag

* Sat Nov  7 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.6.22-1
- new upstream release
- applied new versioning policy, spec in UTF-8

* Sat Sep 16 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.6.20-0vl2
- fixed Group typo

* Wed Sep 13 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.6.20-0vl1
- new upstream release
- changed rd-mode Group to Appliations/Editors/Emacs <BTS:VineLinux:163>
- s/Copyright/License/

* Mon Nov 15 2004 IWAI, Masaharu <iwai@alib.jp> 0.6.17-0vl1
- new upstream release
- drop unnecessary packages in BuildRequires: racc and ruby-amstd
- update Source0 URL
- drop obsolete patch: rdtoolconf.rb.patch ( Patch0 )
- drop obsolete patch: rd-mode patch ( Patch2 )
- update setup and intall sections: new upstream package using setup.rb
- add README.ja.html in %%doc
- fix missing rd/dot.rd2rc

* Mon Oct 06 2003 akira yamada <akira@vinelinux.org> rdtool-0.6.13-0vl3
- build with ruby-1.8.0.  it requires libruby >= 1.8.0.

* Fri May 23 2003 IWAI Masaharu <iwai@alib.jp> 0.6.13-0vl2
- fix typo in %%description -l ja for rdtool package
- generate rd-mode package

* Thu May 22 2003 IWAI Masaharu <iwai@alib.jp> 0.6.13-0vl1
- new upstream version
- update rdtoolconf.rb.patch (Patch0)
- drop close-dt.patch (Pathc1): upstream merged
- drop test in %%docdir

* Sun Jun 16 2002 akira yamada <akira@vinelinux.org> 0.6.11-0vl2
- added rdtool-0.6.11-close-dt.patch: ruby-ext#02080: missing </dt>
- added rdtool-0.6.11-rd-mode.patch: ruby-list#35281: rd-mode.el - a bit fix

* Mon Feb 04 2002 akira yamada <akira@vinelinux.org> 0.6.11-0vl1
- new upstream version.
- added ruby-optparse to BuildRequires.

* Thu Jul 26 2001 akira yamada <akira@vinelinux.org> 0.6.10-0vl4
- fixed bug in rd/rd2html-lib.rb (prepare_footnotes)
- fixed bug in rd/rdblockparser.ry (desclistitem)

* Thu Jul 26 2001 akira yamada <akira@vinelinux.org>
- Rebuild with ruby-devel-1.6.4-0vl3.

* Thu Jun 28 2001 akira yamada <akira@vinelinux.org>
- Applied bugfix patch for rdvisitor.rb.

* Tue Jun 12 2001 akira yamada <akira@vinelinux.org>
- New upstream version 0.6.10.

* Tue Mar 27 2001 akira yamada <akira@vinelinux.org>
- Initial packaging.
