##
##  tiff.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:         tiff
Summary:      Tag Image File Format (TIFF) Image Library
URL:          http://simplesystems.org/libtiff/
Vendor:       Sam Leffler
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Graphics
License:      GPL
Version:      4.7.1
Release:      20250920

#   package options
%option       with_cxx  no

#   list of sources
Source0:      http://download.osgeo.org/libtiff/tiff-%{version}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  jpeg, zlib
PreReq:       jpeg, zlib
%if "%{with_cxx}" == "yes"
BuildPreReq:  gcc
PreReq:       gcc
%endif

%description
    Tag Image File Format (TIFF) is a widely used format for storing
    Timage data. he library, along with associated tool programs, should
    Thandle most of your needs for reading and writing TIFF images.

%track
    prog tiff = {
        version   = %{version}
        url       = http://download.osgeo.org/libtiff/
        regex     = tiff-((\d+\.)*\d+)\.tar\.gz
    }

%prep
    %setup -q
    %{l_shtool} subst \
        -e 's;== "x";= "x";' \
        -e 's;\[^-_$as_cr_alnum];[^+-_$as_cr_alnum];' \
        -e 's;\(echo \$ac_feature | sed \)\(.\)\([^\`]*\);\1\2\3 | sed \2s/+/x/g\2;g' \
        -e '/LINENO: error: C[+]* preprocessor/{N;N;N;N;s/.*/:/;}' \
        configure

%build
%if "%{with_cxx}" == "yes"
    #   conditionally build libtiff_cxx with C++ streams
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --includedir=%{l_prefix}/include/tiff \
        --disable-shared \
        --enable-static \
        --enable-cxx \
        --enable-zlib \
        --with-zlib-include-dir=%{l_prefix}/include \
        --with-zlib-lib-dir=%{l_prefix}/lib \
        --enable-jpeg \
        --with-jpeg-include-dir=%{l_prefix}/include \
        --with-jpeg-lib-dir=%{l_prefix}/lib \
        --disable-jbig \
        --disable-lzma \
        --disable-lzw \
        --disable-zstd \
        --disable-webp \
        --without-x
    %{l_make} %{l_mflags -O}

    #   save C++ library for later installation, and clean out the rest
    %{l_shtool} mkdir -f -p -m 755 tmpcxx/.libs
    mv libtiff/.libs/libtiff.a tmpcxx/.libs/libtiff_cxx.a
    mv libtiff/.libs/libtiff.lai tmpcxx/.libs/libtiff_cxx.lai
    mv libtiff/libtiff.la tmpcxx/libtiff_cxx.la
    ln -s ../libtiff_cxx.la tmpcxx/.libs/libtiff_cxx.la
    %{l_shtool} subst \
        -e 's;libtiff;libtiff_cxx;g' \
        tmpcxx/.libs/libtiff_cxx.lai \
        tmpcxx/.libs/libtiff_cxx.la
    %{l_make} %{l_mflags -O} distclean
%endif

    #   unconditionally build libtiff without C++ streams
    CC="%{l_cc}" \
    CXX="" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="" \
    CPPFLAGS="%{l_cppflags}" \
    LDFLAGS="%{l_ldflags}" \
    ./configure \
        --prefix=%{l_prefix} \
        --mandir=%{l_prefix}/man \
        --includedir=%{l_prefix}/include/tiff \
        --disable-shared \
        --enable-static \
        --disable-cxx \
        --enable-zlib \
        --with-zlib-include-dir=%{l_prefix}/include \
        --with-zlib-include-dir=%{l_prefix}/include \
        --with-zlib-lib-dir=%{l_prefix}/lib \
        --enable-jpeg \
        --with-jpeg-include-dir=%{l_prefix}/include \
        --with-jpeg-lib-dir=%{l_prefix}/lib \
        --disable-jbig \
        --disable-lzma \
        --disable-lzw \
        --disable-zstd \
        --disable-webp \
        --without-x
    %{l_make} %{l_mflags -O}

%install
    %{l_make} %{l_mflags -O} install DESTDIR=$RPM_BUILD_ROOT
%if "%{with_cxx}" == "yes"
    #   conditionally install libtiff_cxx just like the Makefile does
    ( cd tmpcxx
      ../libtool --mode=install \
          `grep "^INSTALL =" ../libtiff/Makefile | %{l_shtool} subst -e 's;[^=]*= \(.*\)$;\1;'` \
          libtiff_cxx.la \
          $RPM_BUILD_ROOT%{l_prefix}/lib
    ) || exit $?
%endif
    ( cd $RPM_BUILD_ROOT%{l_prefix}/man/man3
      for manpage in *.3tiff; do
          base=`echo $manpage | sed -e 's;\.3tiff$;;'`
          mv $base.3tiff $base.3
      done
    ) || 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

