# Detect the distribution in use
%global __despace head -n 1 | tr -d '[:space:]' | sed -e 's/[(].*[)]//g'
%global __lower4 cut -c 1-4 | tr '[:upper:]' '[:lower:]'
%global __distfile %([ -f /etc/SuSE-release ] && echo /etc/SuSE-release || echo /etc/redhat-release)
%global __distinit %(sed -e 's/ release .*//' -e 's/\\([A-Za-z]\\)[^ ]*/\\1/g' %{__distfile} | %{__despace} | %{__lower4})
%global __distvers %(sed -e 's/.* release \\([^. ]*\\).*/\\1/' %{__distfile} | %{__despace})
# Identify Alma, CentOS, CentOS Stream and Rocky Linux as rhel
%if "%{__distinit}" == "a" || "%{__distinit}" == "c" || "%{__distinit}" == "cl" || "%{__distinit}" == "cs" || "%{__distinit}" == "rl"
%global __distinit rhel
%endif
# Dist tag for Fedora is still "fc"
%if "%{__distinit}" == "f"
%global __distinit fc
%endif

Name: xv
Version: 4.1.1
Release: 1.%{__distinit}%{__distvers}
Summary: X based image viewer for darned near all images
Summary(de.UTF-8): X-basierender Bild-Viewer für praktische sämtliche Grafiken
Summary(es.UTF-8): Visualizador de imágenes para X para cuasi todos los formatos de imágenes
Summary(fr.UTF-8): Visualisateur sous X pour quasiment tous les types d'images
Summary(pl.UTF-8): Przeglądarka różnego rodzaju plików graficznych pracująca w X Window
Summary(pt_BR.UTF-8): Visualizador de imagens para X para quase todos os formatos de imagens
Summary(ru.UTF-8): Программа для просмотра и преобразования файлов изображений для X
Summary(tr.UTF-8): X tabanlı resim görüntüleyici
Summary(uk.UTF-8): Програма для перегляду та перетворення файлів зображень для X
License: Shareware
URL: https://github.com/jasper-software/xv
Source0: https://github.com/jasper-software/xv/archive/refs/tags/v%{version}.tar.gz
Source2: DISTRIBUTE.txt
Source3: xv.desktop
Source4: xv.png
BuildRequires: cmake >= 3.12
BuildRequires: coreutils
BuildRequires: desktop-file-utils
BuildRequires: gcc
BuildRequires: jasper-devel
BuildRequires: libjpeg-devel
BuildRequires: libpng-devel
BuildRequires: libtiff-devel
BuildRequires: libwebp-devel
BuildRequires: libX11-devel
BuildRequires: libXt-devel
# Require hicolor-icon-theme ownership of %%{_datadir}/icons/hicolor/48x48/apps/
Requires: hicolor-icon-theme

%description
This is the famous 'xv' by John Bradley. It is shareware, but we ship
it with the permission of the authors. It is a graphics viewer for
many file types, including gif, jpg, tiff, xwd, etc. It also has
manipulation features such as cropping, expanding, etc. Patched to
include flmask, a popular feature in Japan.

%description -l de.UTF-8
Dies ist das berühmte 'xv' von John Bradley, ein Shareware- Programm,
das wir mit Erlaubnis des Autors liefern. Es ist ein Grafik-Viewer für
diverse Dateitypen, einschließlich gif, funktionen wie Trimmen,
Strecken u.ä. Mit flmask.

%description -l es.UTF-8
Este es el famoso 'xv' de John Bradley. Es shareware, pero nosotros lo
distribuimos con la permisión de los autores. Es un visor gráfico para
varios tipos de archivos, incluyendo gif, jpg, tiff, xwd, etc. También
posee características de manejo como corte, expansión, etc.

%description -l fr.UTF-8
Le célébre xv de John Bradley. C'est shareware, mais nous le
distribuons avec la permission de l'auteur. C'est un visualiseur
graphique pour de nombreux formats de fichier dont gif, jpg, tiff,
xwd, etc. Il offre aussi des fonctionnalités comme la capture,
l'extension, la retouche de palette, etc. Flmask.

%description -l pl.UTF-8
Słynne 'xv' Johna Bradleya. Jest to program shareware, ale
udostępniamy go za zgodą autora. Jest to przeglądarka plików
graficznych w różnych formatach, takich jak: gif, jpg, tiff, xwd i
innych. Ma też proste możliwości obróbki obrazków, takie jak obcinanie
czy rozszerzanie. Zawiera obsługę flmask.

%description -l pt_BR.UTF-8
Este é o famoso 'xv' de John Bradley. Ele é shareware, mas nós o
distribuimos com a permissão dos autores. É um visualizador gráfico
para vários tipos de arquivos, incluindo gif, jpg, tiff, xwd, etc.
Também possui características de manipulação como corte, expansão,
etc.

%description -l ru.UTF-8
Xv - это программа для просмотра и преобразования изображений для X
Window System. Xv умеет показывать GIF, JPEG, TIFF, PBM, PPM, PDF, X11
bitmap, Utah Raster Toolkit RLE, PDS/VICAR, Sun Rasterfile, BMP, PCX,
IRIS RGB, XPM, Targa, XWD, PostScript(TM) и PM. Xv также умеет делать
простую обработку изображений - cropping, expanding, снимки экрана и
т.п.

%description -l tr.UTF-8
xv başta PNG, GIF, JPG, BMP, XBM, XPM olmak üzere birçok resim
dosyasını görüntüleyebilir, değişik formatlarda kaydedebilir ve
üzerinde boyutlandırma, renk değiştirme gibi bazı temel işlemleri
yapabilir. Çok detaylı işlemler yapamamasına rağmen temel resim
işlemlerinde öncellikle kullanılabilecek, kullanışlı arayüzüne sahip
bir programdır. Flmask.

%description -l uk.UTF-8
Xv - це програма для перегляду та перетворення зображень для X Window
System. Xv вміє показувати GIF, JPEG, TIFF, PBM, PPM, PDF, X11 bitmap,
Utah Raster Toolkit RLE, PDS/VICAR, Sun Rasterfile, BMP, PCX, IRIS
RGB, XPM, Targa, XWD, PostScript(TM) та PM. Xv також вміє робити
просту обробку зображень - cropping, expanding, знімки экрану і т.і.

%package doc
Summary: Manuals in various formats for the xv image viewer
BuildArch: noarch

%description doc
Manuals in various formats for the xv image viewer, plus technical details
of the various image file formats supported.

%prep
%setup -q -n xv-%{version}

# Include permission to distribute
install -m 0644 -p %{SOURCE2} .

%build
%cmake -DCMAKE_INSTALL_SYSCONFDIR:PATH=%{_sysconfdir}
%cmake_build

%install
%cmake_install

desktop-file-install \
  --dir %{buildroot}%{_datadir}/applications \
  %{SOURCE3}

install -D -p -m 0644 %{SOURCE4} \
  %{buildroot}%{_datadir}/icons/hicolor/48x48/apps/xv.png

# Add DISTRIBUTE.txt to the docs directory
cp -a DISTRIBUTE.txt %{buildroot}%{_docdir}/xv/

# Icon cache and desktop database updates redundant from Fedora 26 onwards
%if (0%{?rhel} && 0%{?rhel} <= 7) || (0%{?fedora} && 0%{?fedora} <= 25)
%post
touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
update-desktop-database &> /dev/null || :

%postun
if [ $1 -eq 0 ] ; then
  touch --no-create %{_datadir}/icons/hicolor &>/dev/null || :
  gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
fi
update-desktop-database &> /dev/null || :

%posttrans
gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :
%endif

%files
%doc %{_docdir}/xv/BUGS
%doc %{_docdir}/xv/CHANGELOG
%doc %{_docdir}/xv/copyright.h
%doc %{_docdir}/xv/CPMASK
%doc %{_docdir}/xv/DISTRIBUTE.txt
%doc %{_docdir}/xv/IDEAS
%doc %{_docdir}/xv/README
%doc %{_docdir}/xv/README.FLmask
%doc %{_docdir}/xv/README.jumbo
%doc %{_docdir}/xv/README.pcd
%{_bindir}/bggen
%{_bindir}/vdcomp
%{_bindir}/xcmap
%{_bindir}/xv
%{_bindir}/xvpictoppm
%config(noreplace) %{_sysconfdir}/xv_mgcsfx
%{_datadir}/applications/xv.desktop
%{_datadir}/icons/hicolor/48x48/apps/xv.png
%{_mandir}/man1/bggen.1*
%{_mandir}/man1/vdcomp.1*
%{_mandir}/man1/xcmap.1*
%{_mandir}/man1/xv.1*
%{_mandir}/man1/xvpictoppm.1*
%lang(fi) %{_mandir}/fi/man1/xv.1*
%lang(pl) %{_mandir}/pl/man1/xvpictoppm.1*

%files doc
%doc %{_docdir}/xv/README.docs
%doc %{_docdir}/xv/bigxv.jpg
%doc %{_docdir}/xv/formats/
%doc %{_docdir}/xv/manuals/

%changelog
* Wed Jun  7 2023 Paul Howarth <paul@city-fan.org> - 4.1.1-1
- Updated to 4.1.1 (release build with upstream tarball)
- Enable webp support

* Thu Mar  3 2022 Paul Howarth <paul@city-fan.org> - 4.0.0~alpha7-0
- Updated to 4.0.0 alpha 7 (fix crash with GIF files)

* Tue Mar  1 2022 Paul Howarth <paul@city-fan.org> - 4.0.0~alpha5-0
- xv_mgcsfx file no longer needs to be installed manually

* Fri Feb 25 2022 Paul Howarth <paul@city-fan.org> - 4.0.0~alpha3-0
- Switch to using cmake

* Thu Feb 17 2022 Paul Howarth <paul@city-fan.org> - 4.0.0~alpha2-0
- Set up for building from tagged archive tarballs

* Thu Feb 10 2022 Paul Howarth <paul@city-fan.org> - 3.10a.GitHub-0
- Reworked spec to test builds from GitHub

* Sun Jan 30 2022 Paul Howarth <paul@city-fan.org> - 3.10a-37.0
- Fix Jasper support to use proper library APIs (patch from Michael Adams,
  Jasper upstream maintainer)

* Tue Mar  2 2021 Paul Howarth <paul@city-fan.org> - 3.10a-36.0
- Fix jas_memdump replacement function

* Sun May 17 2020 Paul Howarth <paul@city-fan.org> - 3.10a-34.3
- Build dependencies should not include %%{?_isa} as it makes the resulting
  source packages arch-specific

* Wed Feb 26 2020 Paul Howarth <paul@city-fan.org> - 3.10a-34.2
- Builds for Fedora 32 also use libpng rather than libpng10

* Wed Feb 26 2020 Paul Howarth <paul@city-fan.org> - 3.10a-34.1
- Builds for Fedora 33 and RHEL 8 onwards use libpng rather than libpng10

* Sun Feb  9 2020 Paul Howarth <paul@city-fan.org> - 3.10a-34
- Fix FTBFS with GCC 10

* Tue Mar 12 2019 Paul Howarth <paul@city-fan.org> - 3.10a-31
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Tue Sep 18 2018 Paul Howarth <paul@city-fan.org> - 3.10a-30
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Wed Feb  7 2018 Paul Howarth <paul@city-fan.org> - 3.10a-27
- Hopefully fix signal bug (#3044)
- Icon cache and desktop database updates redundant from Fedora 26 onwards
- Drop support for EOL distributions prior to Fedora 13, EL-6
  - Always have modular X
  - Always have Jasper
  - Always have noarch sub-packages
  - Always have hicolor-icon-theme
  - Always have %%posttrans support in rpm
  - Drop redundant explicit buildroot cleaning
  - Drop legacy BuildRoot: and Group: tags
  - Drop redundant %%defattr

* Mon Jul  6 2015 Paul Howarth <paul@city-fan.org> - 3.10a-23
- Patch by Erling A. Jacobsen to fix iTXt/utf8 png comment bug (#3141, #3704)
- Patch by Erling A. Jacobsen to fix smoothing off-by-one bug (#3142)

* Wed Oct 22 2014 Paul Howarth <paul@city-fan.org> - 3.10a-20
- Fix build with -Werror=format-security

* Fri Mar 29 2013 Paul Howarth <paul@city-fan.org> - 3.10a-18
- Patch for cut/paste bug in 24+ bit mode (by Mark Brader <msb@vex.net>)
- Further buffer overflow fix for overly long command line argument

* Thu Mar 14 2013 Paul Howarth <paul@city-fan.org> - 3.10a-17
- Additional fix for long filename buffer overflow

* Tue Mar  5 2013 Paul Howarth <paul@city-fan.org> - 3.10a-16
- Fix buffer overflow caused by filenames longer than the window title limit

* Mon Aug  6 2012 Paul Howarth <paul@city-fan.org> - 3.10a-15
- Rebuild for libtiff.so.5 (libtiff 4.0) in Rawhide

* Fri Dec  9 2011 Paul Howarth <paul@city-fan.org> - 3.10a-13
- Add patch from Gentoo for libpng 1.5 compatibility

* Thu Sep  8 2011 Paul Howarth <paul@city-fan.org> - 3.10a-12
- Fix wait timer for slideshows (http://bugzilla.rpmfusion.org/1929)

* Mon Aug  1 2011 Paul Howarth <paul@city-fan.org> - 3.10a-9
- Use patch instead of scripted iconv to convert character encodings
- Nobody else likes macros for commands
- Fix dist tag for CentOS 6 and Scientific Linux

* Sun Jul 18 2010 Paul Howarth <paul@city-fan.org> - 3.10a-8
- Drop dependency on man from RHEL-5 onwards, where %%{_mandir}/{fi,pl} are
  included in the filesystem package

* Wed May 12 2010 Paul Howarth <paul@city-fan.org> - 3.10a-7
- Fix dist tag for RHEL-6 Beta

* Mon Feb 22 2010 Paul Howarth <paul@city-fan.org> - 3.10a-6
- Dist tag for Rawhide no longer needs special-casing

* Wed Sep 16 2009 Paul Howarth <paul@city-fan.org> - 3.10a-5
- Update desktop file MimeType list (thanks to goeran@uddeborg.se)

* Sat Sep  5 2009 Paul Howarth <paul@city-fan.org> - 3.10a-4
- Resync with RPM Fusion package (cosmetic changes mainly)
- Add image format docs in doc subpackage

* Thu Aug 20 2009 Paul Howarth <paul@city-fan.org> - 3.10a-3
- Include Greg Roelofs' jumbo patch (20070520)
- Include Greg Roelofs' jumbo patch update (20081216)
- Drop patches included in/superseded by the jumbo patch:
  - xv-3.10a-lvalue.patch
  - xv-3.10a-png-1.2d.tar.gz
  - xv-croppad.patch
  - xv-deepcolor.patch
  - xv-exceed_grab_patch.txt
  - xv-gifpatch
  - xv-grabpatch
  - xv-JPEG.patch
  - xv-longname.patch
  - xv-mp-tiff-patch
  - xv-pdf.patch
  - xv-png-fix2.patch
  - xv-TIFF.patch
  - xv-vispatch
- Include RPM Fusion Makefile patch (adds JPEG2000 support)
- Drop xv-PLD.patch, superseded by combination of jumbo and RPM Fusion patches
- Only explicitly buildrequire pkgconfig for FC5 build
- Define RPM macros in global scope
- Switch upstream URL to ftp.trilon.com
- Add DISTRIBUTE.txt - permission to distribute from John Bradley
- Add doc subpackage for XV manual in PS, PDF, and HTML formats
- Disable JPEG2000 (jasper) support for releases prior to Fedora 7
- Install icon in %%{_datadir}/icons/hicolor/48x48/apps/ rather than
  %%{_datadir}/pixmaps/
- Add scriptlets for updating the icon cache and MIME databases
  (desktop-file-utils scriptlet dependencies only needed prior to FC5)
- Include non-English man pages from PLD in package
- Add translations for spec and desktop file from PLD
- Make docs package noarch where possible (RHEL6, FC10 onwards)

* Wed Oct 29 2008 Paul Howarth <paul@city-fan.org> - 3.10a-2
- Fixed up patches to apply without fuzz

* Wed May 30 2007 Paul Howarth <paul@city-fan.org> - 3.10a-1
- Import from PLD release 3.10a-21; reluctantly removed the translations in
  the spec file because I couldn't figure out what encoding(s) they were in
  (certainly not UTF-8)