Name:            netpbm
Version:         10.83.01
Release:         6
Summary:         A library for handling different graphics file formats
License:         BSD and GPLv2 and IJG and MIT and Public Domain
URL:             http://netpbm.sourceforge.net/

Source0:         netpbm-%{version}.tar.xz

Patch0000:       netpbm-security-scripts.patch
Patch0001:       netpbm-security-code.patch
Patch0002:       netpbm-ppmfadeusage.patch
Patch0003:       netpbm-noppmtompeg.patch
Patch0004:       netpbm-CVE-2017-2587.patch
Patch0005:       netpbm-python3.patch
Patch0006:       netpbm-time.patch
Patch0007:       netpbm-gcc4.patch
Patch0008:       netpbm-bmptopnm.patch
Patch0009:       netpbm-CAN-2005-2471.patch
Patch0010:       netpbm-xwdfix.patch
Patch0011:       netpbm-multilib.patch
Patch0012:       netpbm-glibc.patch
Patch0013:       netpbm-docfix.patch
Patch0014:       netpbm-fiasco-overflow.patch
Patch0015:       netpbm-cmuwtopbm.patch
Patch0016:       netpbm-pamtojpeg2k.patch
Patch0017:       netpbm-manfix.patch
Patch0018:       netpbm-manual-pages.patch
Patch0019:       netpbm-jasper.patch

BuildRequires:   libjpeg-devel, libpng-devel, libtiff-devel, flex jbigkit-devel jasper-devel
BuildRequires:   libX11-devel perl-generators python3 libxml2-devel ghostscript-core gcc perl
Requires:        ghostscript
Provides:        bundled(jbigkit) netpbm-progs = %{version}-%{release}
Obsoletes:       netpbm-progs < %{version}-%{release}

%description
The netpbm package contains a library of functions that support the following features:
Program for handling various graphic file formats and so on.

%package devel
Summary:         Provides development tools for programs
Requires:        netpbm = %{version}-%{release}

%description devel
The netpbm-devel package provides tools for developing programs which will use the netpbm libraries.

%package        help
Summary:        Help document for the netpbm package
Requires:       netpbm-progs = %{version}-%{release}
Provides:       netpbm-doc = %{version}-%{release}
Obsoletes:      netpbm-doc < %{version}-%{release}

%description    help
Help document for the netpbm package.

%prep
%autosetup -n %{name}-%{version} -p1
rm -rf converter/other/jpeg2000/libjasper/
rm -rf converter/other/jbig/libjbig/

%build
./configure <<EOF

gnu
regular
shared
y

n
libjpeg.so
default
libtiff.so
default
libz.so
default
none
http://netpbm.sourceforge.net/doc/
EOF

TOP=`pwd`

make \
  CC="%{__cc}" LDFLAGS="$RPM_LD_FLAGS -L$TOP/pbm -L$TOP/pgm -L$TOP/pnm -L$TOP/ppm" \
  CFLAGS="$RPM_OPT_FLAGS -fPIC -flax-vector-conversions -fno-strict-aliasing" \
  CFLAGS_CONFIG="$RPM_OPT_FLAGS" LADD="-lm" JPEGINC_DIR=%{_includedir} PNGINC_DIR=%{_includedir} \
  TIFFINC_DIR=%{_includedir} JPEGLIB_DIR=%{_libdir} PNGLIB_DIR=%{_libdir} TIFFLIB_DIR=%{_libdir} \
  LINUXSVGALIB="NONE" X11LIB=%{_libdir}/libX11.so XML2LIBS="NONE" JBIGLIB=%{_libdir}/libjbig.so.2.1

cd userguide
rm -f ppmtompeg* *.manual-pages *.manfix

for i in *.html ; do
  ../buildtools/makeman ${i}
done

mkdir -p man/{man1,man3,man5}
mv *.1 man/man1
mv *.3 man/man3
mv *5 man/man5

%install
make package pkgdir=%{buildroot}/usr LINUXSVGALIB="NONE" XML2LIBS="NONE"

install -d %{buildroot}%{_libdir}
if [ "%{_libdir}" != "/usr/lib" ]; then
  mv %{buildroot}/usr/lib/lib* %{buildroot}%{_libdir}
fi

cp -af lib/libnetpbm.a %{buildroot}%{_libdir}/libnetpbm.a
cp -l %{buildroot}%{_libdir}/libnetpbm.so.?? %{buildroot}%{_libdir}/libnetpbm.so

install -d %{buildroot}%{_datadir}
mv userguide/man %{buildroot}%{_mandir}

sed -i 's/\xa0//' %{buildroot}%{_mandir}/man1/pgmminkowski.1

for i in hpcdtoppm ppmsvgalib vidtoppm picttoppm  directory error extendedopacity \
         pam pbm pgm pnm ppm index libnetpbm_dir liberror ppmtotga; do
    rm -f %{buildroot}%{_mandir}/man1/${i}.1
done

install -d %{buildroot}%{_datadir}/netpbm
mv %{buildroot}/usr/misc/{*.map,rgb.txt} %{buildroot}%{_datadir}/netpbm/

cd %{buildroot}%{_bindir}
rm -f pgmtopbm pnmcomp
ln -s pamcomp pnmcomp
echo -e '#!/bin/sh\npamditherbw $@ | pamtopnm\n' > pgmtopbm
chmod 0755 pgmtopbm
cd -

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%check
cd test
export LD_LIBRARY_PATH=%{buildroot}%{_libdir} PBM_TESTPREFIX=%{buildroot}%{_bindir} PBM_BINPREFIX=%{buildroot}%{_bindir}
./Execute-Tests && exit 0
cd -

%files
%doc doc/copyright_summary doc/COPYRIGHT.PATENT README doc/GPL_LICENSE.txt
%{_libdir}/lib*.so*
%{_bindir}/*
%{_datadir}/netpbm/
%exclude %{_mandir}/man5/extendedopacity.5
%exclude %{_libdir}/lib*.a

%files devel
%{_includedir}/netpbm/*.h
%exclude /usr/{README,VERSION,link,misc,man,pkginfo,config_template,pkgconfig_template}

%files help
%doc userguide/* doc/HISTORY
%{_mandir}/man1/*
%{_mandir}/man3/*
%{_mandir}/man5/*

%changelog
* Mon Jan 06 2025 wangkai <13474090681@163.com> - 10.83.01-6
- Use system version of jasper and jbigkit for fix CVE-2008-3522

* Wed Jan 05 2022 Ge Wang <wangge20@huawei.com> - 10.83.01-5
- Fix building error: Can not locate English.pm
- Add perl in BuildRequires

* Wed Jun 16 2021 zhaoyao <zhaoyao32@huawei.com> - 10.83.01-4
- Fix buiding error:  Can't exec "-c": No such file or directory
- Add gcc in BuildRequires

* Thu Jan 23 2020 openEuler Buildteam <buildteam@openeuler.org> - 10.83.01-3
- Type:bugfix
- Id:NA
- SUG:NA
- DESC:delete the jasper

* Tue Nov 26 2019 wangzhishun <wangzhishun1@huawei.com> - 10.83.01-2
- Package init
