##
##  qpdf.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 information
Name:         qpdf
Summary:      C/C++ PDF Manipulation Toolkit
URL:          http://qpdf.sourceforge.net/
Vendor:       Jay Berkenbilt
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Graphics
License:      Apache
Version:      12.2.0
Release:      20250505

#   list of sources
Source0:      https://github.com/qpdf/qpdf/releases/download/v%{version}/qpdf-%{version}.tar.gz
Patch0:       qpdf.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes, cmake
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  jpeg, zlib, openssl
PreReq:       jpeg, zlib, openssl

%description
     QPDF is a command-line program that does structural,
     content-preserving transformations on PDF files. It could have been
     called something like PDF-to-PDF. It also provides many useful
     capabilities to developers of PDF-producing software or for people
     who just want to look at the innards of a PDF file to learn more
     about how they work. QPDF is capable of creating linearized (also
     known as web-optimized) files and encrypted files. It is also
     capable of converting PDF files with object streams (also known
     as compressed objects) to files with no compressed objects or to
     generate object streams from files that don't have them (or even
     those that already do). QPDF also supports a special mode designed
     to allow you to edit the content of PDF files in a text editor.
     QPDF includes support for merging and splitting PDFs through the
     ability to copy objects from one PDF file into another and to
     manipulate the list of pages in a PDF file.

%track
    prog qpdf = {
        version   = %{version}
        url       = https://github.com/qpdf/qpdf/releases
        regex     = tree/v(__VER__)
    }

%prep
    %setup -q
    %patch -p0

%build
    %{l_shtool} subst \
        -e 's;/bin/bash;%{l_bash};g' \
        appimage/build-appimage \
        appimage/entrypoint
    mkdir build
    cd build
    cmake \
        -Wno-dev \
        -DCMAKE_BUILD_TYPE="Release" \
        -DCMAKE_INSTALL_PREFIX="%{l_prefix}" \
        -DCMAKE_C_COMPILER="%{l_cc}" \
        -DCMAKE_C_FLAGS="%{l_cflags} %{l_cppflags}" \
        -DCMAKE_CXX_COMPILER="%{l_cxx}" \
        -DCMAKE_CXX_FLAGS="%{l_cxxflags} %{l_cppflags}" \
        -DCMAKE_EXE_LINKER_FLAGS="%{l_ldflags}" \
        -DDEFAULT_CRYPTO="openssl" \
        -DBUILD_SHARED_LIBS=OFF \
        -DBUILD_STATIC_LIBS=ON \
        -DBUILD_DOC_HTML=ON \
        -DBUILD_DOC_PDF=OFF \
        -DREQUIRE_CRYPTO_OPENSSL=ON \
        -DREQUIRE_CRYPTO_GNUTLS=OFF \
        -DUSE_IMPLICIT_CRYPTO=OFF \
        -DALLOW_CRYPTO_NATIVE=ON \
        -DDEFAULT_CRYPTO="openssl" \
        -DINSTALL_EXAMPLES=OFF \
        ..
    %{l_make} %{l_mflags -O}

%install
    (   cd build
        %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
    ) || exit $?
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

