%global _use_internal_dependency_generator 0

%global tl_version 20180414
%global tl_epoch 7
%global shortname texlive
%global source_name %{shortname}-%{tl_version}-source

%{!?_texdir: %global _texdir %{_datadir}/texlive}
%{!?_texmf_var: %global _texmf_var %{_var}/lib/texmf}

# don't export private perl modules
%global __provides_exclude %{?__provides_exclude:%__provides_exclude|}^perl\\(
%global __requires_exclude %{?__requires_exclude:%__requires_exclude|}^perl\\((PDF::Reuse.*|Pedigree.*|TeXLive.*|Tk::path_tre)\\)

%global _configure ../configure

%global macrosdir %(d=%{_rpmconfigdir}/macros.d; [ -d $d ] || d=%{_sysconfdir}/rpm; echo $d)

# don't figure any perl requires
%global __perl_requires %{nil}
%global __find_provides %{nil}
%global __os_install_post /usr/lib/rpm/brp-compress %{nil}
%global __arch_install_post %{nil}

Name: texlive-extension
Version: %{tl_version}
Release: 2%{?dist}
Epoch: %{tl_epoch}
Summary: TeX formatting system
Group: Applications/Publishing
License: Artistic 2.0 and GPLv2 and GPLv2+ and LGPLv2+ and LPPL and MIT and Public Domain and UCD and Utopia
URL: http://tug.org/texlive/

BuildRequires: xz
BuildRequires: libXaw-devel
BuildRequires: libXi-devel
BuildRequires: ncurses-devel
BuildRequires: bison
BuildRequires: flex
BuildRequires: file
BuildRequires: perl(Digest::MD5)
BuildRequires: texinfo
BuildRequires: gcc-c++
BuildRequires: gd-devel
%if 0%{?system_teckit}
BuildRequires: teckit-devel >= 2.5.7
%endif
BuildRequires: freetype-devel
BuildRequires: libpng-devel
BuildRequires: zlib-devel
BuildRequires: poppler-devel
BuildRequires: zziplib-devel
BuildRequires: libicu-devel
BuildRequires: cairo-devel
BuildRequires: harfbuzz-devel
#BuildRequires: perl-generators
BuildRequires: pixman-devel
BuildRequires: graphite2-devel
BuildRequires: ghostscript-devel
BuildRequires: libpaper-devel
%if 0%{?system_potrace}
BuildRequires: potrace-devel
%endif
BuildRequires: autoconf
BuildRequires: automake
BuildRequires: libtool
BuildRequires: gmp-devel
BuildRequires: mpfr-devel
BuildRequires: chrpath

Source0: ftp://tug.org/historic/systems/texlive/2018/%{source_name}.tar.xz
Source1: texlive-licenses.tar.xz
# chktex
Source50: http://ctan.math.illinois.edu/systems/texlive/tlnet/archive/chktex.doc.tar.xz
Source51: http://ctan.math.illinois.edu/systems/texlive/tlnet/archive/chktex.tar.xz
# German language support
Source0489: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/babel-german.tar.xz
Source0490: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/babel-german.doc.tar.xz
Source2753: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/german.tar.xz
Source2754: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/german.doc.tar.xz
Source2756: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/germbib.tar.xz
Source2757: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/germbib.doc.tar.xz
Source4788: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/nomencl.tar.xz
Source4789: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/nomencl.doc.tar.xz
# add missing translator.sty
Source8032: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/translator.tar.xz
Source8033: ftp://tug.org/historic/systems/texlive/2018/tlnet-final/archive/translator.doc.tar.xz

Patch1: tl-kpfix.patch
Patch2: tl-format.patch
Patch3: texlive-20180414-selinux-context.patch
Patch5: texlive-2016-kpathsea-texlive-path.patch
# fixes from arch and upstream texlive for poppler 0.6x
Patch7: texlive-20180414-new-poppler.patch
# XML validity
Patch8: texlive-20180414-xml.patch
# python3 support and mangling shebang
Patch9: texlive-2017-python3.patch
# fix for poppler-0.63
Patch10: texlive-20180414-poppler-0.63.patch
# annocheck distro flag failures
Patch11: texlive-20180414-annocheck.patch
# CVE-2018-17407
Patch12: texlive-20180414-CVE-2018-17407.patch
# covscan
Patch13: texlive-20180414-covscan.patch

%description
%name includes many texlive extension which are dropped in RHEL

%package -n %{shortname}-chktex
Provides: tex-chktex = %{epoch}:%{tl_version}-%{release}
Provides: texlive-chktex-bin = %{epoch}:%{tl_version}-%{release}
Provides: tex-chktex-bin = %{epoch}:%{tl_version}-%{release}
Obsoletes: texlive-chktex-bin < 7:20170520
Provides: tex-chktex-doc = %{epoch}:%{tl_version}-%{release}
Provides: texlive-chktex-doc = %{epoch}:%{tl_version}-%{release}
Obsoletes: texlive-chktex-doc < 7:20170520
License: GPL+
Summary: Check for errors in LaTeX documents
Requires: texlive-base
Requires: texlive-kpathsea

%description -n %{shortname}-chktex
The program reports typographic and other errors in LaTeX
documents. Filters are also provided for checking the LaTeX
parts of CWEB documents.

%package -n %{shortname}-lacheck
Provides: tex-lacheck = %{epoch}:%{tl_version}-%{release}
Provides: texlive-lacheck-bin = %{epoch}:%{tl_version}-%{release}
Provides: tex-lacheck-bin = %{epoch}:%{tl_version}-%{release}
Obsoletes: texlive-lacheck-bin < 7:20170520
License: GPL+
Summary: LaTeX checker
Requires: texlive-base
Requires: texlive-kpathsea

%description -n %{shortname}-lacheck
Lacheck is a tool for finding common mistakes in LaTeX
documents. The distribution includes sources, and executables
for OS/2 and Win32 environments.

%package -n %{shortname}-babel-german
Provides: tex-babel-german = %{tl_version}
License: LPPL 1.3
Summary: Babel support for documents written in German
BuildArch: noarch
Requires: texlive-base
Requires: texlive-kpathsea-bin, tex-kpathsea
Provides: tex(austrian.ldf) = %{tl_version}
Provides: tex(german.ldf) = %{tl_version}
Provides: tex(germanb.ldf) = %{tl_version}
Provides: tex(naustrian.ldf) = %{tl_version}
Provides: tex(ngerman.ldf) = %{tl_version}
Provides: tex(ngermanb.ldf) = %{tl_version}
Provides: tex(nswissgerman.ldf) = %{tl_version}
Provides: tex(swissgerman.ldf) = %{tl_version}

%description -n %{shortname}-babel-german
The package defines LaTeX support, within the Babel package, of
German (including its Austrian dialect), in both 'old' and
'new' orthographies.

%package -n %{shortname}-german
Provides: tex-german = %{tl_version}
License: LPPL
Summary: Support for German typography
BuildArch: noarch
Requires: texlive-base
Requires: texlive-kpathsea-bin, tex-kpathsea
Provides: tex(german.sty) = %{tl_version}
Provides: tex(ngerman.sty) = %{tl_version}

%description -n %{shortname}-german
Supports the new German orthography (neue deutsche
Rechtschreibung).

%package -n %{shortname}-germbib
Provides: tex-germbib = %{tl_version}
License: Bibtex
Summary: German variants of standard BibTeX styles
BuildArch: noarch
Requires: texlive-base
Requires: texlive-kpathsea-bin, tex-kpathsea
Requires: tex(german.sty)
Provides: tex(bibgerm.sty) = %{tl_version}
Provides: tex(mynormal.sty) = %{tl_version}

%description -n %{shortname}-germbib
A development of the (old) german.sty, this bundle provides
German packages, BibTeX styles and documentary examples, for
writing documents with bibliographies. The author has since
developed the babelbib bundle, which (he asserts) supersedes
germbib.


%package -n %{shortname}-nomencl
Provides: tex-nomencl = %{tl_version}
License: LPPL
Summary: Produce lists of symbols as in nomenclature
BuildArch: noarch
Requires: texlive-base
Requires: texlive-kpathsea-bin, tex-kpathsea
Provides: tex(nomencl.sty) = %{tl_version}
Provides: tex(sample01.cfg) = %{tl_version}
Provides: tex(sample02.cfg) = %{tl_version}
Provides: tex(sample04.cfg) = %{tl_version}
Provides: tex(sample05.cfg) = %{tl_version}

%description -n %{shortname}-nomencl
Produces lists of symbols using the capabilities of the
MakeIndex program.

%package -n %{shortname}-translator
Summary: Easy translation of strings in LaTeX
BuildArch: noarch
License: LPPL or GPL+
Requires: texlive-base texlive-kpathsea
Requires: tex(keyval.sty)
Provides: tex(translator.sty) = %{tl_version}

%description -n %{shortname}-translator
This LaTeX package provides a flexible mechanism for
translating individual words into different languages. For
example, it can be used to translate a word like "figure" into,
say, the German word "Abbildung". Such a translation mechanism
is useful when the author of some package would like to
localize the package such that texts are correctly translated
into the language preferred by the user. This package is not
intended to be used to automatically translate more than a few
words.

%prep
%setup -q -c -T -a 0 -a 1
[ -e %{source_name} ] && mv %{source_name} source
%patch1 -p0
%patch2 -p1
%patch3 -p1
%patch5 -p0
%if 0%{?fedora} >= 28 || 0%{?rhel} >= 8
%patch7 -p1 -b .newpoppler
%patch10 -p1 -b .poppler-0.63.0
%endif
%patch11 -p1 -b .annocheck
%patch12 -p1
%patch13 -p1

%build
cd source
PREF=`pwd`/inst
rm -rf texk/
mkdir -p work
cd work
%configure \
   --prefix=$PREF --datadir=$PREF \
   --libdir=$PREF/lib \
   --includedir=$PREF/include \
   --datarootdir=$PREF/share \
   --mandir=$PREF/share/man \
   --infodir=$PREF/share/info \
   --exec_prefix=$PREF \
   --bindir=$PREF/bin \
   --with-system-zlib \
   --with-system-libpng \
   --with-system-xpdf \
   --with-system-gd \
%if 0%{?system_teckit}
   --with-system-teckit \
%endif
   --with-system-freetype2 \
   --with-system-poppler \
   --with-system-zziplib \
   --with-system-cairo \
   --with-system-icu \
   --with-system-harfbuzz \
   --with-system-graphite2 \
   --with-system-libgs \
   --with-system-pixman \
   --with-system-libpaper \
%if 0%{?system_potrace}
   --with-system-potrace \
%endif
   --with-pic \
   --with-xdvi-x-toolkit=xaw \
   --with-system-mpfr \
   --with-system-gmp \
   --disable-xindy \
   --disable-xindy-docs \
   --disable-xindy-make-rules \
   --enable-shared \
   --enable-compiler-warnings=max \
   --without-cxx-runtime-hack \
   --disable-native-texlive-build \
   --disable-t1utils \
   --disable-t1lib \
   --disable-psutils \
   --disable-biber \
   --disable-ptexenc \
   --disable-largefile \
   %ifarch aarch64 %{mips} %{power64} s390 s390x x86_64
   --disable-luajittex \
   --disable-mfluajit \
   %endif
   --disable-texk \
   --disable-rpath

# disable rpath
for i in `find . -name libtool`; do
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' $i
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' $i
done

make world %{?_smp_mflags} STRIPPROG=/bin/true STRIP=/bin/true

%install
# create directory tree
mkdir -p %{buildroot}%{_texdir}/../texmf
mkdir -p %{buildroot}%{_texdir}/texmf-config/web2c
mkdir -p %{buildroot}%{_texmf_var}
mkdir -p %{buildroot}%{_texdir}/texmf-dist
mkdir -p %{buildroot}%{_texdir}/texmf-local

# install lacheck and chktex
mkdir -p %{buildroot}%{_bindir} %{buildroot}%{_mandir}/man1
for f in lacheck chktex chkweb deweb ; do
cp -a source/inst/bin/$f %{buildroot}%{_bindir}
cp -a source/inst/share/man/man1/$f*  %{buildroot}%{_mandir}/man1/
done

# extract sources
# chktex
xz -dc %{SOURCE50} | tar x -C %{buildroot}%{_texdir}/
xz -dc %{SOURCE51} | tar x -C %{buildroot}%{_texdir}/
# babel-german
xz -dc %{SOURCE489} | tar x -C %{buildroot}%{_texdir}/texmf-dist
xz -dc %{SOURCE490} | tar x -C %{buildroot}%{_texdir}/texmf-dist
# german
xz -dc %{SOURCE2753} | tar x -C %{buildroot}%{_texdir}/texmf-dist
xz -dc %{SOURCE2754} | tar x -C %{buildroot}%{_texdir}/texmf-dist
# germbib
xz -dc %{SOURCE2756} | tar x -C %{buildroot}%{_texdir}/texmf-dist
xz -dc %{SOURCE2757} | tar x -C %{buildroot}%{_texdir}/texmf-dist
# nomencl
xz -dc %{SOURCE4788} | tar x -C %{buildroot}%{_texdir}/texmf-dist
xz -dc %{SOURCE4789} | tar x -C %{buildroot}%{_texdir}/texmf-dist
# translator
xz -dc %{SOURCE8032} | tar x -C %{buildroot}%{_texdir}/texmf-dist
xz -dc %{SOURCE8033} | tar x -C %{buildroot}%{_texdir}/texmf-dist

# nuke useless tlmgr packaging stuff and doc droppings
rm -rf %{buildroot}%{_texdir}/tlpkg
rm -rf %{buildroot}%{_texdir}/texmf-dist/tlpkg
rm -rf %{buildroot}%{_texdir}/texmf-dist/doc/man
rm -rf %{buildroot}%{_texdir}/texmf-dist/doc/info
rm -rf %{buildroot}%{_texdir}/texmf-dist/doc/texlive/texlive-common/tlmgr*
rm -rf %{buildroot}%{_texdir}/texmf-dist/doc/texlive/texlive-common/tlcockpit-packages.png
rm -rf %{buildroot}%{_texdir}/texmf-dist/doc/texlive/texlive-common/tlshell-macos.png

# Also nuke any sources that come out
rm -rf %{buildroot}%{_texdir}/texmf-dist/source

%files -n %{shortname}-chktex
%license gpl.txt
%{_bindir}/chktex
%{_bindir}/chkweb
%{_bindir}/deweb
%{_mandir}/man1/chktex.1*
%{_mandir}/man1/chkweb.1*
%{_mandir}/man1/deweb.1*
%{_texdir}/texmf-dist/chktex/
%{_texdir}/texmf-dist/scripts/chktex/
%doc %{_texdir}/texmf-dist/doc/chktex/

%files -n %{shortname}-lacheck
%license gpl.txt
%{_bindir}/lacheck
%{_mandir}/man1/lacheck.1*

%files -n %{shortname}-babel-german
%license lppl1.3.txt
%{_texdir}/texmf-dist/tex/generic/babel-german/
%doc %{_texdir}/texmf-dist/doc/generic/babel-german/

%files -n %{shortname}-german
%license lppl1.txt
%{_texdir}/texmf-dist/tex/generic/german/
%doc %{_texdir}/texmf-dist/doc/generic/german/

%files -n %{shortname}-germbib
%{_texdir}/texmf-dist/bibtex/bst/germbib/
%{_texdir}/texmf-dist/tex/latex/germbib/
%doc %{_texdir}/texmf-dist/doc/bibtex/germbib/

%files -n %{shortname}-nomencl
%license lppl1.txt
%{_texdir}/texmf-dist/makeindex/nomencl/
%{_texdir}/texmf-dist/tex/latex/nomencl/
%doc %{_texdir}/texmf-dist/doc/latex/nomencl/

%files -n %{shortname}-translator
%license lppl1.3.txt
%license gpl.txt
%{_texdir}/texmf-dist/tex/latex/translator/
%doc %{_texdir}/texmf-dist/doc/latex/translator/

%changelog
* Fri Feb 28 2020 Than Ngo <than@redhat.com> - 20180414-2
- added lacheck and chktex

* Mon Jan 13 2020 Than Ngo <than@redhat.com> - 20180414-1
- initial rpm for rhel8 
