##
##  cflow.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_cflow       2.0
%define       V_cflow2vcg   0.5

#   package information
Name:         cflow
Summary:      C Source Code Program Flow Analysis
URL:          http://www.ibiblio.org/pub/Linux/devel/lang/c/
Vendor:       Andrew Moore et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Development
License:      PD
Version:      %{V_cflow}
Release:      20080101

#   list of sources
Source0:      http://www.ibiblio.org/pub/Linux/devel/lang/c/cflow-%{V_cflow}.tar.gz
Source1:      http://download.sourceforge.net/cflow2vcg/cflow2vcg-%{V_cflow2vcg}.tar.gz
Patch0:       cflow.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make, gcc
PreReq:       OpenPKG, openpkg >= 20160101

%description
    The cflow command reads the given program C source code and attempts
    to print a graph of the program's function call hierarchy to the
    standard output.

%track
    prog cflow:cflow = {
        version   = %{version}
        url       = http://www.ibiblio.org/pub/Linux/devel/lang/c/
        regex     = cflow-(__VER__)\.tar\.gz
    }
    prog cflow:cflow2vcg = {
        version   = %{V_cflow2vcg}
        url       = http://sourceforge.net/projects/cflow2vcg/files/
        regex     = cflow2vcg-(__VER__)\.tar\.gz
    }

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

%build
    ( cd cflow-%{V_cflow}
      %{l_shtool} subst \
          -e 's;-Wall;;' \
          -e 's;$(PREFIX)/bin/;$(PREFIX)/libexec/cflow/;' \
          Makefile
      %{l_make} %{l_mflags} \
          CC="%{l_cc}" \
          OPT="%{l_cflags -O}" \
          PREFIX=%{l_prefix} \
          CFLOW_SHELL=%{l_bash}
    ) || exit $?
    ( cd cflow2vcg-%{V_cflow2vcg}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      ./configure
      cd src
      %{l_make} %{l_mflags}
    ) || exit $?

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/cflow \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1
    ( cd cflow-%{V_cflow}
      %{l_shtool} install -c -m 755 \
          cflow $RPM_BUILD_ROOT%{l_prefix}/bin/
      %{l_shtool} install -c -s -m 755 \
          prcc prcg $RPM_BUILD_ROOT%{l_prefix}/libexec/cflow/
      %{l_shtool} install -c -m 644 \
          cflow.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
    ) || exit $?
    ( cd cflow2vcg-%{V_cflow2vcg}
      %{l_shtool} install -c -s -m 755 \
          src/cflow2vcg $RPM_BUILD_ROOT%{l_prefix}/bin/
    ) || exit $?
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

