%ifarch x86_64
%if ! 0%{?__isa_bits:1}
%ifarch x86_64
%global __isa_bits 64
%endif
%endif
%endif

%global __provides_exclude_from ^%{_libdir}/GraphicsMagick-%{version}/.*\\.(la|so)$

Name:          GraphicsMagick
Version:       1.3.30
Release:       7
Summary:       Derived from ImageMagick, providing faster image generation speed and better quality
License:       MIT
Source0:       http://downloads.sourceforge.net/sourceforge/graphicsmagick/GraphicsMagick-%{version}.tar.xz
Url:           http://www.graphicsmagick.org/

Patch0000:     GraphicsMagick-1.3.14-perl_linkage.patch
Patch0001:     GraphicsMagick-1.3.16-multilib.patch
Patch0002:     CVE-2019-11007.patch
Patch0003:     CVE-2019-11505.patch
Patch0004:     CVE-2019-11008.patch
Patch0005:     CVE-2019-11506.patch
Patch0006:     CVE-2019-11009.patch

BuildRequires: bzip2-devel freetype-devel gcc-c++ giflib-devel lcms2-devel libjpeg-devel
BuildRequires: libpng-devel librsvg2-devel libtiff-devel libtool-ltdl-devel libxml2-devel lpr
BuildRequires: libX11-devel libXext-devel libXt-devel perl-devel perl-generators perl(ExtUtils::MakeMaker)
BuildRequires: xdg-utils xz-devel zlib-devel time jbigkit-devel libwebp-devel

Requires:      urw-fonts

%description
GraphicsMagick is the swiss army knife of image processing. Comprised of 267K physical lines
(according to David A. Wheeler's SLOCCount) of source code in the base package
(or 1,225K including 3rd party libraries) it provides a robust and efficient collection of tools
and libraries which support reading, writing, and manipulating an image in over 89 major formats
including important formats like DPX, GIF, JPEG, JPEG-2000, PNG, PDF, PNM, TIFF, and WebP.

%package devel
Summary:       Libraries and header files for GraphicsMagick
Requires:      %{name} = %{version}-%{release}

%description devel
GraphicsMagick-devel contains libraries and header files needed to
develop GraphicsMagick applications. This is an image processing program.

If you want to create an application that will use GraphicsMagick code
or API, you need to install GraphicsMagick-devel and GraphicsMagick.
If you just want to use, don't install

%package help
Provides:      %{name}-doc = %{version}-%{release}
Obsoletes:     %{name}-doc < %{version}-%{release}
Summary:       GraphicsMagick documentation and usage introduction
Obsoletes:     GraphicsMagick < 1.3.19-4
BuildArch: noarch

%description help
GraphicsMagick documentation and usage introduction.

%package perl
Summary:       GraphicsMagick perl package
Requires:      %{name} = %{version}-%{release}
Requires:      perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))

%description perl
GraphicsMagick's perl package

Use GraphicsMagick's perl script to install the GraphicsMagick-perl package.

%package c++
Summary:       GraphicsMagick c ++ package
Requires:      %{name} = %{version}-%{release}

%description c++
This package contains the GraphicsMagick ++ library, which is
a C ++ library for the GraphicsMagick graphics manipulation library.

To use any application that uses GraphicsMagick ++,
install GraphicsMagick-c ++.

%package c++-devel
Summary:       GraphicsMagick's C ++ Development Kit
Requires:      %{name}-c++ = %{version}-%{release}
Requires:      %{name}-devel = %{version}-%{release}

%description c++-devel
GraphicsMagick-devel contains libraries and header files needed to
develop GraphicsMagick applications using Magick ++ C ++ bindings.

If you want to create an application that uses Magick ++ code or API,
you need to install GraphicsMagick-c ++-devel, ImageMagick devel, and GraphicsMagick.

If you are just using GraphicsMagick, or you want to develop / compile
applications using the GraphicsMagick C interface, you do not need to install it.

%prep
%autosetup -p1

%if "%{_libdir}" != "/usr/lib"
sed -i -e 's|"/lib /usr/lib|"%{_lib} %{_libdir}|' configure
%endif


%build
%configure --enable-shared --disable-static --docdir=%{_pkgdocdir} --with-lcms2 --with-magick_plus_plus \
           --with-modules --with-perl --with-perl-options="INSTALLDIRS=vendor %{?perl_prefix}" \
           --with-quantum-depth=16 --enable-quantum-library-names --with-threads --with-wmf --with-x \
           --with-xml --without-dps --without-gslib --with-gs-font-dir=%{_datadir}/fonts/default/Type1

%make_build
%make_build perl-build


%install
%make_install
%make_install -C PerlMagick

%{__perl} -MExtUtils::MakeMaker -e 'MY->fixin(@ARGV)' PerlMagick/demo/*.pl

find %{buildroot} -type f -name "*.bs" -delete
find %{buildroot} -type f -name ".packlist" -delete
find %{buildroot} -type f -name "perllocal.pod" -delete

chmod 755 %{buildroot}%{perl_vendorarch}/auto/Graphics/Magick/Magick.so

find %{buildroot}/%{_libdir}/perl* -type f -print \
    | sed "s@^%{buildroot}@@g" > perl-pkg-files
find %{buildroot}%{perl_vendorarch} -type d -print \
    | sed "s@^%{buildroot}@%dir @g" \
    | grep -v '^%dir %{perl_vendorarch}$' \
    | grep -v '/auto$' >> perl-pkg-files
if [ -z perl-pkg-files ] ; then
    echo "ERROR: FILE LIST EMPTY"
    exit -1
fi

rm -rf %{buildroot}%{_datadir}/GraphicsMagick
rm -rf %{buildroot}%{_datadir}/%{name}-%{version}/[a-b,d-z,A-Z]*
find  %{buildroot}%{_libdir} -type f -name "lib*.la" -delete

%ifarch x86_64
mv %{buildroot}%{_includedir}/GraphicsMagick/magick/magick_types.h \
   %{buildroot}%{_includedir}/GraphicsMagick/magick/magick_types-%{__isa_bits}.h

cat >%{buildroot}%{_includedir}/GraphicsMagick/magick/magick_types.h <<EOF
#ifndef MAGICK_TYPES_MULTILIB
#define MAGICK_TYPES_MULTILIB

#include <bits/wordsize.h>

#if __WORDSIZE == 32
# include "magick/magick_types-32.h"
#elif __WORDSIZE == 64
# include "magick/magick_types-64.h"
#else
# error "unexpected value for __WORDSIZE macro"
#endif

#endif
EOF
%endif


%check
time %make_build check ||:

%post
/sbin/ldconfig
%postun
/sbin/ldconfig

%post c++ -p /sbin/ldconfig
%postun c++ -p /sbin/ldconfig

%files
%dir %{_pkgdocdir}
%license %{_pkgdocdir}/Copyright.txt
%{_libdir}/libGraphicsMagick-Q16.so.3*
%{_libdir}/libGraphicsMagickWand-Q16.so.2*
%{_bindir}/[a-z]*
%{_libdir}/GraphicsMagick-%{version}/
%{_datadir}/GraphicsMagick-%{version}/

%files devel
%{_bindir}/GraphicsMagick-config
%{_bindir}/GraphicsMagickWand-config
%{_libdir}/libGraphicsMagick.so
%{_libdir}/libGraphicsMagickWand.so
%{_libdir}/pkgconfig/GraphicsMagick.pc
%{_libdir}/pkgconfig/GraphicsMagickWand.pc
%dir %{_includedir}/GraphicsMagick/
%{_includedir}/GraphicsMagick/magick/
%{_includedir}/GraphicsMagick/wand/

%files help
%dir %{_pkgdocdir}
%{_pkgdocdir}/ChangeLog*
%{_pkgdocdir}/*.txt
%{_pkgdocdir}/www/
%{_mandir}/man[145]/[a-z]*
%{_mandir}/man1/GraphicsMagick-config.*
%{_mandir}/man1/GraphicsMagickWand-config.*
%{_mandir}/man1/GraphicsMagick++-config.*
%{_mandir}/man3/*

%files c++
%{_libdir}/libGraphicsMagick++-Q16.so.12*

%files c++-devel
%{_bindir}/GraphicsMagick++-config
%{_includedir}/GraphicsMagick/Magick++/
%{_includedir}/GraphicsMagick/Magick++.h
%{_libdir}/libGraphicsMagick++.so
%{_libdir}/pkgconfig/GraphicsMagick++.pc

%files perl -f perl-pkg-files
%doc PerlMagick/demo/ PerlMagick/Changelog PerlMagick/README.txt


%changelog
* Tue May 19 2020 openEuler Buildteam <buildteam@openeuler.org> - 1.3.30-7
- rebuild for libwebp-1.1.0

* Thu Jan 23 2020 openEuler Buildteam <buildteam@openeuler.org> - 1.3.30-6
- Type:bugfix
- Id:NA
- SUG:NA
- DESC:delete the jasper

* Tue Dec 24 2019 shijian<shijian16@huawei.com> - 1.3.30-5
- Type:cves
- ID:CVE-2019-11007.patch CVE-2019-11505.patch CVE-2019-11008.patch CVE-2019-11506.patch CVE-2019-11009.patch
- SUG:restart
- DESC: fix CVE-2019-11007.patch CVE-2019-11505.patch CVE-2019-11008.patch CVE-2019-11506.patch CVE-2019-11009.patch

* Fri Dec 13 2019 yangjian<yangjian79@huawei.com> - 1.3.30-4
- Package init
