%define _localstatedir	/var
%define _docdir %{_defaultdocdir}
%define vinedocver 4.1
%define nmzver 2.0.20
%define tknamazuver 1.90

Summary: Namazu is a search engine intented for easy use
Summary(ja): 日本語全文検索エンジン
Name: namazu
Version: %{nmzver}
Release: 2%{?_dist_release}
Group: Applications/Text
License: GPL2
URL: http://www.namazu.org/
Source0: http://www.namazu.org/stable/namazu-%{nmzver}.tar.gz
Source1: http://www.cwo.zaq.ne.jp/vine-linux/text/TCL-scroll.txt
Source2: namazu-vinehtml-%{vinedocver}.tar.gz
Source3: tknamazurc.vine
Source4: dw3m

Source10: filter-requires-namazu.sh
%define __find_requires %{SOURCE10}

Patch0: namazu-2.0.20-nkf.patch
Patch5: tknamazu.tcl.selall.patch
Patch6: tknamazu.tcl.wheel.patch
Patch7: tknamazu.tcl.w3m.patch
Patch8: tknamazu-nowishjp.patch

BuildRoot: %{_tmppath}/%{name}-%{nmzver}-root
BuildRequires: kakasi
BuildRequires: perl
BuildRequires: perl-File-MMagic >= 1.21
BuildRequires: nkf

Requires: perl
Requires: perl-File-MMagic >= 1.21
Requires: kakasi >= 2.3.2
Requires: w3m

Vendor: Project Vine
Distribution: Vine Linux

%description
Namazu is a search engine software intended for easy use.  Not
only it works as CGI program for small or medium scale WWW search
engine, but also works as personal use such as search system for
local HDD.  Now, search clients for Mule and Tcl/Tk, JAVA and
Win32 are available.

%description -l ja
日本語全文検索エンジンです。 CGI として動作させることにより小中規模の 
WWW 全文検索システムを構築することができるほか、ハードディスク内のファ 
イルを対象としたようなパーソナルな用途にも使えるます。 

namazu_VineDocsdb, namazu_JFdb, namazu_JMANdb をインストールすると、
tknamazuなどから Vine のオリジナルドキュメントや、JF、jman-pages の全文
検索をできるようになります。apacheなどでhttpdを立ち上げれば、
http://localhost/search.html から検索をすることもできます。

!!!注意!!! namazu-2 で用いるインデックスファイルとnamazu-1で用いる
インデックスファイルは互換性がありません。namazu-1でインデックスを
作成しているかたは、namazu-1を用いるか、インデックスを作り直すよう
にしてください。

%package devel
Summary: Libraries and include files of Namazu
Summary(ja): Namazu の開発用ライブラリおよびヘッダファイル
Group: Development/Libraries
Requires: %{name} = %{version}

%description devel
Namazu の開発用ライブラリとヘッダファイルです。

%package cgi
Summary: A CGI interface for Namazu
Summary(ja): Namazu用 CGI インターフェイス
Group: Applications/Text
Requires: %{name} = %{version}
Requires: webserver

%description cgi
A CGI interface for Namazu.

%description cgi -l ja
Namazu 用の CGI インターフェイスです。

%package -n tknamazu
Summary: A Tcl/Tk interface for Namazu
Summary(ja): Namazu用 Tcl/Tk インターフェイス
Version: 1.90_%{nmzver}
Group: Applications/Text
Requires: namazu = %{nmzver}
Requires: tk
Requires: webclient

%description -n tknamazu
A TK interface for Namazu.

%description -n tknamazu -l ja
Namazu 用の Tcl/TK インターフェイスです。

%prep 
%setup -q -a 2 -n namazu-%{nmzver}
%patch0 -p1
cd tknamazu
%patch5 -p0
%patch6 -p0
%patch7 -p0
%patch8 -p0
cd ..

%build
if [ ! -f configure ]; then
CFLAGS="%{optflags}" ./autogen.sh \
	--prefix=%{_prefix} \
	--libdir=%{_libdir} \
	--sysconfdir=%{_sysconfdir} \
	--mandir=%{_mandir} \
	--localstatedir=%{_localstatedir} \
	--libexecdir=/var/www/cgi-bin
else
CFLAGS="$RPM_OPT_FLAGS" ./configure \
	--prefix=%{_prefix} \
	--libdir=%{_libdir} \
	--sysconfdir=%{_sysconfdir} \
	--mandir=%{_mandir} \
	--localstatedir=%{_localstatedir} \
	--libexecdir=/var/www/cgi-bin
fi
make

pushd tknamazu
CFLAGS="%{optflags}" ./configure \
	--prefix=%{_prefix} \
	--with-namazu=%{_bindir} \
	--with-mknmz=%{_bindir} \
	--with-lynx=%{_bindir} \
	--with-indexdir=%{_localstatedir}/namazu/index 
make
popd

%install
rm -rf %{buildroot}
make prefix=%{buildroot}%{_prefix} \
     libdir=%{buildroot}%{_libdir} \
     sysconfdir=%{buildroot}%{_sysconfdir} \
     mandir=%{buildroot}%{_mandir} \
     localstatedir=%{buildroot}%{_localstatedir} \
     libexecdir=%{buildroot}/var/www/cgi-bin \
     install
chmod a+rwt -R %{buildroot}%{_localstatedir}/namazu
chmod a+rwt -R %{buildroot}%{_localstatedir}/namazu/index
#mv -f $RPM_BUILD_ROOT%{_sysconfdir}/namazu/namazurc-sample \
#	$RPM_BUILD_ROOT%{_sysconfdir}/namazu/namazurc
#mv -f $RPM_BUILD_ROOT%{_sysconfdir}/namazu/mknmzrc-sample \
#	$RPM_BUILD_ROOT%{_sysconfdir}/namazu/mknmzrc

# Vine stuff below 
# config stuff is to be installed afterwards
rm -f %{buildroot}%{_sysconfdir}/namazu/*-sample

# prepare documents 
rm -rf docs-to-include
mkdir -p docs-to-include
cp -pr %{buildroot}%{_datadir}/namazu/doc/* docs-to-include/
rm -rf %{buildroot}%{_datadir}/namazu/doc/*

# compress huge files in %doc :-)
# gzip --force --best ChangeLog ChangeLog.1 || :

# install tknamazu
make -C tknamazu DESTDIR=%{buildroot} install
install -m 644 %{SOURCE3} %{buildroot}%{_datadir}/tknamazu/tknamazurc
cp -p %{SOURCE1} %{buildroot}%{_datadir}/tknamazu/wheel.tcl
install -p -m 755 %{SOURCE4} %{buildroot}%{_bindir}

# install items for Vine Linux
make -C namazu-vinehtml-%{vinedocver} \
	DESTDIR=%{buildroot} NAMAZUVER=%{version} install

%find_lang %{name}

%clean
rm -rf %{buildroot}

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%triggerpostun -- namazu < 2.0.4
case "$LANG" in
ja*)
echo "!!!注意!!! namazu-2 で用いるインデックスファイルとnamazu-1で用いる";
echo "インデックスファイルは互換性がありません。namazu-1でインデックスを";
echo "作成しているかたは、namazu-1を用いるか、インデックスを作り直すよう";
echo "にしてください。";
;;
*)
echo "!!!warning!!! Index files for namazu-2 are not compatible with those";
echo "for namazu-1. If you have already created any index on namazu-1,";
echo "make sure you remake index on namazu-2, or you should still use";
echo "namazu-1 packages.";
;;
esac

%files -f %{name}.lang
%defattr(-, root, root)
%doc AUTHORS ChangeLog* COPYING CREDITS INSTALL* README* HACKING*
%doc NEWS THANKS TODO
%doc lisp/ etc/namazu.png docs-to-include/*
%config %{_sysconfdir}/namazu/*
%{_bindir}/namazu
%{_bindir}/bnamazu
%{_bindir}/*nmz
%{_bindir}/mailutime
%{_bindir}/nmzcat
%{_bindir}/nmzegrep
%{_bindir}/nmzgrep
%{_bindir}/nmzmerge
%{_libdir}/libnmz.so.*
%{_mandir}/man1/*
%dir %{_datadir}/namazu
%{_datadir}/namazu/*
%dir %{_localstatedir}/namazu
%dir %{_localstatedir}/namazu/index

%files devel
%defattr(-, root, root)
%{_bindir}/nmz-config
%{_includedir}/namazu/*.h
%{_libdir}/libnmz.so
%exclude %{_libdir}/libnmz.la
%{_libdir}/libnmz.a

%files cgi
%defattr(-, root, root)
/var/www/cgi-bin/namazu.cgi
%config(noreplace) /var/www/cgi-bin/.namazurc
/var/www/icons/*
%config(noreplace) /var/www/html/*

%files -n tknamazu
%doc tknamazu/{AUTHORS,COPYING,ChangeLog,INSTALL,NEWS,README}
%defattr(-, root, root)
%{_bindir}/dw3m
%{_bindir}/tknamazu
%dir %{_datadir}/tknamazu
%{_datadir}/tknamazu/*

%changelog
* Wed Apr 14 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.20-2
- fixed build dependencies
- updated SOURCE10

* Sat Mar 27 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.20-1
- new upstream release
- built with new toolchain
- updated Patch0

* Sat Oct 18 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.18-2
- spec in UTF-8

* Sat May 17 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.18-1
- applied new versioning policy
- removed libnmz.la from devel package

* Wed Mar 12 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.18-0vl1
- new upstream release
- updated namazu-vinehtml
- namazu-cgi files are installed to /var/www 

* Sun Feb 17 2008 Shu KONNO <owa@bg.wakwak.com> 2.0.16-0vl4
- rebuild with tcl/tk-8.4.18

* Tue Oct 09 2007 Shu KONNO <owa@bg.wakwak.com> 2.0.16-0vl3
- rebuild with tcl/tk-8.4.16

* Sun Oct 29 2006 NAKAMURA Kenta <kenta@vinelinux.org> 2.0.16-0vl2
- added --libdir=%%{_libdir} configure option

* Sat May 27 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.16-0vl1
- updated 2.0.16
- added Source10 from Fedora
  * Wed Mar  8 2006 Akira TAGOH <tagoh@redhat.com> - 2.0.15-3
  - filter-requires-namazu.sh: updated to fix much more self-dependencies. (#184149)

* Fri Aug 19 2005 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.14-0vl1
- updated 2.0.14
- dropped Patch20, merged into upstream
- changed tknamazu versioning

* Tue Dec 28 2004 IKEDA Katsumi <ikeda@webmasters.gr.jp> 2.0.13-1vl4.1
- added security fix patch namazu-2.0.13-xss-tab.patch.

* Sun Oct 17 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.13-1vl4
- namazu-vinehtml-3.1
  updated namazu.vine.default

* Tue Jul 13 2004 Tomoya TAKA <taka@vinelinux.org> 2.0.13-1vl3
- remove 'Requires: tk' from namazu, add it to tknamazu

* Mon Jul 12 2004 Satoshi MACHINO <machino@vinelinux.org> 2.0.13-1vl2
- added Require: tk

* Wed May 12 2004 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.13-1vl1
- updated Patch10 from Fedora 
  * Fri Apr 16 2004 Akira TAGOH <tagoh@redhat.com> 2.0.13-2
  - namazu-2.0.13-de.patch: applied to fix German templates.
- separated package namazu-cgi, tknamazu
- Require: perl-File-MMagic >= 1.21, BuildRequire: perl-File-MMagic >= 1.21

* Fri Apr 11 2003 IWAI Masaharu <iwai@alib.jp> 2.0.12-0vl3
- build with new toolchain
- add namazu-2.0.12-de.diff (Patch10)

* Tue Nov 19 2002 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp>
- 2.0.12-0vl2
- add %config(noreplace) tag /home/httpd/cgi-bin/.namazurc
- add %config(noreplace) tag /home/httpd/html/*

* Thu Sep 05 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 2.0.12-0vl1
- updated to new upstream release

* Thu Dec 27 2001 Toru Sagami <sagami@vinelinux.org>
- 2.0.10-0vl1

* Fri Nov 30 2001 Toru Sagami <sagami@vinelinux.org>
- 2.0.9-0vl1

* Tue Nov 27 2001 Toru Sagami <sagami@vinelinux.org>
- 2.0.8-0vl1

* Thu Sep 13 2001 Toru Sagami <sagami@vinelinux.org>
- 2.0.7-0vl1
- namazu-vinehtml-2.5.tar.gz: handle namazu version

* Fri Aug 17 2001 <sagami@vinelinux.org>
- 2.0.6-0vl1
- chmod a+rwt %%{_localstatedir}/namazu{,index}
- introduced %%{_docdir} definition
8
* Mon Jul 16 2001 Jun Nishii <jun@vinelinux.org> 2.0.5-0vl6
- change nkf option [vine-users:036182]

* Wed Jun 13 2001 Jun Nishii <jun@vinelinux.org> 2.0.5-0vl5
- added dep for perl-File-MMagic

* Sun May 13 2001 <sagami@vinelinux.org>
- 2.0.5-0vl4: add ad-hoc patch to erase Requirement for wish8.0jp

* Fri Apr 20 2001 <sagami@vinelinux.org>
- 2.0.5-0vl3
- namazu-vinehtml-2.4.tar.gz: fixed typo 

* Wed Jan 10 2001 Jun Nishii <jun@vinelinux.org>
- 2.0.5-0vl2
- use nkf/kakasi-modules in mknmzrc, because /usr/bin/nkf
  seems not to work correctly with namazu

* Fri Jan  5 2001 Jun Nishii <jun@vinelinux.org>
- 2.0.5-0vl1
- added lisp/ in %doc

* Thu Dec 28 2000 Tomoya TAKA <tomoya@olive.plala.or.jp> 2.0.4-0vl8
- changed character encoding of namazu-vinehtml from ISO-2022-JP to EUC-JP

* Wed Dec 27 2000 Tomoya TAKA <tomoya@olive.plala.or.jp> 2.0.4-0vl8
- some fixes to handle man pages correctly with _mandir
- replaced prefix and sysconfdir macros with rpm's _prefix and _sysconfdir

* Sun Nov 12 2000 MACHINO, Satoshi <machino@vinelinux.org> 2.0.4-0vl7
- build on gcc-2.95.3
- partially used rpmmacros

* Wed Oct 25 2000 Jun Nishii <jun@vinelinux.org>
- 2.0.4-0vl6
- fix bug in .tknamazurc

* Fri Oct 13 2000 Jun Nishii <jun@vinelinux.org>
- 2.0.4-0vl5
- fix bug in .namazurc and missing NMZ.*

* Fri Sep 15 2000 Jun Nishii <jun@vinelinux.org>
- 2.0.4-0vl4
- added some lacked binaries in /usr/bin

* Tue Aug 01 2000 Toru Sagami <czs14350@mb.infoweb.ne.jp>
- 2.0.4-0vl3
- handle /usr/share/namazu/etc correctly (should be moved to docdir...)

* Thu Jul 05 2000 Toru Sagami <czs14350@nifty.ne.jp>
- added Distribution/Vendor tag, just in case...
- moved post stuff to triggerpostun -- namazu < 2.0.4
- fixed RPM packaging stuff (files in docdir and doc in /usr/share, and more)
- namazu-vinehtml-2.1: freshen some files and add default ones

* Thu Jun 15 2000 Jun Nishii <jun@vinelinux.org>
- 2.0.4-0vl1
- ported for Vine Linux
- now, use w3m in tknamazu!

* Sun Feb 20 2000 Ryuji Abe <raeva@t3.rim.or.jp>
- Install namazu.cgi at /home/httpd/cgi-bin.
- Fixed typo.

* Sat Feb 19 2000 Satoru Takabayashi <satoru-t@is.aist-nara.ac.jp>
- Change URL.

* Tue Feb 15 2000 Ryuji Abe <raeva@t3.rim.or.jp>
- Delete package entries elisp and cgi.

* Wed Feb 02 2000 Ryuji Abe <raeva@t3.rim.or.jp>
- Apapted for namazu-current.
- Changed group Utilities/Text -> Applications/Text.

* Thu Dec 30 1999 Ryuji Abe <raeva@t3.rim.or.jp>
- rpm-3.0.x adaptations.
- Added package entries elisp and cgi (currently comment out). 
  [Merged SAKA Toshihide's changes for Kondara MNU/Linux.]

* Mon Nov 08 1999 Ryuji Abe <raeva@t3.rim.or.jp>
- Changed includedir %{prefix}/include/namazu.
- Bug fix at configure section.

* Thu Nov 04 1999 Ryuji Abe <raeva@t3.rim.or.jp>
- Added nmz-config in devel package.

* Wed Nov 03 1999 Ryuji Abe <raeva@t3.rim.or.jp>
- Use our definite macros, ver, rel, prefix, sysconfdir, and localstatedir.
- If configure not found, use autogen.sh.
- Optimized for SMP environment.
- Build devel package.

* Tue Oct 12 1999 Ryuji Abe <raeva@t3.rim.or.jp>
- Fixed correctly executables entry at %files.
- Added missing /usr/share/locale entry at %files.
 
* Thu Aug 26 1999 Ryuji Abe <raeva@t3.rim.or.jp>
- Requires perl >= 5.004.
- Delete Packager tag.
- Clean up at %prep.
- Use CFLAGS="$RPM_OPT_FLAGS" at %build.
- Use $RPM_BUILD_ROOT variables at %install.
- Change configure option at %build and %files for new namazu directory structure.

* Sun May 23 1999 Taku Kudoh <taku@TAHOO.ORG>
- 

