##
##  graphicsmagick.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_major 1.3
%define       V_minor 36
%define       V_dist  %{V_major}.%{V_minor}
%define       V_opkg  %{V_major}.%{V_minor}

#   package information
Name:         graphicsmagick
Summary:      Graphic Image Conversion Tool
URL:          http://www.graphicsmagick.org/
Vendor:       GraphicsMagick Group
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Graphics
License:      MIT-style
Version:      %{V_opkg}
Release:      20201227

#   list of sources
Source0:      ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/%{V_major}/GraphicsMagick-%{V_dist}.tar.xz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc, grep, sed
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  tiff, jpeg, jasper, bzip2, zlib, png, freetype, fontconfig, lcms, libxml, libiconv
PreReq:       tiff, jpeg, jasper, bzip2, zlib, png, freetype, fontconfig, lcms, libxml, libiconv

%description
    GraphicsMagick is the swiss army knife of image processing. It is a
    fork of ImageMagick as of 2002.

%track
    prog graphicsmagick = {
        version   = %{V_dist}
        url       = ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/%{V_major}/
        regex     = GraphicsMagick-(\d+\.\d+\.\d+(-\d+)?)\.tar\.xz
    }

%prep
    %setup -q -n GraphicsMagick-%{V_dist}

%build
    %{l_shtool} subst \
        -e 's/^\(MagickLibSubdir="\)[^"]*\("\)/\1graphicsmagick\2/' \
        -e 's/\(-lxml2\)/\1 -liconv/' \
        configure
    cppflags=""
    case "%{l_platform -t}" in
        amd64-* ) cppflags="-DPNG_NO_ASSEMBLER_CODE" ;;
    esac
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O} %{l_cppflags tiff}" \
    CPPFLAGS="%{l_cppflags tiff} $cppflags" \
    CXXFLAGS="%{l_cxxflags -O}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-liconv" \
    CONFIG_SHELL="%{l_bash}" \
    %{l_bash} ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --disable-magick-compat \
        --without-magick-plus-plus \
        --without-modules \
        --disable-shared \
        --with-zlib \
        --with-bzlib \
        --with-tiff \
        --with-jpeg \
        --with-png \
        --with-xml \
        --with-lcms2 \
        --with-ttf=yes \
        --without-webp \
        --without-perl \
        --without-x \
        --without-threads
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags} install \
        AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man5/quantize.5
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man4/miff.4
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

