## lyx-fonts
%global fontname lyx
BuildRequires: make
BuildRequires: fontpackages-devel

%global _without_included_boost --without-included-boost
%global texmf %{_datadir}/texlive/texmf-dist

# Do we need to rebuild configuration files?
%global autotools 0

# Trim changelog to a reasonable size
%global _changelog_trimtime %(date +%s -d "1 year ago")

Name:    lyx
Version: 2.3.7
Release: 1%{?dist}
Summary: WYSIWYM (What You See Is What You Mean) document processor
License: GPLv2+
Url:     https://www.lyx.org/
Source0: http://ftp.lyx.org/pub/lyx/stable/2.3.x/lyx-%{version}-1.tar.xz

Source1: lyxrc.dist

# font metainfo file
Source20: %{fontname}.metainfo.xml

## upstreamable patches
# already part of 2.4.x source and fixes
# https://bugzilla.redhat.com/show_bug.cgi?id=1965118
Patch1:  lyx-2.3.6-layout2layout.patch

# workaround/fix cases of: #!/usr/bin/env python
# https://bugzilla.redhat.com/show_bug.cgi?id=1649919
Patch51: lyx-2.3.6-python3.patch

%if 0%{?autotools}
BuildRequires: automake libtool
%endif
# weird but necessary to compare the supported qt version
# see http://comments.gmane.org/gmane.editors.lyx.devel/137498
BuildRequires: bc

%if 0%{?_without_included_boost:1}
BuildRequires: boost-devel
%endif

BuildRequires: gcc-c++
BuildRequires: desktop-file-utils
BuildRequires: enchant-devel
BuildRequires: file-devel
BuildRequires: gettext
BuildRequires: hunspell-devel
BuildRequires: mythes-devel
BuildRequires: python3-devel

BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Widgets)
BuildRequires: pkgconfig(Qt5Gui)
BuildRequires: pkgconfig(Qt5Svg)
BuildRequires: pkgconfig(Qt5X11Extras)

BuildRequires: texlive-texmf-fonts
BuildRequires: tex(dvips)
BuildRequires: tex(latex)
BuildRequires: zlib-devel
%if 0%{?fedora}
BuildRequires: libappstream-glib
%endif

Requires(post): texlive
Requires(postun): texlive
Requires: %{name}-common = %{version}-%{release}
Requires: %{fontname}-fonts = %{version}-%{release}

Requires: ghostscript
Requires: hicolor-icon-theme
Requires: ImageMagick
Requires: xdg-utils

## (mostly) TeX related deps
## some use file path because the package
## names changed between texlive-2007 and texlive>=2010
Requires: /usr/bin/dvipdfm

# Minimal LaTeX dependencies
# For example required to compile the User's Manual
Requires: tex(dvips)
Requires: tex(esint.map)
Requires: tex(esint.sty)
Requires: tex(latex)
Requires: tex(nomencl.sty)
Requires: tex(ulem.sty)
Requires: tex(xcolor.sty)
Requires: tex-epstopdf

%description
LyX is a modern approach to writing documents which breaks with the
obsolete "typewriter paradigm" of most other document preparation
systems.

It is designed for people who want professional quality output
with a minimum of time and effort, without becoming specialists in
typesetting.

The major innovation in LyX is WYSIWYM (What You See Is What You Mean).
That is, the author focuses on content, not on the details of formatting.
This allows for greater productivity, and leaves the final typesetting
to the backends (like LaTeX) that are specifically designed for the task.

With LyX, the author can concentrate on the contents of his writing,
and let the computer take care of the rest.

%package common
Summary:  Common files of %{name}
Requires: %{name} = %{version}-%{release}
BuildArch: noarch
%description common
%{Summary}.

%package fonts
Summary: Lyx/MathML fonts
# The actual license says "The author of these fonts, Basil K. Malyshev, has
# kindly granted permission to use and modify these fonts."
# One of the font files (wasy10) is separately licensed GPL+.
License: Copyright only and GPL+
Requires: fontpackages-filesystem
Provides:  mathml-fonts = 1.0-50
Provides:  lyx-cmex10-fonts = %{version}-%{release}
Provides:  lyx-cmmi10-fonts = %{version}-%{release}
Provides:  lyx-cmr10-fonts = %{version}-%{release}
Provides:  lyx-cmsy10-fonts = %{version}-%{release}
BuildArch: noarch
%description  fonts
A collection of Math symbol fonts for %{name}.


%prep

%autosetup -p1

# prefer xdg-open over alternatives in configuration
for prog in xv firefox kghostview pdfview xdvi
do
    sed -i -e "s/'$prog'/'xdg-open', '$prog'/" lib/configure.py
done

%if 0%{?autotools}
./autogen.sh
%endif


%build
%configure \
  --disable-dependency-tracking \
  --disable-rpath \
  --disable-silent-rules \
  --enable-build-type=release \
  --enable-optimization="%{optflags}" \
  --without-included-boost \
  --enable-qt5 \
  --with-enchant \
  --with-hunspell

%make_build


%install
%make_install

%py_byte_compile /usr/bin/python3 %{buildroot}%{_datadir}/lyx/lyx2lyx

# misc/extras
install -p -m644 -D %{SOURCE1} %{buildroot}%{_datadir}/lyx/lyxrc.dist

# Set up the lyx-specific class files where TeX can see them
mkdir -p %{buildroot}%{texmf}/tex/latex
mv %{buildroot}%{_datadir}/lyx/tex \
   %{buildroot}%{texmf}/tex/latex/lyx

# icon
install -p -D -m644 lib/images/lyx.png \
  %{buildroot}%{_datadir}/icons/hicolor/48x48/apps/lyx.png

install -p -D -m644 lib/images/lyx.svg \
  %{buildroot}%{_datadir}/icons/hicolor/scalable/apps/lyx.svg

# ghost'd files
touch %{buildroot}%{_datadir}/lyx/lyxrc.defaults
touch %{buildroot}%{_datadir}/lyx/{packages,textclass}.lst

# fonts
install -m 0755 -d %{buildroot}%{_fontdir}
mv %{buildroot}%{_datadir}/lyx/fonts/*.ttf %{buildroot}%{_fontdir}/
rm -rf %{buildroot}%{_datadir}/lyx/fonts

# Add AppStream metadata
install -Dm 0644 -p %{SOURCE20} \
        %{buildroot}%{_metainfodir}/%{fontname}.metainfo.xml

%find_lang %{name}

# bash completion
install -p -D -m 0644 lib/scripts/bash_completion %{buildroot}%{_sysconfdir}/bash_completion.d/lyx

## appdata
install -p -D lib/appdata.xml %{buildroot}%{_metainfodir}/lyx.appdata.xml


%check
desktop-file-validate %{buildroot}%{_datadir}/applications/lyx.desktop
appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/%{name}.appdata.xml ||:
# tests/test_filetools error bogus ( see http://bugzilla.redhat.com/723938 )
make -k check ||:


%postun common
if [ $1 -eq 0 ] ; then
  texhash >& /dev/null
fi

%posttrans common
texhash >& /dev/null

%files
%doc ANNOUNCE lib/CREDITS NEWS README
%license COPYING
%{_bindir}/*

%files common -f %{name}.lang
%{_mandir}/man1/*
%{_datadir}/applications/*.desktop
%{_datadir}/icons/hicolor/*/*/*
%{_datadir}/lyx/
%config(noreplace) %{_datadir}/lyx/lyxrc.dist
%ghost %{_datadir}/lyx/lyxrc.defaults
%ghost %{_datadir}/lyx/*.lst
%{texmf}/tex/latex/lyx/
%{_metainfodir}/lyx.appdata.xml
%{_sysconfdir}/bash_completion.d/lyx

%_font_pkg
%{_fontdir}/*.ttf
%doc lib/fonts/BaKoMaFontLicense.txt
%doc lib/fonts/ReadmeBaKoMa4LyX.txt
%{_metainfodir}/%{fontname}.metainfo.xml


%changelog
* Mon May 15 2023 wangtaozhi <wangtaozhi@kylinsec.com.cn> - 2.3.7-1
- Package init
