summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TLPackageConfigurations.pm
blob: 6b6903b5a56a789c42e4e05c2f474ec3bd606ba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# $Id$
# TeXLive::TLPackageConfigurations.pm 
# Copyright 2008 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.

package TeXLive::TLPackageConfigurations;

BEGIN {
  use Exporter ();
  use vars qw( @ISA @EXPORT_OK @EXPORT );
  @ISA = qw(Exporter);
  @EXPORT_OK = qw(
    %PackageConfigInstall
    %PackageConfigRemove
  );
  @EXPORT = @EXPORT_OK;
}

use TeXLive::TLUtils qw(win32 mkdirhier copy conv_to_w32_path log debug info
                        touch tlwarn);
use TeXLive::TLWinGoo;
use TeXLive::TLConfig;

my $mainmenu = $TeXLive::TLConfig::WindowsMainMenuName;

our %PackageConfigInstall;
our %PackageConfigRemove;

# xetex
#
sub do_install_xetex {
  my ($texdir, $texdirw, $texmfsysvar) = @_;
  #
  # bin-installs font-config related stuff
  #
  # new version according to Staszek
  if (!defined($texmfsysvar)) {
    $texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`;
    chomp($texmfsysvar);
  }
  if (-r "$texdir/bin/win32/conf/fonts.conf") {
    # we have installed w32, so put it into texmfsysvar
    mkdirhier("$texmfsysvar/fonts");
    TeXLive::TLUtils::rmtree("$texmfsysvar/fonts/conf");
    TeXLive::TLUtils::rmtree("$texmfsysvar/fonts/cache");
    my @cpycmd;
    if (win32()) {
      push @cpycmd, "xcopy", "/e", "/i", "/q", "/y";
    } else {
      push @cpycmd, "cp", "-R";
    }
    system(@cpycmd,
             (win32() ? conv_to_w32_path("$texdir/bin/win32/conf") :
                       "$texdir/bin/win32/conf"),
             (win32() ? conv_to_w32_path("$texmfsysvar/fonts/conf") :
                       "$texmfsysvar/fonts/conf"));
    system(@cpycmd,
             (win32() ? conv_to_w32_path("$texdir/bin/win32/cache") :
                       "$texdir/bin/win32/cache"),
             (win32() ? conv_to_w32_path("$texmfsysvar/fonts/cache") :
                       "$texmfsysvar/fonts/cache"));
    if (open(FONTSCONF, "<$texdir/bin/win32/conf/fonts.conf")) {
      my @lines = <FONTSCONF>;
      close(FONTSCONF);
      if (open(FONTSCONF, ">$texmfsysvar/fonts/conf/fonts.conf")) {
        my $winfontdir;
        if (win32()) {
          $winfontdir = $ENV{'SystemRoot'}.'/fonts';
          $winfontdir =~ s!\\!/!g;
          #mkdirhier("$texmfsysvar/fonts/cache");

          # fc-cache breaks often on w32 in some strange way
          # there are claims that touching a font file in $winfontdir
          # would solve that problem. So lets touch some of them
          if (opendir (WINFONT, $winfontdir)) {
            my @dirents = readdir (WINFONT);
            closedir (WINFONT) || warn "closedir($winfontdir) failed: $!";
            # do not actually touch anything by now, maybe already the
            # opendir is enough ...

            # for my $dirent (@dirents) {
            #   if ($dirent =~ m/\.(ttf|otf)$/i) {
            #     touch("$winfontdir/$dirent");
            #     tlwarn("touching $dirent in $winfontdir to make fc-cache work\n");
            #     # one file touched should be enough
            #     last;
            #   }
            # }
          }
        }
        foreach (@lines) {
          $_ =~ s!c:/Program Files/texlive/$TeXLive::TLConfig::ReleaseYear!$texdir!;
          $_ =~ s!c:/windows/fonts!$winfontdir! if win32();
          # hack around fc-cache problem in from_dvd case:
          #if (win32() and (uc($texdir) ne uc($texdirw)) and
          #    ($_ =~ m!^<dir>.*texmf-dist.*</dir>!)) { $_ = '<!-- '.$_.' -->'; }
          print FONTSCONF;
        }
        close(FONTSCONF);
      } else {
        warn("Cannot open $texmfsysvar/fonts/conf/fonts.conf for writing\n");
      }
    } else {
      warn("Cannot open $texdir/bin/win32/conf/fonts.conf\n");
    }
  }
  # call fc-cache but only when we install on w32!
  if (win32()) {
    info("Running fc-cache -v -r\n");
    log(`fc-cache -v -r 2>&1`);
    #system("fc-cache","-v", "-r");
  }
}
$PackageConfigInstall{"xetex"} = \&do_install_xetex;


1;


=head1 NAME

C<TeXLive::TLPackageConfigurations> -- Special Configuration function for TeX Live packages

=head1 SYNOPSIS

  use TeXLive::TLPackageConfigurations;

=head1 DESCRIPTION

The L<TeXLive::TLPackageConfigurations> module exports the 
C<%PackageConfigInstall> and the C<%PackageConfigRemove> hashes indexed by
package names providing code references.

These code references are called with the root of the installation as
argument (C<$SELFAUTOPARENT>). Additional arguments, but not necessarily
present, are the value of C<TEXMFSYSVAR> and C<TEXMFLOCAL>.

=head1 SEE ALSO

The modules L<TeXLive::TLUtils>, L<TeXLive::TLPSRC>,
L<TeXLive::TLPDB>, L<TeXLive::TLTREE>, L<TeXLive::TeXCatalogue>.

=head1 AUTHORS AND COPYRIGHT

This script and its documentation were written for the TeX Live
distribution (L<http://tug.org/texlive>) and both are licensed under the
GNU General Public License Version 2 or later.

=cut

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #