# Path under which mozjpeg should be installed
%define _prefix %{__prefix}

# Path under which executables should be installed
%define _bindir %{__bindir}

# Path under which Java classes and man pages should be installed
%define _datadir %{__datadir}

# Path under which docs should be installed
%define _docdir /usr/share/doc/%{name}-%{version}

# Path under which headers should be installed
%define _includedir %{__includedir}

# _libdir is set to %{_prefix}/%{_lib} by default
%ifarch x86_64
%define _lib lib64
%else
%if "%{_prefix}" == "/opt/mozjpeg"
%define _lib lib32
%endif
%endif

# Path under which man pages should be installed
%define _mandir %{__mandir}

Summary: A JPEG codec that provides increased compression for JPEG images (at the expense of compression performance)
Name: @PKGNAME@
Version: @VERSION@
Vendor: Mozilla Research
URL: https://github.com/mozilla/mozjpeg
Group: System Environment/Libraries
#-->Source0: https://github.com/mozilla/mozjpeg/archive/v%{version}.tar.gz
Release: @BUILD@
License: BSD-style
BuildRoot: %{_blddir}/%{name}-buildroot-%{version}-%{release}
Prereq: /sbin/ldconfig
%ifarch x86_64
Provides: %{name} = %{version}-%{release}, @PACKAGE_NAME@ = %{version}-%{release}, libturbojpeg.so()(64bit)
%else
Provides: %{name} = %{version}-%{release}, @PACKAGE_NAME@ = %{version}-%{release}, libturbojpeg.so
%endif

%description
mozjpeg is a fork of libjpeg-turbo that aims to speed up load times of web
pages by reducing the size (and, by extension, the transmission time) of JPEG
files.  It accomplishes this by enabling optimized Huffman trees and
progressive entropy coding by default in the JPEG compressor, as well as
splitting the spectrum of DCT coefficients into separate scans and using
Trellis quantisation.

Although it is based on libjpeg-turbo, mozjpeg is not intended to be a
general-purpose or high-performance JPEG library.  Its performance is highly
"asymmetric".  That is, the JPEG files it generates require much more time to
compress than to decompress.  When the default settings are used, mozjpeg is
considerably slower than libjpeg-turbo or even libjpeg at compressing images.
Thus, it is not generally suitable for real-time compression.  It is best used
as part of a web encoding workflow.

#-->%prep
#-->%setup -q -n mozjpeg-%{version}

#-->%build
#-->./configure prefix=%{_prefix} bindir=%{_bindir} datadir=%{_datadir} \
#-->	docdir=%{_docdir} includedir=%{_includedir} libdir=%{_libdir} \
#-->	mandir=%{_mandir} JPEG_LIB_VERSION=@JPEG_LIB_VERSION@ \
#-->	SO_MAJOR_VERSION=@SO_MAJOR_VERSION@ SO_MINOR_VERSION=@SO_MINOR_VERSION@ \
#-->	--with-pic @RPM_CONFIG_ARGS@
#-->make DESTDIR=$RPM_BUILD_ROOT

%install

rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT docdir=%{_docdir} exampledir=%{_docdir}
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
/sbin/ldconfig -n $RPM_BUILD_ROOT%{_libdir}

#-->%if 0

LJT_LIBDIR=%{__libdir}
if [ ! "$LJT_LIBDIR" = "%{_libdir}" ]; then
	echo ERROR: mozjpeg must be configured with libdir=%{_prefix}/%{_lib} when generating an in-tree RPM for this architecture.
	exit 1
fi

#-->%endif

LJT_DOCDIR=%{__docdir}
if [ "%{_prefix}" = "/opt/mozjpeg" -a "$LJT_DOCDIR" = "/opt/mozjpeg/doc" ]; then
	ln -fs %{_docdir} $RPM_BUILD_ROOT/$LJT_DOCDIR
fi

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root)
%dir %{_docdir}
%doc %{_docdir}/*
%dir %{_prefix}
%if "%{_prefix}" == "/opt/mozjpeg" && "%{_docdir}" != "%{_prefix}/doc"
 %{_prefix}/doc
%endif
%dir %{_bindir}
%{_bindir}/cjpeg
%{_bindir}/djpeg
%{_bindir}/jpegtran
%{_bindir}/tjbench
%{_bindir}/rdjpgcom
%{_bindir}/wrjpgcom
%dir %{_libdir}
%{_libdir}/libjpeg.so.@SO_MAJOR_VERSION@.@SO_AGE@.@SO_MINOR_VERSION@
%{_libdir}/libjpeg.so.@SO_MAJOR_VERSION@
%{_libdir}/libjpeg.so
%{_libdir}/libjpeg.a
%{_libdir}/pkgconfig
%{_libdir}/pkgconfig/libjpeg.pc
%{_libdir}/libturbojpeg.so.0.1.0
%{_libdir}/libturbojpeg.so.0
%{_libdir}/libturbojpeg.so
%{_libdir}/libturbojpeg.a
%{_libdir}/pkgconfig/libturbojpeg.pc
%dir %{_includedir}
%{_includedir}/jconfig.h
%{_includedir}/jerror.h
%{_includedir}/jmorecfg.h
%{_includedir}/jpeglib.h
%{_includedir}/turbojpeg.h
%dir %{_mandir}
%dir %{_mandir}/man1
%{_mandir}/man1/cjpeg.1*
%{_mandir}/man1/djpeg.1*
%{_mandir}/man1/jpegtran.1*
%{_mandir}/man1/rdjpgcom.1*
%{_mandir}/man1/wrjpgcom.1*
%if "%{_prefix}" != "%{_datadir}"
 %dir %{_datadir}
%endif
@JAVA_RPM_CONTENTS_1@
@JAVA_RPM_CONTENTS_2@

%changelog
