File generate of Package Meta

#!/usr/bin/perl

require File::Temp;
require File::Glob;
require Archive::Tar;
require POSIX;

use English;
use Data::Dumper;
use strict;
use warnings;
use integer;
use attributes ();
use utf8;
use Cwd;

use File::Glob ':glob';
use Getopt::Std;

use IO::Handle;
use open OUT => ':utf8';
use open IN  => ':bytes';
use open ':std';

no warnings;

use File::Temp qw(:mktemp);
use File::Glob qw(:globally :case);
use Text::ParseWords;
use sort qw(stable);

use POSIX qw(setlocale LC_ALL mktime strftime);
use Date::Parse qw(str2time strptime);

use File::stat;
use File::Which qw(which where);

package main;
setlocale(LC_ALL, "POSIX");
my $has_avfsd = which('avfsd') || '';

my $vffont = which('vffont') || './vffont';
if (! -x $vffont) {
    system("gcc -O2 -DUNIX -DGCC -DMAPFONT chkfont.c -o vffont");
    $vffont = which('vffont') || './vffont';
    if (! -x $vffont) {
	print STDERR "Failed to compile vvffont tool\n";
	exit 2;
    }
}

our %opts=();
my $err = getopts('dmbPp:', \%opts);
if ($err != 1) {
    die "Known options:\
    -d		for debug
    -m		for main file system
    -b		for binary packages
    -p letter	for all noarch package below one letter
    -P		for all noarch packages (a-z)\n";
}
my @source=split('-', <basesystem/texlive-*-source.tar.xz>);
my $srcdate = $source[1];
my $version = substr($srcdate,0,4);
my $release = $srcdate;
my $noarch_release;
my $previous = "2022";
@source=split('-', <basesystem/biber-*.tar.*>);
@source=split('\.tar', "$source[1]");
my $biberversion = $source[0];

#
# Common use
#
my $cwd = `pwd`;
chomp($cwd);

#
#
# Clean out e.g mounts at SIGINT
#
my @clean = ();
sub cleaner {
    while (@clean) {
	my $c = pop(@clean);
	if (-e "$c") {
	    unlink($c);
	    next;
	}
	if ($c) {
	    &$c();
	}
    }
}
END { cleaner(); }
$SIG{INT} = sub { cleaner(); exit; };

#
# Open the spec file template for packages
#
if ( -x $has_avfsd) {
    my $handler = sub { `fusermount -u -z mnt/` if -d 'mnt/Meta.changes'; };
    `fusermount -q -u -z mnt/`;
    sleep(1.0);
    `avfsd -o ro,nodev,noexec,nosuid,intr,kernel_cache,noatime,large_read,auto_unmount,modules=subdir,subdir=$cwd mnt/`;
    sleep(1.0);
    if (-e 'mnt/Meta.changes') {
	push @clean, $handler;
    } else {
	print STDERR "NO avfsd running!!!\n";
	$has_avfsd = "";
    }
}

open(SED, '-|', 'sed', '-rn', '1{s/<.*[[:blank:]]rev="([[:digit:]]+)".*>/\1/p;}', 'packages/.osc/_files');
chomp($noarch_release = <SED>);
close SED;

my $source = "mnt/texlive-${srcdate}-source";
if ( ! -x $has_avfsd) {
    my $handler = sub { `fusermount -u -z mnt/` if -d "${source}" };
    `archivemount -r -o kernel_cache,intr,async_read "basesystem/texlive-${srcdate}-source.tar.xz" mnt/`;
    sleep(0.02);
    push @clean, $handler if -d "mnt/texlive-${srcdate}-source/";
} else {
    $source = "mnt/basesystem/texlive-${srcdate}-source.tar.xz#/texlive-${srcdate}-source";
}

my $kpseversion;
open(SED, '-|', "sed -rn '/^KPSEVERSION=/{p;q}' < ${source}/texk/kpathsea/configure");
chomp($kpseversion = <SED>);
close SED;
$kpseversion =~ s/.*=//;

my $ptexencversion;
open(SED, '-|', "sed -rn '/^PTEXENCVERSION=/{p;q}' < ${source}/texk/ptexenc/configure");
chomp($ptexencversion = <SED>);
close SED;
$ptexencversion =~ s/.*=//;

my $synctexversion;
open(SED, '-|', "cat < ${source}/texk/web2c/synctexdir/synctex_parser_version.txt");
chomp($synctexversion = <SED>);
close SED;

my @luaconfs=<${source}/libs/lua[0-9][0-9]/configure>;
# die "To many lua packages around" if @luaconfs != 1;
my $texluaversion52;
my $texluaversion53;
for my $conf (@luaconfs) {
    my $tlv;
    open(SED, '-|', "sed -rn '/^PACKAGE_VERSION=/{p;q}' < $conf");
    chomp($tlv = <SED>);
    close SED;
    $tlv =~ s/.*=//;
    $tlv =~ s/\'//g;
    $tlv =~ s/-//g;
    print STDERR "TeXLua Version $tlv\n";
    $texluaversion52 = $tlv if ($tlv =~ /5\.2/);
    $texluaversion53 = $tlv if ($tlv =~ /5\.3/);
}

my $texluajitversion;
open(SED, '-|', "sed -rn '/^PACKAGE_VERSION=/{p;q}' < ${source}/libs/luajit/configure");
chomp($texluajitversion = <SED>);
close SED;
$texluajitversion =~ s/.*=//;
$texluajitversion =~ s/\'//g;
$texluajitversion =~ s/-//g;

my $asymptoteversion;
open(SED, '-|', "sed -rn '/^PACKAGE_VERSION=/{p;q}' < ${source}/utils/asymptote/configure");
chomp($asymptoteversion = <SED>);
close SED;
$asymptoteversion =~ s/.*=//;
$asymptoteversion =~ s/\'//g;
$asymptoteversion =~ s/-//g;

### Setup start #########################################################################################

#my $tlnet   = "ftp://ftp.ctan.org/pub/tex/systems/texlive/tlnet";
my $tlnet   = "ftp://ftp.tug.org/texlive/tlnet";
#my $tlnet   = "ftp://ftp.tug.org/texlive/tlpretest";
my $tlpkg  = "$tlnet/tlpkg";
my $srcurl  = "$tlnet/archive";

my @subscripts = ('sty', 'cls', 'clo', 'cbx', 'bbx', 'lbx', 'def');
my $regsubscr = '\.(' . join('|', @subscripts) . ')$';

my @subothers = ('ldf', 'def', 'dat', 'dat.lua', 'cnf', 'cfg', 'map', 'enc', 'fd', 'tfm', 'vf', 'tex', 'rtx', 'jar');
my $regsuboth = '\.(' . join('|', @subothers) . ')$';

my @configs = ('mexconf.tex', 'cyrtex.cfg', 'cont-usr.tex', 'language.def', 'amsppt.sti',
               'pdftexconfig.tex', 'language.dat', 'language.dat.lua', 'texmf.cnf', 'mktex.cnf', 'latexmk.conf',
	       'texmfcnf.lua', 'fmtutil.cnf', 'updmap.cfg', 'XDvi', 'config.ps', 'config', 'dvipdfmx.cfg');
my @noreplace = ('texmf.cnf', 'fmtutil.cnf', 'texmfcnf.lua');

my @skip    = (
    ".*wintools.*",			# Win soft
    ".*texworks.*",			# Win soft
    "tcdialog.*",			# We have a separate dialog program
    "t1utils.*",			# We have a separate t1util package
    "psutils.*",			# We have a separate psutils package
    "dvi2tty.*",			# License problems
    "floatflt",				# License problems
    "sphack",				# License problems
    "xindy.*",				# Requires clisp
    "installfont.*",			# No download support
    "texlive-docindex.*",		# No auto update
    "texlive-msg-translations.*",	# No auto update
    "tlshell.*",			# No auto update
    "tlcockpit.*",			# No auto update
#   "texlive-scripts.*",		# Includes older scripts (Was: No auto update)
#   "xecyr.ARCH",			# Only Win
    "ebong.*",				# python2 based package
    "sympytexpackage.*"			# python2 based package
);
#
# Do not include into any SLES product
#
my $regexp = join '|', @skip;

#
# Packages with sources + doc but we skip sources
#
my @nosource = (
    "biber",
    "lualatex-doc",
    "koma-script",
);

# Compare with:
# https://www.tex.ac.uk/tex-archive/help/Catalogue/licenses.html
# https://www.tex.ac.uk/tex-archive/help/Catalogue/licenses.knuth.html
# https://license.opensuse.org/
#
my %licenses = (
    'apache2'	=> 'Apache-2.0',
    'apache'	=> 'Apache-1.0',
    'artistic2' => 'Artistic-2.0',
    'artistic'	=> 'Artistic-1.0',
    'bsd'	=> 'BSD-3-Clause',
    'fdl'	=> 'GFDL-1.3-or-later',
    'gfl'	=> 'LPPL-1.3c', # LPPL-1.3c-with-fonts-exception
    'gfsl'	=> 'LPPL-1.3c', # LPPL-1.3c-with-fonts-exception
    'gpl3'	=> 'GPL-3.0-or-later',
    'gpl2'	=> 'GPL-2.0-or-later',
    'gpl'	=> 'GPL-2.0-or-later',
    'lgpl'	=> 'LGPL-2.1-or-later',
    'lgpl3'	=> 'LGPL-3.0-or-later',
    'lgpl2.1'	=> 'LGPL-2.1-or-later',
    'lppl1.3'	=> 'LPPL-1.3c',
    'lppl1.2'	=> 'LPPL-1.2',
    'lppl1'	=> 'LPPL-1.0',
    'lppl'	=> 'LPPL-1.0',
    'knuth'	=> 'SUSE-TeX',
    'ofl'	=> 'OFL-1.1',
    'pd'	=> 'SUSE-Public-Domain'
);

#
# Map ldf files to the appropiate hyphen package
#
my %ldfmap = ();
open LIST, "ldf-map-hyhen" || die "Can't open ldf-map-hyhen: $!";
while (<LIST>) {
    next if m/^$/;
    next if m/^#.*/;
    chomp;
    my ($from, $to) = split(/\s+/, $_);
    $ldfmap{$from} = $to;
}
close LIST;

#
# Script extensions
#
my $subexe = '\.(rb|lua|pl|perl|sh|bash|csh|py|tlu)';

#
# Tools we don't have
#
my @noexec = ('pfaedit');

#
# Determined by
#
#   grep non-executable-script .build.log | grep -v /source/ | \
#   awk '{print $4}' | sed -u 's@.*/@@' | grep -vE '.*\.(rb|lua|pl|perl|sh|bash|csh|py|tlu)$'
#
my @non_executable_scripts = ('cleantmp', 'ctxtools', 'makepdf', 'makepdf', 'cleantmp', 'bibhtml', 'bibtexall',
'makedoc', 'updmap.my', 'makefakeMnSymbol', 'mklinks', 'doit', 'latex2pdf', 'tex-it', 'addpsctrl',
'grafig.shar', 'trimsee', 'idxuniq', 'runlatex', 'rundvips', 'makemfs', 'delfin', 'fancy-preview',
'fancy-preview', 'makedoc-patched', 'makedoc', 'make_Palatino', 'makefrutiger', 'makeberling',
'forarray', 'post-xxx-sample.txt', 'normtext.awk', 'getNewBibtex', 'simplify-rename.pe', 'listkeys',
'inst', 'jura2html', 'dat2tex', 'dat2tex', 'dvipdfm_call', 'startacroread', 'l1', 'l2', 'trans.pl',
'pst2pdf_for_latexmk', 'dvipdfmx_call', 'kickxdvi', 'makeall', 'testfont', 'makefont', 'addpsctrl',
'listbib', 'listings-ext.makemake', 'alt_getopt', 'fmk', 'tmk', 'emk', 'xmk', 'pmk', 'imk',
'rmk', 'cmk', 'bibtexall', 'make_unix', 'make_clean', 'makedoc', 'mktextfm', 'mktfm8z', 'mktextfm.ext',
'pst2pdf', 'pn2pdf', 'RunDoc', 'mksbadx', 'mksbtdx', 'mksbkdx', 'crd2sb', 'modulate', 'showenc',
'ruinpenc', 'rumakeindex', 'rubibtex', 'rubibtex.old', 'texi2dvi', 'letr', 'vntex-update-maps',
'compilefonts', 'install-tds', 'dvitogif89a', 'makeydoc', 'yplan', 'mptopdf', 'pstopdf');
my @shell_scripts = ('fontgen', 'docversion');
my @python_scripts = ('MacTT', 'OpenType', 'TrueType', 'WOFF');
#
### Setup end ###########################################################################################

my $count;
my $tlpfh;
my $tlpdb = "/tmp/texlive.tlpdb.XXXXXXXX";
#my $archive = tar::new();

-e "texlive.tlpdb.xz" or `wget --progress=bar:force -N $tlpkg/texlive.tlpdb.xz`;

($tlpfh, $tlpdb) = mkstemp($tlpdb);
push @clean, $tlpdb;

`xz -dc texlive.tlpdb.xz > $tlpdb`;

my @files = ();
my $sed = '\@^[[:blank:]](RELOC|texmf|texmf-dist)/.*/.*';
   $sed .= '\.(' . join('|', @subscripts) . '|' . join('|', @subothers) . ')$';
   $sed .= '@{ s@.*/@@gp }';
open(SED, '-|', 'sed', '-rn', $sed, $tlpdb);
chomp(@files = <SED>);
close SED;
my %allfiles = map { $_, 1 } @files;
@files = ();
my $sed = '\@^[[:blank:]](RELOC|texmf|texmf-dist)/tex/latex-dev/.*';
   $sed .= '\.(' . join('|', @subscripts) . '|' . join('|', @subothers) . ')$';
   $sed .= '@{ s@.*/@@gp }';
open(SED, '-|', 'sed', '-rn', $sed, $tlpdb);
chomp(@files = <SED>);
close SED;
my %devfiles = map { $_, 1 } @files;
@files = ();

my $sed = '\@^[[:blank:]](RELOC|texmf|texmf-dist)/doc/man/man[15]/.*\.[15]$';
   $sed .= '@{ s@.*/@@gp }';
open(SED, '-|', 'sed', '-rn', $sed, $tlpdb);
chomp(@files = <SED>);
close SED;
my %manfiles = map { $_, 1 } @files;
@files = ();

sub lseek {
    while (<>) {
	last if (@_ && /@_/);
	print $_;
    }
}
sub lnseek {
    while (<>) {
	if (@_ && /@_/) {
	    chomp;
	    s/@_//;
	    print $_;
	    last;
	}
	print $_;
    }
}
sub lskip {
    while (<>) {
	last if (@_ && /@_/);
    }
}

my @dirstack = cwd;
sub pushd ($)
{
    unshift @dirstack, $_[0];
    chdir $_[0];
}
sub popd ()
{
    @dirstack > 1 and shift @dirstack;
    chdir $dirstack[0];
}

sub packages;
sub doprovide;
sub filelist;
sub texmftree;
sub scripts;
sub reorder;

my %names = ();
my @packages = ();

my @tarball = ();
my $scx = 0;

my @docfiles = ();
my $scd = 0;

my @chmod = ();
my @runfiles = ();
my $scr = 0;

my @binfiles = ();
my $scb = 0;

my @srcfiles = ();
my $src = 0;

my %sc = ();

my $name;
my $target;
my $type;
my $flags;
my $pos;

my $global_source_counter;
my $install_lines;
my %versions;
my %pkg_licenses;
my %used_files;

#
# Compare strings before colon
#
sub compare {
    $a =~ s/:[[digit:]]*//;
    $b =~ s/:[[digit:]]*//;
    $a cmp $b;
}

#
# Collect all packages within one hash
#
$pos = 0;
seek $tlpfh, $pos, 0;
while (<$tlpfh>) {
    $pos++;
    next if ! /^name/;
    next if /^name[[:blank:]]+00/;
    next if /^name[[:blank:]]+($regexp)/;
    next if /^name[[:blank:]]+.*\.win32/;
    next if /^name[[:blank:]]+.*\.win32/;
    next if /^name[[:blank:]]+.*\.windows/;
    if (/^name[[:blank:]]+.*\.i386-linux$/) {
	s/^name[[:blank:]]+//;
	s/\.i386-linux$/.ARCH/;
	s/-bin$/-X_Y_Z/;
	chomp;
	$names{$_} = $pos;
	next;
    }
    next if /^name[[:blank:]]+.*\..*-.*/;
    s/^name[[:blank:]]+//;
    s/-bin$/-X_Y_Z/;
    chomp;
    $names{$_} = $pos;
}

#
# Make a copy of STDIN and STDOUT
#
open OLDIN, '<&', \*STDIN;
open OLDOUT, '>&', \*STDOUT;

# If specified jump further
#
goto MAIN if (exists $opts{b} && $opts{b});
goto MAIN if (exists $opts{m} && $opts{m});

#
# Collect the package entries for the texmf spec files
# that is no collections, schemes, and no binaries.
#

foreach (sort keys %names) {
    next if /^scheme-/;
    next if /^collection-/;
    next if /\.ARCH$/;
    push @packages, $_;
}

-d "targets" or mkdir("targets");

my @patches=();
my @flists=();
my @mvlist=();
my @rmlist=();
my @rqlist=();
my @mkdirs=();
my @rmdirs=();
my @rmfiles=();
my %mvfiles=();
my @reqpack=();
my $patch_hook;
my $macros_hook = 0;
my $source_hook = 0;
my $reorder_hook= 0;
my $script_hook = 0;

my %letter_split = (
	'b' => 'around-the-bend',
	'c' => 'bbding',
	'd' => 'biolett-bst',
	'e' => 'chapterfolder',
	'f' => 'confproc',
	'g' => 'datetime2-basque',
	'h' => 'dvdcoll',
	'i' => 'eskd',
	'j' => 'float',
	'k' => 'gitfile-info',
	'l' => 'hrlatex',
	'm' => 'ionumbers',
	'n' => 'latex-web-companion',
	'o' => 'lshort-slovak',
	'p' => 'menu',
	'q' => 'na-box',
	'r' => 'overlays',
	's' => 'plari',
	't' => 'pst-pdf',
	'u' => 'robustindex',
	'v' => 'simplified-latex',
	'w' => 'tablists',
	'x' => 'tikz-dimline',
	'y' => 'ucharcat',
	'z' => 'wrapfig'
);

sub pick_packages_by_letter {
  my ($packages, $letter) = @_;

  my @ret;
  my $next_letter = chr(ord($letter) + 1);
  for my $package (@$packages) {
    next if $letter ne 'z' && ($package cmp $letter_split{$next_letter}) >= 0;
    next if $letter ne 'a' && ($package cmp $letter_split{$letter}) < 0;
    push(@ret, $package);
  }

  return @ret;
}

for my $letter ('a'..'z') {

  $global_source_counter = 1;
  $install_lines = '';
  my @next_packages = pick_packages_by_letter(\@packages, $letter);
 
  if (exists $opts{p} && $opts{p}) {
    next unless $letter eq $opts{p};
  }

  -d "targets/texlive-specs-$letter" or system("osc co -o targets/texlive-specs-$letter -u Publishing:TeXLive/texlive-specs-$letter");

  #
  # Open the new main spec file
  #
  my $specfile = "targets/texlive-specs-$letter/texlive-specs-$letter.spec";
  open(my $specfh, '>', "$specfile.new");
  select $specfh;

  print "%define texlive_version  " . $version . "\n";
  print "%define texlive_previous " . $previous . "\n";
  print "%define texlive_release  " . $release . "\n";
  print "%define texlive_noarch   " . $noarch_release . "\n";
  print "%define biber_version    " . $biberversion . "\n";
  print "\n";

  print q(
#!BuildIgnore:          texlive
#!BuildIgnore:          texlive-scripts
#!BuildIgnore:          texlive-scripts-extra
#!BuildIgnore:          texlive-scripts-bin
#!BuildIgnore:          texlive-scripts-extra-bin
#!BuildIgnore:          texlive-gsftopk
#!BuildIgnore:          texlive-gsftopk-bin
#!BuildIgnore:          texlive-kpathsea
#!BuildIgnore:          texlive-kpathsea-bin

%global _varlib         %{_localstatedir}/lib
%global _libexecdir     %{_prefix}/lib

%define _texmfdistdir   %{_datadir}/texmf
%if 0%{texlive_version} >= 2013
%define _texmfmaindir   %{_texmfdistdir}
%define _texmfdirs      %{_texmfdistdir}
%else
%define _texmfmaindir   %{_libexecdir}/texmf
%define _texmfdirs      \{%{_texmfdistdir},%{_texmfmaindir}\}
%endif

%define _texmfconfdir   %{_sysconfdir}/texmf
%define _texmfvardir    %{_varlib}/texmf
%define _texmfcache     %{_localstatedir}/cache/texmf
%define _fontcache      %{_texmfcache}/fonts
#
%define _x11bin         %{_prefix}/bin
%define _x11lib         %{_libdir}
%define _x11data        %{_datadir}/X11
%define _x11inc         %{_includedir}
%define _appdefdir      %{_x11data}/app-defaults

%if ! %{defined python3_bin_suffix}
%global python3_bin_suffix 3
%endif

);

  print "Name:           texlive-specs-$letter\n";
  print "Version:        $version\n";
  print "Release:        0\n";
  print 'BuildRequires:  ed' . "\n";
  print 'BuildRequires:  fontconfig' . "\n";
  print 'BuildRequires:  fontpackages-devel' . "\n";
  print 'BuildRequires:  mkfontdir' . "\n";
  print 'BuildRequires:  mkfontscale' . "\n";
  print 'BuildRequires:  t1utils' . "\n";
  print 'BuildRequires:  texlive-filesystem' . "\n";
  print 'BuildRequires:  xorg-x11-fonts-core' . "\n";
  print 'BuildRequires:  xz' . "\n";
  print "BuildArch:      noarch\n";
  print "Summary:        Meta package for $letter\n";
  # some marker license
  print "License:        SUSE-Ubuntu-Font-License-1.0\n"; 
  print "URL:            https://build.opensuse.org/package/show/Publishing:TeXLive/Meta\n";
  print "Group:          Productivity/Publishing/TeX/Base\n";
  print "Source0:        texlive-specs-$letter-rpmlintrc\n";

  print <<'EOF';
%description
Meta package to build tons of noarch texlive packages.

EOF

  # prune
  my @alldocs = ();
  %pkg_licenses = ();
  %used_files = ();

  foreach my $package (@next_packages) {
    $target = $package;
    $pos = $names{$target};
    $type=6;
    $flags=1;
    $name=$target;
    $target =~ s/-X_Y_Z$/-bin/;
    #
    # Scheme for names of patches and file lists
    #  <name>_<specifier>.<ext>
    # with <ext> equal with `dif' or `diff' or `patch' or `list'
    #
    @patches=<packages/$target\_*\.\{dif,diff,patch\}>;
    @flists=<packages/$target\_*\.list>;
    @mvlist=<packages/$target\.moves>;
    @rmlist=<packages/$target\.removes>;
    @rqlist=<packages/$target*\.requires>;

    if ($#patches > -1) {
	$patch_hook = sub {
	    foreach my $patch (@patches) {
		next if ! -e $patch;
		my $add = "";
		open PATCH, "<$patch" or next;
		while (<PATCH>) {
		    #
		    # Test if files are added and if so then add them also to the lists!
		    #
		    if (/^\+\+\+[[:blank:]]([^[:blank:]]+)/ .. /^@@[[:blank:]]/) {
			if (defined $^N) {
			    $add = $^N;
			} elsif (/^@@[[:blank:]]-0,0/ && $add) {
			    $_ = $add;
			    s@^texmf-dist/@%{_texmfdistdir}/@;
			    s@^texmf/@%{_texmfmaindir}/@;
			    m@^%\{_texmf(dist|main)dir\}?/doc/@ && do {
				$docfiles[$scd++] = $_;
				push @chmod, $_ if m@.*/[^/]*$subexe@;
				next;
			    };
			    $runfiles[$scr++] = $_;
			    $flags |= 4;
			    push @chmod, $_ if m@.*/[^/]*$subexe@;
			}
		    }
		}
		$_ = "";
		close PATCH;
		$patch =~ s@packages/@@;
		$used_files{$patch} = $global_source_counter;
		printf("%-16s%s\n", "Source" . $global_source_counter++ . ":", $patch);
	      }
	  };
    } else {
	$patch_hook = 0;
    }

    #
    # Add file lists if any
    #
    foreach (@flists) {
	next if ! -e $_;
	m@packages/$target\_runfiles\.list@ && do {
	    open LIST, "<$_";
	    while (<LIST>) {
		chomp;
		$runfiles[$scr++] = $_;
		$flags |= 4;
		next if ! s/^%dir[[:blank:]]+//;
		push @mkdirs, $_;
	    }
	    close LIST;
	    next;
	};
	m@packages/$target\_docfiles\.list@ && do {
	    open LIST, "<$_";
	    while (<LIST>) {
		chomp;
		$docfiles[$scd++] = $_;
		next if ! s/^%dir[[:blank:]]+//;
		push @mkdirs, $_;
	    }
	    close LIST;
	    next;
	};
    }

    #
    # Move files if any
    #
    foreach (@mvlist) {
	next if ! -e $_;
	m@packages/$target\.moves@ && do {
	    my $from;
	    my $to;
	    open LIST, "<$_";
	    while (<LIST>) {
		chomp;
		next if $_ eq "";
		($from, $to) = split(/\s+/, $_);
		$mvfiles{$from} = $to;
	    }
	    close LIST;
	    next;
	}
    }

    #
    # Remove files if any
    #
    foreach (@rmlist) {
	next if ! -e $_;
	m@packages/$target\.removes@ && do {
	    open LIST, "<$_";
	    while (<LIST>) {
		chomp;
		next if $_ eq "";
		push @rmfiles, $_;
	    }
	    close LIST;
	    next;
	}
    }

    #
    # Further required packages
    #
    foreach (@rqlist) {
	next if ! -e $_;
	m@packages/$target.*\.requires@ && do {
	    push @reqpack, $_;
	    open LIST, "<$_";
	    while (<LIST>) {
		chomp;
		next if m@^$@;
		next if m@^#@;
		push @reqpack, $_;
	    }
	    close LIST;
	    next;
	}
    }

    if ($target eq 'lcdftypetools') {
	print '%global		with_lcdf_typetools 1' . "\n";
	print '%bcond_with	lcdf_typetools' . "\n";
    }

    seek $tlpfh, $pos, 0;
    ($name, $flags) = packages ($name, $target, $flags);

    filelist ($target, $type, $flags);
    print "\n";

    push(@alldocs, @docfiles);

    %mvfiles = ();
    @rmlist = @rmfiles = @rmdirs = @reqpack = ();
    @chmod = @patches = @flists = @mkdirs = ();
    @tarball = @docfiles = @runfiles = @binfiles = @srcfiles = ();
    $scx = $scd = $scr = $scb = $src = 0;

  } # next package

  print <<'EOF';
%prep
%setup -q -c -T

%build

%install
    rm -rf %{buildroot}
    mkdir -p %{buildroot}%{_texmfdistdir}
    mkdir -p %{buildroot}%{_texmfmaindir}/tlpkg/tlpostcode
    mkdir -p %{buildroot}%{_datadir}/texlive/tlpkg
    mkdir -p %{buildroot}/var/adm/update-scripts
    ln -sf ../../share/texmf        %{buildroot}%{_datadir}/texlive/texmf-dist
    ln -sf ../../share/texmf        %{buildroot}%{_datadir}/texlive/texmf
    ln -sf ../../../share/texmf/tlpkg/tlpostcode \
                                    %{buildroot}%{_datadir}/texlive/tlpkg/tlpostcode
    ln -sf tlpkg/tlpostcode         %{buildroot}%{_texmfmaindir}/tlpostcode
EOF
    print $install_lines;

    print <<'EOF';
    # Remove this
    rm -vrf %{buildroot}%{_texmfdistdir}/tlpkg/tlpobj
    rm -vrf %{buildroot}%{_texmfmaindir}/tlpkg/tlpobj
    rm -v  %{buildroot}%{_datadir}/texlive/texmf
    rm -v  %{buildroot}%{_datadir}/texlive/texmf-dist
    rm -v  %{buildroot}%{_texmfmaindir}/tlpostcode
    rm -vr %{buildroot}%{_datadir}/texlive
EOF

    if (grep /%\{_mandir\}/, @alldocs) {
        print <<'EOF';
    # Handle manual pages
    rm -vf %{buildroot}%{_texmfmaindir}/doc/man/Makefile
    rm -vf %{buildroot}%{_texmfmaindir}/doc/man/man*/*.pdf
    rm -vf %{buildroot}%{_texmfdistdir}/doc/man/Makefile
    rm -vf %{buildroot}%{_texmfdistdir}/doc/man/man*/*.pdf
    for path in %{buildroot}%{_texmfmaindir}/doc/man/man? \
               %{buildroot}%{_texmfdistdir}/doc/man/man?
    do
        test -d "$path" || continue
        sec=${path##*/}
        mkdir -p %{buildroot}%{_mandir}/${sec}
        for page in ${path}/*.*
        do
            test -e "$page" || continue
            mv -f $page %{buildroot}%{_mandir}/${sec}/
        done
    done
    rm -rf %{buildroot}%{_texmfmaindir}/doc/man
    rm -rf %{buildroot}%{_texmfdistdir}/doc/man
EOF
    }

    if (grep /%\{_infodir\}/, @alldocs) {
        print <<'EOF';
    # Handle info documents
    rm -vf  %{buildroot}%{_texmfmaindir}/doc/info/dir
    rm -vf  %{buildroot}%{_texmfdistdir}/doc/info/dir
    mkdir -p %{buildroot}%{_infodir}
    for inf in %{buildroot}%{_texmfmaindir}/doc/info/*.info \
               %{buildroot}%{_texmfdistdir}/doc/info/*.info
    do
        test -e "$inf" || continue
        mv -f $inf %{buildroot}%{_infodir}/
    done
    rm -rf %{buildroot}%{_texmfmaindir}/doc/info
    rm -rf %{buildroot}%{_texmfdistdir}/doc/info
EOF
    }

  print <<'EOF';
    find %{buildroot}%{_texmfmaindir}/ %{buildroot}%{_texmfdistdir}/ \
        -type f -a -perm /g+w,o+w | xargs --no-run-if-empty chmod g-w,o-w
EOF

  # Close main spec
  #
  select STDOUT;
  close $specfh;

  # now the final touch
  open($specfh, ">", $specfile);
  open(PREPARED, "/usr/lib/obs/service/format_spec_file.files/prepare_spec $specfile.new|");
  while ( <PREPARED> ) {
    if (m/^License:.*SUSE-Ubuntu-Font-License-1.0/) {
      print $specfh "License:        " . join(' and ', sort(keys %pkg_licenses)) . "\n";
    } elsif (m/^# spec file for package/) {
      print $specfh "# spec file for package texlive-specs-$letter\n";
    } elsif (m/^# Please submit bugfixes or comments/) {
      print $specfh $_;
      print $specfh "#\n##### WARNING: Please do not edit this auto generated spec file.\n";
    } else {
      print $specfh $_;
    }
  }
  close(PREPARED);
  close($specfh);

  unlink("$specfile.new");
  chmod(0644, $specfile);
  system("cp packages/texlive-specs.changes targets/texlive-specs-$letter/texlive-specs-$letter.changes");
  system("cp packages/texlive-specs-rpmlintrc targets/texlive-specs-$letter/texlive-specs-$letter-rpmlintrc");
  system("cp packages/_constraints targets/texlive-specs-$letter/_constraints");

  open(LINK, ">targets/texlive-specs-$letter/_link");
  print LINK '<link cicount="copy" package="texlive-specs">' . "\n";
  print LINK '  <patches>' . "\n";
  opendir(DIR, 'packages');
  my @allfiles = grep { -f "packages/$_" } readdir(DIR);
  closedir(DIR);
  for my $file (sort @allfiles) {
    next if $used_files{$file};
    next if "$file" eq "texlive-specs-$letter-rpmlintrc";
    next if "$file" eq "texlive-specs-$letter.spec";
    next if "$file" eq "_constraints";
    print LINK "    <delete name='$file' />\n";
  }
  print LINK "    <delete name='texlive-specs-rpmlintrc' />\n";
  print LINK "  </patches>\n";
  print LINK "</link>\n";
}
open STDIN, '<&', \*OLDIN;
if ( -x $has_avfsd) {
    `fusermount -u -z mnt`;
    sleep(0.02);
    pop @clean;
}
exit (0) if (exists $opts{p} || exists $opts{P});

MAIN:

$patch_hook  = 0;
$macros_hook = 0;
$source_hook = 0;
$script_hook = 0;
$reorder_hook= 0;

#
# Both main and make binary spec file require the full texmf tree
#
seek $tlpfh, 0, 0;
my %texmftree = texmftree();

#
# Skip main and make binary spec file
#
goto BIN if (exists $opts{b} && $opts{b});

#
# Open the spec file template for main package
#
open STDIN, "<_main.spec";

#
# Open the new main spec file
#
my ($specfh, $spec) = mkstemp("filesystem/spec.XXXXXXXX");
push @clean, $spec;
select $specfh;

lseek '@@VERSION@@';

print "%define texlive_version  " . $version . "\n";
print "%define texlive_previous " . $previous . "\n";
print "%define texlive_release  " . $release . "\n";
print "%define texlive_noarch   " . $noarch_release . "\n";
print "%define texlive_source   texlive-" . $srcdate . "-source" . "\n";
print "%define biber_version    " . $biberversion . "\n";

lseek '@@SOURCES@@';

#
# Collect the package entries for the main spec file
# that is all collections, schemes, most binaries, but
# without upload and download support.
#

my @basesystem = ();

foreach (sort keys %names) {
    push @basesystem, $_ if /^scheme-/;
}
foreach (sort keys %names) {
    push @basesystem, $_ if /^collection-/;
}

#
# Write out a spec file core
#
$count = 1000;
print "# Download at " . $srcurl . "/\n";
print "# from $srcdate\n";
foreach my $package (@basesystem) {
    $target = $package;
    $pos = $names{$target};
    printf("%-16s%s\n", "Source" . $count++ . ":", $target . ".tar.xz");
}

lseek '@@PACKAGES@@';

foreach my $package (@basesystem) {
    $target = $package;
    $pos = $names{$target};
    $name=$target;
    print "\n";
    seek $tlpfh, $pos, 0;
    ($name, $flags) = packages ($name, $target, 0, "texlive-");
}

lseek '@@TEXMFTREE@@';

foreach my $d (sort keys %texmftree) {
    next if (!$texmftree{$d});
    print '    mkdir -p %{buildroot}' . $d . "\n";
}

lseek '@@INSTALL@@';

#
# Install the TeXLive tar balls
#
$count = 1000;
foreach (@basesystem) {
    print '    tar --use-compress-program=xz -xf %{S:' . $count++ .  '} -C %{buildroot}%{_datadir}/texlive/texmf-dist' . "\n";
}

lseek '@@TEXMFTREE@@';

foreach my $d (sort keys %texmftree) {
    print '%dir ' . $d . "\n";
}

lseek '@@FILES@@';

#
# Now Just generate file lists
#
foreach my $package (@basesystem) {
    $target = $package;
    $pos = $names{target};
    $type=4;
    $name=$target;
    if ($target =~ m/^texlive-scripts/) {
	print "\n%files -n " . $target . "\n";
    } else {
	print "\n%files -n texlive-" . $target . "\n";
    }
    filelist ($name, $type, $flags);
}
close($tlpfh);

lseek;

#
# Close and rename main spec file
#
open STDIN, '<&', \*OLDIN;
select STDOUT;
$target = "filesystem/texlive-filesystem.spec";
-e "filesystem/texlive-filesystem.spec" and rename($target, $target . ".bak");
system("sed", "-ri", "-e s/\@\@KPSEVERSION\@\@/$kpseversion/", "-e s/\@\@PTEXENCVERSION\@\@/$ptexencversion/",
       "-e s/\@\@SYNCTEXVERSION\@\@/$synctexversion/",
       "-e s/\@\@TEXLUAVERSION52\@\@/$texluaversion52/",
       "-e s/\@\@TEXLUAVERSION53\@\@/$texluaversion53/",
       "-e s/\@\@TEXLUAJITVERSION\@\@/$texluajitversion/", "$spec");
if (-x "/usr/lib/obs/service/format_spec_file.files/prepare_spec") {
    open(STDOUT, '>', $target) || die "Can't open $target: $!";
    system("/usr/lib/obs/service/format_spec_file.files/prepare_spec", $spec);
    open STDOUT, '>&', \*OLDOUT;
    system("sed", "-ri", "-e /^# spec file for package/{ s/spec\\.[[:alnum:]]+/texlive-filesystem/ }", $target);
    unlink($spec);
} else {
    rename($spec, $target);
}
chmod(0644, $target);
pop @clean;

exit (0) if (exists $opts{m} && $opts{m});
BIN:

%mvfiles = ();
@rmfiles = @rmdirs = @reqpack = ();
@chmod = @patches = @flists = @mkdirs = ();
@tarball = @docfiles = @runfiles = @binfiles = @srcfiles = ();
$scx = $scd = $scr = $scb = $src = 0;

#
# Open the spec file template for main package
#
open STDIN, "<_bin.spec";

#
# Open the new main spec file
#
($specfh, $spec) = mkstemp("basesystem/spec.XXXXXXXX");
push @clean, $spec;
select $specfh;

lseek '@@VERSION@@';

print "%define texlive_version  " . $version . "\n";
print "%define texlive_previous " . $previous . "\n";
print "%define texlive_release  " . $release . "\n";
print "%define texlive_noarch   " . $noarch_release . "\n";
print "%define texlive_source   texlive-" . $srcdate . "-source" . "\n";
print "%define biber_version    " . $biberversion . "\n";

lseek '@@SOURCES@@';

#
# Collect the package entries for the main spec file
# that is all collections, schemes, most binaries, but
# without upload and download support.
#
@basesystem = ();
foreach (sort keys %names) {
    next if /.*texlive.infra.*/; # No binary package for texlive.infra
    push @basesystem, $_ if /\.ARCH$/;
}

lseek '@@PACKAGES@@';

    foreach my $package (@basesystem) {
    $target = $package;
    $pos = $names{$target};
    $name=$target;
    if ($target =~ /\.ARCH$/) {
	$name   =~ s/\.ARCH$/\.i386-linux/;
	$target =~ s/\.ARCH$/-bin/;
    }   
    $target =~ s/-X_Y_Z$/-bin/;
    print "\n";
    seek $tlpfh, $pos, 0;
    ($name, $flags) = packages ($name, $target, 0);
}

lseek '@@FILES@@';

#
# Now Just generate file lists
#
foreach my $package (@basesystem) {
    $target = $package;
    $pos = $names{$target};
    $type=4;
    $name=$target;
    if ($target =~ /\.ARCH$/) {
	$name   =~ s/\.ARCH$/\.i386-linux/;
	$target =~ s/\.ARCH$/-bin/;
	$type=8;
    } elsif ($target =~ /-doc/) {
	$type=2;
    }
    $target =~ s/-X_Y_Z$/-bin/;
    if ($target =~ m/^texlive-scripts/) {
	print "\n%files -n " . $target . "\n";
    } else {
	print "\n%files " . $target . "\n";
    }
    filelist ($name, $type, $flags);
}
close($tlpfh);

lseek;

#
# Close and rename bin spec file
#
open STDIN, '<&', \*OLDIN;
select STDOUT;
$target = "basesystem/texlive.spec";
-e "basesystem/texlive.spec" and rename($target, $target . ".bak");
system("sed", "-ri", "-e s/\@\@KPSEVERSION\@\@/$kpseversion/", "-e s/\@\@PTEXENCVERSION\@\@/$ptexencversion/",
       "-e s/\@\@SYNCTEXVERSION\@\@/$synctexversion/",
       "-e s/\@\@TEXLUAVERSION52\@\@/$texluaversion52/",
       "-e s/\@\@TEXLUAVERSION53\@\@/$texluaversion53/",
       "-e s/\@\@TEXLUAJITVERSION\@\@/$texluajitversion/", "$spec");
if (-x "/usr/lib/obs/service/format_spec_file.files/prepare_spec") {
    open(STDOUT, '>', $target) || die "Can't open $target: $!";
    system("/usr/lib/obs/service/format_spec_file.files/prepare_spec", $spec);
    open STDOUT, '>&', \*OLDOUT;
    system("sed", "-ri", "-e /^# spec file for package/{ s/spec\\.[[:alnum:]]+/texlive/ }", $target);
    unlink($spec);
} else {
    rename($spec, $target);
}
chmod(0644, $target);
pop @clean;

#
# Here the sub routines and classes follow
#

sub packages {
    my $n;
    my $mnt = 0;
    my $idx = 0;
    my $cnt = 0;
    my @desc = ();
    my @dependx = ();
    my @execute = ();
    my $provide = shift;
    $provide =~ s/-X_Y_Z$/-bin/;
    my $name = $provide;
    my $target = shift;
    my %provides = ();
    my %pscripts = ();
    my @locales = ();
    my $entry = "^name[[:blank:]]$provide";
    my $noarch = 'BuildArch: noarch';
    my $date = '';
    my $license = '';
    my $summary = '';
    my $revision = '';
    my $catversion = '';
    my $realversion = '';
    my $isreloc = 0;
    my $flags = 0;
    my $pkg = shift;
    my $full = shift;
    my @return = ("",$pkg);
    my $loads = $pkg;
    my $reqpack;
    my $hyphens;
    my $origin;

    $sc{$name} = filenum::new($scx, $scd, $scr, $scb, $src);

    if (($provide =~ s/^collection-lang//)) {
	if ($provide eq 'cjk') {
	    $provides{'chinese'} = 1;
	    $provides{'japanese'} = 1;
	    $provides{'korean'} = 1;
	    $dependx[$cnt++] = 'Provides:       locale(texlive:zh;ja;ko)';
	}
	if ($provide ne 'other') {
	    $provides{$provide} = 1;
	}
        $provide =~ s/-/_/g;
	$dependx[$cnt++] = 'Provides:       pattern-category() = TeXLive%20Collection%20Language';
	$dependx[$cnt++] = "Provides:       pattern() = texlive_lang_$provide";
    } elsif (($provide =~ s/^collection-//)) {
	$provides{$provide} = 1;
	if ($provide eq 'basic') {
	    $provides{'tex'} = 1;
	}
        $provide =~ s/-/_/g;
	$dependx[$cnt++] = 'Provides:       pattern-category() = TeXLive%20Collection';
	$dependx[$cnt++] = "Provides:       pattern() = texlive_collection_$provide";
    } elsif (($provide =~ s/^scheme-//)) {
	$provides{$provide} = 1;
        $provide =~ s/-/_/g;
	$dependx[$cnt++] = 'Provides:       pattern-category() = TeXLive%20Scheme';
	$dependx[$cnt++] = "Provides:       pattern() = texlive_scheme_$provide";
    } elsif (($provide =~ s/^texlive-//)) {
	if ($provide eq 'dvips') {
	    $provides{$provide} = 1;
	}
    }

    if ($name =~ m/^collection-documentation-base/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-doc <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-basic$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-xetex$/) {
	$dependx[$cnt++] = 'Obsoletes: texlive-xetex <= %{texlive_previous}';
    } elsif ($target =~ m/^xetex$/) {
	$dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-xetex';
    } elsif ($target =~ m/^xetex-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-xetex <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-latex$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-latex <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-latex-doc <= %{texlive_previous}';
    } elsif ($target =~ m/^latex-bin$/) {
	$dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-latexrecommended';
    } elsif ($target =~ m/^context$/) {
	$dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-context';
    } elsif ($target =~ m/^tex$/) {
	$dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-basic';
    } elsif ($target =~ m/^pdftex$/) {
	$dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
	$dependx[$cnt++] = 'Recommends:     texlive-collection-basic';
	$dependx[$cnt++] = 'Requires:       tex(pdftexconfig.tex)';
	$dependx[$cnt++] = 'Requires:       tex(load-unicode-data.tex)';
    } elsif ($target =~ m/^epstopdf$/) {
	$dependx[$cnt++] = 'Requires:       tex(epstopdf-base.sty)';
    } elsif ($target =~ m/^latex-bin-bin$/) {
	$dependx[$cnt++] = '# Needs to have the same version of zlib on system that it is compiled against';
	$dependx[$cnt++] = '%requires_eq    libz1';
    } elsif ($target =~ m/^luahbtex-bin$/) {
	$dependx[$cnt++] = '# Needs to have the same version of zlib on system that it is compiled against';
	$dependx[$cnt++] = '%requires_eq    libz1';
    } elsif ($target =~ m/^luajittex-bin$/) {
	$dependx[$cnt++] = '# Needs to have the same version of zlib on system that it is compiled against';
	$dependx[$cnt++] = '%requires_eq    libz1';
    } elsif ($target =~ m/^luatex-bin$/) {
	$dependx[$cnt++] = '# Needs to have the same version of zlib on system that it is compiled against';
	$dependx[$cnt++] = '%requires_eq    libz1';
    } elsif ($target =~ m/^luatex$/) {
	$dependx[$cnt++] = 'Requires:       tex(luatexconfig.tex)';
	$dependx[$cnt++] = 'Requires:       tex(load-unicode-data.tex)';
    } elsif ($name =~ m/^collection-binextra$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-dvilj <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      tetex-bin <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-xetex$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-xetex <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-langarabic$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-arab <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-langcjk$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-cjk <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-cjk-latex-extras <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-music$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-musictex <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-htmlxml$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-jadetex <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-tex4ht <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-xmltex <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-fontsextra$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-fonts-extra <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-fonts-extra-doc <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-context$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-context <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-omega$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-omega <= %{texlive_previous}';
    } elsif ($name =~ m/^collection-metapost$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-metapost <= %{texlive_previous}';
    } elsif ($target =~ m/^cjkutils-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-cjk <= %{texlive_previous}';
    } elsif ($target =~ m/^omegaware-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-omega <= %{texlive_previous}';
	$dependx[$cnt++] = 'Requires:       texlive-uptex-bin';
    } elsif ($target =~ m/^pdfjam-bin$/) {	# Correct provide see boo#1211877
	$dependx[$cnt++] = 'Provides:       pdfjam = %{texlive_version}';
	$dependx[$cnt++] = 'Obsoletes:      pdfjam < %{texlive_version}';
    } elsif ($target =~ m/^ps2pk-bin$/) {	# Nasty rename see boo#965472
	$dependx[$cnt++] = 'Obsoletes:      texlive-ps2pkm-bin < 2015';
    } elsif ($target =~ m/^ps2pk$/) {		# Nasty rename see boo#965472
	$dependx[$cnt++] = 'Obsoletes:      texlive-ps2pkm < 2015';
    } elsif ($target =~ m/^tex4ht-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-tex4ht <= %{texlive_previous}';
	$dependx[$cnt++] = 'Conflicts:      ht';
    } elsif ($target =~ m/^xetex-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-xetex <= %{texlive_previous}';
    } elsif ($target =~ m/^xmltex-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-xmltex <= %{texlive_previous}';
    } elsif ($target =~ m/^musixtex-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-musictex <= %{texlive_previous}';
	$dependx[$cnt++] = 'Requires:       texlive-m-tx-bin';
	$dependx[$cnt++] = 'Requires:       texlive-pmx-bin';
    } elsif ($target =~ m/^metapost-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-metapost <= %{texlive_previous}';
    } elsif ($target =~ m/^jadetex-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-jadetex <= %{texlive_previous}';
    } elsif ($target =~ m/^dviljk-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-bin-dvilj <= %{texlive_previous}';
	$dependx[$cnt++] = 'Provides:       texlive-bin-dvilj   = %{texlive_version}';
    }  elsif ($target =~ m/^dvipdfmx-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-dvipdfm-bin < 2013';
	$dependx[$cnt++] = 'Provides:       texlive-dvipdfm-bin = %{texlive_version}';
	$dependx[$cnt++] = 'Requires:       texlive-xetex-bin';
	# The rungs(.tlu) script is located there
	$dependx[$cnt++] = 'Requires:       texlive-scripts >= %{texlive_version}';
    } elsif ($target =~ m/^lcdftypetools-bin$/) {
	$dependx[$cnt++] = '%if %{with lcdf_typetools}';
	$dependx[$cnt++] = 'Conflicts:      lcdf-typetools';
	$dependx[$cnt++] = '%else';
	$dependx[$cnt++] = 'Requires:       lcdf-typetools';
	$dependx[$cnt++] = '%endif';
	$binfiles[$sc{$name}->bin++] = '%if %{with lcdf_typetools}';
    } elsif ($target =~ m/^lcdftypetools$/) {
	$dependx[$cnt++] = '%if %{with lcdf_typetools}';
	$dependx[$cnt++] = 'Conflicts:      lcdf-typetools';
	$dependx[$cnt++] = '%else';
	$dependx[$cnt++] = 'Requires:       lcdf-typetools';
	$dependx[$cnt++] = '%endif';
	$docfiles[$sc{$name}->doc++] = '%if %{with lcdf_typetools}';
	push @rmfiles, '%if ! %{with lcdf_typetools}';
    } elsif ($target =~ m/^ascii-font$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-ascii < 2013';
	$dependx[$cnt++] = 'Provides:       texlive-ascii = %{texlive_version}';
    } elsif ($target =~ m/^knuth-lib$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-misc < 2015';
	$dependx[$cnt++] = 'Provides:       texlive-misc = %{texlive_version}';
    } elsif ($target =~ m/graphics$/) {
	$dependx[$cnt++] = 'Requires:       tex(color.cfg)';
    } elsif ($target =~ m/texlive-scripts$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-tetex <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      tlshell <= %{texlive_previous}';
    } elsif ($target =~ m/texlive-scripts-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-tetex-bin <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      tlshell-bin <= %{texlive_previous}';
    } elsif ($target =~ m/texlive-scripts-extra$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-pdftools <= %{texlive_previous}';
	$dependx[$cnt++] = 'Obsoletes:      texlive-pstools <= %{texlive_previous}';
	$dependx[$cnt++] = 'Conflicts:      texlive-texconfig';
	$dependx[$cnt++] = 'Provides:       texlive-texconfig:%{_texmfdistdir}/texconfig/README';
	$dependx[$cnt++] = 'Provides:       texlive-texconfig:%{_texmfdistdir}/texconfig/tcfmgr';
	$dependx[$cnt++] = 'Provides:       texlive-texconfig:%{_texmfdistdir}/texconfig/tcfmgr.map';
    } elsif ($target =~ m/boldtensors$/) {
	$dependx[$cnt++] = 'Requires:       tex(bbold.map)';
	$dependx[$cnt++] = 'Requires:       font(bbold)';
    } elsif ($target =~ m/iftex$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-ifluatex <= 2019';
    }

    if ($name =~ m/^collection-fontutils$/) {
	$dependx[$cnt++] = 'Requires:       psutils';
    } elsif ($name =~ m/^pstools$/) {
	$dependx[$cnt++] = 'Requires:       psutils';
    } elsif ($name =~ m/^latex$/) {
	# Solves old dependencies of former TeXLive packages on openSUSE <= 12.1
	$dependx[$cnt++] = 'Requires(pre):  texlive-latex-bin';
    } elsif ($name =~ m/^tools$/) {
	# Solves old dependencies of former TeXLive on openSUSE <= 12.1
	$dependx[$cnt++] = 'Requires:       texlive-extratools';
    } elsif ($target =~ m/^biber-bin$/ || $target =~ m/^biber-ms-bin$/) {
	$dependx[$cnt++] = '%if %{with buildbiber}';
	$dependx[$cnt++] = 'Requires:       perl = %{perl_version}';
	$dependx[$cnt++] = 'Recommends:     ca-certificates';
	$dependx[$cnt++] = 'Recommends:     ca-certificates-mozilla';
	$dependx[$cnt++] = 'Requires:       perl(Biber) == %{biber_version}';
	$dependx[$cnt++] = 'Requires:       perl(LWP::UserAgent)';
	$dependx[$cnt++] = 'Requires:       perl(Text::BibTeX)';
	$dependx[$cnt++] = 'Requires:       perl(Text::Roman)';
	$dependx[$cnt++] = '%endif';
	$dependx[$cnt++] = 'BuildArch: noarch';
    } elsif ($target =~ m/^diadia-bin$/) {
	$dependx[$cnt++] = 'BuildArch: noarch';
    } elsif ($target =~ m/^kpathsea-bin$/) {
	$dependx[$cnt++] = 'Requires(pre):  %{name}-filesystem >= %{texlive_version}';
	$dependx[$cnt++] = 'Requires(pre):  user(mktex)';
	$dependx[$cnt++] = 'Requires(pre):  group(mktex)';
	$dependx[$cnt++] = 'Requires(post): %{name}-filesystem';
	$dependx[$cnt++] = 'Requires(post): permissions';
	$dependx[$cnt++] = 'Requires:       %{name}-gsftopk-bin';
	$dependx[$cnt++] = 'Requires(pre):  %{name}-scripts-bin';
	$dependx[$cnt++] = 'Requires(verify): %{name}-filesystem';
	$dependx[$cnt++] = 'Requires(verify): permissions';
    } elsif ($target =~ m/^xpdfopen-bin$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-pdftools-bin < 2020';
    } elsif ($target =~ m/^xpdfopen$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-pdftools < 2020';
	$dependx[$cnt++] = 'Obsoletes:      texlive-pdftools-doc < 2020';
	$dependx[$cnt++] = 'Recommends:     texlive-pdftosrc';
	$dependx[$cnt++] = 'Provides:       texlive-pdftools-doc:%{_mandir}/man1/pdfclose.1%{?ext_man}';
	$dependx[$cnt++] = 'Provides:       texlive-pdftools-doc:%{_mandir}/man1/pdfopen.1%{?ext_man}';
    } elsif ($target =~ m/^pdftosrc$/) {
	$dependx[$cnt++] = 'Conflicts:      texlive-pdftools-doc';
	$dependx[$cnt++] = 'Provides:       texlive-pdftools-doc:%{_mandir}/man1/pdftosrc.1%{?ext_man}';
    } elsif ($target =~ m/^ps2eps$/) {
	$dependx[$cnt++] = 'Conflicts:      texlive-pstools';
	$dependx[$cnt++] = 'Provides:       texlive-pstools:%{_texmfdistdir}/scripts/ps2eps/ps2eps.pl';
    } elsif ($target =~ m/^dtxgallery$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-dtxgallery-doc';
	$dependx[$cnt++] = 'Provides:       texlive-dtxgallery-doc';
    } elsif ($target =~ m/^ptex$/) {
	$dependx[$cnt++] = 'Obsoletes:      texlive-ptex-doc';
	$dependx[$cnt++] = 'Provides:       texlive-ptex-doc:%{_mandir}/man1/makejvf.1%{?ext_man}';
	$dependx[$cnt++] = 'Provides:       texlive-ptex-doc:%{_mandir}/man1/makejvf.1%{?ext_man}';
    } elsif ($target =~ m/^pdfjam-bin$/) {
	$dependx[$cnt++] = 'Requires:       /usr/bin/pdflatex';
    }

    LINE: while (<$tlpfh>) {
	if (/$entry/ .. /^[[:blank:]]*$/) {

	    last if /^[[:blank:]]*$/;

	    chomp;

	    $revision = $_ if s/^revision[[:blank:]]+//;
	    if (s/shortdesc[[:blank:]]+//) {
		s/i386-linux/Binary/;
		s/^(.)/\U$1/;
		s/[[:blank:]\.]+$//;
		s/([[:blank:]]+)etc$/$1etcetera/;
		s/independant/independent/g;
		s/langauage/language/g;
		s/powerfull/powerful/g;
		s/pacakge/package/g;
		$summary = $_;
		next;
	    }

	    $noarch = "" if /^binfiles arch=i386-linux/;
	    if (s/^longdesc[[:blank:]]+//) {
		s/independant/independent/g;
		s/langauage/language/g;
		s/powerfull/powerful/g;
		s/pacakge/package/g;
		s/([Pp]rovides):/\1/g;					# Bug in prepare_spec script
		s/([Rr]equires):/\1/g;					# Bug in prepare_spec script
		$desc[$idx++] = "$_";
		next;
	    }
	    push @execute,$_ if s/^(execute)[[:blank:]]+/$1=/;
	    push @execute,$_ if s/^(postaction)[[:blank:]]+/$1=/;	# Handle postaction tag

	    if (/^depend[[:blank:]]+/) {
		next if /^depend[[:blank:]]+($regexp)/;
		s/^depend[[:blank:]]+//;
		s/-bin$/-X_Y_Z/;
		next if (!exists $names{$_});
		s/\.ARCH$/-bin/;
		$dependx[$cnt++] = $_;
		next;
	    }
	    if ($pkg && /^docfiles[[:blank:]]+/) {
		if ($name =~ m/^amscls$/) {
		    $return[1] |= 4;					# Has docfiles but also a further amscls-doc package
		    $loads |= 2;
		} else {
		    $return[1] |= 2;					# Has docfiles
		    $loads |= 2;
		}
	    }
	    if (/^runfiles[[:blank:]]+/) {
		$return[1] |= 4;					# Has runfiles
		$loads |= 4;
	    }
	    if (/^binfiles[[:blank:]]+/) {
		$return[1] |= 8;					# Has binfiles
		$loads |= 8;
	    }
	    if (/^srcfiles[[:blank:]]+/) {
		$return[1] |= 32;					# Has srcfiles
		$loads |= 16;
	    }
	    $catversion = $_ if s/^catalogue-version[[:blank:]]+//;
	    if (s/^catalogue\-license[[:blank:]]+//) {
		foreach my $key (sort keys %licenses) {
		    if ($_ =~ /^$key/) {
			if (($_ =~ /^artistic/) && ($target =~ /biber/)) {
			    $license = 'Artistic-2.0 and GPL-2.0-or-later';
			    last;
			}
			if (($_ =~ /gpl/) && ($target =~ /asymptote/)) {
			    $license = 'LGPL-3.0-or-later';
			    last;
			}
			$license = $licenses{$key};
			last;
		    }
		}
		if (! $license) {
		    s/(.)/\U$1/g;
		    $license =~ $_;
		}
	    }
	    $date = $_ if s/^catalogue-date[[:blank:]]+//;
	    $flags = 0 if /^[[:^blank:]]/;
	    if ($flags > 0) {
		$isreloc = 1 if m@^[[:blank:]]+RELOC/@;
		if ($flags == 2 && /^[[:blank:]]+[[:^blank:]]+([[:blank:]]+[[:^blank:]]+="[^"]+")+/p) {
		    my $match = $^N;
		    if ($match =~ /[[:blank:]]+language=/) {
			$match =~ s/[[:blank:]]+language="([^"]+)"/$1/;
			$match = 'en_GB' if ($match =~ /uk/);
			$match = 'pt_BR' if ($match =~ /pt-br/);
			$match = 'es_VE' if ($match =~ /es-ve/);
			push @locales, $match if ! grep m@$match@, @locales;
		    }
		}
#
# Use it, compare with line 2495ff (%post -n texlive-*)
#
##		next if m@^[[:blank:]]+tlpkg/tlpostcode@;		# Ignore postaction script
		if (m@^[[:blank:]]+texmf(-dist)?/texconfig/[gvx]/@) {		# Ignore terminfo
		    if (! grep /terminfo/, @dependx) {
			$dependx[$cnt++] = 'Requires:       terminfo-base';
		    }
		    s@^[[:blank:]]texmf/@%{_texmfmaindir}/@;
		    s@^[[:blank:]]texmf-dist/@%{_texmfdistdir}/@;
		    if (m@^(%\{_texmfmaindir\}/texconfig/[gvx])/@) {
			my $x = $1;
			my $r = $1;
			$r =~ s@\{@[{]@g;
			$r =~ s@\}@[}]@g;
			push @rmdirs, $x if ! grep /$r/, @rmdirs;
		    } elsif (m@^(%\{_texmfdistdir\}/texconfig/[gvx])/@) {
			my $x = $1;
			my $r = $1;
			$r =~ s@\{@[{]@g;
			$r =~ s@\}@[}]@g;
			push @rmdirs, $x if ! grep /$r/, @rmdirs;
		    }
		    next;
		}
		next if (m@/man$@);					# Ignore man program
		s/[[:blank:]]+details=.*$//;
		s/[[:blank:]]+language=.*$//;
		if ($flags == 4) {
		    $provide = doprovide($_);
		    if ($provide) {
			if ($name =~ m/.*-dev$/) {			# A developement package with doubled name space
			    $provides{$provide} = 2;
			} else {
			    $provides{$provide} = 1;
			}
		    }
		}
		if ($flags == 2 && m/man[15]\/[^\.]+\.[15]$/) {
		    $provide = $_;
		    $provide =~ s@^[[:blank:]](RELOC/)?@@;
		    $provides{$provide} = 3;
		}
		$origin = $_;
		s@^[[:blank:]]bin/.*-linux/@%{_bindir}/@;
		s@^[[:blank:]]RELOC/@%{_texmfdistdir}/@;
		s@^[[:blank:]]texmf-dist/@%{_texmfdistdir}/@;
		s@^[[:blank:]]texmf/@%{_texmfmaindir}/@;
		s@^[[:blank:]]@%{_texmfmaindir}/@;
		if (m@^(%\{_texmf(main|dist)dir\}/source)/@) {		# No source like seen in koma-script
                    push @srcfiles, $_; # delete later
		    next if ($flags != 32);
		    # fall through for pure source packages
		}
		if (m@^%.*/.*\.(orig|bak)$@) {				# Not allowed
		    push @rmfiles, $_;
		    next;
		}
		if (m@^%.*/(\.[^/]*)$@ && m@/doc/@) {			# Not allowed
		    push @rmfiles, $_;
		    next;
		}
		if (m@^(%.*/scripts/context/stubs/(mswin|source))/@) {	# No windows files for context
		    my $x = $1;
		    my $r = $1;
		    $r =~ s@\{@[{]@g;
		    $r =~ s@\}@[}]@g;
		    push @rmdirs, $x if ! grep m@$r@, @rmdirs;
		    next;
		}
		if (m@^%.*/([^/]*\.(bat|exe))$@i) {			# No windows bat or exe files
		    push @rmfiles, $_;
		    next;
		}
	    }
	    if ($flags >= 2) {						# Ignore files which becomes removed
		my $match = 0;
		foreach my $r (@rmfiles) {
		    if ($r eq $_) {
			$match = 1;
			last;
		    }
		}
		next if ($match > 0);
	    }
	    if ($flags == 2) {
		foreach my $k (keys %mvfiles) {
		    next if $_ ne $k;
		    $runfiles[$sc{$name}->run++] = $mvfiles{$k};
		    $return[1] |= 4;					# Has runfiles
		    next LINE;
		}
		if (m@/doc/man/@) {
		    next if (m@\.pdf$@);				# Ignore manual pages as pdf
		    s@(%\{_texmfmaindir\}|%\{_texmfdistdir\})/doc/man@%{_mandir}@;
		    $_ = $_ . '*';
		}
		if (m@/doc/info/@) {
		    next if (m@/doc/info/dir@);				# Ignore dir db file
		    s@(%\{_texmfmaindir\}|%\{_texmfdistdir\})/doc/info@%{_infodir}@;
		    $_ = $_ . '*';
		}
		if ($name !~ /.*texlive.infra.*/) {
		    $docfiles[$sc{$name}->doc++] = $_;
		} else {
		    s@%\{_texmfmaindir\}@%{_texmfdistdir}@;
		    $_ = '%exclude ' . $_ if m@tlmgr\.1@;
		    $_ = '%exclude ' . $_ if m@/installer/.*@;
		    $docfiles[$sc{$name}->doc++] = $_;
		}
		push @rmfiles, $_ if ($target =~ m/^lcdftypetools$/);
	    }
	    if ($flags == 4) {						# May has font files
		if (m@/doc/man/@) {
		    next if (m@\.pdf$@);				# Ignore manual pages as pdf
		    s@(%\{_texmfmaindir\}|%\{_texmfdistdir\})/doc/man@%{_mandir}@;
		    $_ = $_ . '*';
		    $docfiles[$sc{$name}->doc++] = $_;			# Oops
		    $return[1] |= 2;					# Has docfiles
		    next;
		}
		if (m@/doc/info/@) {
		    next if (m@/doc/info/dir@);				# Ignore dir db file
		    s@(%\{_texmfmaindir\}|%\{_texmfdistdir\})/doc/info@%{_infodir}@;
		    $_ = $_ . '*';
		    $docfiles[$sc{$name}->doc++] = $_;			# Oops
		    $return[1] |= 2;					# Has docfiles
		    next;
		}
		if (m@dir}/doc/@) {
		    if ($name =~ m/^amscls$/) {
			$runfiles[$sc{$name}->run++] = $_;
		    } else {
			$docfiles[$sc{$name}->doc++] = $_;		# Oops
			$return[1] |= 2;				# Has docfiles
		    }
		    next;
		}
		$return[1] |= 16 if m@/(opentype|truetype|type1)/.*\.(pf[ab]|[ot]tf)$@;
		if ($name !~ /.*texlive.infra.*/) {
		    $runfiles[$sc{$name}->run++] = $_;
		    if (m@/scripts/@) {
			$origin =~ s@^[[:blank:]](RELOC/)?@@;
			$pscripts{$origin} = 1;
		    }
		} else {
		    s@%\{_texmfmaindir\}@%{_texmfdistdir}@;
		    $_ = '%exclude ' . $_  if m@README$@;
		    $_ = '%exclude ' . $_  if m@index\.html$@;
		    $_ = '%exclude ' . $_  if m@readme-html\.dir/.*@;
		    $_ = '%exclude ' . $_  if m@readme-txt\.dir/.*@;
		    $_ = '%exclude ' . $_  if m@scripts/.*@;
		    $_ = '%exclude ' . $_  if m@web2c/.*@;
		    $_ = '%exclude ' . $_  if m@/TLDownload\.pm$@;
		    $_ = '%exclude ' . $_  if m@/installer/.*@;
		    $runfiles[$sc{$name}->run++] = $_;
		}
	    }
	    if ($flags == 8) {
		next if (m@.*/memoize-(extract|clean)\.pl@);
		if (m@.*/memoize-(extract|clean)\.py@) {
		    my $base = $_;
		    $base =~ s@\.p[ly]$@@;
		    $binfiles[$sc{$name}->bin++] = $base;
		    next;
		}
		$binfiles[$sc{$name}->bin++] = $_;
	    }
	    if ($flags == 32) {
		$srcfiles[$sc{$name}->src++] = $_;
	    }
	    $flags = 32 if /^srcfiles/;
	    $flags = 8  if /^binfiles/;
	    $flags = 4  if /^runfiles/;
	    if ($name =~ m/^amscls$/) {
		$flags = 4  if /^docfiles/;
	    } else {
		$flags = 2  if /^docfiles/;
	    }
	}
    }

    #
    # Just to be sure to have all dependcies for %post perl scripts
    #
    if (grep /postaction=script.*\.pl/, @execute) {
	$dependx[$cnt++] = 'Requires(post): perl = %{perl_version}';
	$dependx[$cnt++] = 'Requires(post): perl(TeXLive::TLUtils)';
	$dependx[$cnt++] = 'Requires(post): tex(texmf.cnf)';
	$dependx[$cnt++] = 'Requires(post): texlive-kpathsea-bin >= %{texlive_version}';
	$dependx[$cnt++] = 'Requires(post): texlive-texlive.infra >= %{texlive_version}';
	$dependx[$cnt++] = '#!BuildIgnore: texlive-kpathsea';
    }

    if ($target eq 'lcdftypetools-bin') {
	$binfiles[$sc{$name}->bin++] = '%endif';
    } elsif ($target eq 'lcdftypetools') {
	$docfiles[$sc{$name}->doc++] = '%endif';
	push @rmfiles, '%endif';
    } elsif ($target eq 'texdoc') {
	$runfiles[$sc{$name}->run++] = '%{_texmfdistdir}/tlpkg/texlive.tlpdb';
    }
    if ($pkg) {
	#
	# package includes documentation files below its `runfiles' tag
	#
	if (($sc{$name}->run == $sc{$name}->cun) && (($return[1] & 6) == 6)) {
	    $return[1] &= ~4;
	}
    } else {
	#
	# support the `public' proggy
	# also manual page of biber executable
	#
	if ($target =~ /kpathsea-bin/) {
	    $binfiles[$sc{$name}->bin++] = '%{_bindir}/mktexlsr';
	    $binfiles[$sc{$name}->bin++] = '%attr(2755,root,%{texgrp}) %{_libexecdir}/mktex/public';
	    $binfiles[$sc{$name}->bin++] = '%{_libexecdir}/mktex/*tex*';
	} elsif ($target eq 'biber-bin') {
	    $binfiles[$sc{$name}->bin++] = '%if %{with buildbiber}';
	    $binfiles[$sc{$name}->bin++] = '%{_mandir}/man1/biber.1%{ext_man}';
	    $binfiles[$sc{$name}->bin++] = '%endif';
	} elsif ($target eq 'biber-ms-bin') {
	    $binfiles[$sc{$name}->bin++] = '%if %{with buildbiber}';
	    $binfiles[$sc{$name}->bin++] = '%{_mandir}/man1/biber-ms.1%{ext_man}';
	    $binfiles[$sc{$name}->bin++] = '%endif';
	} elsif ($target eq 'context-bin') {
	    $binfiles[$sc{$name}->bin++] = '%{_bindir}/mtx-context.lua';
	}
    }
    if ($catversion) {
	if ($catversion =~ /^\.[[:digit:]]/) {
	    $catversion = sprintf('0%s', $catversion);
	}
	if ($catversion =~ /^0+\./) {
	    $catversion = sprintf('0.%s', $catversion);
	}
	$catversion =~ s@([0-9]{4})[/-]([0-9]{2})[/-]([0-9]{2})@$1$2$3@g;
	$catversion =~ s/[\(\)]+//g;
	$catversion =~ s/,+/\./g;
	$catversion =~ s@[[:blank:]~:/-]+@_@g;
	$catversion =~ s/_rev//g;
	$catversion = lc($catversion);
	$realversion = $catversion;

	if ($target =~ m/^mgltex$/) {
	    $dependx[$cnt++] = 'Obsoletes:      mathgl-tex <= 2.3.5.1';
	    $dependx[$cnt++] = 'Provides:       mathgl-tex = ' . "$realversion";
	}
    }
    if ($pkg) {
	my $add = 0;
	$add++ if grep /execute=/, @execute;
	if ($name =~ m/^kpathsea$/) {
	    $dependx[$cnt++] = 'Requires(pre):  texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires:       texlive-gsftopk';
	    $dependx[$cnt++] = 'Requires:       texlive-updmap-map';
	    $dependx[$cnt++] = '#!BuildIgnore: texlive-gsftopk';
	    $dependx[$cnt++] = '#!BuildIgnore: texlive-gsftopk-bin';
	    $dependx[$cnt++] = '#!BuildIgnore: texlive-updmap-map';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts >= %{texlive_version}';
	} elsif ($name =~ m/^tetex$/) {
	    $dependx[$cnt++] = 'Requires(pre):  texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-texlive.infra >= %{texlive_version}';
	    $dependx[$cnt++] = 'Provides:       texlive-texconfig-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Provides:       texlive-texconfig >= %{texlive_version}';
	} elsif ($name =~ m/^texlive-scripts$/) {
	    $dependx[$cnt++] = 'Requires(pre):  texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-texlive.infra >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts-extra >= %{texlive_version}';
	    $dependx[$cnt++] = 'Obsoletes:      texlive-texconfig < 2018';
	} elsif ($name =~ m/^texconfig$/) {
	    $dependx[$cnt++] = 'Requires(pre):  texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-kpathsea >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts-extra-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts-extra >= %{texlive_version}';
	} else {
	    $dependx[$cnt++] = 'Requires(pre):  texlive-filesystem >= %{texlive_version}';
	}
	#
	# mkdir in %post and %postun
	#
	if ($name =~ m/^kpathsea$/) {
	    $dependx[$cnt++] = 'Requires(post): diffutils';
	}
	$dependx[$cnt++] = 'Requires(post): coreutils';
	$dependx[$cnt++] = 'Requires(postun): coreutils';
	#
	# mktexlsr and texmf.cnf
	#
	if ($name =~ m/^kpathsea$/) {
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	} elsif ($name =~ m/^tetex$/) {
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea >= %{texlive_version}';
	} elsif ($name =~ m/^texlive-scripts$/) {
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea >= %{texlive_version}';
	} elsif ($name =~ m/^texconfig$/) {
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-scripts-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-scripts >= %{texlive_version}';
	} elsif ($name =~ m/^tetex$/) {
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea >= %{texlive_version}';
	} elsif ($name =~ m/^texlive-scripts$/) {
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea >= %{texlive_version}';
	} else {
	    $dependx[$cnt++] = 'Requires(postun): texlive >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-kpathsea >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-scripts-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(postun): texlive-scripts >= %{texlive_version}';
	}
	#
	# TeXLive 2022
	#
	if ($target =~ m/^asana-math$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-Asana-Math < 2022';
	} elsif ($target =~ m/^esieecv$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-ESIEEcv < 2022';
	} elsif ($target =~ m/^gs1$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-GS1 < 2022';
	} elsif ($target =~ m/^ha-prosper$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-HA-prosper < 2022';
	} elsif ($target =~ m/^ieeeconf$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-IEEEconf < 2022';
	} elsif ($target =~ m/^ieeetran$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-IEEEtran < 2022';
	} elsif ($target =~ m/^memoirchapterstyles$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-MemoirChapStyles < 2022';
	} elsif ($target =~ m/^pst-hsb$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-pst-ghsb < 2022';
	} elsif ($target =~ m/^sistyle$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-SIstyle < 2022';
	} elsif ($target =~ m/^siunits$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-SIunits < 2022';
	} elsif ($target =~ m/^tabbing$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-Tabbing < 2022';
	} elsif ($target =~ m/^tipauni$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-unitipa < 2022';
	}
	#
	#
	if ($add) {
	    my $updmap = 0;
	    $updmap++ if grep /execute=[aA]dd(Mixed|Kanji)?Map/, @execute;
	    $add++    if grep /execute=[aA]dd(Format|Hyphen)/,   @execute;
	    #
	    # fmtutil.cnf, mktex.cnf, and texmf.cnf a well as language.dat, language.def, and language.dat.lua
	    #
	    if ($add > 1) {
		$dependx[$cnt++] = 'Requires(post): findutils';
		$dependx[$cnt++] = 'Requires(post): grep';
		$dependx[$cnt++] = 'Requires(post): sed';
		$dependx[$cnt++] = 'Requires(post): texlive >= %{texlive_version}';
		$dependx[$cnt++] = 'Requires(post): tex(language.dat)';
		$dependx[$cnt++] = 'Requires(post): tex(language.def)';
		$dependx[$cnt++] = 'Requires(post): tex(language.dat.lua)';
		$dependx[$cnt++] = '#!BuildIgnore:  tex(language.dat)';
		$dependx[$cnt++] = '#!BuildIgnore:  tex(language.def)';
		$dependx[$cnt++] = '#!BuildIgnore:  tex(language.dat.lua)';
		$dependx[$cnt++] = 'Requires(postun): findutils';
		$dependx[$cnt++] = 'Requires(postun): grep';
		$dependx[$cnt++] = 'Requires(postun): sed';
		$dependx[$cnt++] = 'Requires(postun): texlive >= %{texlive_version}';
		$dependx[$cnt++] = 'Requires(postun): tex(language.dat)';
		$dependx[$cnt++] = 'Requires(postun): tex(language.def)';
		$dependx[$cnt++] = 'Requires(postun): tex(language.dat.lua)';
	    }
	    #
	    # updmap.cfg
	    #
	    if ($updmap) {
		$dependx[$cnt++] = 'Requires(post): findutils';
		$dependx[$cnt++] = 'Requires(post): grep';
		$dependx[$cnt++] = 'Requires(post): sed';
		$dependx[$cnt++] = 'Requires(post): texlive >= %{texlive_version}';
		$dependx[$cnt++] = 'Requires(post): tex(updmap.cfg)';
		$dependx[$cnt++] = '#!BuildIgnore:  tex(updmap.cfg)';
		$dependx[$cnt++] = 'Requires(postun): findutils';
		$dependx[$cnt++] = 'Requires(postun): grep';
		$dependx[$cnt++] = 'Requires(postun): sed';
		$dependx[$cnt++] = 'Requires(postun): texlive >= %{texlive_version}';
		$dependx[$cnt++] = 'Requires(postun): tex(updmap.cfg)';
	    }
	    #
	    # Generate file patterns for hyphen patterns it any
	    #
	    if (grep /execute=[aA]dd(Hyphen)/, @execute) {
		$hyphens = hyphen::new();
		foreach my $e (sort @execute) {
		    next if ($e !~ m/execute=[aA]dd(Hyphen)/);
		    my $line = $e;
		    $line =~ s/execute=//;
		    chomp($line);
		    $hyphens->store("$line");
		}
	    }
	}
	if (grep /%\{_infodir\}/, @runfiles) {
	    $dependx[$cnt++] = 'Requires(preun): %install_info_prereq';
	    $dependx[$cnt++] = 'Requires(post): %install_info_prereq';
        }
	#
	# tools required by /usr/lib/texmf/texconfig/update in %posttrans scriptlet
	#
	$dependx[$cnt++] = 'Requires(posttrans): coreutils';
	$dependx[$cnt++] = 'Requires(posttrans): ed';
	$dependx[$cnt++] = 'Requires(posttrans): findutils';
	$dependx[$cnt++] = 'Requires(posttrans): grep';
	$dependx[$cnt++] = 'Requires(posttrans): sed';
	if ($name =~ m/^kpathsea$/) {
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-filesystem >= %{texlive_version}';
	} elsif ($name =~ m/^tetex$/) {
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea >= %{texlive_version}';
	} elsif ($name =~ m/^texlive-scripts$/) {
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea >= %{texlive_version}';
	} elsif ($name =~ m/^texconfig$/) {
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(pre):  texlive-scripts >= %{texlive_version}';
	} else {
	    $dependx[$cnt++] = 'Requires(posttrans): texlive >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-filesystem >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-kpathsea >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-scripts-bin >= %{texlive_version}';
	    $dependx[$cnt++] = 'Requires(posttrans): texlive-scripts >= %{texlive_version}';
	}
	if ($return[1] & 16) {
	    if ($target =~ m/^texlive-scripts/) {
		$dependx[$cnt++] = 'Requires:       ' . $name . '-fonts';
	    } else {
		$dependx[$cnt++] = 'Requires:       texlive-' . $name . '-fonts';
	    }
	}
    }

    #
    # Check for not required removes
    #
    if (($return[1] & (1|4|32)) == (1|32)) {
	my @tmp = ();
	# pure source packages, do not remove the source directory
	foreach (@rmdirs) {
	    next if (m@^(%\{_texmf(main|dist)dir\}/source)@);
	    push @tmp, $_;
	}
	@rmdirs = @tmp;
    } elsif (($return[1] & (1|4|32)) == (1|4|32)) {
	my @tmp = ();
	# we do not install sources, but do not delete piece by piece
	foreach (@rmfiles) {
	    next if (m@^(%\{_texmf(main|dist)dir\}/source)@);
	    push @tmp, $_;
	}
	@rmfiles = @tmp;
	@srcfiles = ();
	$return[1] &= ~32;
    }
    #
    # which packages are required?
    #
    $name =~ s/-X_Y_Z$/-bin/;
    if (grep /^$name$/, @nosource) {
	$loads |= 4;
	$loads &= ~16;
	$return[1] &= ~32;
    }
    if ($pkg) {
	#
	# Check for a documentation package and if so recommend it
	#
	if (($return[1] & 39) == 7 || ($return[1] & 39) == 35) {
	    if ($target =~ m/^texlive-scripts/) {
		$dependx[$cnt++] = 'Suggests:       ' . $name . '-doc';
	    } else {
		$dependx[$cnt++] = 'Suggests:       texlive-' . $name . '-doc';
	    }
	}
    }
    if (($loads & (1|4|16)) == (1|4|16)) {
	# runfiles aka nosource
	$loads &= ~16 if @runfiles > 0;
    }
    if (($loads & (1|2|4)) == (1|2|4)) {
	# runfiles aka nosource
	$loads &= ~4 if @runfiles < 1;
    }
    if (($loads & (1|4)) == (1|4)) {
	$tarball[$sc{$name}->tar++] = $name . '.tar.xz';
    }
    if (($loads & (1|16)) == (1|16)) {
	$tarball[$sc{$name}->tar++] = $name . '.source.tar.xz';
    }
    if (($loads & (1|2)) == (1|2)) {
	$tarball[$sc{$name}->tar++] = $name . '.doc.tar.xz';
    }
    if ($loads == 0 || $loads == 1) {
	$tarball[$sc{$name}->tar++] = $name . '.tar.xz';
    }
    #
    # load or link them into the appropriate package sub directory
    #
    for ($n = $sc{$name}->cur; $n < $sc{$name}->tar; $n++) {
 	my $this = 'texlive-' . $version . '-texmf/archive/' . $tarball[$n];
	my $pack = 'basesystem/';
	my $replace;
	next if ($name =~ m/i386-linux/);
	$pack = 'packages/' if ($pkg);
	$pack = 'filesystem/' if ($full);
	$replace = $pack . $tarball[$n];
	if (-e $this) {
	    unlink $replace if (-e $replace && ! -l $replace);
	    -l $replace or symlink('../' . $this, $replace);
	    next;
	}
	next if (-e $replace);
	`wget --progress=bar:force -N -P $pack "$srcurl/$tarball[$n]"`;
    }
    if (!$pkg) {
	if ($full) {
	    print '%package -n ' . $full . $target . "\n";
	} else {
	    if ($target =~ m/^texlive-scripts/) {
		print '%package -n ' . $target . "\n";
	    } else {
		print '%package ' . $target . "\n";
	    }
	    if ($target =~ m/.*-bin$/) {
		my $noarch = $target;
		$noarch =~ s/-bin$//;
		if ($noarch =~ m/^texlive-scripts$/) {
		    $dependx[$cnt++] = 'Requires(pre):  ' . $noarch;
		    $dependx[$cnt++] = '#!BuildIgnore:  ' . $noarch;
		} else {
		    if ($noarch =~ m/^texlive-scripts/) {
			$dependx[$cnt++] = 'Requires(pre):  ' . $noarch;
			$dependx[$cnt++] = '#!BuildIgnore:  ' . $noarch;
		    } else {
			$dependx[$cnt++] = 'Requires(pre):  texlive-' . $noarch;
			$dependx[$cnt++] = '#!BuildIgnore:  texlive-' . $noarch;
		    }
		}

		if ($noarch =~ m/xetex/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-xetex';
		} elsif ($noarch =~ m/latex/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-latexrecommended';
		} elsif ($noarch =~ m/context/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-context';
		} elsif ($noarch =~ m/pdftex/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-basic';
		} elsif ($noarch =~ m/luatex/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-luatex';
		} elsif ($noarch =~ m/xmltex/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-htmlxml';
		} elsif ($noarch =~ m/omega/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-omega';
		} elsif ($noarch =~ m/tex/) {
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-fontsrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-genericrecommended';
		    $dependx[$cnt++] = 'Recommends:     texlive-collection-basic';
		}

		if ($noarch =~ m/attachfile2/) {
		    $dependx[$cnt++] = 'Conflicts:      texlive-pdftools-bin';
		    $dependx[$cnt++] = 'Provides:       texlive-pdftools-bin:%{_bindir}/pdfatfi';
		} elsif ($noarch =~ m/pdftosrc/) {
		    $dependx[$cnt++] = 'Conflicts:      texlive-pdftools-bin';
		    $dependx[$cnt++] = 'Provides:       texlive-pdftools-bin:%{_bindir}/pdftosrc';
		} elsif ($noarch =~ m/texlive-scripts-extra/) {
		    $dependx[$cnt++] = 'Obsoletes:      texlive-pdftools-bin < 2020';
		    $dependx[$cnt++] = 'Obsoletes:      texlive-pstools-bin < 2020';
		    $dependx[$cnt++] = 'Obsoletes:      texlive-tetex-bin < 2020';
		    $dependx[$cnt++] = 'Obsoletes:      texlive-texconfig-bin < 2018';
		    $dependx[$cnt++] = 'Provides:       texlive-pdftools-bin:%{_bindir}/e2pall';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/allcm';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/allneeded';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/dvi2fax';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/dvired';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/kpsetool';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/kpsewhere';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/texconfig-dialog';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/texconfig-sys';
		    $dependx[$cnt++] = 'Provides:       texlive-tetex-bin:%{_bindir}/texlinks';
		    $dependx[$cnt++] = 'Provides:       texlive-texconfig-bin:%{_bindir}/texconfig';
		} elsif ($noarch =~ m/ps2eps/) {
		    $dependx[$cnt++] = 'Conflicts:      texlive-pstools-bin';
		    $dependx[$cnt++] = 'Provides:       texlive-pstools-bin:%{_bindir}/bbox';
		    $dependx[$cnt++] = 'Provides:       texlive-pstools-bin:%{_bindir}/ps2eps';
		}
	    }
	}
	if (m@/mtxrun$@) {
	    my $base = $_;
	}
    } else {
	my $cur = $sc{$name}->cur;
	if ($target =~ m/^texlive-scripts/) {
	    print '%package -n ' . $target . "\n";
	} else {
	    print '%package -n texlive-' . $target . "\n";
	}
        # avoid bootstrap problems
        my @bootstraps;
	@bootstraps = qw(scripts kpathsea);
	if (grep { $_ eq $target } @bootstraps) {
           for my $bs (@bootstraps) {
     	       print "#!BuildIgnore:   texlive-$bs\n";
           }
        } 
	if ($target =~ m/^texlive-scripts/) {
	    $return[0] = $target;
	} else {
	    $return[0] = 'texlive-' . $target;
	}
	if (-e "packages/$tarball[$cur]" && ! -x $has_avfsd) {
	    my $handler = sub { `fusermount -u -z mnt/` if -d "mnt/tlpkg" };
	    `archivemount -r -o kernel_cache,intr,async_read "packages/$tarball[$cur]" mnt/`;
	    sleep(0.02);
	    if (-d "mnt/tlpkg") {
		push @clean, $handler;
		$mnt++;
		open TLPOBJ, <mnt/tlpkg/tlpobj/*.tlpobj> or die "tlpobj data base required";
		while (<TLPOBJ>) {
		    chomp;
		    if (m@^[[:blank:]]+RELOC/@) {
			$isreloc = 1;
			last;
		    }
		}
		close TLPOBJ;
	    }
	}
	if (-e "packages/$tarball[$cur]" && -x $has_avfsd) {
		my $tlpobj = 'mnt/packages/' . $tarball[$cur] . '#/' . 'tlpkg/tlpobj/';
		$tlpobj = `ls ${tlpobj}*.tlpobj`;
		open TLPOBJ, "<${tlpobj}" or die "tlpobj data base required $^E $tarball[$cur]: $cur $name -- ${tlpobj}";
		while (<TLPOBJ>) {
		    chomp;
		    if (m@^[[:blank:]]+RELOC/@) {
			$isreloc = 1;
			last;
		    }
		}
		close TLPOBJ;
	}
    }
    my $pkg_version = '%{texlive_version}';
    if ($revision) {
	$revision = 'svn' . $revision;
	$catversion .= $revision;
    }
    if ($noarch) {
	if ($target =~ m/^biber-bin$/) {
	    $pkg_version = "%{biber_version}";
	} elsif ($target =~ m/^biber-ms-bin$/) {
	    $pkg_version = "4.0";
	} elsif ($catversion) {
	    $pkg_version .= '.%{texlive_noarch}.' . $catversion;
	} else {
	    $pkg_version .= '.%{texlive_noarch}';
	}
    } else {
	if ($catversion) {
	    $pkg_version .= '.%{texlive_release}.' . $catversion;
	} else {
	    $pkg_version .= '.%{texlive_release}';
	}
    }
    print "Version:        $pkg_version\n";
    print "Release:        0\n";
    $license ||= 'LPPL-1.0';
    $pkg_licenses{$license} = 1;
    print 'License:        ' . $license . "\n";

    $summary ||= 'Package ' . $name;
    print 'Summary:        ' . $summary . "\n";
    if (!$noarch) {
      print 'Group:          Productivity/Publishing/TeX/Utilities' . "\n";
    } elsif ($target =~ /collection-texinfo/) {
      print 'Group:          Productivity/Publishing/Texinfo' . "\n";
    } elsif ($target =~ /scheme-/) {
      print 'Group:          Productivity/Publishing/TeX/Frontends' . "\n";
    } elsif ($target =~ /collection-(music|omega|xetex|latex|htmlxml|formatsextra|context|basic)/) {
      print 'Group:          Productivity/Publishing/TeX/Frontends' . "\n";
    } elsif ($target =~ /collection-fonts/) {
      print 'Group:          Productivity/Publishing/TeX/Fonts' . "\n";
    } else {
      print 'Group:          Productivity/Publishing/TeX/Base' . "\n";
    }
    print 'URL:            https://www.tug.org/texlive/' . "\n";

    if (keys %pscripts && $pkg) {
	my %pmodules = ();
	my $cur = $sc{$name}->cur;
	my $tpath = "";
	if (-e "packages/$tarball[$cur]") {
	    if ($mnt) {
		$tpath = 'mnt/';
	    } elsif (-x $has_avfsd) {
		$tpath = 'mnt/packages/' . $tarball[$cur] . '#/';
	    }
	}
	foreach my $path (sort keys %pscripts) {
	    if ($mnt || -x $has_avfsd) {
		my $found = 0;
		if (-e $tpath . $path) {
		    $found++;
		} else {
		    $path =~ s@texmf[^/]*/@@;
		}
		if (-e $tpath . $path) {
		    $found++;
		}
		if ($found == 0) {
		    print STDERR "Script of $name $path does not exist\n";
		    next;
		}
		$path = $tpath . $path;
		my $magic = `head -n 1 '$path'`;
		my $base = $path;
		$base =~ s@.*/@@g;
		if ($magic =~ m@^#!.*perl@ || $base =~ m@.*\.(pl|pm|perl)@) {
		    my @modules = `/usr/lib/rpm/perl.req $path`;
		    foreach my $dep (@modules) {
			chomp($dep);
			next if ($dep =~ m/(pdfTeX|only)/);  # Wrong as this is in a comment!
			next if ($dep =~ m/(path_tre)/);     # Provides as Tk::path_tre in the same package (texlive-context)
			next if ($dep =~ m/perl /);   # Mostly old versions
			next if ($dep =~ m/tools/);   # Patched out
			next if ($dep =~ m/LatexIndent::/ && $name =~ m/latexindent/);	# Package latexindent does include this
			next if ($dep =~ m/\.yaml/ && $name =~ m/latexindent/);		# Package latexindent use this optional
			$dep = 'perl(strict)' if ($name =~ m/a2ping/); # Perl script includes its own dependcies
			$pmodules{$dep} = 1;
		    }
		}
	    }
	}
	foreach my $dep (sort keys %pmodules) {
	    $dependx[$cnt++] = 'Requires:       ' . "$dep";
	    $dependx[$cnt++] = '#!BuildIgnore:  ' . "$dep";
	}
    }

    foreach my $depend (@dependx) {
	if ($depend =~ /^%/) {
	    print $depend;
	    print "\n";
	    next;
	}
	if ($depend =~ /^(Requires|Recommends|Suggests)/) {
	    print $depend;
	    print  ' >= %{texlive_version}' if ($depend =~ /texlive/ && $depend !~ /[<>=]/);
	    print "\n";
	    next;
	}
	if ($depend =~ /^(Obsoletes|Provides|Conflicts|BuildArch)/) {
	    print $depend;
	    print "\n";
	    next;
	}
	if ($depend =~ /^#/) {
	    print $depend;
	    print "\n";
	    next;
	}
	if ($noarch && $depend =~ /.*-bin$/) {
	    if ($depend =~ m/^texlive-scripts/) {
		print 'Requires(pre):  ' . $depend .  ' >= %{texlive_version}' . "\n" if $name !~ /.*texlive.infra.*/;
		print '#!BuildIgnore: ' . $depend .  "\n" if $name !~ /.*texlive.infra.*/;
	    } else {
		print 'Requires(pre):  texlive-' . $depend .  ' >= %{texlive_version}' . "\n" if $name !~ /.*texlive.infra.*/;
		print '#!BuildIgnore: texlive-' . $depend .  "\n" if $name !~ /.*texlive.infra.*/;
	    }
	} else {
	    $depend =~ s/-X_Y_Z$/-bin/;
	    if ($depend =~ m/^texlive-scripts/) {
		print 'Requires:       ' . $depend .  ' >= %{texlive_version}' . "\n";
		print '#!BuildIgnore: ' . $depend .  "\n";
	    } else {
		print 'Requires:       texlive-' . $depend .  ' >= %{texlive_version}' . "\n";
		print '#!BuildIgnore: texlive-' . $depend .  "\n";
	    }
	}
    }
    @dependx = ();
    $cnt = 0;

    $reqpack = shift(@reqpack);
    $reqpack =~ s@[^\/]+/([^\.\/]+)\.requires@$1@g;
    if ($reqpack =~ m/^$target$/) {
	foreach (@reqpack) {
	    next if m@^$@;
	    next if m@^packages/@;
	    print $_;
	    print ' >= %{texlive_version}' if /texlive/ && ! /[<>=]/;
	    print "\n";
	}
    }
    if (keys %provides) {
	my $cur = $sc{$name}->cur;
	my $inc = 256;
	my $beg = 0;
	my $end = 0;
	my %requires = ();
	my %seen = ();
	my @unique = ();
	my @vffonts = ();
	my $tpath = "";
	if (-e "packages/$tarball[$cur]") {
	    if ($mnt) {
		$tpath = 'mnt/';
	    } elsif (-x $has_avfsd) {
		$tpath = 'mnt/packages/' . $tarball[$cur] . '#/';
	    }
	    if ("$tarball[$cur]" =~ /asymptote\.tar\.xz/) {
		if ($mnt || -x $has_avfsd) {
		    my $file;
		    if (-e $tpath . "texmf/asymptote/version.asy") {
			$file = $tpath . "texmf/asymptote/version.asy";
		    } elsif (-e $tpath . "texmf-dist/asymptote/version.asy") {
			$file = $tpath . "texmf-dist/asymptote/version.asy";
		    } else {
			$file = $tpath . "asymptote/version.asy";
		    }
		    open(FILE, "cat $file |") or next;
		} else {
		    my $file = "texmf/asymptote/version.asy";
		    open(FILE, "tar OxJf packages/$tarball[$cur] $file |") or next;
		}
		my $found = 0;
		while (<FILE>) {
		    chomp();
		    s/.*=//;
		    s/[\"\;]//g;
		    if ("$asymptoteversion" eq "$_") {
			$found++;
			last;
		    }
		}
		FILE->autoflush(1);
		close(FILE);
		die "Asymptote: binary version does not match package version" if ($found <= 0);
	    }
	}
	foreach my $path (sort keys %provides) {
	    my $provide = $path;
	    my $type = $provides{$path};
	    if ($pkg && ($mnt || -x $has_avfsd)) {
		my $found = 0;
		for (my $n = $sc{$name}->cur; $n < $sc{$name}->tar; $n++) {
		    next if (! -e "packages/$tarball[$n]");
		    $tpath = 'mnt/packages/' . $tarball[$n] . '#/';
		    if (-e $tpath . $path) {
			$found++;
			$provides{$path} = 4 if ($tarball[$n] =~ m/\.doc.tar.xz/ && ($loads & (1|4)) == (1|4));
			$type = $provides{$path};
			last;
		    } else {
			my $short = $path;
			$short =~ s@texmf[^/]*/@@;
			if (-e $tpath . $short)  {
			    $found++;
			    $provides{$path} = 4 if ($tarball[$n] =~ m/\.doc.tar.xz/ && ($loads & (1|4)) == (1|4));
			    $type = $provides{$path};
			    $path = $short;
			    last;
			}	
		    }
		}
		if ($found == 0) {
		    print STDERR "Provides of $name $provide does not exist\n";
		    next;
		}
		$path = $tpath . $path;
	    }
	    $provide =~ s@.*/@@;

	    $seen{$provide} = 1;
	    if ($provide =~ /\.vf$/) {
		push @vffonts, $path;
	    }

	    print STDERR "Provides > $provide\n" if ($opts{d});
	    print 'Provides:       tex(' . $provide . ")\n" if ($type == 1);
	#
	# For dev(elopment) packages to avoid conflicts with standard packages
	# providing the same e.g. style or class file
	#
	    print 'Provides:       texdev(' . $provide . ")\n" if ($type == 2);
	    print 'Provides:       man(' . $provide . ")\n" if ($type == 3);
	    $requires{'java'} = 1 if ($provide =~ m@\.jar$@);
	    if ($provide =~ m@\.ldf$@ && $ldfmap{$provide}) {
		my $hp = 'texlive-' . "$ldfmap{$provide}";
		$requires{$hp} = 1;
	    }
	    next if (!$pkg);
	    push @unique, $path if ($path =~ m@$regsubscr@);
	    push @unique, $path if ($path =~ m@\.[15]$@);
	}
	if ($#vffonts > 0) {
	    for ($beg = 0, $end = $inc; $beg <= $#vffonts;) {
		my @tmp = @vffonts[$beg .. $end];
		$beg += ($#tmp + 1);
		$end += ($#tmp + 1);
 		open TFM, '-|', join(' ', "$vffont", '-p', @tmp, '|', 'sort', '-u');
		while (<TFM>) {
		    chomp;
		    $requires{$_} = 1 if (!exists $seen{$_});
		}
		close TFM;
	    }
	}
	@vffonts = ();
	for (my $n = $sc{$name}->cur; $n < $sc{$name}->tar; $n++) {
	    next if (! -e "packages/$tarball[$n]");
	    next if ($#unique < 0);
	    if ($mnt || -x $has_avfsd) {
		my $files = join(' ', @unique);
		open(FILE, "cat $files |") or next;
	    } else {
		my $files = join(' ', @unique);
		open(FILE, "tar OxJf packages/$tarball[$n] $files |") or next;
	    }
	    @unique = ();
	    while (<FILE>) {
		next if /^[[:blank:]]*%/;
		next if /^[[:blank:]]*$/;
		next if /\\(def|newcommand)/;
		/\\(usepackage|RequirePackage|RequirePackageWithOptions)[[:blank:]]*(\[.*\])?[[:blank:]]*{([^}]*)}.*/ && do {
		    s/[[:blank:]]*//g;
		    my @listy = split(/\\(usepackage|RequirePackageWithOptions|RequirePackage)/, $_);
		    foreach my $l (@listy) {
			chomp($l);
			$l =~ s/%.*//g;
			$l =~ s/[[:blank:]]*//g;
			$l =~ m/(\[.*\])?{([^}]*)}.*/;
			$l = $2;
			$l =~ s/[{%}]//g;
			$l =~ s/,[[:blank:]]+/,/;
			my @styles = split(/,/, $l);
			foreach my $sty (@styles) {
			    next if ($sty =~ /^\\/);
			    next if ($sty !~ /^[[:alnum:]\._-]+$/);
			    $sty = $sty . '.sty';
			    print STDERR "RequirePackage of $name < $sty\n" if ($opts{d});
			    $requires{$sty} = 1 if (!exists $seen{$sty});
			}
		    }
		    next;
		};
		/^[[:blank:]]*\\LoadClass(\[.*\])?{([^}]*)}.*/ && do {
		    s/.*\\LoadClass(\[.*\])?{([^}]*)}.*/$2/;
		    s/[{%}]//g;
		    s/,[[:blank:]]*/ /g;
		    my @classes = split(' ', $_);
		    foreach my $class (@classes) {
			next if ($class =~ /^\\/);
			next if ($class !~ /^[[:alnum:]\._-]+$/);
			$class = $class . '.cls';
			print STDERR "RequirePackage of $name < $class\n" if ($opts{d});
			$requires{$class} = 1 if (!exists $seen{$class});
		    }
		    next;
		};
		/^[[:blank:]]*\\input([[:blank:]]+|{?)([^[:blank:]}]*)([[:blank:]]+|}?).*/ && do {
		    s/.*\\input([[:blank:]]+|{?)([^[:blank:]}]*)([[:blank:]]+|}?).*/$2/;
		    s/[{%}]//g;
		    s/[[:blank:]]*//g;
		    chomp;
		    if ((/$regsubscr/ || /$regsuboth/) && /^[[:alnum:]\._-]+$/) {
			print STDERR "input of $name < $_\n" if ($opts{d});
			$requires{$_} = 1 if (!exists $seen{$_});
		    }
		    next;
		};
		/^[[:blank:]]*\\RequireBibliographyStyle(\[.*\])?{([^}]*)}.*/ && do {
		    s/.*\\RequireBibliographyStyle(\[.*\])?{([^}]*)}.*/$2/;
		    s/[{%}]//g;
		    s/,[[:blank:]]*/ /g;
		    my @styles = split(' ', $_);
		    foreach my $bbx (@styles) {
			next if ($bbx =~ /^\\/);
			next if ($bbx !~ /^[[:alnum:]\._-]+$/);
			$bbx = $bbx . '.bbx';
			print STDERR "RequireBibliographyStyle of $name < $bbx\n" if ($opts{d});
			$requires{$bbx} = 1 if (!exists $seen{$bbx});
		    }
		    next;
		};
		/^[[:blank:]]*\\RequireCitationStyle(\[.*\])?{([^}]*)}.*/ && do {
		    s/.*\\RequireCitationStyle(\[.*\])?{([^}]*)}.*/$2/;
		    s/[{%}]//g;
		    s/,[[:blank:]]*/ /g;
		    my @styles = split(' ', $_);
		    my $bbx;
		    foreach my $cbx (@styles) {
			next if ($cbx =~ /^\\/);
			next if ($cbx !~ /^[[:alnum:]\._-]+$/);
			$bbx = $cbx . '.bbx';
			$cbx = $cbx . '.cbx';
			print STDERR "RequireCitationStyle of $name < $cbx\n" if ($opts{d});
			$requires{$cbx} = 1 if (!exists $seen{$cbx} && !exists $seen{$bbx});
		    }
		    next;
		};
		/^[[:blank:]]*\\InheritBibliographyStrings(\[.*\])?{([^}]*)}.*/ && do {
		    s/.*\\InheritBibliographyStrings(\[.*\])?{([^}]*)}.*/$2/;
		    s/[{%}]//g;
		    s/,[[:blank:]]*/ /g;
		    my @langs = split(' ', $_);
		    foreach my $lng (@langs) {
			next if ($lng =~ /^\\/);
			next if ($lng !~ /[[:alnum:]\._-]/);
			$lng = $lng . '.lbx';
			print STDERR "InheritBibliographyStrings of $name < $lng\n" if ($opts{d});
			$requires{$lng} = 1  if (!exists $seen{$lng});
		    }
		};
		/^\.so[[:blank:]]+man[15]\// && do {
		    s/^\.so[[:blank:]]+man[15]\///;
		    s/[[:blank:]]*//g;
		    chomp;
		    print STDERR "Current manual page of $name < $_\n" if ($opts{d});
		    $requires{$_} = 3 if (!exists $seen{$_});
		};
		#
		# Some more Requires?
		#
	    }
	    FILE->autoflush(1);
	    close(FILE);
	}
	@unique = ();
	foreach my $require (sort keys %requires) {
	    my $found = "";
	    my $type = $requires{$require};
	    print 'Requires:       java' . "\n" if ($require =~ m@java@);
	    print 'Recommends:     ' . "$require\n" if ($require =~ m@texlive-hyphen@);
	    next if (exists $seen{$require});
	    next if (!exists $allfiles{$require} && !exists $devfiles{$require} && !exists $manfiles{$require});
	    foreach my $k (keys %mvfiles) {
		my $move = $k;
		$move =~ s@.*/@@;
		next if ($move ne $require);
		$found = $move;
		last;
	    }
	    next if ($require =~ m/milog\.cfg/);    # This is an example as well as it is optional
	    if ($pkg && $name =~ m/.*-dev$/ && exists $devfiles{$require}) {
		if ($found) {
		    print 'Provides:       texdev(' . $require . ')' . "\n";
		    print 'Provides:       man(' . $require . ")\n" if ($type == 3);
		} else {
		    print 'Requires:       texdev(' . $require . ')' . "\n";
		    print 'Suggests:       man(' . $require . ")\n" if ($type == 3);
		}
		next;
	    }
	    if ($found) {
		print 'Provides:       tex(' . $require . ')' . "\n" if ($type == 1);
		print 'Provides:       texdev(' . $require . ")\n" if ($type == 2);
		print 'Provides:       man(' . $require . ")\n" if ($type == 3);
	    } else {
		print 'Requires:       tex(' . $require . ')' . "\n" if ($type == 1);
		print 'Requires:       texdev(' . $require . ")\n" if ($type == 2);
		print 'Suggests:       man(' . $require . ")\n" if ($type == 3);
	    }
	}
    }
    if ($pkg) {
	print "# Download at " . $srcurl . "/\n";
	print "# from $srcdate\n";
	for ($n = $sc{$name}->cur; $n < $sc{$name}->tar; $n++, $global_source_counter++) {
	  printf("%-16s%s\n", "Source" . $global_source_counter . ":", $tarball[$n]);
	  $used_files{$tarball[$n]} = $global_source_counter;
	}
    }
    if ($pkg && $patch_hook) {
	($scx, $scd, $scr, $scb, $src) = $sc{$name}->current;
	&$patch_hook();
	$sc{$name}->update($scx, $scd, $scr, $scb, $src);
    }
    if ($noarch) {
	print $noarch . "\n" unless $pkg;
    } else {
	print 'Prefix: %{_bindir}' . "\n";
    }
    &$macros_hook() if ($pkg && $macros_hook);
    if (!$pkg) {
	if ($full) {
	    print "\n%description -n " . $full . $target . "\n";
	} else {
	    if ($target =~ m/^texlive-scripts/) {
		print "\n%description -n " . $target . "\n";
	    } else {
		print "\n%description " . $target . "\n";
	    }
	}
    } else {
	if ($target =~ m/^texlive-scripts/) {
	    print "\n%description -n $target" . "\n";
	} else {
	    print "\n%description -n texlive-$target" . "\n";
	}
    }
    if ($desc[0]) {
	for ($n = 0; $n < $idx; $n++) {
	    print $desc[$n] . "\n";
	}
    } elsif (!$noarch) {
	print $summary . "\n";
    } else {
	print 'The ' . $target . ' package' . "\n";
    }
    if ($date) {
	$date = `date --date="$date" --utc +"%Y-%m-%d %T %z"`;
	print "\ndate: " . $date . "\n";
    }
    if (($return[1] & 39) == 7 || ($return[1] & 39) == 35) {
	#
	# Here we handle dependencies for all doc packages
	#
	if ($target =~ m/texlive-scripts$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-tetex-doc < 2020';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/fmtutil-sys.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/fmtutil-user.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/fmtutil.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/updmap-sys.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/updmap-user.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/updmap.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man5/fmtutil.cnf.5%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man5/updmap.cfg.5%{?ext_man}';
	    $dependx[$cnt++] = 'Conflicts:      texlive-texconfig-doc';
	    $dependx[$cnt++] = 'Provides:       texlive-texconfig-doc:%{_mandir}/man1/texconfig-sys.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-texconfig-doc:%{_mandir}/man1/texconfig.1%{?ext_man}';
	} elsif ($target =~ m/^texlive-scripts-extra$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-texconfig-doc < 2018';
	    $dependx[$cnt++] = 'Obsoletes:      texlive-pdftools-doc < 2020';
	    $dependx[$cnt++] = 'Provides:       texlive-pdftools-doc:%{_mandir}/man1/e2pall.1%{?ext_man}';
	    $dependx[$cnt++] = 'Obsoletes:      texlive-pstools-doc < 2020';
	    $dependx[$cnt++] = 'Provides:       texlive-pstools-doc:%{_mandir}/man1/ps2frag.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-pstools-doc:%{_mandir}/man1/pslatex.1%{?ext_man}';
	    $dependx[$cnt++] = 'Conflicts:      texlive-tetex-doc < 2020';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/allcm.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/allec.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/allneeded.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/dvi2fax.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/dvired.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/kpsepath.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/kpsetool.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/kpsewhere.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/kpsexpand.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-tetex-doc:%{_mandir}/man1/texlinks.1%{?ext_man}';
	} elsif ($target =~ m/^ps2eps$/) {
	    $dependx[$cnt++] = 'Conflicts:      texlive-pstools-doc';
	    $dependx[$cnt++] = 'Provides:       texlive-pstools-doc:%{_mandir}/man1/bbox.1%{?ext_man}';
	    $dependx[$cnt++] = 'Provides:       texlive-pstools-doc:%{_mandir}/man1/ps2eps.1%{?ext_man}';
	}
	#
	# TeXLive 2022
	#
	if ($target =~ m/^asana-math$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-Asana-Math-doc < 2022';
	} elsif ($target =~ m/^esieecv$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-ESIEEcv-doc < 2022';
	} elsif ($target =~ m/^gs1$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-GS1-doc < 2022';
	} elsif ($target =~ m/^ha-prosper$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-HA-prosper-doc < 2022';
	} elsif ($target =~ m/^ieeeconf$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-IEEEconf-doc < 2022';
	} elsif ($target =~ m/^ieeetran$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-IEEEtran-doc < 2022';
	} elsif ($target =~ m/^memoirchapterstyles$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-MemoirChapStyles-doc < 2022';
	} elsif ($target =~ m/^pst-hsb$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-pst-ghsb-doc < 2022';
	} elsif ($target =~ m/^sistyle$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-SIstyle-doc < 2022';
	} elsif ($target =~ m/^siunits$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-SIunits-doc < 2022';
	} elsif ($target =~ m/^tabbing$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-Tabbing-doc < 2022';
	} elsif ($target =~ m/^tipauni$/) {
	    $dependx[$cnt++] = 'Obsoletes:      texlive-unitipa-doc < 2022';
	}
        #
	#
	if ($name =~ m/^texlive-scripts/) {
	    print "\n%package -n $name-doc\n";
            $dependx[$cnt++] = 'Supplements:    (' . $name . ' and texlive-alldocumentation)';
	} else {
	    print "\n%package -n texlive-$name-doc\n";
            $dependx[$cnt++] = 'Supplements:    (texlive-' . $name . ' and texlive-alldocumentation)';
	}
	print "Version:        $pkg_version\n";
	print "Release:        0\n";
	if ($name =~ m/^texlive-scripts/) {
	    print 'Summary:        Documentation for ' . $name . "\n";
	} else {
	    print 'Summary:        Documentation for texlive-' . $name . "\n";
	}
	print "License:        $license\n";
	print 'Group:          Productivity/Publishing/TeX/Base' . "\n";
	print 'URL:            https://www.tug.org/texlive/' . "\n";
	if ($reqpack =~ m/^$target-doc$/) {
	    foreach (@reqpack) {
		next if m@^$@;
		next if m@^packages/@;
		print $_;
		print ' >= %{texlive_version}' if /texlive/ && ! /[<>=]/;
		print "\n";
	    }
	}
	foreach my $depend (@dependx) {
	    if ($depend =~ /^(Obsoletes|Provides|Conflicts|BuildArch|Supplements|Enhances|Recommends)/) {
		print $depend;
		print "\n";
		next;
	    }
	}
	if (keys %provides) {
	    foreach my $provide (sort keys %provides) {
		my $type = $provides{$provide};
		next if ($type != 4);
		$provide =~ s@.*/@@;
		print 'Provides:       man(' . $provide . ")\n";
	    }
	}
	if ($#locales > -1) {
	    print "Provides:       locale(texlive-" . $name . "-doc:";
	    my $c = 0;
	    foreach my $l (@locales) {
		print ";" if ($c++ > 0);
		print $l
	    }
	    print ")\n";
	}
	if ($realversion) {
	    if ($target =~ m/^mgltex$/) {
		print 'Obsoletes:      mathgl-tex-doc <= 2.3.5.1' . "\n";
		print 'Provides:       mathgl-tex-doc = ' . "$realversion\n";
	    }
	}
	if (grep /%\{_infodir\}/, @docfiles) {
	    print 'Requires(preun): %install_info_prereq' . "\n";
	    print 'Requires(post): %install_info_prereq' . "\n";
	}
	if ($name =~ m/^texlive-scripts/) {
	    print "\n%description -n $name-doc\n";
	} else {
	    print "\n%description -n texlive-$name-doc\n";
	}
	if ($name =~ m/^texlive-scripts/) {
	    print 'This package includes the documentation for ' . $name . "\n";
	} else {
	    print 'This package includes the documentation for texlive-' . $name . "\n";
	}
	print "\n";
    }
    if (($return[1] & 17) == 17) {
	print "\n%package -n texlive-$name-fonts\n";
	print "Version:        $pkg_version\n";
	print "Release:        0\n";
	print 'Summary:        Severed fonts for texlive-' . $name . "\n";
	print "License:        $license\n";
	print 'URL:            https://www.tug.org/texlive/' . "\n";
	print 'Group:          Productivity/Publishing/TeX/Fonts' . "\n";
	if ($reqpack =~ m/^$target-fonts$/) {
	    foreach (@reqpack) {
		next if m@^$@;
		next if m@^packages/@;
		print $_;
		print ' >= %{texlive_version}' if /texlive/ && ! /[<>=]/;
		print "\n";
	    }
	}
	print '%reconfigure_fonts_prereq' . "\n";
	print 'Requires(posttrans): fontconfig' . "\n";
	print 'Requires(posttrans): ghostscript-fonts-std' . "\n";
#	print 'Requires(posttrans): mkfontdir' . "\n";
#	print 'Requires(posttrans): mkfontscale' . "\n";
#
# We do not use xfs at all (would require some lua code in spec %post scriptlet)
#
#	print 'Requires(post): xfs' . "\n";
	if (grep /post=fonts/, @execute) {
	    print 'Requires(posttrans): xfs' . "\n";
	}
#	print 'Requires(posttrans): xorg-x11-fonts-core' . "\n";
	print 'Suggests:       xorg-x11-fonts-core' . "\n";
	print 'BuildArch: noarch' . "\n" unless $pkg;
	print "\n%description -n texlive-$name-fonts\n";
	print 'The  separated fonts package for texlive-' . $name . "\n";
    }
    if ($pkg) {
        $versions{$name} = $pkg_version;

	my $limit = $sc{$name}->tar - $sc{$name}->cur;
	for ($n = 0; $n < $limit; $n++) {
	    if ($name =~ /.*texlive.infra.*/) {
		$install_lines .= '    pushd %{buildroot}%{_texmfdistdir}' . "\n";
		$install_lines .= '        tar --use-compress-program=xz --wildcards -xf %{S:' . $used_files{$tarball[$n]} .  '} --exclude=texmf\*/\*' . "\n";
		$install_lines .= '    popd' . "\n";
		$install_lines .= '    tar --use-compress-program=xz --wildcards -xf %{S:' . $used_files{$tarball[$n]} .  '} -C %{buildroot}%{_datadir}/texlive texmf\*/' . "\n";
		next;
	    }
	    if ($isreloc) {
		$install_lines .= '    tar --use-compress-program=xz -xf %{S:' . $used_files{$tarball[$n]} .  '} -C %{buildroot}%{_datadir}/texlive/texmf-dist' . "\n";
            } else {
		$install_lines .= '    tar --use-compress-program=xz -xf %{S:' . $used_files{$tarball[$n]} .  '} -C %{buildroot}%{_datadir}/texlive' . "\n";
	    }
	}
	if ($#patches > -1) {
	    $install_lines .= '    pushd %{buildroot}%{_datadir}/texlive/texmf-dist' . "\n";
	    for ($n = 0; $n <= $#patches; $n++) {
		$install_lines .= "\t" . 'patch --reject-format=unified --quoting-style=literal -f -p1 -F0 -T < %{S:' . $used_files{$patches[$n]} . "}\n";
	    }
	    $install_lines .= "    popd\n";
	}
	if (defined($hyphens)) {
	    $install_lines .= '    mkdir -p %{buildroot}%{_texmfdistdir}/tex/generic/config/language.splits' . "\n";
	    $install_lines .= '    (cat > %{buildroot}%{_texmfdistdir}/tex/generic/config/language.splits/' . "$name" . ".dat)<<'EOF'" . "\n";
	    $install_lines .= join("", $hyphens->dat_lines($name));
	    $install_lines .= 'EOF' . "\n";
	    $install_lines .= '    (cat > %{buildroot}%{_texmfdistdir}/tex/generic/config/language.splits/' . "$name" . ".def)<<'EOF'" . "\n";
	    $install_lines .= join("", $hyphens->def_lines($name));
	    $install_lines .= 'EOF' . "\n";
	    $install_lines .= '    (cat > %{buildroot}%{_texmfdistdir}/tex/generic/config/language.splits/' . "$name" . ".dat.lua)<<'EOF'" . "\n";
	    $install_lines .= join("", $hyphens->lua_lines($name));
	    $install_lines .= 'EOF' . "\n";
	    $runfiles[$sc{$name}->run++] = '%{_texmfdistdir}/tex/generic/config/language.splits/' . "$name" . '.dat';
	    $runfiles[$sc{$name}->run++] = '%{_texmfdistdir}/tex/generic/config/language.splits/' . "$name" . '.def';
	    $runfiles[$sc{$name}->run++] = '%{_texmfdistdir}/tex/generic/config/language.splits/' . "$name" . '.dat.lua';
	    $return[1] |= 4;	# Has runfiles, indeed!
	}
	if ($name eq 'texdoc') {
	    $install_lines .= '    mkdir -p %{buildroot}%{_texmfdistdir}/tlpkg' . "\n";
	    $install_lines .= '    echo %% empty > %{buildroot}%{_texmfdistdir}/tlpkg/texlive.tlpdb' . "\n";
	}
    }
    if ($pkg) {
	($scx, $scd, $scr, $scb, $src) = $sc{$name}->current;
	push @execute, reorder($name, $isreloc);
	$sc{$name}->update($scx, $scd, $scr, $scb, $src);
    }
    if ($pkg) {
	scripts($name, @execute);
    }
    ($scx, $scd, $scr, $scb, $src) = $sc{$name}->current;

    if ($mnt) {
	`fusermount -u -z mnt/`;
	sleep(0.02);
	pop @clean;
    }

    return @return;
}

sub doprovide {
    my $path = shift;
    if ($path =~ m@/[^/]+$regsubscr@) {
	$path =~ s@^[[:blank:]](RELOC/)?@@;
	return $path;
    }
    if ($path =~ m@/[^/]+$regsuboth@) {
	$path =~ s@^[[:blank:]](RELOC/)?@@;
 	return "" if ($path =~ m@/language\.us@);
	return $path;
    }
    return "";
}

sub filelist {
    my $n;
    my $provide = shift;
    my $name = $provide;
    my $type = shift;
    my $pkg = shift;

    if ($pkg & 1) {
	if ($pkg & (4|32)) {
	    if ($pkg & 2) {
		if ($name =~ m/^texlive-scripts/) {
		    print "%files -n $name-doc\n";
		} else {
		    print "%files -n texlive-$name-doc\n";
		}
		print "$_\n" foreach (@docfiles);
		print "\n";
	    }
	    # either source files only or run files will be installed
	    if ($name =~ m/^texlive-scripts/) {
		print "%files -n $name\n";
	    } else {
		print "%files -n texlive-$name\n";
	    }
	    print "$_\n" foreach (@srcfiles);
	    print "$_\n" foreach (@runfiles);
	} elsif ($pkg & 2) {
	    if ($name =~ m/^texlive-scripts/) {
		print "%files -n $name\n";
	    } else {
		print "%files -n texlive-$name\n";
	    }
	    print "$_\n" foreach (@docfiles);
	} else {
	    # empty packages like `bibtexu' which simply requires `bibtexu-bin'
	    # or several hyphen packages which simply runs some scriplets
	    if ($name =~ m/^texlive-scripts/) {
		print "%files -n $name\n";
	    } else {
		print "%files -n texlive-$name\n";
	    }
	}
	return;
    }

    for ($n = $sc{$name}->cin; $n < $sc{$name}->bin; $n++) {
	$_ = $binfiles[$n];
	# :NB:
	# Special setup: we use xaw3d for xdvi and also have some
	# added formats for musixtex around.  Beside this add
	# missed binaries for musixtex.
	#
	s/-xaw$/-xaw3d/;
	print '%if %{with LuaJIT}' . "\n" if m@/mfluajit.*@;
	print "$_\n";
	print '%endif' . "\n" if m@/mfluajit.*@;
	if (m@/musixtex$@) {
	    my $base = $_;
	    $base =~ s@/musixtex$@/@;
	    print $base . "pdfmusixtex\n";
	}
	if (m@/ovp2ovf$@) {
	    my $base = $_;
	    $base =~ s@/ovp2ovf$@/@;
	}
	if (m@/dvitodvi$@) {
	    my $base = $_;
	    $base =~ s@/dvitodvi$@/@;
	    print $base . "a4toa5\n";
	    print $base . "mydvichk\n";
	    print $base . "odd2even\n";
	}
	if (m@/mtxrun$@) {
	    my $base = $_;
	    $base =~ s@/mtxrun$@/@;
	    print $base . "rlxtools\n";
	}
	if (m@/texdef$@) {
	    my $base = $_;
	    $base =~ s@/texdef$@/@;
	}
    }
}

sub texmftree {
    my $flags=0;
    my $skip=0;
    my $dir;
    my @dirs;
    my %hash;
    my @src=();

    while (<$tlpfh>) {
	if (/^name/ .. /^[[:blank:]]*$/) {
	    my $max;
	    my $n;
	    if (/^[[:blank:]]*$/) {
		$skip=0;
		next;
	    }
	    next if ($skip);
	    chomp;
	    $flags|=1 if (/^srcfiles/);
	    $flags|=2 if (/^docfiles/);
	    $flags|=4 if (/^runfiles/);
	    $flags=8  if (/^binfiles/);
	    $skip++ if /^name[[:blank:]]+00/;
	    $skip++ if /^name[[:blank:]]+($regexp)/;
	    $skip++ if /^name[[:blank:]]+scheme-/;
	    $skip++ if /^name[[:blank:]]+collection-/;
	    $skip++ if /^name[[:blank:]]+.*\..*-.*/;
	    $skip++ if /^name[[:blank:]]+.*\.win32/;
	    $skip++ if /^name[[:blank:]]+.*\.windows/;
	    if (/^name[[:blank:]]+/) {
		my $name;
		s/^name[[:blank:]]+//;
		$name = $_;
		$flags=0;
		$flags=16 if (grep /^$name$/, @nosource);
		@src=();
		next;
	    }
	    next if (!/^[[:blank:]]/);
	    next if ((7 & $flags) == 0);
	    s/[[:blank:]]+details=.*$//;
	    s@^[[:blank:]]RELOC/@%{_texmfdistdir}/@ if (m@^[[:blank:]]RELOC/@);
	    s@^[[:blank:]]texmf-dist/@%{_texmfdistdir}/@ if (m@^[[:blank:]]texmf-dist/@);
	    s@^[[:blank:]]texmf/@%{_texmfmaindir}/@ if (m@^[[:blank:]]texmf/@);
	    s@^[[:blank:]]@%{_texmfmaindir}/@ if (/^[[:blank:]]/);
	    if ($flags & 16) {
		next if (m@^%\{_texmf(main|dist)dir\}/source/@);
	    }
	    next if (m@/tlpkg/installer/.*@);
	    next if (m@/tlpkg/tlp.*/.*@);
	    next if (m@/texconfig/[xvg]/.*@);
	    next if (m@/doc/info/.*@);
	    next if (m@/doc/man/.*@);

	    #
	    # forget source directories if runfiles are found
	    #
	    if (4 & $flags) {
		foreach $dir (@src) {
		    delete $hash{$dir} if (defined($hash{$dir}));
		}
		@src=();
	    }

	    #
	    # Split path and forget last entry
	    #
	    @dirs = split(/\/+/);
	    pop(@dirs);
	    $dir = shift(@dirs);

	    $max = $#dirs;
	    foreach my $d (@dirs) {
		$dir=join('/', $dir, $d);
		if (($flags & 7) <= 3 && m@dir}/source@) {
		    # Only remove later on if not already added !!
		    push @src, $dir if !defined($hash{$dir});
		}
		if ($max-- <= 0) {
		    next if (defined($hash{$dir}) && $hash{$dir});
			$hash{$dir} = 1;
		    } else {
		    next if (defined($hash{$dir}) && !$hash{$dir});
		    $hash{$dir} = 0;
		}
	    }
	}
    }
    return %hash;
}

sub scripts {
    my $name = shift;
    my @execute = @_;
    my $varrun = "/var/run/texlive";
    my $dohash = "/var/run/texlive/run-mktexlsr";
    my $doupdate = "/var/run/texlive/run-update";
    my $dofmtu = "/var/run/texlive/run-fmtutil";
    my $doupdm = "/var/run/texlive/run-updmap";
    my $dohyph = "";
    my $post = "";
    my $doconly = 1;
    my @trigger = ();
    for (my $n = $sc{$name}->cur; $n < $sc{$name}->tar; $n++) {
        next if ($tarball[$n] !~ /.*\.doc\.tar\.xz/);
        next if ($n == $sc{$name}->cur);
	$doconly = 0;
    }
    $execute[0] = "empty" if ($#execute < 0);
    if (grep /execute=[aA]dd(Hyphen)/, @execute) {
	$dohyph = "/var/run/texlive/run-hyphen";
    }
    if ($doconly && grep /%\{_infodir\}/, @docfiles) {
	if ($name =~ m/^texlive-scripts/) {
	    print "%preun -n $name\n";
	} else {
	    print "%preun -n texlive-$name\n";
	}
	print 'if test $1 = 0; then' . "\n";
	foreach my $info (grep /%\{_infodir\}/, @docfiles) {
	    $info =~ s@\*$@@;
	    print '    %install_info_delete --info-dir=%{_infodir} ' . "$info\n";
	    $info = $info . '*';
	}
	print "fi\n\n";
    } elsif (grep /%\{_infodir\}/, @runfiles) {
	if ($name =~ m/^texlive-scripts/) {
	    print "%preun -n $name\n";
	} else {
	    print "%preun -n texlive-$name\n";
	}
	print 'if test $1 = 0; then' . "\n";
	foreach my $info (grep /%\{_infodir\}/, @runfiles) {
	    $info =~ s@\*$@@;
	    print '    %install_info_delete --info-dir=%{_infodir} ' . "$info\n";
	    $info = $info . '*';
	}
	print "fi\n\n";
    }
    if ($target =~ m/^texlive-scripts/) {
	print "%post -n $target\n";
    } else {
	print "%post -n texlive-$target\n";
    }
    print "mkdir -p $varrun\n";
    foreach (grep /postaction=script/, @execute) {
        if (m/\.pl$/) {
	    s/.*file=//;
	    print "mkdir -p $varrun/scriptlets\n";
	    print "cat > $varrun/scriptlets/$name << 'EOF'\n";
	    print '/usr/bin/perl %{_texmfmaindir}/' . "$_ install " . '%{_texmfmaindir}' . "\n";
	    print "EOF\n";
	    next;
	}
	s@.*/([^\.]*)(\.[^\.]*)?@packages/$1.post@;
	print "mkdir -p $varrun/scriptlets\n";
	print "cat > $varrun/scriptlets/$name << 'EOF'\n";
	open POST, "<$_" or die "File $_ is missed as a replacement for postaction script";
	my @lines = <POST>;
	close POST;
	print @lines;
	print "EOF\n";
    }
    $post = "packages/" . $name . ".post";
    if (-e $post) {
	print "mkdir -p $varrun/scriptlets\n";
	print "cat > $varrun/scriptlets/$name << 'EOF'\n";
	open POST, "<$post" or die "File $post is missed for post scriptlet";
	my @lines = <POST>;
	close POST;
	print @lines;
	print "EOF\n";
    }
    if ($doconly) {
	foreach my $info (grep /%\{_infodir\}/, @docfiles) {
	    $info =~ s@\*$@@;
	    print '%install_info --info-dir=%{_infodir} ' . "$info\n";
	    $info = $info . '*';
	}
    }
    print "> $dohash\n";
    print "> $doupdate\n" if ($name !~ m/^hyphen-base$/);
    print "> $dofmtu.language\n" if ($dohyph);
    print "> $dohyph\n" if ($dohyph);
    foreach my $e (sort @execute) {
	if ($e =~ m/execute=[aA]dd(Format)/) {
	    my @line = quotewords('[[:blank:]]+', 1, $e);
	    my %format = map { quotewords('=', 0, $_) } @line;
	    next if ! exists $format{name};

	    my @tmpt = split(/,/, $format{fmttriggers});
	    my %hash   = map { $_, 1 } @tmpt;
	    @trigger = keys %hash;			# For later use

	    print "> $dofmtu.$format{name}\n";
	    print "sed -ri '" . 's/^\#\![[= =]]+' . $format{name} . '\b.*/';
	    print $format{name};
	    print " $format{engine}";
	    if (exists $format{patterns} && $format{patterns}) {
		print " $format{patterns}";
	    } else {
		print ' -';
	    }
	    print " $format{options}";
	    print '/' . "'" . ' %{_texmfconfdir}/web2c/fmtutil.cnf || :' . "\n";
	    next;
	}
	if ($e =~ m/execute=[aA]dd(Mixed|Kanji)?Map/) {
	    my $line = $e;
	    $line =~ s/execute=//;
	    chomp($line);
	    print "echo '$line' >> $doupdm\n";
	}
    }
    foreach my $info (grep /%\{_infodir\}/, @runfiles) {
	$info =~ s@\*$@@;
	print '%install_info --info-dir=%{_infodir} ' . "$info\n";
	$info = $info . '*';
    }
    print "\n";
    if ($target =~ m/^texlive-scripts/) {
	print '%postun' . " -n $target\n";
    } else {
	print '%postun' . " -n texlive-$target\n";
    }
    print "mkdir -p $varrun\n";
    print "> $dohash\n";
    print "> $doupdate\n" if ($name !~ m/^hyphen-base$/);
    print 'if test $1 = 0; then' . "\n";
    print "    > $dofmtu.language\n" if ($dohyph);
    print "    > $dohyph\n" if ($dohyph);
    foreach my $e (sort @execute) {
	if ($e =~ m/[aA]dd(Format)[[:blank:]]+/) {
	    my @line = quotewords('[[:blank:]]+', 1, $e);
	    my %format = map { quotewords('=', 0, $_) } @line;
	    next if ! exists $format{name};
	    print "    sed -ri '" . 's/^(' . $format{name} . '\b)/\#\!\ \1';
	    print '/' . "'" . ' %{_texmfconfdir}/web2c/fmtutil.cnf || :' . "\n";
	    print '    rm -f %{_texmfvardir}/web2c/' . "$format{engine}/$format{name}.*\n";
	    next;
	}
	if ($e =~ m/execute=[aA]dd(Mixed|Kanji)?Map/) {
	    my $line = $e;
	    $line =~ s/execute=[aA]dd/delete/;
	    chomp($line);
	    print "    echo '$line' >> $doupdm\n";
	}
    }
    foreach my $info (grep /%\{_infodir\}/, @runfiles) {
	$info =~ s@\*$@@;
	print '%install_info_delete --info-dir=%{_infodir} ' . "$info\n";
	$info = $info . '*';
    }
    print "    exit 0\n";
    print "fi\n";
    print "\n";
    if ($#trigger >= 0) {
	foreach my $t (sort @trigger) {
	    next if ($target eq $t);
	    my $triggerlines = "";
	    foreach my $e (sort @execute) {
		if ($e =~ m/execute=[aA]dd(Format)/) {
		    my @line = quotewords('[[:blank:]]+', 1, $e);
		    my %format = map { quotewords('=', 0, $_) } @line;
		    next if ! exists $format{name};
		    $triggerlines .= "> $dofmtu.$format{name}\n";
		}
	    }
	    next if ($triggerlines eq "");
	    print "\n";
	    print '%triggerin' . " -n texlive-$target -- texlive-$t\n";
	    print $triggerlines;
	    print "\n";
	    print '%triggerun' . " -n texlive-$target -- texlive-$t\n";
	    print $triggerlines;
	}
    }
    if ($target =~ m/^texlive-scripts/) {
	print '%posttrans' . " -n $target\n";
    } else {
	print '%posttrans' . " -n texlive-$target\n";
    }
    print "test -d $varrun || exit 0\n";
    if ($name =~ m/^kpathsea$/) {
	print 'test -e /var/run/texlive/run-mktexlsr || exit 0' . "\n";
        print '%{_bindir}/mktexlsr > /dev/null 2>&1 || :' . "\n";
	print 'rm -f /var/run/texlive/run-mktexlsr' . "\n";
    } elsif ($name =~ m/^texconfig$/) {
	print 'test -e /var/run/texlive/run-mktexlsr || exit 0' . "\n";
        print '%{_bindir}/mktexlsr > /dev/null 2>&1 || :' . "\n";
	print 'rm -f /var/run/texlive/run-mktexlsr' . "\n";
    } else {
	print 'VERBOSE=false %{_texmfdistdir}/texconfig/update || :' . "\n";
    }
    if ($name =~ m/^texlive-scripts/) {
	print 'test -e /var/run/texlive/run-mktexlsr || exit 0' . "\n";
	print '%{_bindir}/mktexlsr > /dev/null 2>&1 || :' . "\n";
	print 'rm -f /var/run/texlive/run-mktexlsr' . "\n";
    }
    print "\n";
    if (!$doconly && grep /%\{_infodir\}/, @docfiles) {
	print "\n%preun -n texlive-$name-doc\n";
	print 'if test $1 = 0; then' . "\n";
	foreach my $info (grep /%\{_infodir\}/, @docfiles) {
	    $info =~ s@\*$@@;
	    print '    %install_info_delete --info-dir=%{_infodir} ' . "$info\n";
	    $info = $info . '*';
	}
	print "fi\n\n";
	if ($name =~ m/^texlive-scripts/) {
	    print "%post -n $name-doc\n";
	} else {
	    print "%post -n texlive-$name-doc\n";
	}
	foreach my $info (grep /%\{_infodir\}/, @docfiles) {
	    $info =~ s@\*$@@;
	    print '%install_info --info-dir=%{_infodir} ' . "$info\n";
	    $info = $info . '*';
	}
    }
    # Add post/postun for fonts package if any
    if (grep /post=fonts/, @execute) {
	print <<"EOF";
%reconfigure_fonts_scriptlets -n texlive-$name-fonts
EOF
    }
}

sub reorder {
    my $return = "";
    my $name = shift;
    my $isreloc = shift;
    
    my $reg;
    $reg = '/(' . join('|', @configs) . ')$';
    $reg =~ s/\./\\\./g;
    my @dirs = ();
    my @conf = ();
    for (my $n = $sc{$name}->cun; $n < $sc{$name}->run; $n++) {
	my $file = $runfiles[$n];
	next if $file !~ m@$reg@;
	my $cnf = $1;
	my $dir = $file;
	$dir =~ s@$reg@@;
	$dir =~ s@^[^/]*/@%{_texmfconfdir}/@;
	my $rdir = $dir;
	$rdir =~ s@\{@[{]@g;
	$rdir =~ s@\}@[}]@g;
	push @dirs, $dir if ! grep m@^$rdir@, @dirs;
	push @conf, "mv -f  %{buildroot}$file %{buildroot}$dir/";
	push @conf, "rm -f  %{buildroot}$file";
	push @conf, "ln -sf $dir/$cnf %{buildroot}$file";
	$runfiles[$n] = '%verify(link) ' . $runfiles[$n];
	if (grep /$cnf/, @noreplace) {
	    $runfiles[$scr++] = "%config(noreplace) %verify(not md5 mtime size) $dir/$cnf";
	} else {
	    $runfiles[$scr++] = "%config %verify(not md5 mtime size) $dir/$cnf";
	}
	next if $file !~ m@/XDvi$@;
	push @dirs, '%{_datadir}/X11/app-defaults';
	push @conf, "ln -sf $dir/$cnf %{buildroot}%{_datadir}/X11/app-defaults/";
	$runfiles[$scr++] = '%verify(link) %{_datadir}/X11/app-defaults/' . $cnf;
    }
    if ($#conf > -1) {
	$install_lines .= <<'EOF';
    # Move configuration files
EOF
    }
    $install_lines .= "    mkdir -p %{buildroot}$_\n" foreach (@dirs);
    $install_lines .= "    $_\n" foreach (@conf);
    #
    # Create directories from our extend file list if any
    #
    $install_lines .= '    mkdir -p %{buildroot}' . "$_\n" foreach (@mkdirs);
    if (@rmfiles > 0) {
	$install_lines .= <<'EOF';
    # Remove files
EOF
    }
    foreach (@rmfiles) {
	if (/^%(if|endif)/) {
	    $install_lines .= "$_\n";
	    next;
	}
	$install_lines .= '    rm -vf  %{buildroot}' . "$_\n";
    }
    $install_lines .= '    rm -vrf %{buildroot}' . "$_\n" foreach (@rmdirs);
    foreach my $k (keys %mvfiles) {
	$install_lines .= '    mv -vf %{buildroot}' . "$k" . ' %{buildroot}' . "$mvfiles{$k}\n";
    }
    #
    # Check for scripts
    #
    my $scripts = '(.*' . $subexe . '|(' . join('|', @non_executable_scripts) . '))$';
    my $shebang = '(.*\.(mki[iv]|tex|xml|sty|bst|ist|pm|pe|pro|bib|txt|html|pdf|1|mp|jpg|ind|yaml|def)$|(readme|changes)[^/]*$)';
    my $pyscripts = '(.*' . join('|', @python_scripts) . ')$';
    my $shscripts = '(.*' . join('|', @shell_scripts) . ')$';
    my @executable = ();
    push @executable, @chmod if ($#chmod > -1);
    my @nonexecute = ();
    my @wrongps = ();
    my @locals = ();
    my @rubys = ();
    my @python = ();
    my @python2 = ();
    my @python3 = ();
    my @perls = ();
    my @perlsexec = ();
    my @shell = ();
    my @bash = ();
    my @luas = ();
    my @paths = ();
    my @envs = ();
    my $cur = $sc{$name}->cur;
    my $tpath = 'mnt/';
    for (my $t = $sc{$name}->cur; $t < $sc{$name}->tar; $t++) {
	$tpath = 'mnt/packages/' . $tarball[$t] . '#/' if -x $has_avfsd;
	my @pointer;
	my $start;
	my $stop;
	if ($tarball[$t] !~ /.*\.doc\.tar\.xz/) {
	    if ($#runfiles > -1) {
		@pointer = @runfiles;
		$start = $sc{$name}->cun;
		$stop  = $sc{$name}->run;
	    } else {
		@pointer = @srcfiles;
		$start = $sc{$name}->crc;
		$stop  = $sc{$name}->src;
	    }
	} else {
	    @pointer = @docfiles;
	    $start = $sc{$name}->coc;
	    $stop  = $sc{$name}->doc;
	}
	my $comm = 0;
	for (my $n = $start; $n < $stop; $n++) {
	    my $file = $pointer[$n];
	    my $test = $file;
	    my $base = $file;
	    if ($isreloc) {
		$test =~ s@^%\{_texmfdistdir\}/@@;
	    } else {
		$test =~ s@^%\{_texmfdistdir\}/@texmf-dist/@;
		$test =~ s@^%\{_texmfmaindir\}/@texmf/@;
	    }
	    $test = $tpath . $test;
	    next if ! -e $test;
	    my $stats = stat(qq/$test/);
	    $base =~ s@.*/@@g;

	    if (($stats->mode & 07755) == 0755) {
		my $magic = `head -n 1 "$test"`;
		chomp($magic);
		if ($magic =~ m@^%![[:blank:]]*/@i) {
		    push @wrongps, $file;
		    next;
		}
		if ($magic =~ m@^#![[:blank:]]*(/usr/[^/]+|/opt(/[^/]+)?)/bin@i) {
		    push @locals, $file;
		    next;
		}
		if ($magic =~ m@^#![[:blank:]]*.*bash@i) {
		    next if ($magic =~ m@^#![[:blank:]]*/bin/bash@i);
		    push @bash, $file;
		    next;
		}
		if ($magic =~ m@^#![[:blank:]]*(/usr)?/bin/env@i) {
		    next if ($magic =~ m@fontforge-interp\.sh@i); # gnu-freefont
		    push @envs, $file;
		    # fall through, sigh!
                }
		if ($magic !~ m@^#!.*ruby@ && $base =~ m@.*\.(rb|ruby)@) {
		    push @rubys, $file;
		    next;
		}
		if ($magic !~ m@^#!.*python@ && $base =~ m@.*\.(py|python)@) {
		    push @python, $file;
		    next;
		}
		if ($magic !~ m@^#!.*python@ && $base =~ m@$pyscripts@) {
		    push @python, $file;
		    next;
		}
		if ($magic !~ m@^#!@ && $base =~ m@.*\.(sh)@) {
		    push @shell, $file;
		    next;
		}
		if ($magic !~ m@^#!.*python@ && $base =~ m@$shscripts@) {
		    push @shell, $file;
		    next;
		}
		if ($magic =~ m@eval[[:blank:]]+["']exec[[:blank:]]+perl@) {
		    push @perlsexec,   $file;
		    next;
		}
		if ($magic !~ m@^#!.*perl@ && $base =~ m@.*\.(pl|perl)@) {
		    push @perls, $file;
		    next;
		}
		if ($magic !~ m@^#!.*(luatex|texlua|lua)@ && $base =~ m@.*\.(lua)@) {
		    if ($magic =~ m@^#[[:blank:]]*(/usr)?/bin/env@i) {
			push @envs, $file;
			next;
		    }
		    push @luas,    $file;
		    next;
		}
		if ($magic !~ m@^#!@ && $base =~ m@$shebang@i) {
		    push @nonexecute, $file;
		    next;
		}
		if ($magic =~ m@^#!.*python@ && $magic !~ m@^#!.*python3@) {
		    push @python2,   $file;
		    next;
		}
		if ($magic =~ m@^#!.*python3@) {
		    push @python3,   $file;
		    next;
		}
		if ($magic !~ m@^#!@ && $base =~ m@.*\.(jar)@) {
		    push @nonexecute, $file;
		    next;
		}
		if ($magic !~ m@^#!@ && $base =~ m@.*\.(tlu)@) {
		    push @nonexecute, $file;
		    next;
		}
		if ($magic !~ m@^#!@ && $base =~ m@.*\.(glsl)@) {
		    push @nonexecute, $file;
		    next;
		}
		if ($magic !~ m@^#!@ && $base =~ m@LICENCE@) {
		    push @nonexecute, $file;
		    next;
		}
		if ($magic !~ m@^#!@) {
		    next if ($base =~ m@.*\.(cmd)@);
		    print STDERR "unknown script for $name: $file\n";
		    push @nonexecute, $file;
		}
	    } elsif (($stats->mode & 07755) != 0755 && $base =~ m@$scripts@i) {
		my $magic = `head -n 1 "$test"`;
		chomp($magic);
		if ($magic =~ m@^#![[:blank:]]*(/usr/[^/]+|/opt(/[^/]+)?)/bin@i) {
		    push @locals, $file;
		}
		if ($magic =~ m@^#![[:blank:]]*.*bash@i) {
		    next if ($magic =~ m@^#![[:blank:]]*/bin/bash@i);
		    push @bash, $file;
		    push @executable, $file if ($magic =~ m@^#!@);
		    next;
		}
		if ($magic =~ m@^#![[:blank:]]*.*sh@i) {
		    push @executable, $file if ($magic =~ m@^#!@);
		    next;
		}
		if ($magic =~ m@^#![[:blank:]]*/bin/(env)@i) {
		    my $skip = 0;
		    foreach my $no (@noexec) {
			$skip = 1 if ($magic =~ m@^#![[:blank:]]*.*$no@i);
		    }
		    next if ($skip == 1);
		    push @paths, $file;
		}
		if ($magic =~ m@^#![[:blank:]]*(/usr)?/bin/env@i) {
		    my $skip = 0;
		    foreach my $no (@noexec) {
			$skip = 1 if ($magic =~ m@^#![[:blank:]]*.*$no@i);
		    }
		    next if ($skip == 1);
		    push @envs, $file;
		}
		if ($magic =~ m@^#!.*python@ && $magic !~ m@^#!.*python3@) {
		    push @python2,   $file;
		}
		if ($magic =~ m@^#!.*python3@) {
		    push @python3,   $file;
		}
		push @executable, $file if ($magic =~ m@^#!@);
	    }
	} # for (my $n = $start; $n < $stop; $n++)
	foreach my $k (keys %mvfiles) {
	    my $file = $k;
	    my $test = $file;
	    my $base = $file;
	    if ($isreloc) {
		$test =~ s@^%\{_texmfdistdir\}/@@;
	    } else {
		$test =~ s@^%\{_texmfdistdir\}/@texmf-dist/@;
		$test =~ s@^%\{_texmfmaindir\}/@texmf/@;
	    }
	    $test = $tpath . $test;
	    next if ! -e $test;
	    my $stats = stat(qq/$test/);
	    $base =~ s@.*/@@g;
	    if (($stats->mode & 07755) == 0755) {
		my $magic = `head -n 1 "$test"`;
		chomp($magic);

		if ($magic !~ m@^#!@ && $base =~ m@$shebang@i) {
		    push @nonexecute, $mvfiles{$k};
		    next;
		}
	    }
	}
    } # for (my $t = $sc{$name}->cur; $t < $sc{$name}->tar; $t++)
    if ($#wrongps > -1) {
        $install_lines .= "    # Correct wrong magic of scripts if any\n";
        $install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@wrongps) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s/^%/#/
		.
		w
		q
	EOF
    done
);
    }
    if ($#rubys > -1) {
        $install_lines .= "    # Correct wrong ruby scripts if any\n";
        $install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@rubys) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		i
		#! /usr/bin/ruby
		.
		w
		q
	EOF
    done
);
    }
    if ($#python > -1) {
        $install_lines .= "    # Correct wrong python scripts if any\n";
        $install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@python) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	head -n 1 %{buildroot}/$scr | grep -q python3 && continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		i
		#! /usr/bin/python%python3_bin_suffix
		.
		w
		q
	EOF
    done
);
    }
    if ($#python2 > -1) {
        $install_lines .= "    # Correct shebang of python3 scripts if any\n";
        $install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@python2) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
        $install_lines .= q(
    do
        test -e %{buildroot}/$scr || continue
	head -n 1 %{buildroot}/$scr | grep -q python%python3_bin_suffix && continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s@python[23]\?[^\s]*@python%python3_bin_suffix@
		.
		w
		q
	EOF
    done
);
    }
    if ($#shell > -1) {
	$install_lines .= "    # Add shebang e.g. correct perl wrapper scripts if any\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@shell) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		i
		#! /bin/sh
		.
		w
		q
	EOF
    done
);
    }
    if ($#perlsexec > -1) {
	$install_lines .= "    # Correct wrong perl scripts if any\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@perlsexec) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		1,/\sif 0;$/d
		1
		i
		#! /usr/bin/perl
		.
		w
		1,3p
		q
	EOF
    done
);
    }
    if ($#perls > -1) {
	$install_lines .= "    # Correct wrong perl scripts if any\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@perls) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		i
		#! /usr/bin/perl
		.
		w
		q
	EOF
    done
);
    }
    if ($#luas > -1) {
	$install_lines .= "    # Correct wrong luaTeX scripts if any\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@luas) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		i
		#! /usr/bin/luatex
		.
		w
		q
	EOF
    done
);
    }
    if ($#executable > -1) {
	$install_lines .= "    # Make possible scripts usable if any\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@executable) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	chmod 0755 %{buildroot}/$scr
    done
);
    }
    if ($#locals > -1) {
	$install_lines .= "    # Avoid /usr/local/bin or similar\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@locals) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s@\\(/usr/[^/]\+\|/opt\\(/[^/]\+\\)\?\\)/bin@/usr/bin@
		.
		w
		q
	EOF
    done
);
    }
    if ($#bash > -1) {
	$install_lines .= "    # Avoid /usr/bin/bash or similar\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@bash) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s@^#!.*bash@#!/bin/bash@
		.
		w
		q
	EOF
    done
);
    }
    if ($#paths > -1) {
	$install_lines .= "    # Avoid short paths\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@paths) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s@/bin/@/usr/bin/@
		.
		w
		q
	EOF
    done
);
    }
    if ($#python3 > -1) {
        $install_lines .= "    # Extend python3 scripts with major version only if any\n";
        $install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@python3) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s@python3@python%python3_bin_suffix@
		.
		w
		q
	EOF
    done
);
    }
    if ($#envs > -1) {
	$install_lines .= "    # Avoid /usr/bin/env <prog>\n";
	$install_lines .= "    for scr in ";
	my $start = '';
	foreach my $file (@envs) {
	    $install_lines .= $start;
	    $install_lines .= $file;
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$scr || continue
	ed %{buildroot}/${scr} <<-'EOF'
		1
		s@/env[[:blank:]]\+@/@
		.
		w
		q
	EOF
    done
);
    }
    if ($#nonexecute > -1) {
        $install_lines .= "    # Strip executable bit from non-scripts\n";
        $install_lines .= "    for txt in ";
	my $start = '';
	foreach my $file (@nonexecute) {
	    $install_lines .= "$start$file";
	    $start = " \\\n\t       ";
	}
	$install_lines .= q(
    do
	test -e %{buildroot}/$txt || continue
	chmod 0644 %{buildroot}/$txt
    done
);
    }
    #
    # Move font files below /usr/share/fonts and link them back
    #
    my @fonts = ();
    my %paths = ();
    my $hasotf = 0;
    my $hasttf = 0;
    my $haspff = 0;
    for (my $n = $sc{$name}->cun; $n < $sc{$name}->run; $n++) {
	my $file = $runfiles[$n];
	next if $file !~ m@/(opentype|truetype|type1)/.*\.(pf[ab]|[ot]tf)$@;
	$hasotf = 1 if $file =~ m@/(opentype|truetype|type1)/.*\.otf$@;
	$hasttf = 1 if $file =~ m@/(opentype|truetype|type1)/.*\.ttf$@;
	$haspff = 1 if $file =~ m@/(opentype|truetype|type1)/.*\.pf[ab]$@;
	$runfiles[$n] = '%verify(link) ' . $file;
	push @fonts, $file;
    }
    if ($#fonts > -1) {
	my $newdir = '%{_datadir}/fonts/texlive-' . $name;
	$runfiles[$scr++] = "\n%files -n texlive-$name-fonts";
	$runfiles[$scr++] = '%dir ' . $newdir;
	my @list;
	my %paths = ();
	foreach (@fonts) {
	    @list = split('/');
	    pop @list;
	    $paths{join('/', @list)} = 1;
	}
	my $font_lines = "    # Move font files\n";
	$font_lines .= "    mkdir -p %{buildroot}%{_datadir}/fonts/%{name}\n";
        $font_lines .= "    for font in ";
        my $start = '';
        foreach my $path (sort keys %paths) {
            $font_lines .= $start;
            $font_lines .= '%{buildroot}/' . $path . '/*.{pf[ab],[ot]tf}';
            $start = " \\\n\t\t";
        }
        $font_lines .= "\n";

        $font_lines .= q(    do
        test -e $font || continue
        mv -f $font %{buildroot}%{_datadir}/fonts/%{name}
        base=${font##*/}
        ln -sf %{_datadir}/fonts/%{name}/${base} ${font}
    done
    /usr/bin/mkfontscale %{buildroot}%{_datadir}/fonts/%{name}/
    /usr/bin/mkfontdir -e /usr/share/fonts/encodings/ %{buildroot}%{_datadir}/fonts/%{name}/
    mkdir -p %{buildroot}%{_datadir}/fontconfig/conf.avail
    (cat > %{buildroot}%{_datadir}/fontconfig/conf.avail/58-%{name}.conf)<<-'EOF'
	<?xml version="1.0"?>
	<!DOCTYPE fontconfig SYSTEM "fonts.dtd">

	<!-- ************************************************ -->
	<!-- Use this to disable the TeX fonts of the package -->
	<!--    %{name}    -->
	<!-- Be aware that the configurations in the files    -->
	<!-- 09-texlive*.conf will not be affected by this    -->
	<!-- ************************************************ -->

	<fontconfig>
	  <rejectfont>
	    <glob>%{_datadir}/fonts/%{name}/*</glob>
	  </rejectfont>
	</fontconfig>
	EOF
);
	if ($haspff && ($hasttf || $hasotf)) {
	    $font_lines .= q(
    mkdir -p %{buildroot}%{_sysconfdir}/fonts/conf.d
    (cat > %{buildroot}%{_datadir}/fontconfig/conf.avail/55-%{name}.conf)<<-'EOF'
	<?xml version="1.0"?>
	<!DOCTYPE fontconfig SYSTEM "fonts.dtd">

	<!-- ************************************************ -->
	<!-- Disable plain Type1 font to let fontconfig       -->
	<!-- prefere the OpenType and TrueType fonts          -->
	<!-- ************************************************ -->

	<fontconfig>
	  <selectfont>
	    <rejectfont>
	      <glob>%{_datadir}/fonts/%{name}/*.pf*</glob>
	    </rejectfont>
	  </selectfont>
	</fontconfig>
	EOF
    ln -sf %{_datadir}/fontconfig/conf.avail/55-%{name}.conf %{buildroot}%{_sysconfdir}/fonts/conf.d/55-%{name}.conf
);
	}
	if ($name =~ m/source(code|sans)pro/) {
	    $font_lines .= q(
    pushd %{buildroot}%{_datadir}/fonts/%{name}
	for pfb in *.pfb
	do
	    test -e "$pfb" || continue
	    ! grep -qa /Weight $pfb || continue
	    ! grep -qa /FullName $pfb || continue
	    dicts=$(sed -rn 's@/FontInfo ([0-9]+) dict dup begin@\1@p' $pfb)
	    dicts=$(expr $dicts + 2) || exit 2
	    name=$(echo ${pfb%.*}|sed -r 's/([A-Z])/ \1/g;s/- / /g;s/^ //')
	    weight=$(echo ${pfb%.*}|sed -r 's/.*-//;s/(It.*|LCDFJ)//;s/bold/Bold/')
	    test -n "$weight" || weight=Regular
	    t1ascii $pfb | sed -r "s@(FontInfo )([0-9]+)( dict dup begin)@\1${dicts}\3@;\@^/FamilyName@a \
/FullName ($name) readonly def\n\
/Weight ($weight) readonly def" | t1binary > ${pfb}.tmp
	    mv ${pfb}.tmp $pfb
	done
    popd
);
	}
	if ($name =~ m/sourceserifpro/) {
	    $font_lines .= q(
    pushd %{buildroot}%{_datadir}/fonts/%{name}
	for pfb in *.pfb
	do
	    test -e "$pfb" || continue
	    #(
	    case "$pfb" in
	    *Semibold*.pfb)
		sed -ri 's@(/Weight.*)Semibold(.*def)@\1SemiBold\2@' $pfb ;;
	    esac
	done
    popd
);
	}
	if ($name =~ m/stix/) {
	    $font_lines .= q(
    pushd %{buildroot}%{_datadir}/fonts/%{name}
	for pfb in *.pfb
	do
	    test -e "$pfb" || continue
	    #((((
	    case "$pfb" in
	    *BoldItalic*.pfb)
		sed -ri 's@(/Weight.*)BoldItalic(.*def)@\1Bold\2@' $pfb ;;
	    *-Italic*.pfb)
		sed -ri 's@(/Weight.*)Italic(.*def)@\1Normal\2@' $pfb ;;
	    *mathbbit-bold.pfb)
		sed -ri 's@(/Weight.*)BoldItalic(.*def)@\1Bold\2@' $pfb ;;
	    *mathbbit.pfb)
		sed -ri 's@(/Weight.*)Italic(.*def)@\1Normal\2@' $pfb ;;
	    esac
	done
    popd
);
	}
	$font_lines =~ s/%\{name\}/texlive-$name/g;
	$install_lines .= $font_lines;

	$runfiles[$scr++] = '%{_datadir}/fontconfig/conf.avail/58-texlive-' . $name . '.conf';
	if ($haspff && ($hasttf || $hasotf)) {
	    $runfiles[$scr++] = '%{_datadir}/fontconfig/conf.avail/55-texlive-' . $name . '.conf';
	    $runfiles[$scr++] = '%config %{_sysconfdir}/fonts/conf.d/55-texlive-' . $name . '.conf';
	}
	$runfiles[$scr++] = '%verify(not md5 size mtime) %{_datadir}/fonts/texlive-' . $name . '/encodings.dir';
	$runfiles[$scr++] = '%verify(not md5 size mtime) %{_datadir}/fonts/texlive-' . $name . '/fonts.dir';
	$runfiles[$scr++] = '%verify(not md5 size mtime) %{_datadir}/fonts/texlive-' . $name . '/fonts.scale';
	foreach (@fonts) {
	    s@^.*/@$newdir/@;
	    $runfiles[$scr++] = $_;
	}
	# post/postun for fonts package
	$return = 'post=fonts';
    }
    return $return;
}

#
# A simple package to hold current start and stop number for arrays
# of the used files of one or more package(s).
#
package filenum;
sub new {
    my $self  = {};
    $self->{tar} = 0;
    $self->{doc} = 0;
    $self->{run} = 0;
    $self->{bin} = 0;
    $self->{src} = 0;
    $self->{cur} = 0;
    $self->{coc} = 0;
    $self->{cun} = 0;
    $self->{cin} = 0;
    $self->{crc} = 0;
    bless ($self);
    $self->initialize(@_) if (@_);
    return $self;
}
sub tar : lvalue {
    my $self = shift;
    $self->{tar} = shift if (@_);
    $self->{tar};
}
sub doc : lvalue {
    my $self = shift;
    $self->{doc} = shift if (@_);
    $self->{doc};
}
sub run : lvalue {
    my $self = shift;
    $self->{run} = shift if (@_);
    $self->{run};
}
sub bin : lvalue {
    my $self = shift;
    $self->{bin} = shift if (@_);
    $self->{bin};
}
sub src : lvalue {
    my $self = shift;
    $self->{src} = shift if (@_);
    $self->{src};
}
sub cur : lvalue {
    my $self = shift;
    $self->{cur};
}
sub coc : lvalue {
    my $self = shift;
    $self->{coc};
}
sub cun : lvalue {
    my $self = shift;
    $self->{cun};
}
sub cin : lvalue {
    my $self = shift;
    $self->{cin};
}
sub crc : lvalue {
    my $self = shift;
    $self->{crc};
}
sub initialize {
    my $self = shift;
    $self->{cur} = $self->{tar} = shift if (@_);
    $self->{coc} = $self->{doc} = shift if (@_);
    $self->{cun} = $self->{run} = shift if (@_);
    $self->{cin} = $self->{bin} = shift if (@_);
    $self->{crc} = $self->{src} = shift if (@_);
}
sub update {
    my $self = shift;
    $self->{tar} = shift if (@_);
    $self->{doc} = shift if (@_);
    $self->{run} = shift if (@_);
    $self->{bin} = shift if (@_);
    $self->{src} = shift if (@_);
}
sub current : lvalue {
    my $self = shift;
    my @return=($self->{tar},$self->{doc},$self->{run},$self->{bin},$self->{src});
    @return;
}

#
# It seems that our perl maintainers do not maintain the perl classes
# as I'm missing IO::Uncompress::UnLzma and IO::Uncompress::UnXz based
# on perl::IO::Compress::Base and perl::IO::UnCompress::Base 
#
## use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError);
## use IO::File;
#
package tar;

no warnings;
our ($archive, $handle, @tar);
use warnings;
sub new {
    my $self = {};
    bless ($self);
    $self->read(@_) if (@_);
    return $self;
}
sub read {
    my $self = shift;
    $archive = shift;
    @tar = ();
    return if ! $archive;
    close($handle) if ($handle);
    $handle = 0 if ! open($handle, 'tar tvfJ ' . $archive . '|');
}
sub close {
    close($handle) if ($handle);
}
sub _octalmod {
    my %rwx = ('---' => 0,'--x' => 1,'-w-' => 2,'-wx' => 3,'r--' => 4,'r-x' => 5,'rw-' => 6,'rwx' => 7);
    my $mode = shift;
    my $type = substr($mode,0,1);
    my $user = substr($mode,1,3);
    my $group = substr($mode,4,3);
    my $other = substr($mode,7,3);
    my $special = 0;
    $special |= 01000 if ($other =~ s/(..)t/$1x/);
    $special |= 02000 if ($group =~ s/(..)s/$1x/);
    $special |= 04000 if ($user =~ s/(..)s/$1x/);
    return $special + oct($rwx{$user}*100 + $rwx{$group}*10 + $rwx{$other});
}
sub list_files {
    my $self = shift;
    my %hash = (mode => 0, ugid => 1, size => 2, date => 3, time => 4, name => 5, arrw => 6, link => 7);
    my @return = ();
    return @return if ! $archive;
    @tar = <$handle> if $#tar < 0;
    chomp (@tar);
    @return = map { my @o = split(/(?:[[:blank:]]+|\->)/); $o[0] = _octalmod($o[0]);
		    $o[5] =~ s@^texmf-dist/@%{_texmfdistdir}/@;
		    $o[5] =~ s@^texmf/@%{_texmfmaindir}/@;
		    $o[5] =~ s@^([^%])@%{_texmfmaindir}/$1@;
		    +{ map { $_ => $o[$hash{$_}] } keys %hash } } @tar;
    return @return;
}

#
# A package to read and convert the hyphen data from execute lines
# into a useful structure to be able to write out entries of the
# several hyphen configurations files out as single files.
# 
#
package hyphen;
use warnings;
use Text::ParseWords;

our @hyphenlist;

sub new {
    my $self = {};
    bless ($self);
    @hyphenlist = ();
    $self->store(@_) if (@_);
    return $self;
}

sub DESTROY {
    for my $list (@hyphenlist) {
	undef %{$list}
    }
    @hyphenlist = ();
}

sub store
{
    my $self = shift;
    my $line = shift;
    my %hyphens;

    $hyphens{"lefthyphenmin"} = 2;
    $hyphens{"righthyphenmin"} = 3;
    $hyphens{"synonyms"} = [];

    for my $piece (quotewords('\s+', 0, "$line")) {
	next if ($piece =~ m/^[Aa]ddHyphen$/);
 	my ($tag, $value) = split(/=/, $piece); 
	if ($tag eq "name") {
	    if (!$value) {
		$hyphens{"error"} = "AddHyphen line needs name=something";
		last;
	    }
	    $hyphens{$tag} = $value;
	    next;
	}
	if ($tag eq "lefthyphenmin") {
	    $hyphens{"lefthyphenmin"} = $value if ($value);
	    next;
	}
	if ($tag eq "righthyphenmin") {
	    $hyphens{"righthyphenmin"} = $value if ($value);
	    next;
	}
	if ($tag eq "file") {
	    if (!$value) {
		$hyphens{"error"} = "AddHyphen line needs file=something";
		last;
	    }
	    $hyphens{$tag} = $value;
	    next;
	}
	if ($tag eq "file_patterns") {
	    $hyphens{"file_patterns"} = $value;
	    next;
	}
	if ($tag eq "file_exceptions") {
	    $hyphens{"file_exceptions"} = $value;
	    next;
	}
	if ($tag eq "luaspecial") {
	    $hyphens{"luaspecial"} = $value if ($value);
	    next;
	}
	if ($tag eq "databases") {
	    @{$hyphens{"databases"}} = split(/,/, $value);
	    next;
	}
	if ($tag eq "synonyms") {
	    @{$hyphens{"synonyms"}} = split(/,/, $value);
	    next;
	}
	if ($tag eq "comment") {
	    $hyphens{"comment"} = $value if ($value);
	    next;
	}
	# should not be reached at all
	$hyphens{"error"} = "Unknown language directive $tag";
	last;
    }
    if ($hyphens{"error"}) {
	print STDERR $hyphens{"error"} . "\n";
	exit 1;
    }
    if (not defined($hyphens{"databases"})) {
	if (defined $hyphens{"file_patterns"} or defined $hyphens{"file_exceptions"} or defined $hyphens{"luaspecial"}) {
	    @{$hyphens{"databases"}} = qw(dat def lua);
	} else {
	    @{$hyphens{"databases"}} = qw(dat def);
	}
    }
    push @hyphenlist, \%hyphens;
}

sub dat_lines {
    my $self = shift;
    my $from = shift;
    my @lines = ();

    push @lines, "%% from $from:\n";
    for my $list (@hyphenlist) {
	my %hyphen = %{$list};

	push @lines, "$hyphen{name} $hyphen{file}\n";
	for my $syn (@{$hyphen{synonyms}}) {
	    push @lines, "=$syn\n";
	}
    }
    return @lines;
}

sub def_lines {
    my $self = shift;
    my $from = shift;
    my @lines = ();

    push @lines, "%% from $from:\n";
    for my $list (@hyphenlist) {
	my %hyphen = %{$list};

	push @lines, "\\addlanguage\{$hyphen{name}\}\{$hyphen{file}\}\{\}\{$hyphen{lefthyphenmin}\}\{$hyphen{righthyphenmin}\}\n";
	for my $syn (@{$hyphen{synonyms}}) {
	    push @lines, "\\addlanguage\{$syn\}\{$hyphen{file}\}\{\}\{$hyphen{lefthyphenmin}\}\{$hyphen{righthyphenmin}\}\n";
	}
    }
    return @lines;
}

sub lua_lines {
    my $self = shift;
    my $from = shift;
    my @lines = ();

    push @lines, "-- from $from:\n";
    for my $list (@hyphenlist) {
	my %hyphen = %{$list};
	my @synonyms = (@{$hyphen{synonyms}});

	map { $_ = "'$_'" } @synonyms;
	push @lines, "['$hyphen{name}'] = {", "\tloader = '$hyphen{file}',",
		     "\tlefthyphenmin = $hyphen{lefthyphenmin},",
		     "\trighthyphenmin = $hyphen{righthyphenmin},",
		     "\tsynonyms = { " . join(', ', @synonyms) . " },";
	push @lines, "\tpatterns = '$hyphen{file_patterns}'," if defined($hyphen{file_patterns});
	push @lines, "\thyphenation = '$hyphen{file_exceptions}'," if defined($hyphen{file_exceptions});
	push @lines, "\tspecial = '$hyphen{luaspecial}'," if defined($hyphen{luaspecial});
	push @lines, '},';
    }
    map { $_ = "\t$_\n" if ($_ !~ m/^--/) } @lines;
    return @lines;
}
openSUSE Build Service is sponsored by