%define gimpdirs %(/bin/ls -d %{_libdir}/gimp/*/plug-ins 2> /dev/null)
%global gimpplugindir %(gimptool --gimpplugindir 2>/dev/null || echo INVALID)/plug-ins
%global iconrootdir %{_datadir}/icons/hicolor

# needed for off-root building
%global _configure ../configure

Name: xsane
Summary: XSane is a graphical frontend for scanners. It uses the library SANE.
Summary(ja): SANE スキャナインタフェースの Xウィンドウ用フロントエンドです
Version: 0.999
Release: 3%{?_dist_release}
Group: Applications/Multimedia
Vendor: Project Vine
Distribution: Vine Linux

License: GPL
URL: http://www.xsane.org/
Source: http://www.xsane.org/download/%{name}-%{version}.tar.gz
Source1: xsane-256x256.png
# use "xdg-open" instead of "netscape" to launch help browser
# submitted to upstream (Oliver Rauch) via email, 2013-06-04
Patch0: xsane-0.995-xdg-open.patch
# submitted to upstream (Oliver Rauch) via email, 2009-08-18
Patch1: xsane-0.995-close-fds.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=504344
# distro-specific(?), upstream won't accept it: "don't show license dialog"
# submitted to upstream (Oliver Rauch) anyway via email, 2013-06-04
Patch2: xsane-0.996-no-eula.patch
# enable off-root building
# submitted to upstream (Oliver Rauch) via email, 2010-06-23
Patch3: xsane-0.997-off-root-build.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=608047
# https://bugzilla.redhat.com/show_bug.cgi?id=621778
# submitted to upstream (Oliver Rauch) via email, 2013-07-05
Patch4: xsane-0.999-no-file-selected.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=198422
# submitted to upstream (Oliver Rauch) via email, 2010-06-29
Patch5: xsane-0.997-ipv6.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=624190
# fix from: https://bugs.launchpad.net/ubuntu/+source/xsane/+bug/370818
# submitted to upstream (Oliver Rauch) via email, 2011-06-01
Patch6: xsane-0.998-preview-selection.patch
# fix building with libpng >= 1.5
# submitted to upstream (Oliver Rauch) via email, 2011-11-21
Patch7: xsane-0.998-libpng.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=795085
# set program name/wmclass so GNOME shell picks appropriate high resolution
# icon file
# submitted to upstream (Oliver Rauch) via email, 2013-06-04
Patch8: xsane-0.998-wmclass.patch
# partly distro-specific: customize desktop file
# submitted to upstream (Oliver Rauch) via email, 2013-06-04
Patch9: xsane-0.998-desktop-file.patch
# man page: update command line options
# submitted to upstream (Oliver Rauch) via email, 2013-07-08
Patch10: xsane-0.999-man-page.patch
# avoid producing PDFs with bpp > 8
# submitted to upstream (Oliver Rauch) via email, 2013-09-09
Patch11: xsane-0.999-pdf-no-high-bpp.patch
# build against lcms 2.x
# submitted to upstream (Oliver Rauch) via email, 2013-09-23
Patch12: xsane-0.999-lcms2.patch
# fix issues found during static analysis that don't require far-reaching
# refactoring
# submitted to upstream (Oliver Rauch) via email, 2014-04-02
Patch13: xsane-0.999-coverity.patch
# update lib/snprintf.c to the latest version from LPRng that has a Free license
# submitted to upstream (Oliver Rauch) via email, 2014-05-29
Patch14: xsane-0.999-snprintf-update.patch
# fix signal handling (#1073698)
# submitted to upstream (Oliver Rauch) via email, 2014-07-03
Patch15: xsane-0.999-signal-handling.patch

# autoconf-generated files
Patch100: xsane-0.999-7-autoconf.patch.bz2

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: sane-devel
BuildRequires: gimp-devel
BuildRequires: lcms2-devel
BuildRequires: libjpeg-devel
BuildRequires: libpng-devel
BuildRequires: desktop-file-utils >= 0.2.92
BuildRequires: libtiff-devel
BuildRequires: gettext-devel
Requires: hicolor-icon-theme

%description
Xsane is a grahical frontend for sane. Install this if you want a grahpical
frontend for sane for use in the X Windowing System.

%description -l ja
XSane は、多くのスキャナ、デジタルカメラ、その他の画像取り込み装置に対応
した SANE スキャナインタフェースの Xウィンドウ用フロントエンドです。
XSane は GTK+ で書かれ、画像取り込みや取込み画像の操作を行うことができま
す。


%prep
%setup -q

# convert some files to UTF-8
for doc in xsane.{CHANGES,PROBLEMS,INSTALL}; do
    iconv -f ISO-8859-1 -t utf8 "$doc" -o "$doc.new" && \
    touch -r "$doc" "$doc.new" && \
    mv "$doc.new" "$doc"
done

%patch0 -p1 -b .xdg-open
%patch1 -p1 -b .close-fds
%patch2 -p1 -b .no-eula
%patch3 -p1 -b .off-root-build
%patch4 -p1 -b .no-file-selected
%patch5 -p1 -b .ipv6
%patch6 -p1 -b .preview-selection.patch
%patch7 -p1 -b .libpng
%patch8 -p1 -b .wmclass
%patch9 -p1 -b .desktop-file
%patch10 -p1 -b .man-page
%patch11 -p1 -b .pdf-no-high-bpp
%patch12 -p1 -b .lcms2
%patch13 -p1 -b .coverity
%patch14 -p1 -b .snprintf-update
%patch15 -p1 -b .signal-handling

%patch100 -p1 -b .autoconf

# in-root config.h breaks off-root building
rm include/config.h

mkdir build-with-gimp
mkdir build-without-gimp


%build
CFLAGS='%optflags -fno-strict-aliasing'
export CFLAGS

pushd build-with-gimp
%configure --enable-gimp
make %{?_smp_mflags}
popd

pushd build-without-gimp
%configure --disable-gimp
make
popd

cp %{SOURCE1} src/


%install
%__rm -rf $RPM_BUILD_ROOT
pushd build-without-gimp
make DESTDIR=%{buildroot} install
popd

# install GIMP plugin
install -m 0755 -d %{buildroot}%{gimpplugindir}
install -m 0755 build-with-gimp/src/xsane %{buildroot}%{gimpplugindir}

# install customized desktop file
rm %{buildroot}%{_datadir}/applications/xsane.desktop

cat > src/xsane.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=XSane
Name[ja]=XSane スキャナ操作
Comment=Scanner program
Comment[ja]=スキャナを操作するツールです
Terminal=false
Type=Application
Icon=%{iconrootdir}/48x48/apps/xsane.png
Exec=xsane 
X-MultipleArgs=false
Categories=Application;Graphics;
EOF

desktop-file-install \
    --dir %{buildroot}%{_datadir}/applications \
    src/xsane.desktop

# icon files in multiple resolutions
for res in 16 32 48 256; do
    tdir="%{buildroot}%{iconrootdir}/${res}x${res}/apps"
    install -m 0755 -d "$tdir"
    install -m 0644 src/xsane-${res}x${res}.png "${tdir}/xsane.png"
done

# Register as an application to be visible in the software center
#
# NOTE: It would be *awesome* if this file was maintained by the upstream
# project, translated and installed into the right place during `make install`.
#
# See http://www.freedesktop.org/software/appstream/docs/ for more details.
#

mkdir -p $RPM_BUILD_ROOT%{_datadir}/appdata
cat > $RPM_BUILD_ROOT%{_datadir}/appdata/%{name}.appdata.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2014 Ryan Lerch <rlerch@redhat.com> -->
<!--
EmailAddress: Oliver.Rauch@xsane.org
SentUpstream: 2014-09-17
-->
<application>
  <id type="desktop">xsane.desktop</id>
  <metadata_license>CC0-1.0</metadata_license>
  <summary>Scan images with a scanner</summary>
  <description>
    <p>
      XSane is an application to scan images using a hardware scanner attached
      to your computer.
      It is able to save in a variety of image formats, including TIFF and JPEG
      and can even save your scan as a PDF.
      XSane also has support for scanning multiple pages and merging them into
      a single document.
    </p>
  </description>
  <url type="homepage">http://www.xsane.org/</url>
  <screenshots>
    <screenshot type="default">http://www.xsane.org/doc/xsane-save.jpg</screenshot>
  </screenshots>
</application>
EOF

%find_lang %{name}


%clean
rm -rf $RPM_BUILD_ROOT


%pre
# remove obsolete gimp-plugin-mgr managed symlink
if [ -L "%{gimpplugindir}/xsane" ]; then
    rm -f "%{gimpplugindir}/xsane"
fi


%files -f %{name}.lang
%defattr(-,root,root)
%doc xsane.ACCELKEYS xsane.AUTHOR xsane.BEGINNERS-INFO xsane.BUGS xsane.CHANGES xsane.FAQ xsane.LANGUAGES xsane.LOGO xsane.NEWS xsane.ONLINEHELP xsane.PROBLEMS xsane.ROOT xsane.TODO
%license xsane.COPYING
%{_bindir}/*
%{_mandir}/*/*
%dir %{_datadir}/sane
%{_datadir}/sane/*
%{gimpplugindir}/xsane
%{_datadir}/appdata/%{name}.appdata.xml
%{_datadir}/applications/xsane.desktop
%{_datadir}/pixmaps/xsane.xpm
%{iconrootdir}/*/apps/%{name}.png


%changelog
* Mon May 04 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.999-3
- rebuilt with lcms2.
- dropped Patch0.
- imported patches from rawhide.

* Mon Feb 09 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.999-2
- rebuild with libgphoto2-2.5.7
- add BuildRequires: lcms-devel

* Wed Jan 14 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.999-1
- update to 0.999
- add Patch0 (xsane-0.999-libpng.patch)

* Fri Jan 11 2013 IWAI, Masaharu <iwai@alib.jp> 0.997-2
- build with libgphoto2 2.5.0-1

* Sun Jul 25 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.997-1
- new upstream release
- add BuildRequires: gimp-devel
- remove configure option (--enable-gimp)
- fix %files

* Sat Jul 26 2008 Shu KONNO <owa@bg.wakwak.com> 0.995-1vl5
- applied new versioning policy
- updated script to create %{name}.desktop

* Mon Dec 24 2007 Shu KONNO <owa@bg.wakwak.com> 0.995-0vl1
- new upstream
- updated xsane.desktop

* Sat Jan 08 2005 Satoshi MACHINO <machino@vinelinux.org> 0.96-0vl1
- new upstream version (xsane-0.96)
- fixed spec file
	-- cleaned up
	-- added Requires: sane >= 1.0.0, gtk2, glib2, atk, pango, zlib
	-- added BuildRequires: sane-devel, gtk2-devel, atk-devel, pango-devel
	-- added BuildRequires: gimp >= 1.3.23
	-- added BuildRequires: libjpeg-devel, libpng-devel, libtiff-devel,zlib-devel

* Fri Oct 25 2002 Tomoya TAKA <taka@vinelinux.org> 0.89-0vl1
- new upstream release

* Mon May 13 2002 Satoshi MACHINO <machino@vinelinux.org> xsane-0.86-0vl1
- updated xsane-0.86

* Thu Apr 4 2002 Masaki Shinomiya <shino@pos.to>
- 0.84-0vl1 for Vine Linux-2.x
- 0.84-0.1
- symlink for gimp listed in %file section
- some html-documents
- set %_sysconfdir to /etc for RedHat6.x/Vine2.x
- RPM Group move to Applications/Multimedia

* Tue Mar 12 2002 Masaki Shinomiya <shino@pos.to>
- 0.84-0
- bugfix in %post script

* Sun Dec 23 2001 Masaki Shinomiya <shino@pos.to>
- 0.82-0.1
- use mocros as possible, nosrc

* Thu Jul 5 2001 Masaki Shinomiya <shino@pos.to>
- 0.79-0test
- remove the patch of the tooltips

* Thu Jul 5 2001 Masaki Shinomiya <shino@pos.to>
- 0.78-1vl2
- fixed script for gimp plug-in setup

* Sat Jun 23 2001 Masaki Shinomiya <shino@pos.to>
- rename for VinePlus. program registoration for gnome

* Tue Jun 19 2001 Masaki Shinomiya <shino@pos.to>
- patch to provide proper fonts for the tooltips

* Thu Jun 14 2001 Masaki Shinomiya <shino@pos.to>
- 0.78-1
- escape confliction of the document file 'sane-pnm-doc.html' with one from SANE

* Sun Jun 3 2001 Masaki Shinomiya <shino@pos.to>
- 0.77-1

* Mon May 21 2001 Masaki Shinomiya <shino@pos.to>
- 0.76-1
- refined script for gimp plug-in setup

* Wed Nov 15 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 0.64-0vl1
- updated to 0.64 (hope it'll be compatible with gimp-1.1.27...)

* Mon Oct 16 2000 Jun Nishii <jun@vinelinux.org>
- 0.61-0vl3
- build with gimp-1.1.27

* Mon Sep 25 2000 Jun Nishii <jun@vinelinux.org>
- 0.61-0vl2
- build with gimp-1.1.25

* Thu Sep 21 2000 Jun Nishii <jun@vinelinux.org>
- 0.61-0vl1

* Sat Jan 22 2000 Jun Nishii <jun@vinelinux.org>
- 0.51-0vl1

* Mon Aug 30 1999 Tim Powers <timp@redhat.com>
- changed group

* Mon Jul 26 1999 Tim Powers <timp@redhat.com>
- update to 0.30
- added %defattr
- built for 6.1

* Thu Apr 22 1999 Preston Brown <pbrown@redhat.com>
- initial RPM for PowerTools 6.0






