File microtex.spec of Package microtex

#
# spec file for package microtex
#
# Copyright (c) 2021/22 Florian "sp1rit" <packaging@sp1rit.anonaddy.me>
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%if 0%{?suse_version} || 0%{?fedora_version}
%bcond_with bundled_fonts
%else
%bcond_without bundled_fonts
%endif

%if %{with bundled_fonts}
%define lm_path latinmodern-math.otf
%define xits_path XITSMath-Regular.otf
%else
%if 0%{?suse_version}
%define lm_package font(latinmodernmath)
# tumbleweed or leap 15.3 and up (XITS in leap is still called xits-math.otf)
%if 0%{?suse_version} > 1500 || 0%{?sle_version} >= 150300
%define xits_package font(xitsmath)
%endif
%endif
%if 0%{?fedora_version}
%define lm_package texlive-lm-math
%define xits_package texlive-xits
%endif
# replace with hardcoded path for repo publishing
%define lm_path %(fc-list -f "%%{file}\\n" "Latin Modern Math" | head -n1)
%define xits_path %(fc-list -f "%%{file}\\n" "XITS Math" | grep -iv "bold" | head -n1)
%endif

Name:           microtex
Version:        0
Release:        0
Summary:        A dynamic, cross-platform, and embeddable LaTeX rendering library
Group:          Development/Libraries/C and C++
License:        MIT
URL:            https://github.com/NanoMichael/MicroTeX
Source0:        %{name}-%{version}.tar.xz
Source99:       LICENSE
BuildRequires:  gcc-c++ meson pkgconfig
# CAIRO platform
BuildRequires:  pkgconfig(fontconfig)
BuildRequires:  pkgconfig(cairo)
BuildRequires:  pkgconfig(cairo-ft)
BuildRequires:  pkgconfig(pango)
BuildRequires:  pkgconfig(pangocairo)
# GTK demo
BuildRequires:  pkgconfig(gtkmm-3.0)
BuildRequires:  pkgconfig(gtksourceviewmm-3.0)
# QT platform
BuildRequires:  pkgconfig(Qt5Core)
BuildRequires:  pkgconfig(Qt5Gui)
# QT demo
BuildRequires:  pkgconfig(Qt5Widgets)

# microtex-font-{latinmodern,xits}-math
%if ! %{with bundled_fonts}
BuildRequires:  python3
BuildRequires:  fontforge >= 20200314
%if %{defined lm_package}
BuildRequires:  %{lm_package}
%endif
%if %{defined xits_package}
BuildRequires:  %{xits_package}
%endif
%endif

%global soversion    1
%global libname      lib%{name}%{soversion}
%global cairolibname lib%{name}-cairo%{soversion}
%global qtlibname    lib%{name}-qt%{soversion}

%global _description %{expand:
µTeX is a dynamic, cross-platform, and embeddable LaTeX rendering
library. Its main purpose is to display mathematical formulas
written in LaTeX. It can be embedded in applications on various
platforms (Android, iOS, Windows, Linux GTK, Qt...).}

%description %{_description}

%package -n     %{libname}
Summary:        A dynamic, cross-platform, and embeddable LaTeX rendering library
Group:          System/Libraries
Recommends:     %{name}-font-latinmodern-math
Suggests:       %{name}-font-xits-math

%package        devel
Summary:        Development files for %{name}
Group:          Development/Languages/C and C++
Requires:       %{libname} = %{version}


%package -n     %{cairolibname}
Summary:        Cairo platform for %{name}
Group:          System/Libraries
#Requires:       %%{libname} = %%{version}

%package        cairo-devel
Summary:        Development files for %{name}-cairo
Group:          Development/Languages/C and C++
Requires:       %{cairolibname} = %{version}

%package        gtk-demo
Summary:        µTeX gtkmm demo application
Group:			Development/Tools/Other
Requires:       %{cairolibname} = %{version}

%package -n     %{qtlibname}
Summary:        Qt5 platform for %{name}
Group:          System/Libraries
#Requires:       %%{libname} = %%{version}

%package        qt-devel
Summary:        Development files for %{name}-qt
Group:          Development/Languages/C and C++
Requires:       %{qtlibname} = %{version}

%package        qt-demo
Summary:        µTeX qt5 demo application
Group:			Development/Tools/Other
Requires:       %{qtlibname} = %{version}

%package        font-devel
Summary:        Script to create µTeX mappings
Group:          Productivity/Graphics/Other
Requires:       fontconfig

%if %{defined lm_package} || %{with bundled_fonts}
%package        font-latinmodern-math
Summary:        µTeX mapping for Latin Modern Math
Group:          Productivity/Graphics/Other
License:        LPPL-1.3c
%if ! %{with bundled_fonts}
Requires:       %{lm_package}
%endif
%endif
%if %{defined xits_package} || %{with bundled_fonts}
%package        font-xits-math
Summary:        µTeX mapping for XITS Math Regular
Group:          Productivity/Graphics/Other
License:        OFL-1.1
%if ! %{with bundled_fonts}
Requires:       %{xits_package}
%endif
%endif


%description -n %{libname} %{_description}

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%description -n %{cairolibname} %{_description}

%description    cairo-devel
The %{name}-cairo-devel package contains libraries and header files
for developing applications that use %{name}-cairo.

%description    gtk-demo
Contains a simple gtkmm application that can be used to test
µTeX/Cairo's capabilities.

%description -n %{qtlibname} %{_description}

%description    qt-devel
The %{name}-qt-devel package contains libraries and header files for
developing applications that use %{name}-qt.

%description    qt-demo
Contains a simple qt5 application that can be used to test
µTeX/Qt's capabilities.

%description    font-devel
Contains script to generate µTeX OTF font file mapping

%if %{defined lm_package} || %{with bundled_fonts}
%description    font-latinmodern-math
Contains a µTeX OTF font file mapping of "Latin Modern Math"
%endif
%if %{defined xits_package} || %{with bundled_fonts}
%description    font-xits-math
Contains a µTeX OTF font file mapping of "XITS Math"
%endif


%prep
%autosetup -p1
cp %{_sourcedir}/LICENSE .
find example/ -name meson.build -exec \
	sed -E 's/microtex-([a-z0-9]+)-example/microtex-\1/' -i {} \;

%build
%meson \
	-DTARGET_DEVEL=true \
	-DTEST=true \
	-DCAIRO=true \
	-DEXAMPLE_GTK=true \
	-DQT=true \
	-DEXAMPLE_QT=true \
	-DGDI=disabled \
	-DEXAMPLE_WIN32=false

%meson_build

%install
%meson_install

%if %{with bundled_fonts}
install -Dm644 res/lm-math/latinmodern-math.{otf,clm2} -t %{buildroot}%{_datadir}/%{name}/
install -Dm644 res/xits/XITSMath-Regular.{otf,clm2} -t %{buildroot}%{_datadir}/%{name}/
pushd prebuilt
%else
# build fonts
pushd prebuilt
mkdir -p %{buildroot}%{_datadir}/%{name}/
# LatinModern Math
%if %{defined lm_package}
./otf2clm.sh --single %{lm_path} true %{buildroot}%{_datadir}/%{name}/
ln -s %{lm_path} %{buildroot}%{_datadir}/%{name}/
%endif
# XITS Math
%if %{defined xits_package}
./otf2clm.sh --single %{xits_path} true %{buildroot}%{_datadir}/%{name}/
ln -s %{xits_path} %{buildroot}%{_datadir}/%{name}/
%endif
%endif

sed -e 's|/usr/bin/env sh|%{_bindir}/sh|' \
    -e 's|otf2clm.py|%{_libexecdir}/%{name}-otf2clm.py|' \
    -i otf2clm.sh
install -Dm755 otf2clm.py %{buildroot}%{_libexecdir}/%{name}-otf2clm.py 
install -Dm755 otf2clm.sh %{buildroot}%{_bindir}/%{name}-otf2clm 
popd

%post   -n %{libname}      -p /sbin/ldconfig
%postun -n %{libname}      -p /sbin/ldconfig
%post   -n %{cairolibname} -p /sbin/ldconfig
%postun -n %{cairolibname} -p /sbin/ldconfig
%post   -n %{qtlibname}    -p /sbin/ldconfig
%postun -n %{qtlibname}    -p /sbin/ldconfig

%files -n %{libname}
%license LICENSE
%dir %{_datadir}/%{name}/
%{_libdir}/lib%{name}.so.%{soversion}*

%files devel
%doc README.md
%doc readme/
%dir %{_includedir}/%{name}/
%dir %{_includedir}/%{name}/platform/
%{_includedir}/%{name}/{%{name}{,api,config,export}.h,atom,box,core,env,graphic,macro,otf,render,unimath,utils}
%{_libdir}/pkgconfig/%{name}.pc
%{_libdir}/lib%{name}.so

%files -n %{cairolibname}
%{_libdir}/lib%{name}-cairo.so.%{soversion}*

%files cairo-devel
%{_includedir}/%{name}/platform/cairo
%{_libdir}/pkgconfig/%{name}-cairo.pc
%{_libdir}/lib%{name}-cairo.so

%files gtk-demo
%{_bindir}/%{name}-gtk

%files -n %{qtlibname}
%{_libdir}/lib%{name}-qt.so.%{soversion}*

%files qt-devel
%{_includedir}/%{name}/platform/qt
%{_libdir}/pkgconfig/%{name}-qt.pc
%{_libdir}/lib%{name}-qt.so

%files qt-demo
%{_bindir}/%{name}-qt

%files font-devel
%{_bindir}/%{name}-otf2clm
%{_libexecdir}/%{name}-otf2clm.py
%if 0%{?mageia} && 0%{?mageia} <= 8
%dir %{_libexecdir}/__pycache__/
%{_libexecdir}/__pycache__/%{name}-otf2clm*
%endif


%if %{defined lm_package} || %{with bundled_fonts}
%files font-latinmodern-math
%{_datadir}/%{name}/%(basename %{lm_path})
%{_datadir}/%{name}/%(basename %{lm_path} | sed 's/otf/clm2/')
%endif
%if %{defined xits_package} || %{with bundled_fonts}
%files font-xits-math
%{_datadir}/%{name}/%(basename %{xits_path})
%{_datadir}/%{name}/%(basename %{xits_path} | sed 's/otf/clm2/')
%endif

%changelog
openSUSE Build Service is sponsored by