%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

Name:           lynx
Version:        2.9.2
Release:        %mkrel 1.2
Summary:        Text based browser for the world wide web
License:        GPLv2
Group:          Networking/WWW
URL:            https://lynx.invisible-island.net/
Source0:        https://invisible-island.net/archives/lynx/tarballs/%{name}%{version}%{?prev}.tar.bz2
Source1:        %{name}.desktop
Source2:        %{name}.png
# Approximately how Lynx looked before there were color styles:
Source3:        hela.lss
# Source0:        http://invisible-mirror.net/archives/lynx/tarballs/lynx%%{version}%%{prev}.tar.bz2
Patch0:         lynx-2.8.9-adapt-to-modern-file-localizations.patch
Patch1:         lynx-2.9.2-default-config.patch
Patch2:         lynx2-8-6-fix-ugly-color.patch
Patch3:         lynx2-9-2-tmp_dir.patch
Patch4:         lynx2-8-6-don-t-accept-command-line-args-to-telnet.patch
Patch6:         lynx-is-not-a-spambot.diff
BuildRequires:  gcc
BuildRequires:  make
BuildRequires:  perl
BuildRequires:  gettext
BuildRequires:  unzip
BuildRequires:  (netkit-telnet or /usr/bin/telnet)
BuildRequires:  pkgconfig(gnutls)
BuildRequires:  pkgconfig(ncurses)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  pkgconfig(ncursesw)
BuildRequires:  pkgconfig(libidn2)
BuildRequires:  pkgconfig(libbrotlidec)
BuildRequires:  pkgconfig(bzip2)

# For mhtml-tool
Requires:       perl

Provides:       webclient = %{version}-%{release}

%description
This a terminal based WWW browser. While it does not make any attempt
at displaying graphics, it has good support for HTML text formatting,
forms, and tables.


%prep
%autosetup  -p1 -n %{name}%{version}%{?prev}

perl -pi -e 's,^#LOCALE_CHARSET:.*,LOCALE_CHARSET:TRUE,' lynx.cfg

%build

# Enabeled by default in modern Lynx versions
debian_default_options=`cat << DEBIAN_DEFAULT
        --enable-persistent-cookies
        --enable-prettysrc
	--enable-source-cache
        --enable-read-eta
DEBIAN_DEFAULT`

debian_options=`cat << DEBIAN
        --enable-warnings
        --enable-externs
        --enable-cgi-links
        --enable-nls
        --enable-charset-choice
        --enable-ipv6
        --enable-nested-tables
        --with-zlib
DEBIAN`
# removed --enable-exec-links --enable-exec-scripts,
# it goes together with LOCAL_EXECUTION_LINKS_* in lynx.cfg


redhat_options=`cat << REDHAT
        --with-screen=ncursesw
	--enable-widec
        --enable-internal-links
        --enable-scrollbar
        --enable-file-upload
        --enable-locale-charset
        --with-gnutls
        --enable-addrlist-page
        --enable-justify-elts
	--enable-japanese-utf8
	--enable-gzip-help
	--with-bzlib
	--with-brotli
REDHAT`

other_options=`cat << OTHER
        --enable-color-style
        --enable-nsl-fork
        --enable-debug
        --disable-rpath-hack
OTHER`

# Not supported in modern Lynx versions
legacy_options=`cat << LEGACY
        --enable-8bit-toupper
        --enable-libjs
LEGACY`

# (cf INSTALLATION file for more about the options)
# --with-included-gettext  is the default
# --enable-kbd-layout not useful enough
# --enable-cjk not needed for CJK and may go away in a future release
%configure --libdir=%{_datadir}/lynx $debian_default_options $debian_options $redhat_options $other_options
%make_build

%install
%make_install install-help
install -m755 -p samples/mhtml-tool %{buildroot}%{_bindir}

%if 0%{!?_desktopdir:1}
%define _desktopdir %{_datarootdir}/applications
%endif

%if 0%{!?_pixmapsdir:1}
%define _pixmapsdir %{_datarootdir}/pixmaps
%endif

install -d %{buildroot}/%{_desktopdir}
install -m644 -p %{SOURCE1} %{buildroot}%{_desktopdir}

install -d %{buildroot}/%{_pixmapsdir}
install -m644 -p %{SOURCE2} %{buildroot}%{_pixmapsdir}

install -d %{buildroot}%{_sysconfdir}
cat > %{buildroot}%{_sysconfdir}/lynx-site.cfg <<EOF
# Place any local lynx configuration options (proxies etc.) here.
EOF
install -m644 -p samples/*.lss %{SOURCE3} %{buildroot}%{_sysconfdir}

%find_lang %{name}

%files -f lynx.lang
%doc CHANGES COPYHEADER PROBLEMS README lynx_help lynx.hlp samples test docs/README*
%config(noreplace,missingok) %{_sysconfdir}/lynx-site.cfg
%config(noreplace) %{_sysconfdir}/lynx.cfg
%config(noreplace) %{_sysconfdir}/*.lss
%{_mandir}/man1/%{name}.1*
%{_bindir}/*
%{_datadir}/lynx_help/
%{_desktopdir}/%{name}.desktop
%{_pixmapsdir}/%{name}.png