source: trunk/dports/_resources/port1.0/group/texlive-1.0.tcl @ 107988

Last change on this file since 107988 was 107988, checked in by dports@…, 6 years ago

texlive portgroup: prevent updmap failures from causing activation to
fail (#39690). We already do this for fmtutil.

File size: 20.8 KB
Line 
1# $Id: texlive-1.0.tcl 107988 2013-07-10 04:20:53Z dports@macports.org $
2#
3# Copyright (c) 2010 Dan R. K. Ports <dports@macports.org>
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. Neither the name of The MacPorts Project nor the names of its
16#    contributors may be used to endorse or promote products derived from
17#    this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30#
31
32#
33# This portgroup contains common definitions for a MacPorts
34# installation of TeX Live. It can be used in one of two ways:
35#
36# 1. for installing "texmf ports". These contain tex files and are
37#    installed from preprocessed distfiles made from TeXLive
38#    packages. These ports should invoke texlive.texmfport to set up
39#    the installation process.
40#
41# 2. other ports, like texlive-common or texlive-bin can include this
42#    portgroup (but not call texlive.texmfport) to get texlive path
43#    definitions and the like.
44
45#
46# texmf tree paths
47#
48
49# texmf files installed by texlive
50# TeXLive used to maintain a separation between files that were
51# nominally distribution-independent ("texmf-dist") and those that
52# were tied to the binaries. This separation is now gone; everything
53# now goes into the texmfdist tree. $texlive_texmfmain points to the
54# same place for backwards-compatibility.
55set texlive_texmfdist "${prefix}/share/texmf-texlive"
56set texlive_texmfmain "${texlive_texmfdist}"
57
58# texmf files installed by ports other than texlive
59set texlive_texmfports "${prefix}/share/texmf"
60
61# optional tree for user-installed texmf files
62set texlive_texmflocal "${prefix}/share/texmf-local"
63
64# variable runtime data, e.g. formats
65set texlive_texmfsysvar "${prefix}/var/db/texmf"
66
67# configuration data from texconfig
68set texlive_texmfsysconfig "${prefix}/etc/texmf"
69
70# user's local texmf tree.
71# Note that this path is specified relative to the user's
72# home directory, i.e. it begins with an implicit ~/
73set texlive_texmfhome "Library/texmf"
74
75
76# location of binaries installed by texlive-bin
77#
78# All TeXLive binaries are built by texlive-bin, but most of them
79# aren't usable without the support files installed by other ports:
80# for example, xetex needs texlive-xetex, tex4ht needs
81# texlive-htmlxml, and just about everything needs texlive-basic.  We
82# don't want to install useless files into $prefix/bin, so instead
83# texlive-bin installs its binaries into this "hidden" directory, and
84# other ports "activate" them when they are ready to be used by creating
85# symlinks into $prefix/bin.
86set texlive_bindir "${prefix}/libexec/texlive/binaries"
87
88# another directory containing symlinks to activated texlive binaries
89#
90# This is provided to support MacTeX's TeX Distribution preference
91# pane: it can select the active TeX distribution by pointing the
92# /usr/texbin symlink here
93#
94# It also seems like the prefpane wants architecture-specific links,
95# and may want version-specific ones in the future, so create those in
96# ${texlive_mactex_texdistdir}.
97set texlive_mactex_texbindir "${prefix}/libexec/texlive/texbin"
98set texlive_mactex_texdistdir "${prefix}/libexec/texlive/texdist"
99
100# update texmf file path databases (ls-R)
101#
102# This should be run in the post-activate/deactivate hooks of any port
103# that installs texmf files. It updates the kpathsea database using
104# mktexlsr (formerly texhash), as well as ConTeXt's cache.
105proc texlive.mktexlsr {} {
106    global prefix
107
108    # Run mktexlsr. If that's not available, something's wrong.
109    system "${prefix}/bin/mktexlsr"
110
111    # If mtxrun is available (i.e. ConTeXt is installed), update its
112    # cache too. If it's not installed, that's OK.
113    if [file exists "${prefix}/bin/mtxrun"] {
114        system "${prefix}/bin/mtxrun --generate"
115    }
116}
117
118# Remove dependencies on any texlive-documentation-* ports, for use by
119# -doc variants
120proc texlive.removedocdepends {} {
121    global depends_lib
122    foreach dep $depends_lib {
123        if [regexp {^port:texlive-documentation-} $dep] {
124            depends_lib-delete $dep
125        }
126    }
127}
128
129#
130# For installing texmf ports
131#
132
133# Files to skip installation of, specified in terms of their path in
134# the texmf tree, e.g. texmf-dist/foo/bar/
135options texlive.exclude
136default texlive.exclude {}
137
138options texlive.binaries texlive.formats texlive.languages texlive.maps
139default texlive.binaries {}
140default texlive.formats {}
141default texlive.languages {}
142default texlive.maps {}
143
144# Whether to regenerate all config files, maps, and formats after
145# activation regardless of whether any new ones are installed.
146options texlive.forceupdatecnf
147default texlive.forceupdatecnf no
148
149# Whether to run mktexlsr after (de)activation. Usually required if
150# installing any texmf files.
151options texlive.use_mktexlsr
152default texlive.use_mktexlsr yes
153
154# Running mktexlsr after deactivation can be disabled separately. Note
155# that the value of this option is ignored if use_mktexlsr is disabled.
156options texlive.use_mktexlsr_on_deactivate
157default texlive.use_mktexlsr_on_deactivate yes
158
159proc texlive.texmfport {} {
160    homepage        http://www.tug.org/texlive/
161    platforms       darwin
162
163    supported_archs noarch
164    installs_libs   no
165
166    master_sites    http://giraffe.cs.washington.edu/texlive/
167    use_xz          yes
168
169    global name master_sites distname extract.suffix
170    livecheck.type  regex
171    livecheck.url   ${master_sites}
172    livecheck.regex ${name}-(\\d+)-run\\.tar
173
174    depends_lib-append port:texlive-common port:texlive-bin
175
176    # distfile is split into three parts, all of which extract into
177    # $worksrcdir
178    # - $distname-run contains the runtime files required to install the
179    #   package, as well as the "tlpkginfo" directory containing metadata
180    # - $distname-doc contains optional documentation files
181    # - $distname-src contains optional source code for installed files
182    # The latter two are only downloaded if the corresponding variant
183    # is enabled. Currently, each package must have all three distfiles
184    # even if some are empty.
185    distfiles       ${distname}-run${extract.suffix}
186
187    variant doc description "Install documentation" {
188        distfiles-append ${distname}-doc${extract.suffix}
189    }
190    variant src description "Install TeX source" {
191        distfiles-append ${distname}-src${extract.suffix}
192    }
193    default_variants +doc
194
195    if {![variant_isset "doc"]} {
196        # Skip any dependencies on texlive-documentation-* ports
197        texlive.removedocdepends
198    }
199
200    use_configure   no
201
202    build           { }
203
204    destroot {
205        xinstall -d ${destroot}${texlive_mactex_texbindir}
206
207        set indexlist {"runfiles"}
208        if {[variant_isset "doc"]} { lappend indexlist "docfiles" }
209        if {[variant_isset "src"]} { lappend indexlist "srcfiles" }
210
211        # copy files listed in tlpkginfo/$indexname into destroot
212        foreach indexname $indexlist {
213            set filelist [open ${worksrcpath}/tlpkginfo/${indexname}]
214            while {[gets $filelist line] >= 0} {
215                # Check if file is excluded
216                set excluded false
217                foreach excludeline ${texlive.exclude} {
218                    if {[string equal -nocase $line $excludeline]} {
219                        # file is specifically excluded
220                        set excluded true
221                        break
222                    }
223                    if {[string equal -nocase -length [expr [string length $excludeline] + 1] $line "$excludeline/"]} {
224                        # this is a file in an excluded directory
225                        set excluded true
226                        break;
227                    }
228                }
229                if {$excluded} {
230                    continue
231                }
232
233                set srcfile ${worksrcpath}/${indexname}/$line
234
235                # check for manpages and treat specially
236                if [regexp {^texmf/doc/man/man(\d)/([^/]+)} $line -> section filename] {
237                    if [string match "*.$section" $filename] {
238                        # actually a manpage; install it.  If
239                        # texlive-bin installed a manpage with the
240                        # same name, use it instead to make sure the
241                        # documentation matches the binary.
242                        if [file exists ${texlive_bindir}/man${section}/$filename.gz] {
243                            ln -s ${texlive_bindir}/man${section}/$filename.gz \
244                                ${destroot}${prefix}/share/man/man$section/
245                        } else {
246                            copy $srcfile ${destroot}${prefix}/share/man/man$section/
247                        }
248                    } else {
249                        # not actually a manpage; do nothing
250                        # (e.g. don't install PDF manpages)
251                    }
252                } else {
253                    # not a manpage; install into requested target dir
254                    # translate path in line to destination
255                    set splitline [split $line "/"]
256                    switch [lindex $splitline 0] {
257                        "texmf"      {lset splitline 0 ${texlive_texmfmain}}
258                        "texmf-dist" {lset splitline 0 ${texlive_texmfdist}}
259                        default { ui_msg "warning: unknown file destination" }
260                    }
261                    set dstfile [join $splitline "/"]
262
263                    # create directory if necessary, and install file
264                    xinstall -d ${destroot}[file dirname $dstfile]
265                    copy ${srcfile} ${destroot}${dstfile}
266                }
267            }
268        }
269
270        # install a documentation file containing the list of TeX
271        # packages installed. This also ensures that each port
272        # provides at least one file, even if there's nothing to
273        # install (e.g. documentation ports with -doc)
274        xinstall -d ${destroot}${prefix}/share/doc/texlive
275        set docfile [open ${destroot}${prefix}/share/doc/texlive/${name} "w"]
276        puts $docfile "${name} version ${version} (MacPorts revision ${version}_${revision})"
277        puts $docfile "\nTeX Live packages contained in this port:"
278        set pkgfile [open ${worksrcpath}/tlpkginfo/pkgs]
279        while {[gets $pkgfile line] >= 0} {
280            set splitline [split $line]
281            set pkg [lindex $splitline 0]
282            set pkgdesc [join [lrange $splitline 1 end]]
283            puts $docfile "    $pkg: $pkgdesc"
284        }
285        close $pkgfile
286        close $docfile
287
288        # install fmtutil.cnf file
289        if {${texlive.formats} != ""} {
290            xinstall -d ${destroot}${texlive_texmfsysconfig}/fmtutil.d
291            set fmtfilename \
292                ${destroot}${texlive_texmfsysconfig}/fmtutil.d/10${name}.cnf
293            set fmtfile [open $fmtfilename "w"]
294            foreach x ${texlive.formats} {
295                set fmtenabled [lindex $x 0]
296                set fmtname [lindex $x 1]
297                set fmtengine [lindex $x 2]
298                set fmtpatterns [lindex $x 3]
299                set fmtoptions [lindex $x 4]
300                if {!$fmtenabled} {
301                    set fmtprefix "#! "
302                } else {
303                    set fmtprefix ""
304                }
305
306                puts $fmtfile \
307                    "$fmtprefix$fmtname\t$fmtengine\t$fmtpatterns\t$fmtoptions"
308
309                # Simulate texlinks
310                if {[lsearch -exact ${texlive.binaries} $fmtname] != -1} {
311                    # Decide what to link. Use the specified engine
312                    # unless a binary with the same name as the
313                    # format exists (this can happen for metafont;
314                    # see #28890)
315                    #
316                    # It's OK if the binary named $fmtname is a broken
317                    # symlink, since we might be installing whatever
318                    # it's pointing to, hence the use of 'file lstat'.
319                    if {![catch {file lstat ${texlive_bindir}/$fmtname ignore}]} {
320                        set linksource ${texlive_bindir}/$fmtname
321                    } else {
322                        set linksource ${prefix}/bin/$fmtengine
323                    }
324
325                    ln -s $linksource \
326                        ${destroot}${prefix}/bin/$fmtname
327                    ln -s $linksource \
328                        ${destroot}${texlive_mactex_texbindir}/$fmtname
329
330                    # We've created the symlink for $fmtname; remove
331                    # it from texlive.binaries so we don't try to do
332                    # so again later.
333                    texlive.binaries-delete $fmtname
334                }
335            }
336
337            close $fmtfile
338        }
339
340        # install updmap.cfg file
341        if {${texlive.maps} != ""} {
342            xinstall -d ${destroot}${texlive_texmfsysconfig}/updmap.d
343            set mapfilename \
344                ${destroot}${texlive_texmfsysconfig}/updmap.d/10${name}.cfg
345            set mapfile [open $mapfilename "w"]
346            foreach x ${texlive.maps} {
347                puts $mapfile $x
348            }
349            close $mapfile
350        }
351
352        # install languages.dat and languages.def files
353        if {${texlive.languages} != ""} {
354            xinstall -d ${destroot}${texlive_texmfsysconfig}/language.d
355            set langdatfilename \
356                ${destroot}${texlive_texmfsysconfig}/language.d/10${name}.dat
357            set langdeffilename \
358                ${destroot}${texlive_texmfsysconfig}/language.d/10${name}.def
359            set langluafilename \
360                ${destroot}${texlive_texmfsysconfig}/language.d/10${name}.dat.lua
361            set langdatfile [open $langdatfilename "w"]
362            set langdeffile [open $langdeffilename "w"]
363            set langluafile [open $langluafilename "w"]
364
365            foreach x ${texlive.languages} {
366                set langname [lindex $x 0]
367                set langfile [lindex $x 1]
368                set langlhmin [lindex $x 2]
369                set langrhmin [lindex $x 3]
370                set langsyns [lindex $x 4]
371                set langpatt [lindex $x 5]
372                set langhyph [lindex $x 6]
373                set langspecial [lindex $x 7]
374
375                puts $langdatfile "$langname $langfile"
376                foreach syn $langsyns {
377                    puts $langdatfile "=$syn"
378                }
379
380                foreach syn [concat $langname $langsyns] {
381                    puts $langdeffile "\\addlanguage{$syn}{$langfile}{}{$langlhmin}{$langrhmin}"
382                }
383
384                puts $langluafile "\t\['$langname'\] = {"
385                puts $langluafile "\t\tloader = '$langfile',"
386                puts $langluafile "\t\tlefthyphenmin = $langlhmin,"
387                puts $langluafile "\t\trighthyphenmin = $langrhmin,"
388                set qsyns {}
389                foreach syn $langsyns {
390                    lappend qsyns "'$syn'"
391                }
392                set qsynlist [join $qsyns ", "]
393                puts $langluafile "\t\tsynonyms = { $qsynlist },"
394                if {$langpatt != ""} {
395                    puts $langluafile "\t\tpatterns = '$langpatt',"
396                }
397                if {$langhyph != ""} {
398                    puts $langluafile "\t\thyphenation = '$langhyph',"
399                }
400                if {$langspecial != ""} {
401                    puts $langluafile "\t\tpatterns = '$langspecial',"
402                }
403                puts $langluafile "\t},\n"
404            }
405
406            close $langdatfile
407            close $langdeffile
408            close $langluafile
409        }
410
411        # create symlinks for any binaries activated by the port
412        foreach bin ${texlive.binaries} {
413            ln -s ${texlive_bindir}/$bin ${destroot}${prefix}/bin
414            ln -s ${texlive_bindir}/$bin ${destroot}${texlive_mactex_texbindir}
415        }
416    }
417
418    post-activate {
419        # Disable mktexlsr if it's not installed and this is a
420        # texlive-documentation-* port. It's possible (if unlikely) to
421        # install them without texlive-basic, so mktexlsr might not
422        # exist, but if it does we do want to run it.
423        if {[regexp {^texlive-documentation-} $name] &&
424            ![file exists ${prefix}/bin/mktexlsr]} {
425            texlive.use_mktexlsr no
426        }
427
428        if {${texlive.use_mktexlsr}} {
429            texlive.mktexlsr
430        }
431
432        if {${texlive.forceupdatecnf}} {
433            # If force was specified, update all the config files, and
434            # regenerate all maps and formats.
435            system "${prefix}/libexec/texlive-update-cnf language.dat"
436            system "${prefix}/libexec/texlive-update-cnf language.def"
437            system "${prefix}/libexec/texlive-update-cnf language.dat.lua"
438            system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
439            system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
440            # map/format generation might fail if we are in the middle of
441            # a major upgrade and have not yet updated all texlive ports.
442            # Catch the error to prevent the upgrade from failing.
443            catch {system "${prefix}/bin/updmap-sys"}
444            catch {system "${prefix}/bin/fmtutil-sys --all"}
445        } else {
446            # Otherwise, only update the config files that are
447            # actually affected, and only generate the needed
448            # formats.
449            if {${texlive.languages} != ""} {
450                system "${prefix}/libexec/texlive-update-cnf language.dat"
451                system "${prefix}/libexec/texlive-update-cnf language.def"
452                system "${prefix}/libexec/texlive-update-cnf language.dat.lua"
453            }
454            if {${texlive.maps} != ""} {
455                system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
456                catch {system "${prefix}/bin/updmap-sys"}
457            }
458            if {${texlive.formats} != ""} {
459                system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
460            }
461
462            # Regenerate formats. If we installed any hyphenation
463            # patterns, then we need to regenerate all
464            # formats. Otherwise, just generate the formats we just
465            # installed.
466            if {${texlive.languages} != ""} {
467                catch {system "${prefix}/bin/fmtutil-sys --all"}
468            } elseif {${texlive.formats} != ""} {
469                foreach x ${texlive.formats} {
470                    set fmtname [lindex $x 1]
471                    catch {system "${prefix}/bin/fmtutil-sys --byfmt $fmtname"}
472                }
473            }
474        }
475    }
476
477    post-deactivate {
478        # Disable mktexlsr if it's not installed and this is a
479        # texlive-documentation-* port. See post-activate for why.
480        if {[regexp {^texlive-documentation-} $name] &&
481            ![file exists ${prefix}/bin/mktexlsr]} {
482            texlive.use_mktexlsr no
483        }
484
485        # Update ls-R and any config files to reflect that the package
486        # is now gone
487        if {${texlive.use_mktexlsr} && ${texlive.use_mktexlsr_on_deactivate}} {
488            texlive.mktexlsr
489        }
490        if {${texlive.forceupdatecnf} || ${texlive.languages} != ""} {
491            system "${prefix}/libexec/texlive-update-cnf language.dat"
492            system "${prefix}/libexec/texlive-update-cnf language.def"
493            system "${prefix}/libexec/texlive-update-cnf language.dat.lua"
494        }
495        if {${texlive.forceupdatecnf} || ${texlive.maps} != ""} {
496            system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
497        }
498        if {${texlive.forceupdatecnf} || ${texlive.formats} != ""} {
499            system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
500        }
501
502        # Remove any generated format files
503        foreach x ${texlive.formats} {
504            set fmtname [lindex $x 1]
505            set fmtengine [lindex $x 2]
506            switch $fmtengine {
507                "mf"       -
508                "mf-nowin" {set fmtengine "metafont"}
509                "mpost"    {set fmtengine "metapost"}
510            }
511
512            foreach filename [glob -nocomplain ${texlive_texmfsysvar}/web2c/$fmtengine/$fmtname.*] {
513                delete $filename
514            }
515        }
516    }
517}
Note: See TracBrowser for help on using the repository browser.