##
##  graphviz.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 versions
%define       V_graphviz                     14.0.1
%define       V_graphviz_perl_base           2.24
%define       V_graphviz_perl_data_structure 0.20

#   package information
Name:         graphviz
Summary:      Graph Visualization Tool
URL:          http://www.graphviz.org/
Vendor:       AT&T
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Diagram
License:      GPL
Version:      %{V_graphviz}
Release:      20251006

#   package options
%option       with_perl  no
%option       with_pango no

#   list of sources
Source0:      https://gitlab.com/api/v4/projects/4207231/packages/generic/graphviz-releases/%{V_graphviz}/graphviz-%{V_graphviz}.tar.gz
Source1:      http://www.cpan.org/modules/by-module/GraphViz/GraphViz-%{V_graphviz_perl_base}.tgz
Source2:      http://www.cpan.org/modules/by-module/GraphViz/GraphViz-Data-Structure-%{V_graphviz_perl_data_structure}.tar.gz
Patch0:       graphviz.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make, flex, bison, autoconf, automake
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  freetype, png, zlib, jpeg, gd, poppler
PreReq:       freetype, png, zlib, jpeg, gd, poppler
%if "%{with_perl}" == "yes"
BuildPreReq:  perl, perl-sys, perl-openpkg
PreReq:       perl, perl-sys
%endif
%if "%{with_pango}" == "yes"
BuildPreReq:  pango, cairo
PreReq:       pango, cairo
%endif

%description
    Graphviz is a set of graph drawing tools. Graph drawing addresses
    the problem of visualizing structural information by constructing
    geometric representations of abstract graphs and networks.
    Automatic generation of graph drawings has important applications
    in key technologies such as database design, software engineering,
    VLSI and network design and visual interfaces in other domains.

%track
    prog graphviz = {
        version   = %{V_graphviz}
        url       = https://graphviz.org/download/source/
        regex     = graphviz-(\d+\.\d+(\.\d+)*)\.tar.gz
    }
    prog graphviz:GraphViz = {
        version   = %{V_graphviz_perl_base}
        url       = http://www.cpan.org/modules/by-module/GraphViz/
        regex     = GraphViz-(__VER__)\.tgz
    }
    prog graphviz:GraphViz-Data-Structure = {
        version   = %{V_graphviz_perl_data_structure}
        url       = http://www.cpan.org/modules/by-module/GraphViz/
        regex     = GraphViz-Data-Structure-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %setup -q -D -T -a 1
    %setup -q -D -T -a 2
    %patch -p0

%build
    #   configure program
    %{l_shtool} subst \
        -e 's;SF_FLAGS;SFIO_FLAGS;g' \
        lib/sfio/*.[ch]
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O} -Wno-conversion -Wno-sign-conversion -Wno-float-conversion -Wno-switch-default" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    LIBS="-lbz2" \
    %{l_bash} ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --with-extraincludedir=%{l_prefix}/include \
        --with-extralibdir=%{l_prefix}/lib \
        --with-freetypeincludedir=%{l_prefix}/include \
        --with-freetypelibdir=%{l_prefix}/lib \
        --with-pngincludedir=%{l_prefix}/include \
        --with-pnglibdir=%{l_prefix}/lib \
        --with-jpegincludedir=%{l_prefix}/include \
        --with-jpeglibdir=%{l_prefix}/lib \
        --without-mylibgd \
        --with-libgd \
        --with-gdincludedir=%{l_prefix}/include \
        --with-gdlibdir=%{l_prefix}/lib \
        --with-zincludedir=%{l_prefix}/include \
        --with-zlibdir=%{l_prefix}/lib \
        --with-poppler \
        --without-gtk \
        --disable-swig \
        --disable-sharp \
        --disable-guile \
        --disable-io \
        --disable-java \
        --disable-lua \
        --disable-ocaml \
        --disable-perl \
        --disable-php \
        --disable-python \
        --disable-ruby \
        --disable-tcl \
        --without-tclsh \
        --without-wish \
        --without-x \
%if "%{with_pango}" == "yes"
        --with-pangocairo \
%else
        --without-pangocairo \
%endif
        --disable-shared \
        --enable-static

    #   build program
    %{l_make} %{l_mflags}

%if "%{with_perl}" == "yes"
    #   build Perl API
    %{l_prefix}/bin/perl-openpkg prepare
    ln cmd/dot/dot_static cmd/dot/dot
    PATH="`pwd`/cmd/dot:$PATH"
    %{l_prefix}/bin/perl-openpkg -d %{SOURCE1} configure build
    %{l_prefix}/bin/perl-openpkg -d %{SOURCE2} configure build
%endif

%install
    #   install program
    %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"

%if "%{with_perl}" == "yes"
    #   install Perl API
    %{l_prefix}/bin/perl-openpkg -d %{SOURCE1} install
    %{l_prefix}/bin/perl-openpkg -d %{SOURCE2} install
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%endif

    #   post-adjust installation
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/graphviz/*.tcl
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/graphviz/python*
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/graphviz/doc/html
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/graphviz/lefty
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    for lang in lua ocaml perl php python ruby sharp tcl guile io java; do
        rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/graphviz/$lang 2>/dev/null || true
    done
    mv  $RPM_BUILD_ROOT%{l_prefix}/bin/dot_static \
        $RPM_BUILD_ROOT%{l_prefix}/bin/dot

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
%if "%{with_perl}" == "yes"
        `cat perl-openpkg-files` \
%endif
        '%doc %{l_prefix}/share/graphviz/doc/pdf/*'

%files -f files

%clean

