%global __provides_exclude_from %{_datadir}/%{name}/%{name}.py
%global __requires_exclude_from %{_datadir}/%{name}/%{name}.py

%global optflags %{optflags} -DGLM_ENABLE_EXPERIMENTAL

%define _texmf %(eval "echo `kpsewhich -expand-var '$TEXMFMAIN'`")

Name:           asymptote
Version:        2.83
Release:        %mkrel 1
Summary:        Powerful descriptive vector graphics language
Group:          Sciences/Other
License:        LGPLv3
URL:            http://asymptote.sourceforge.net
Source0:        https://downloads.sourceforge.net/asymptote/%{name}-%{version}.src.tgz
Source1:        xasy.desktop
Patch0:         asymptote-2.67-settings.patch

BuildRequires:  dvipdf
BuildRequires:  pkgconfig(freeglut)
BuildRequires:  imagemagick
BuildRequires:  latex
BuildRequires:  pkgconfig(ncurses)
BuildRequires:  pkgconfig(glm)
BuildRequires:  pkgconfig(gsl)
BuildRequires:  pkgconfig(fftw3)
BuildRequires:  pkgconfig(osmesa)
BuildRequires:  pkgconfig(bdw-gc)
BuildRequires:  pkgconfig(readline)
# requested for pyrcc5
BuildRequires:	python3-qt5-devel
BuildRequires:  texinfo-tex
Requires:       texlive
Requires(post): texlive
Requires(postun):texlive

%description
Asymptote is a powerful descriptive vector graphics language that provides
a natural coordinate-based framework for technical drawing. Labels and equations
are typeset with LaTeX, for high-quality PostScript output.

A major advantage of Asymptote over other graphics packages is that it is
a programming language, as opposed to just a graphics program.

%package gui
Summary:        GUI for Asymptote vector graphics language
Group:          Sciences/Other
Requires:       %{name} = %{version}-%{release}
Requires:       python3-cson
Requires:       python3-numpy
Requires:       python3-pillow-tk
Requires:       python3-qt5-svg
Requires:       python3-qt5-widgets
Requires:       python3-tkinter
BuildArch:      noarch

%description gui
Asymptote is a powerful descriptive vector graphics language that provides
a natural coordinate-based framework for technical drawing. Labels and equations
are typeset with LaTeX, for high-quality PostScript output.

A major advantage of Asymptote over other graphics packages is that it is
a programming language, as opposed to just a graphics program.

This package contains "xasy", a GUI for Asymptote.

%prep
%autosetup -p1
sed -i -e 's/_LIB_/%{_lib}/' -e 's/_GS_MAJOR_/9/' settings.cc

%build
%configure \
    --enable-gc=system \
    --with-latex=%{_texmf}/tex/latex \
    --with-context=%{_texmf}/tex/context

%make_build

%install
%make_install

# Fix info location
mv %{buildroot}%{_infodir}/%{name}/%{name}.info* %{buildroot}%{_infodir}

# Install desktop file
install -D -m644 %{SOURCE1} %{buildroot}%{_datadir}/applications/xasy.desktop

# Install icons
for size in 16x16 32x32 48x48; do
    install -d %{buildroot}%{_iconsdir}/hicolor/$size/apps
    convert -resize $size asy.ico %{buildroot}%{_iconsdir}/hicolor/$size/apps/asy.png
done

%post
texhash

%postun
texhash

%files
%doc %{_docdir}/%{name}
%{_bindir}/asy
%{_datadir}/%{name}
%exclude %{_datadir}/%{name}/GUI
%{_infodir}/asy-faq.info*
%{_infodir}/%{name}.info*
%{_mandir}/man1/asy.1*
%{_texmf}/tex/*/%{name}

%files gui
%{_bindir}/xasy
%{_datadir}/%{name}/GUI
%{_datadir}/applications/xasy.desktop
%{_iconsdir}/hicolor/*/apps/asy.png
%{_mandir}/man1/xasy.1*