%define	modeversion 0.7.0

Name:		gnuplot
Summary:	A program for plotting mathematical expressions and data
Version:	5.4.5
Release:	%mkrel 1
License:	Freeware-like
Group:		Sciences/Other
URL:		http://www.gnuplot.info/
Source0:	https://download.sourceforge.net/gnuplot/%{name}-%{version}.tar.gz
Source1:	https://github.com/bruceravel/gnuplot-mode/archive/%{modeversion}/%{name}-mode-%{modeversion}.tar.gz
Source2:	http://www.gnuplot.info/faq/faq.html
Source11:	%{name}.16.png
Source12:	%{name}.32.png
Source13:	%{name}.48.png
#
Patch0:		gnuplot-mode-0.7.0-disable-f9.patch
Patch1:		gnuplot-5.2.2-link-gobject.patch
#
# from gentoo: avoid usage of missed picins.sty
Patch2:		gnuplot-5.0.6-no-picins.patch
#
# from fedora
Patch21: gnuplot-4.2.0-fonts.patch
Patch23: gnuplot-4.6.1-plot-sigsegv.patch
Patch24: gnuplot-4.6.4-singlethread.patch
Patch25: gnuplot-5.0.0-lua_checkint.patch
Patch28: gnuplot-5.2.8-cmd-opts.patch
Patch29: gnuplot-config.patch
#
# from opensuse
Patch40: gnuplot-5.4.5-fonts.patch
Patch41: gnuplot-4.6.0-demo.patch
Patch42: gnuplot-4.4.0-x11ovf.patch
Patch43: gnuplot-wx3.patch
Patch44: gnuplot-QtCore-PIC.patch
Patch45: gnuplot-gd.patch
Patch46: gnuplot-5.4.0-rediffed.patch
Patch47: gnuplot-5.4.4-grep.patch
#
# from arch
Patch60: lua53_compat.patch
#
# git upstream
Patch90: 7546863b2161f3efb87d687419a0e033c9315768.patch
Patch91: ae7069d2902ab3402aee0c856e44bc5c058e2c94.patch
Patch92: 6c752c3531842c5b78f3167f8339379c628be1cc.patch

BuildRequires:	pkgconfig(x11)
BuildRequires:	pkgconfig(libcerf)
BuildRequires:	emacs-bin
BuildRequires:	pkgconfig(ncurses)
BuildRequires:	pkgconfig(libpng)
BuildRequires:	readline-devel
BuildRequires:	texlive
BuildRequires:	texlive-texmf
BuildRequires:	texinfo
BuildRequires:	pkgconfig(gdlib)
BuildRequires:	pkgconfig(cairo)
BuildRequires:	pkgconfig(lua)
BuildRequires:	wxgtk-devel >= 3.1.2
BuildRequires:	qttools5
BuildRequires:	pkgconfig(Qt5Core)
BuildRequires:	pkgconfig(Qt5Gui)
BuildRequires:	pkgconfig(Qt5Network)
BuildRequires:	pkgconfig(Qt5Svg)
BuildRequires:	pkgconfig(Qt5PrintSupport)

Requires:	%{name}-nox = %{version}-%{release}

%description
Gnuplot is a command-line driven, interactive function plotting program
especially suited for scientific data representation. Gnuplot can be used to
plot functions and data points in both two and three dimensions and in many
different formats.

Install gnuplot if you need a graphics package for scientific data
representation.

%package qt
Summary:        A program for plotting mathematical expressions and data
Group:          Sciences/Other
Requires:       %{name} = %{version}-%{release}

%description qt
Gnuplot is a command-line driven, interactive function plotting program
especially suited for scientific data representation. Gnuplot can be used to
plot functions and data points in both two and three dimensions and in many
different formats.

Install gnuplot-qt if you need a graphics package for scientific data
representation.

%package nox
Summary:	A program for plotting mathematical expressions and data
Group:		Sciences/Other
Obsoletes:	%{name}-doc < 4.4.4-3
Provides:	%{name}-doc = %{version}-%{release}

%description nox
Gnuplot is a command-line driven, interactive function plotting program
especially suited for scientific data representation. Gnuplot can be used to
plot functions and data points in both two and three dimensions and in many
different formats.

Install gnuplot if you need a graphics package for scientific data
representation.

This package provides GNUPlot without any X dependency.

%package mode
Summary:	Yet another Gnuplot mode for Emacs
Group:		Sciences/Other

%description mode
Gnuplot is a major mode for Emacs flavours with the following features:

 - Functions for plotting lines, regions, entire scripts, or entire files
 - Graphical interface to setting command arguments
 - Syntax colorization
 - Completion of common words in Gnuplot
 - Code indentation
 - On-line help using Info for Gnuplot functions and features
 - Interaction with Gnuplot using comint
 - Pull-down menus plus a toolbar in XEmacs
 - Distributed with a quick reference sheet in postscript.

%prep
%setup -q -a 1
%autopatch -p1

perl -pi -e 's|(^\s*)mkinstalldirs\s|$1./mkinstalldirs |' gnuplot-mode-%{modeversion}/Makefile.in
# Non-free stuff. Ouch. -- Geoff
rm -f demo/prob.dem demo/prob2.dem

%build
autoreconf -vfi
export CFLAGS="%{optflags} -fno-fast-math"
export CXXFLAGS="%{optflags} -std=gnu++11"
export CONFIGURE_TOP=..

mkdir build-nox
pushd build-nox
	%configure \
		--with-readline=gnu \
		--without-linux-vga \
		--without-x \
		--without-qt \
		--disable-wxwidgets
	%make_build -C src
	make -C docs ps
	make -C docs pdf
popd

mkdir build-x11
pushd build-x11
	%configure \
		--with-readline=gnu \
		--without-linux-vga \
		--without-qt
	%make_build
popd

mkdir build-qt
pushd build-qt
	%configure \
		--with-readline=gnu \
		--without-linux-vga \
		--with-qt
	%make_build
popd

unset CONFIGURE_TOP
pushd gnuplot-mode-%{modeversion}
	%configure
	%make_build
popd

cp -f %SOURCE2 .
chmod 644 faq.html

%install

pushd build-qt
	%make_install
	mv %{buildroot}%{_bindir}/gnuplot %{buildroot}%{_bindir}/gnuplot-qt
popd

pushd build-nox
	%make_install
	mv %{buildroot}%{_bindir}/gnuplot %{buildroot}%{_bindir}/gnuplot-nox
popd

pushd build-x11
	%make_install
popd

pushd gnuplot-mode-%{modeversion}
	%make_install
	pdflatex gpelcard
	install -d %{buildroot}%{_sysconfdir}/emacs/site-start.d
	install -m 644 dotemacs.el %{buildroot}%{_sysconfdir}/emacs/site-start.d/%{name}.el
popd


# Copy back from build dir to be able to package those files
pushd build-nox
	cp -p docs/*.pdf ../docs/
	cp -p docs/*.ps ../docs/
popd

# menu

mkdir -p %{buildroot}%{_datadir}/applications
cat > %{buildroot}%{_datadir}/applications/%{_real_vendor}-%{name}.desktop << EOF
[Desktop Entry]
Name=Gnuplot
GenericName=Function plotting program
GenericName[ru]=Построение графиков функций
Comment=The famous function plotting program
Comment[af]=Die welbekende funksieplotprogram
Comment[ar]=برنامج تحديد الوظائف الشهير
Comment[az]=Funksiya çap edici proqram
Comment[bg]=Програма за чертане с плотер
Comment[bn]=ফাংশন প্লট অঙ্কনকারী বিখ্যাত প্রোগ্রাম
Comment[bs]=Poznati program za crtanje funkcija
Comment[ca]=El conegut programa de funcions d'impressió amb traçador
Comment[cs]=Známý program pro vytváření grafů funkcí
Comment[cy]=Rhaglen plotio swyddogaeth enwog
Comment[da]=Det berømte funktion-plotteprogram
Comment[de]=Das berühmte Programm zur Darstellung mathematischer Funktionen
Comment[el]=Το διάσημο πρόγραμμα σχεδίασης μαθηματικών συναρτήσεων
Comment[es]=El programa famoso de graficado de funciones
Comment[et]=Kuulus funktsioonide joonistamise rakendus
Comment[eu]=Funtzioak marrazteko programa ospetsua
Comment[fa]=برنامه‌ی مشهور ترسیم تابع
Comment[fi]=Kuuluisa kuvaajienpiirto-ohjelma
Comment[fr]=Le fameux programme de traçage de fonction
Comment[gl]=O famoso programa de representación de funcións
Comment[he]=תוכנת ציור הפונקציות המפורסמת
Comment[hi]=एक प्रसिद्ध फ़ंक्शन प्लौटिंग प्रोग्राम
Comment[hr]=ÄŒuveni program za crtanje funkcija
Comment[hu]=Elterjedt függvényábrázoló
Comment[id]=Program plot terkenal
Comment[is]=Víðfrægt falla-teikniforrit
Comment[it]=Il famoso programma per tracciare funzioni
Comment[ja]=有名な関数プロットソフト
Comment[ky]=Белгилүү функция сызуучу програм
Comment[lt]=Garsioji funkcijų braižymų programa
Comment[lv]=Slavenā programma funkciju zīmēšanai
Comment[mk]=Познатиот програм за цртање графици на функции
Comment[mt]=Programm famuż li jipplottja funzjonijiet
Comment[nb]=Det berømte plotteprogrammet
Comment[nl]=Het beroemde functie-plotprogramma (grafieken van functies)
Comment[nn]=Eit program for plotting av funksjonar
Comment[pl]=Słynny program do rysowania wykresów
Comment[pt]=O famoso programa de gráficos de funções
Comment[pt_BR]=O famoso programa para plotagem de funções
Comment[ro]=Faimosul program de trasare de funcții
Comment[ru]=Знаменитая программа для построения графиков функций
Comment[sc]=Su programa po fai plot de funtzionis
Comment[sk]=Plotting program s mnohými funkciami
Comment[sl]=Znani program za risanje funkcij
Comment[sq]=Program me famë të funksioneve gjurmuese
Comment[sr]=Познати функционални плотинг програм
Comment[sr@Latn]=Poznati funkcionalni ploting program
Comment[sv]=Det berömda programmet för funktionsplotting
Comment[ta]=gவரைவியல்
Comment[tg]=Барномаи машҳури нақшакашии вазифоӣ
Comment[th]=โปรแกรมวาดรูปฟังชั่น
Comment[tl]=Ang tanyag na program na nagpa-plot ng function
Comment[tr]=Fonksiyon çizim programı
Comment[uk]=Відома програма для побудови графіків функцій
Comment[vi]=Chương trình có chức năng vẽ nổi tiếng
Comment[wa]=Li fameus programe di traçaedje di fonccions
Comment[zh_CN]=绘制函数图像
Comment[zh_TW]=著名的函數繪製程式
Exec=%{name}
Icon=%{name}
Terminal=true
Type=Application
StartupNotify=true
Categories=Graphics;Science;
EOF

mkdir -p %{buildroot}%{_datadir}/applications
cat > %{buildroot}%{_datadir}/applications/%{_real_vendor}-%{name}-qt.desktop << EOF
[Desktop Entry]
Name=Gnuplot Qt5
GenericName=Function plotting program
GenericName[ru]=Построение графиков функций
Comment=The famous function plotting program
Comment[af]=Die welbekende funksieplotprogram
Comment[ar]=برنامج تحديد الوظائف الشهير
Comment[az]=Funksiya çap edici proqram
Comment[bg]=Програма за чертане с плотер
Comment[bn]=ফাংশন প্লট অঙ্কনকারী বিখ্যাত প্রোগ্রাম
Comment[bs]=Poznati program za crtanje funkcija
Comment[ca]=El conegut programa de funcions d'impressió amb traçador
Comment[cs]=Známý program pro vytváření grafů funkcí
Comment[cy]=Rhaglen plotio swyddogaeth enwog
Comment[da]=Det berømte funktion-plotteprogram
Comment[de]=Das berühmte Programm zur Darstellung mathematischer Funktionen
Comment[el]=Το διάσημο πρόγραμμα σχεδίασης μαθηματικών συναρτήσεων
Comment[es]=El programa famoso de graficado de funciones
Comment[et]=Kuulus funktsioonide joonistamise rakendus
Comment[eu]=Funtzioak marrazteko programa ospetsua
Comment[fa]=برنامه‌ی مشهور ترسیم تابع
Comment[fi]=Kuuluisa kuvaajienpiirto-ohjelma
Comment[fr]=Le fameux programme de traçage de fonction
Comment[gl]=O famoso programa de representación de funcións
Comment[he]=תוכנת ציור הפונקציות המפורסמת
Comment[hi]=एक प्रसिद्ध फ़ंक्शन प्लौटिंग प्रोग्राम
Comment[hr]=ÄŒuveni program za crtanje funkcija
Comment[hu]=Elterjedt függvényábrázoló
Comment[id]=Program plot terkenal
Comment[is]=Víðfrægt falla-teikniforrit
Comment[it]=Il famoso programma per tracciare funzioni
Comment[ja]=有名な関数プロットソフト
Comment[ky]=Белгилүү функция сызуучу програм
Comment[lt]=Garsioji funkcijų braižymų programa
Comment[lv]=Slavenā programma funkciju zīmēšanai
Comment[mk]=Познатиот програм за цртање графици на функции
Comment[mt]=Programm famuż li jipplottja funzjonijiet
Comment[nb]=Det berømte plotteprogrammet
Comment[nl]=Het beroemde functie-plotprogramma (grafieken van functies)
Comment[nn]=Eit program for plotting av funksjonar
Comment[pl]=Słynny program do rysowania wykresów
Comment[pt]=O famoso programa de gráficos de funções
Comment[pt_BR]=O famoso programa para plotagem de funções
Comment[ro]=Faimosul program de trasare de funcții
Comment[ru]=Знаменитая программа для построения графиков функций
Comment[sc]=Su programa po fai plot de funtzionis
Comment[sk]=Plotting program s mnohými funkciami
Comment[sl]=Znani program za risanje funkcij
Comment[sq]=Program me famë të funksioneve gjurmuese
Comment[sr]=Познати функционални плотинг програм
Comment[sr@Latn]=Poznati funkcionalni ploting program
Comment[sv]=Det berömda programmet för funktionsplotting
Comment[ta]=gவரைவியல்
Comment[tg]=Барномаи машҳури нақшакашии вазифоӣ
Comment[th]=โปรแกรมวาดรูปฟังชั่น
Comment[tl]=Ang tanyag na program na nagpa-plot ng function
Comment[tr]=Fonksiyon çizim programı
Comment[uk]=Відома програма для побудови графіків функцій
Comment[vi]=Chương trình có chức năng vẽ nổi tiếng
Comment[wa]=Li fameus programe di traçaedje di fonccions
Comment[zh_CN]=绘制函数图像
Comment[zh_TW]=著名的函數繪製程式
Exec=%{name}
Icon=%{name}
Terminal=true
Type=Application
StartupNotify=true
Categories=Graphics;Science;Qt;
EOF


# icon
install -m644 %{SOURCE11} -D %{buildroot}%{_miconsdir}/%{name}.png
install -m644 %{SOURCE12} -D %{buildroot}%{_iconsdir}/%{name}.png
install -m644 %{SOURCE13} -D %{buildroot}%{_liconsdir}/%{name}.png

install -m644 %{SOURCE11} -D %{buildroot}%{_miconsdir}/%{name}-qt.png
install -m644 %{SOURCE12} -D %{buildroot}%{_iconsdir}/%{name}-qt.png
install -m644 %{SOURCE13} -D %{buildroot}%{_liconsdir}/%{name}-qt.png

%files
%{_bindir}/gnuplot
%{_datadir}/applications/%{_real_vendor}-%{name}.desktop
%{_miconsdir}/%{name}.png
%{_iconsdir}/%{name}.png
%{_liconsdir}/%{name}.png

%files qt
%{_bindir}/gnuplot-qt
%{_datadir}/applications/%{_real_vendor}-%{name}-qt.desktop
%{_miconsdir}/%{name}-qt.png
%{_iconsdir}/%{name}-qt.png
%{_liconsdir}/%{name}-qt.png

%files nox
%doc demo docs/psdoc docs/gnuplot.pdf docs/gnuplot.ps
%doc Copyright faq.html
%doc README
%doc NEWS
%{_bindir}/gnuplot-nox
%{_mandir}/*/*
%{_libexecdir}/gnuplot
%{_datadir}/gnuplot
%{_datadir}/texmf-local/tex/latex/gnuplot

%files mode
%doc gnuplot-mode-%{modeversion}/gpelcard.pdf
%config(noreplace) %{_sysconfdir}/emacs/site-start.d/*.el
%{_datadir}/emacs/site-lisp/*