##
##  discount.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_discount               2.2.7
%define       V_text_markdown          1.000031
%define       V_text_markdown_discount 0.12

#   package information
Name:         discount
Summary:      Markdown/SmartyPants To HTML Translation Library
URL:          http://www.pell.portland.or.us/~orc/Code/discount/
Vendor:       David Loren Parsons
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Print
License:      BSD
Version:      %{V_discount}
Release:      20210505

#   package options
%option       with_perl  no

#   list of sources
Source0:      http://www.pell.portland.or.us/~orc/Code/discount/discount-%{V_discount}.tar.bz2
Source1:      http://www.cpan.org/authors/id/B/BO/BOBTFISH/Text-Markdown-%{V_text_markdown}.tar.gz
Source2:      http://www.cpan.org/authors/id/S/SE/SEKIMURA/Text-Markdown-Discount-%{V_text_markdown_discount}.tar.gz
Patch0:       discount.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_perl}" == "yes"
BuildPreReq:  perl, perl-openpkg
PreReq:       perl
%endif

%description
    Discount is a C library which provides formatting functions
    Markdown/SmartyPants to HTML translations.

%track
    prog discount = {
        version   = %{V_discount}
        url       = http://www.pell.portland.or.us/~orc/Code/discount/
        regex     = discount-(\d+\.\d+\.\d+(\.\d+)?(?:(?:beta|rc)\d+)?)\.tar\.bz2
    }
    prog discount:text-markdown = {
        version   = %{V_text_markdown}
        url       = http://www.cpan.org/authors/id/B/BO/BOBTFISH/
        regex     = Text-Markdown-(__VER__)\.tar\.gz
    }
    prog discount:text-markdown-discount = {
        version   = %{V_text_markdown_discount}
        url       = http://www.cpan.org/authors/id/S/SE/SEKIMURA/
        regex     = Text-Markdown-Discount-(__VER__)\.tar\.gz
    }

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

%build
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    sh configure.sh \
        --prefix=%{l_prefix} \
        --enable-all-features
    %{l_make} %{l_mflags}

%if "%{with_perl}" == "yes"
    ( cd Text-Markdown-%{V_text_markdown}
      %{l_prefix}/bin/perl-openpkg prepare
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
    ( cd Text-Markdown-Discount-%{V_text_markdown_discount}
      %{l_prefix}/bin/perl-openpkg prepare
      %{l_prefix}/bin/perl-openpkg configure build
    ) || exit $?
%endif

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/man \
        $RPM_BUILD_ROOT%{l_prefix}/lib \
        $RPM_BUILD_ROOT%{l_prefix}/include
    %{l_make} %{l_mflags} \
        install install.samples install.man \
        DESTDIR=$RPM_BUILD_ROOT \
        BINDIR=%{l_prefix}/bin \
        MANDIR=%{l_prefix}/man \
        LIBDIR=%{l_prefix}/lib \
        INCDIR=%{l_prefix}/include
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
%if "%{with_perl}" == "yes"
    ( cd Text-Markdown-%{V_text_markdown}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
    ( cd Text-Markdown-Discount-%{V_text_markdown_discount}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
%else
    >perl-openpkg-files
%endif
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

