%define __perl_requires %{_rpmconfigdir}/perl.req | grep -v w3mhelp

%define _docdir %{_defaultdocdir}

#%define cvsdate 20060815

Summary: A Pager with WWW capability
Summary(ja): World Wide Web に対応したページャ
Name: w3m
Version: 0.5.3
Release: 1%{?_dist_release}
Group: Applications/Internet
License: BSD
URL: http://w3m.sourceforge.net/
Source0: %{name}-%{version}.tar.gz
Source1: w3m.sh
Source2: w3m.csh
Source10: w3m-term
Source11: filter-requires-w3m.sh

Requires: perl, openssl >= 0.9, gc >= 6.2
Requires(post,preun): alternatives
Provides: webclient, pager
Obsoletes: w3m-m17n

BuildRequires: openssl-devel >= 0.9
BuildRequires: ncurses-devel
BuildRequires: gc-devel >= 6.2
BuildRequires: sed
BuildRequires: gtk2-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-root

Vendor: Project Vine
Distribution: Vine Linux
Packager: shaolin

# work around for [VineSeed-x86_64:00178]
%define __find_requires %{SOURCE11}

%description
w3m is a pager with WWW capability. It IS a pager, but it can be
used as a text-mode WWW browser. The features of w3m are as follows:
- When reading HTML document, you can follow links and view images
  (using external image viewer).
- It has 'internet message mode', which determines the type of document
  from header. If the Content-Type: field of the document is text/html,
  that document is displayed as HTML document.
- You can change URL description like 'http://hogege.net' in plain text
  into link to that URL.

%description -l ja
w3m は,ページャfmをベースに開発された World Wide Web に対応したページャ
です.fm の機能に加えて、w3m の特徴には,次のようなものがあります.

・WWW 対応なので,HTML の文書を読んでいる時には,その中のリンクを辿った
  り,画像を見ることができる.
・Internet message 表示のためのモードがある.この時,Content-Type: が
  text/html の場合は,自動的に HTML の文書として表示する.また,自力で
 MIME header のデコードをする.
・見ている plain text 文書中に URL 表記があった場合,その部分からリンク
  をたどることができる.

%package img
Summary: inline image extension support utilities for w3m
Summary(ja): w3m 用インライン画像拡張サポートユーティリティ
Group: Applications/Internet
Requires: %{name} = %{version}-%{release}

%description img
w3m-img provides some utilities to support inline
images for w3m
on terminal emulator in X Window System environments.

%description -l ja img
w3m-img は X 環境のターミナルエミュレータ上の w3m でインライン画像を
表示するためのユーティリティです。

%prep
%setup -q
find Bonus -type f | \
    xargs sed -i -e "s|/usr/local/bin/ruby|/usr/bin/ruby|g;"

%build
%configure \
	--enable-japanese=E \
	--with-termlib=ncurses \
	--enable-image=x11 \
	--with-imagelib=gtk2 \
	--with-browser=gnome-open \
	--with-mailer=gnome-open \
	--with-editor=%{_sysbindir}/vi
sed -i -e 's|#define USE_GPM 1|/* #undef USE_GPM */|' config.h
sed -i -e 's|\-lgpm||g' Makefile
make %{?_smp_mflags}


%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}

mkdir -p %{buildroot}/etc/profile.d
cp %{SOURCE1} %{buildroot}/etc/profile.d/w3m.sh
cp %{SOURCE2} %{buildroot}/etc/profile.d/w3m.csh

mkdir -p %{buildroot}%{_bindir}
cp %{SOURCE10} %{buildroot}%{_bindir}/w3m-term
chmod +x %{buildroot}%{_bindir}/w3m-term

mkdir -p %{buildroot}%{_mandir}/{man1,ja/man1}
install -p -m 644 doc-jp/w3m.1 %{buildroot}%{_mandir}/ja/man1
install -p -m 644 doc/w3m.1 %{buildroot}%{_mandir}/man1
# dont include duplicated man pages and CVS directory in doc
rm -f doc-jp/w3m.1 doc/w3m.1
find . -type d -name "CVS" | xargs rm -rf

# prepare system-wide preference file
mkdir -p %{buildroot}%{_sysconfdir}/w3m

# prepare applnk
%define applnkdir /etc/X11/applnk/Internet
mkdir -p %{buildroot}/%{applnkdir}
cat > %{buildroot}/%{applnkdir}/%{name}.desktop <<EOF
[Desktop Entry]
Name=%{name}
Type=Application
Comment=A Pager with WWW capability
Comment[ja]=WWW対応ページャ
Exec=w3m-term
Terminal=false
EOF

# eliminate executable bit in %doc
find Bonus/ -type f -perm +111 | xargs -r chmod -x


%clean
rm -rf %{buildroot}

%post
%{_syssbindir}/update-alternatives --install /usr/bin/pager pager /usr/bin/w3m 30

%preun
if [ "$1" = "0" ]; then
  %{_syssbindir}/update-alternatives --remove pager /usr/bin/w3m
fi


%files
%defattr(-,root,root)
%doc Bonus ChangeLog NEWS README doc doc-jp
%attr(755,root,root) %config /etc/profile.d/*
%config(missingok) %{applnkdir}/%{name}.desktop
%dir %{_sysconfdir}/w3m
%{_bindir}/w3m*
%exclude %{_libexecdir}/w3m/w3mimgdisplay
%{_libexecdir}/w3m/
%{_datadir}/w3m/
%{_datadir}/locale/*/LC_MESSAGES/*
%{_mandir}/ja/man1/w3m.1*
%{_mandir}/man1/w3m*

%files img
%{_libexecdir}/w3m/w3mimgdisplay

%changelog
* Thu Apr 21 2011 IWAI, Masaharu <iwai@alib.jp> 0.5.3-1
- new upstream release
- drop unnecessary patches: upstream fixed
 - ambwidth patch (Patch10)
 - sudden crash patch (Patch11)
 - x86_64 patch (Patch100)

* Wed Jan 12 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 0.5.2-7
- rebuild with openssl-1.0.0c
- add Patch100 (w3m-0.5.2-x86_64-vine.patch)

* Sun Sep 26 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 0.5.2-6
- add Patch10 to fix display utf8 ambiguous width characters
  (from: http://www.j10n.org/files/w3m-cvs-1.914-ambwidth.patch)
- add Patch11 to fix sudden crash
  (from: http://www.sic.med.tohoku.ac.jp/~satodai/w3m-dev/200708.month/4286.html)

* Fri Feb 12 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 0.5.2-5
- rebuilt with gcc-4.4.3-3 on ppc

* Tue Feb  2 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 0.5.2-4
- rebuilt with new toolchain

* Tue Apr 14 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 0.5.2-2
- spec in utf-8
- remove Requires: indexhtml
- set HTTP_HOME to http://vinelinux.org/
- update w3m-term

* Wed Apr 30 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.5.2-1
- new upstream release
- dropped Patch100 (merged into upstream)

* Sun Jun  3 2007 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.5.1.20060815-0vl6
- rebuilt with new toolchain and environment

* Fri Apr 13 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.5.1.20060815-0vl5
- add Provides: pager
- add Requires(post,preun): alternatives

* Tue Apr 10 2007 KANEKO Seiji <giraffe@m2.pbc.ne.jp> 0.5.1.20060815-0vl3
- add update-alternatives: pager in %post and %preun scriptlet

* Fri Jan 12 2007 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 
- 0.5.1.20060815-0vl2
- rebuilt for VineSeed

* Sat Dec 30 2006 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 
- 0.5.1.20060815-0vl1.1
- add patch100 for fix "inputAnswer()" SSL Certificate Handling Vulnerabilit

* Tue Aug 15 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 
- update to cvs snapshot
- use gtk2 for w3m-img instead of gdk-pixbuf

* Sun Jul 23 2006 NAKAMURA Kenta <kenta@vinelinux.org> 0.5.1-0vl6
- use filter-requires-w3m.sh as find-requires (rpm's bug?)

* Sat Sep 25 2004 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 0.5.1-0vl5
- use %%{_docdir}/Vine/index.html as default homepage

* Sun Jul 25 2004 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 0.5.1-0vl4
- change default editor to %%{_sysbindir}/vi
- use ncurses explicitly as termlib

* Sun Jul 11 2004 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 0.5.1-0vl3
- fix typo
- add BuildPrereq: gtk+-devel, gdk-pixbuf-devel

* Wed Jul 07 2004 Daisuke SUZUKI <daisuke@linux.or.jp> 0.5.1-0vl2
- rebuild without gpm

* Wed May  5 2004 Daisuke SUZUKI <daisuke@linux.or.jp> 0.5.1-0vl1
- new upstream release
- Obsoletes: w3m-m17n

* Fri Mar 27 2004 Daisuke SUZUKI <daisuke@linux.or.jp> 0.5-0vl2
- add message catalogs to %%files

* Fri Mar 27 2004 Daisuke SUZUKI <daisuke@linux.or.jp> 0.5-0vl1
- new upstream release
- fix w3mimgdisplay path in w3m-term

* Sun Dec 14 2003 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.2-0vl1
- new upstream release
- split w3mimgdisplay to w3m-img subpackage.
- Requires: gc >= 6.2

* Sat May 31 2003 Hiroaki Irokawa <irorin@terra.dti.ne.jp> 0.4.1-0vl1
- new upstream release

* Tue Feb 25 2003 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4-0vl1
- new upstream release

* Tue Dec 10 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 0.3.2.2-0vl1
- new upstream release.
  w3m 0.3.2.2 - 2002-12-06
  * security fix: html_quote for img alt attributes

* Fri Nov 28 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 0.3.2.1-0vl2
- change default page path to /usr/doc/HTML.
  this should be changed to /usr/share/doc in next release.
  ( TODO: indexhtml package )

* Wed Nov 27 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 0.3.2.1-0vl1
- new upstream release
  w3m 0.3.2.1 - 2002-11-27
  * security fix: html_quote for frame contents
  * backport from w3m 0.3.2+cvs
    - fix segmentation fault by large complex table.
      [w3m-dev 03371][w3m-dev 03438]

* Wed Nov  6 2002 Daisuke SUZUKI <daisuke@linux.or.jp> 0.3.2-0vl1
- new upstream release
  w3m 0.3.2 - 2002-11-05
  * ~/.netrc: password for ftp
  * rc: display_lineinfo: display current line number
  * rc: passwd_file: passwd file for HTTP auth
  * func: MARK_WORD
  * rc: imgsize: obsoleted
  * w3m-img for framebuffer merged

* Mon Sep 30 2002 Tomoya TAKA <taka@vinelinux.org> 0.3.1-0vl2
- replace gc with an old version on alpha (Source20)

* Wed Jul 17 2002 IWAI Masaharu <iwai@alib.jp> 0.3.1-0vl1
- upstream release
- coped new configure options

* Sun Apr 21 2002 IWAI Masaharu <iwaim@cc.mbn.or.jp> 0.3-0vl2
- fixed configure option ([VineSeed:06372])
- added openssl-devel version in {Build,}Requires

* Mon Mar 18 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.3-0vl1
- updated in sync with upstream 0.3 release
  (now w3m-img patch is included in the upstream version)

* Tue Feb 05 2002 Toru Sagami <sagami@vinelinux.org> 0.2.5-0vl1
- w3m-0.2.5 with 0.2.5+cvs-1.302

* Tue Jan 29 2002 Toru Sagami <sagami@vinelinux.org> 0.2.4-0vl2
- eliminate executable bit in %doc
- spec cleanup

* Wed Jan 16 2002 Toru Sagami <sagami@vinelinux.org> 0.2.4-0vl1
- updated to current stable release

* Thu Jan 03 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.2.3.2-0vl1
- updated to new upstream release
- FIXME: system-wide /etc/w3m/w3mconfig should be prepared. Anyone? :)

* Fri Sep 28 2001 <masato@nets.ce.hiroshima-cu.ac.jp>
- 0.2.1-0vl9
- added sparc patch

* Thu Aug 23 2001 <shom@vinelinux.org>
- 0.2.1-0vl8: add w3m-term script

* Mon Aug 06 2001 <sagami@vinelinux.org>
- 0.2.1-0vl7: added imlib-devel ncurses-devel for BuildPreReq
- update img patch to version 1.10 from 1.9

* Mon Aug  6 2001 Jun Nishii <jun@vinelinux.org> 0.2.1-0vl6
- added img patch

* Mon Jul 16 2001 <sagami@vinelinux.org>
- 0.2.1-0vl5: spec file clean up
- openssl-devel for BuildPrereq, not openssl
- install more sophisticated w3m.sh w3m.csh with any %%{_docdir} definition

* Mon Jul 16 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@vinelinux.org>
- 0.2.1-0vl4
- rebuilt with openssl-0.9.6b

* Sun Jun 23 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@vinelinux.org>
- 0.2.1-0vl3
- security fixes (http://www.lac.co.jp/security/snsadv/32.html)

* Sat Jun 09 2001 <sagami@vinelinux.org>
- 0.2.1-0vl2: minor spec fixes(URL, License and etc.)
- actually rebuilt with ncurses5 (i386)

* Sat Mar 24 2001 Yoichi Imai <yoichi@silver-forest.com>
- 0.2.1-0vl1

* Wed Dec 20 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 0.1.10-0vl6
- use better macros
- rebuilt with ncurses5

* Thu Sep 21 2000 Jun Nishii <jun@vinelinux.org>
- w3m-0.1.10-0vl5
- use applnk instead of wmconfig
- use openssl

* Thu Jul 27 2000 Toru Sagami <czs14350@mb.infoweb.ne.jp>
- w3m-0.1.10-0vl4
- fix typo in w3m.csh and w3m.wmconfig

* Sun Jul 09 2000 Toru Sagami <czs14350@nifty.ne.jp>
- w3m-0.1.10-0vl3
- provide default HTTP_HOME in /etc/profile.d

* Fri Jul 07 2000 Toru Sagami <czs14350@nifty.ne.jp>
- Provides: webclient, Requires: indexhtml (capability of lynx)
- added w3m.wmconfig
- give them(who?) RPM_OPT_FLAGS(what?)
- dont include duplicated man pages and CVS directory in doc

* Wed Jun 21 2000 Jun Nishii <jun@vinelinux.org>
- 0.1.10-0vl1

* Sat Jan 22 2000 Yoichi Imai <yoichi@silver-forest.com>
- fix spec file

* Sat Jan 22 2000 Yoichi Imai <yoichi@silver-forest.com>
- updated from 0.1.4 to 0.1.6

* Thu Jan 13 2000 Yoichi Imai <yoichi@silver-forest.com>
- updated from 991203 to 0.1.4

* Fri Dec 03 1999 Yoichi Imai <yoichi@silver-forest.com>
- updated from 991028 to 991203

* Sat Oct 30 1999 Yoichi Imai <bonaim@mutt.freemail.ne.jp>
- updated from 990820 to 991028

* Tue Aug 26 1999 Ryo Hattori <ryoh@vs01.vaio.ne.jp>
- updated from 990716 to 990820

* Wed Aug 11 1999 Ryo Hattori <ryoh@vs01.vaio.ne.jp>
- initial Release to VinePlus