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
RevLine 
[68605]1# $Id: texlive-1.0.tcl 107988 2013-07-10 04:20:53Z dports@macports.org $
[96776]2#
[68880]3# Copyright (c) 2010 Dan R. K. Ports <dports@macports.org>
[68605]4# All rights reserved.
[96776]5#
[68605]6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
[96776]9#
[68605]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.
[96776]30#
[68605]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
[107915]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}"
[68605]57
[73314]58# texmf files installed by ports other than texlive
59set texlive_texmfports "${prefix}/share/texmf"
[68605]60
[73314]61# optional tree for user-installed texmf files
62set texlive_texmflocal "${prefix}/share/texmf-local"
63
[68605]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
[82097]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
[73314]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
[82097]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}.
[73314]97set texlive_mactex_texbindir "${prefix}/libexec/texlive/texbin"
[82097]98set texlive_mactex_texdistdir "${prefix}/libexec/texlive/texdist"
[73314]99
[82097]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
[68968]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] {
[69102]124            depends_lib-delete $dep
[68968]125        }
126    }
127}
[68605]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
[73314]138options texlive.binaries texlive.formats texlive.languages texlive.maps
139default texlive.binaries {}
[68605]140default texlive.formats {}
141default texlive.languages {}
142default texlive.maps {}
143
[82097]144# Whether to regenerate all config files, maps, and formats after
145# activation regardless of whether any new ones are installed.
[68605]146options texlive.forceupdatecnf
147default texlive.forceupdatecnf no
148
[82189]149# Whether to run mktexlsr after (de)activation. Usually required if
[82097]150# installing any texmf files.
151options texlive.use_mktexlsr
152default texlive.use_mktexlsr yes
153
[82189]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
[68605]159proc texlive.texmfport {} {
160    homepage        http://www.tug.org/texlive/
161    platforms       darwin
[96776]162
[88820]163    supported_archs noarch
164    installs_libs   no
[96776]165
[107915]166    master_sites    http://giraffe.cs.washington.edu/texlive/
[73314]167    use_xz          yes
[68605]168
[82097]169    global name master_sites distname extract.suffix
[68605]170    livecheck.type  regex
171    livecheck.url   ${master_sites}
[82097]172    livecheck.regex ${name}-(\\d+)-run\\.tar
[68605]173
174    depends_lib-append port:texlive-common port:texlive-bin
175
[82097]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
[96776]184    # even if some are empty.
[82097]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    }
[68605]193    default_variants +doc
194
[68968]195    if {![variant_isset "doc"]} {
196        # Skip any dependencies on texlive-documentation-* ports
197        texlive.removedocdepends
198    }
[96776]199
[68605]200    use_configure   no
201
202    build           { }
203
204    destroot {
[73314]205        xinstall -d ${destroot}${texlive_mactex_texbindir}
206
[68605]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
[96776]212        foreach indexname $indexlist {
[68605]213            set filelist [open ${worksrcpath}/tlpkginfo/${indexname}]
214            while {[gets $filelist line] >= 0} {
[70025]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} {
[68605]230                    continue
231                }
[96776]232
[68605]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] {
[73314]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 {
[68605]246                            copy $srcfile ${destroot}${prefix}/share/man/man$section/
247                        }
[73314]248                    } else {
249                        # not actually a manpage; do nothing
250                        # (e.g. don't install PDF manpages)
[68605]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 "/"]
[96776]262
[68605]263                    # create directory if necessary, and install file
264                    xinstall -d ${destroot}[file dirname $dstfile]
265                    copy ${srcfile} ${destroot}${dstfile}
266                }
267            }
268        }
269
[68968]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
[68605]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
[82097]310                if {[lsearch -exact ${texlive.binaries} $fmtname] != -1} {
[77477]311                    # Decide what to link. Use the specified engine
312                    # unless a binary with the same name as the
[82097]313                    # format exists (this can happen for metafont;
[77477]314                    # see #28890)
[82097]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}]} {
[77477]320                        set linksource ${texlive_bindir}/$fmtname
321                    } else {
322                        set linksource ${prefix}/bin/$fmtengine
323                    }
[96776]324
[77477]325                    ln -s $linksource \
[68605]326                        ${destroot}${prefix}/bin/$fmtname
[77477]327                    ln -s $linksource \
[73314]328                        ${destroot}${texlive_mactex_texbindir}/$fmtname
[82097]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
[68605]334                }
335            }
[96776]336
[68605]337            close $fmtfile
338        }
339
[68968]340        # install updmap.cfg file
[68605]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
[68968]352        # install languages.dat and languages.def files
[68605]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
[82097]359            set langluafilename \
360                ${destroot}${texlive_texmfsysconfig}/language.d/10${name}.dat.lua
[68605]361            set langdatfile [open $langdatfilename "w"]
362            set langdeffile [open $langdeffilename "w"]
[82097]363            set langluafile [open $langluafilename "w"]
[96776]364
[68605]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]
[82097]371                set langpatt [lindex $x 5]
372                set langhyph [lindex $x 6]
373                set langspecial [lindex $x 7]
[68605]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                }
[82097]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                }
[96776]403                puts $langluafile "\t},\n"
[68605]404            }
[96776]405
[68605]406            close $langdatfile
407            close $langdeffile
[82097]408            close $langluafile
[68605]409        }
[82097]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        }
[68605]416    }
417
418    post-activate {
[82273]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        }
[96776]427
[82097]428        if {${texlive.use_mktexlsr}} {
429            texlive.mktexlsr
430        }
[96776]431
[69218]432        if {${texlive.forceupdatecnf}} {
433            # If force was specified, update all the config files, and
434            # regenerate all maps and formats.
[68605]435            system "${prefix}/libexec/texlive-update-cnf language.dat"
436            system "${prefix}/libexec/texlive-update-cnf language.def"
[82097]437            system "${prefix}/libexec/texlive-update-cnf language.dat.lua"
[68605]438            system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
[69218]439            system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
[107988]440            # map/format generation might fail if we are in the middle of
[82181]441            # a major upgrade and have not yet updated all texlive ports.
442            # Catch the error to prevent the upgrade from failing.
[107988]443            catch {system "${prefix}/bin/updmap-sys"}
[82181]444            catch {system "${prefix}/bin/fmtutil-sys --all"}
[69218]445        } else {
446            # Otherwise, only update the config files that are
[75187]447            # actually affected, and only generate the needed
448            # formats.
[69218]449            if {${texlive.languages} != ""} {
450                system "${prefix}/libexec/texlive-update-cnf language.dat"
451                system "${prefix}/libexec/texlive-update-cnf language.def"
[82097]452                system "${prefix}/libexec/texlive-update-cnf language.dat.lua"
[69218]453            }
454            if {${texlive.maps} != ""} {
455                system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
[107988]456                catch {system "${prefix}/bin/updmap-sys"}
[69218]457            }
458            if {${texlive.formats} != ""} {
459                system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
[75187]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} != ""} {
[82181]467                catch {system "${prefix}/bin/fmtutil-sys --all"}
[75187]468            } elseif {${texlive.formats} != ""} {
[69218]469                foreach x ${texlive.formats} {
470                    set fmtname [lindex $x 1]
[82181]471                    catch {system "${prefix}/bin/fmtutil-sys --byfmt $fmtname"}
[69218]472                }
473            }
[68605]474        }
475    }
[68678]476
477    post-deactivate {
[82273]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
[68678]485        # Update ls-R and any config files to reflect that the package
486        # is now gone
[82189]487        if {${texlive.use_mktexlsr} && ${texlive.use_mktexlsr_on_deactivate}} {
488            texlive.mktexlsr
489        }
[68678]490        if {${texlive.forceupdatecnf} || ${texlive.languages} != ""} {
491            system "${prefix}/libexec/texlive-update-cnf language.dat"
492            system "${prefix}/libexec/texlive-update-cnf language.def"
[82097]493            system "${prefix}/libexec/texlive-update-cnf language.dat.lua"
[68678]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        }
[96776]501
[68678]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            }
[96776]511
[68678]512            foreach filename [glob -nocomplain ${texlive_texmfsysvar}/web2c/$fmtengine/$fmtname.*] {
513                delete $filename
514            }
515        }
516    }
[68605]517}
Note: See TracBrowser for help on using the repository browser.