%bcond_with shared

Summary:        Improved JPEG encoder
Summary(ja):    改良されたJPEGエンコーダ
Name:           mozjpeg
Version:        4.0.3
Release:        2%{?_dist_release}
Group:          graphics
Vendor:         Project Vine
Distribution:   Vine Linux

License:        IJG and BSD
URL:            https://github.com/mozilla/mozjpeg
Source0:        https://github.com/mozilla/mozjpeg/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
#Patch1000:      CVE-2018-14498.patch
#Patch1001:      CVE-2020-13790.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-root
BuildRequires:  cmake
BuildRequires:  libpng-devel
BuildRequires:  zlib-devel
%if !%{with shared}
BuildRequires:  libpng-static
BuildRequires:  zlib-static
%endif
%ifarch %{ix86} x86_64
BuildRequires:  nasm
%endif

%description
MozJPEG reduces file sizes of JPEG images while retaining quality and
compatibility with the vast majority of the world's deployed decoders.

%description -l ja
MozJPEGは、品質と世界で利用されている大多数のデコーダとの互換性を維持
しつつJPEG画像のファイルサイズを縮小します。

%if %{with shared}
%package libs
Summary:        drop-in libraries of mozjpeg
Group:          system

%description libs
This package contains drop-in libraries of mozjpeg.


%package devel
Summary:        development files of mozjpeg
Group:          programming
Requires:       %{name}-libs

%description devel
This package contains development files of mozjpeg.
%endif


%debug_package


%prep
%setup -q
%autopatch -p1


%build
%cmake \
	-DWITH_JPEG8=ON \
%if %{with shared}
	-DENABLE_STATIC=OFF \
	-DENABLE_SHARED=ON \
%else
	-DENABLE_STATIC=ON \
	-DENABLE_SHARED=OFF \
%endif
	%{nil}

%cmake_build


%install
%{__rm} -rf %{buildroot}
%cmake_install

rm -rf pkgdocs
cp -rf %{buildroot}%{_docdir}/mozjpeg ./pkgdocs
rm -rf %{buildroot}%{_docdir}/mozjpeg

%if %{with shared}
rm -f %{buildroot}%{_libdir}/*.{a,la}
%else
rm -rf %{buildroot}%{_includedir}/*
rm -rf %{buildroot}%{_libdir}/*
%endif


%clean
%{__rm} -rf %{buildroot}


%files
%defattr(-,root,root)
%license LICENSE.md
%doc README.*
%{_bindir}/*
%{_mandir}/man1/*

%if %{with shared}
%files libs
%{_libdir}/*.so.*

%files devel
%doc pkgdocs/*
%{_libdir}/*.so
%{_libdir}/pkgconfig/*
%{_includedir}/*
%endif


%changelog
* Thu Sep 02 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.0.3-2
- rebuilt as statically linked binary.

* Mon Jul 26 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.0.3-1
- new upstream release.

* Thu Jun 18 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.3.1-1
- initial build for Vine Linux

