%global major_minor 5.0
Name: gnuplot
Summary: a portable command-line driven graphing utility
Version: %{major_minor}.6
Release: 14
License: gnuplot and MIT
URL: http://www.gnuplot.info/

Source0: https://sourceforge.net/projects/gnuplot/files/gnuplot/5.0.6/gnuplot-5.0.6.tar.gz

Patch0: gnuplot-4.2.0-refers_to.patch
Patch1: gnuplot-4.2.0-fonts.patch
Patch2: gnuplot-4.6.1-plot-sigsegv.patch
Patch3: gnuplot-4.6.4-singlethread.patch
Patch4: gnuplot-5.0.6-no-lena.patch
Patch5: gnuplot-5.0.6-add-lib-gobject-when-config.patch
Patch6: CVE-2020-25969.patch

BuildRequires: cairo-devel latex2html emacs gd-devel giflib-devel libotf libpng-devel
BuildRequires: librsvg2 texinfo libX11-devel libXt-devel lua-devel  m17n-lib tex-tex4ht
BuildRequires: tex(ecrm1000.tfm) tex(subfigure.sty) tex(cm-super-t1.enc) tex(pdftex.map)
BuildRequires: zlib-devel libjpeg-turbo-devel pango-devel qt5-linguist tex(latex)
BuildRequires: qt5-qtsvg-devel  qt5-qtbase-devel /usr/bin/texi2dvi

Requires: tex-preview dejavu-sans-fonts
Requires: tex(latex) tex(cm-super-t1.enc) tex(ecrm1000.tfm) tex(utf8x.def)

Requires(post): %{_sbindir}/alternatives /sbin/install-info
Requires(preun): %{_sbindir}/alternatives /sbin/install-info

Obsoletes: gnuplot-qt < 5.0.0-4

Obsoletes: %{name}-common = %{version}-%{release}
Provides: %{name}-common = %{version}-%{release}
Obsoletes: %{name}-minimal = %{version}-%{release}
Obsoletes: %{name}-minimal = %{version}-%{release}
Provides: %{name}-latex = %{version}-%{release}
Provides: %{name}-latex = %{version}-%{release}

Obsoletes: emacs-%{name} <= 5.0.0-3
Obsoletes: emacs-%{name}-el <= 5.0.0-3

%description
Gnuplot is a portable command-line driven graphing utility for Linux, OS/2, MS
Windows, OSX, VMS, and many other platforms. The source code is copyrighted but
freely distributed (i.e., you don't have to pay for it). It was originally
created to allow scientists and students to visualize mathematical functions and
data interactively, but has grown to support many non-interactive uses such as
web scripting. It is also used as a plotting engine by third-party applications
like Octave. Gnuplot has been supported and under active development since 1986.

%package_help

%prep
%autosetup -p1
rm -rf demo/lena*

sed -i -e 's:"/usr/lib/X11/app-defaults":"%{_datadir}/X11/app-defaults":' src/gplt_x11.c
iconv -f windows-1252 -t utf-8 ChangeLog > ChangeLog.aux
ln -sf ChangeLog.aux ChangeLog
chmod 644 src/getcolor.h demo/html/webify*

%build

%global configure_opts \\\
        --with-readline=builtin \\\
        --without-linux-vga \\\
        --enable-history-file
mkdir minimal
pushd minimal
cp -a ../configure .
%configure %{configure_opts} \
           --disable-wxwidgets \
           --without-qt
%make_build
popd

mkdir qt
pushd qt
cp -a ../configure .
%configure %{configure_opts} \
           --disable-wxwidgets \
           --enable-qt
%make_build
popd

%configure  %{configure_opts} \
            --with-tutorial
ln -s ../minimal/src/%{name} src/
make -C docs html info
export GNUPLOT_PS_DIR=../../term/PostScript
make -C docs/psdoc ps_symbols.ps ps_fontfile_doc.pdf
make -C tutorial

%install
make -C qt install DESTDIR=%{buildroot} INSTALL='install -p'
cp -a %{buildroot}%{_bindir}/%{name} %{buildroot}%{_bindir}/%{name}-qt
install -p -m 755 minimal/src/%{name} %{buildroot}%{_bindir}/%{name}-minimal
make -C docs install-info DESTDIR=%{buildroot} INSTALL='install -p'
install -d %{buildroot}%{_datadir}/X11/app-defaults
cp -a %{buildroot}%{_datadir}/%{name}/%{major_minor}/app-defaults/Gnuplot %{buildroot}%{_datadir}/X11/app-defaults/Gnuplot
install -d %{buildroot}/%{_mandir}/ja/man1
cp -a %{buildroot}%{_mandir}/man1/%{name}-ja.1 %{buildroot}/%{_mandir}/ja/man1/
touch %{buildroot}%{_bindir}/%{name}

%posttrans
%{_sbindir}/alternatives --install %{_bindir}/%{name} %{name} %{_bindir}/%{name}-qt 61
%{_sbindir}/alternatives --install %{_bindir}/%{name} %{name} %{_bindir}/%{name}-minimal 40

%post
if [ -f %{_infodir}/%{name}.info* ]; then
    /sbin/install-info %{_infodir}/%{name}.info %{_infodir}/dir || :
fi
[ -e %{_bindir}/texhash ] && %{_bindir}/texhash 2> /dev/null;

%preun
if [ $1 = 0 ]; then
    %{_sbindir}/alternatives --remove %{name} %{_bindir}/%{name}-qt || :
    %{_sbindir}/alternatives --remove %{name} %{_bindir}/%{name}-minimal || :
    if [ -f %{_infodir}/%{name}.info* ]; then
        /sbin/install-info --delete %{_infodir}/%{name}.info %{_infodir}/dir || :
    fi
fi

%files
%ghost %attr(0755,-,-) %{_bindir}/%{name}
%{_bindir}/%{name}-qt
%{_libexecdir}/%{name}/%{major_minor}/%{name}_qt
%{_datadir}/%{name}/%{major_minor}/qt/
%dir %{_datadir}/%{name}
%dir %{_datadir}/%{name}/%{major_minor}
%dir %{_datadir}/%{name}/%{major_minor}/PostScript
%{_datadir}/%{name}/%{major_minor}/PostScript/*.ps
%{_datadir}/%{name}/%{major_minor}/PostScript/aglfn.txt
%dir %{_datadir}/%{name}/%{major_minor}/js
%{_datadir}/%{name}/%{major_minor}/js/*
%dir %{_datadir}/%{name}/%{major_minor}/lua/
%{_datadir}/%{name}/%{major_minor}/lua/%{name}-tikz.lua
%{_datadir}/%{name}/%{major_minor}/colors_*
%{_datadir}/%{name}/%{major_minor}/%{name}.gih
%{_datadir}/%{name}/%{major_minor}/%{name}rc
%dir %{_libexecdir}/%{name}
%dir %{_libexecdir}/%{name}/%{major_minor}
%{_libexecdir}/%{name}/%{major_minor}/%{name}_x11
%{_datadir}/X11/app-defaults/Gnuplot
%{_infodir}/%{name}.info.gz
%{_bindir}/%{name}-minimal
%{_datadir}/texmf/tex/latex/%{name}/
%exclude %{_infodir}/dir
%exclude %{_datadir}/%{name}/%{major_minor}/app-defaults/Gnuplot

%files help
%doc BUGS Copyright ChangeLog README NEWS
%{_mandir}/man1/%{name}.1.gz
%{_mandir}/ja/man1/%{name}-ja.1.gz
%doc docs/psdoc/ps_guide.ps
%doc docs/psdoc/ps_symbols.ps
%doc tutorial/tutorial.dvi
%doc docs/psdoc/ps_file.doc demo
%doc docs/psdoc/ps_fontfile_doc.pdf
%doc docs/htmldocs tutorial/eg7.eps
%exclude %{_mandir}/man1/%{name}-ja.1*

%changelog
* Thu Jul 13 2023 yaoxin <yao_xin001@hoperun.com> - 5.0.6-14
- Fix CVE-2020-25969

* Tue Nov 22 2022 Ge Wang <wangge20@h-partners.com> - 5.0.6-13
- Bring source file into correspondence with described in spec file

* Mon Feb 17 2020 Tianfei <tianfei16@huawei.com> - 5.0.6-12
- Package init
