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

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

texlive portgroup: regenerate all formats whenever we install
hyphenation patterns

File size: 15.2 KB
Line 
1# $Id: texlive-1.0.tcl 75187 2011-01-17 10:32:22Z 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
50set texlive_texmfmain "${prefix}/share/texmf-texlive"
51
52# texmf files installed by texlive, but nominally distribution-independent
53# not clear it's really necessary to separate these from texmfmain,
54# but texlive goes to great effort to keep them separate, so we might as
55# well too
56set texlive_texmfdist "${prefix}/share/texmf-texlive-dist"
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# location of binaries installed by texlive-bin
71#
72# All TeXLive binaries are built by texlive-bin, but most of them
73# aren't usable without the support files installed by other ports:
74# for example, xetex needs texlive-xetex, tex4ht needs
75# texlive-htmlxml, and just about everything needs texlive-basic.  We
76# don't want to install useless files into $prefix/bin, so instead
77# texlive-bin installs its binaries into this "hidden" directory, and
78# other ports "activate" them when they are ready to be used by creating
79# symlinks into $prefix/bin.
80set texlive_bindir "${prefix}/libexec/texlive/binaries"
81
82# another directory containing symlinks to activated texlive binaries
83#
84# This is provided to support MacTeX's TeX Distribution preference
85# pane: it can select the active TeX distribution by pointing the
86# /usr/texbin symlink here
87set texlive_mactex_texbindir "${prefix}/libexec/texlive/texbin"
88
89# Remove dependencies on any texlive-documentation-* ports, for use by
90# -doc variants
91proc texlive.removedocdepends {} {
92    global depends_lib
93    foreach dep $depends_lib {
94        if [regexp {^port:texlive-documentation-} $dep] {
95            depends_lib-delete $dep
96        }
97    }
98}
99
100#
101# For installing texmf ports
102#
103
104# Files to skip installation of, specified in terms of their path in
105# the texmf tree, e.g. texmf-dist/foo/bar/
106options texlive.exclude
107default texlive.exclude {}
108
109options texlive.binaries texlive.formats texlive.languages texlive.maps
110default texlive.binaries {}
111default texlive.formats {}
112default texlive.languages {}
113default texlive.maps {}
114
115options texlive.forceupdatecnf
116default texlive.forceupdatecnf no
117
118proc texlive.texmfport {} {
119    homepage        http://www.tug.org/texlive/
120    platforms       darwin
121   
122    supported_archs noarch
123   
124    master_sites    http://flute.csail.mit.edu/texlive/
125    use_xz          yes
126
127    global name master_sites
128    livecheck.type  regex
129    livecheck.url   ${master_sites}
130    livecheck.regex ${name}-(\\d+)\\.tar
131
132    depends_lib-append port:texlive-common port:texlive-bin
133
134    variant doc description "Install documentation" { }
135    variant src description "Install TeX source" { }
136    default_variants +doc
137
138    if {![variant_isset "doc"]} {
139        # Skip any dependencies on texlive-documentation-* ports
140        texlive.removedocdepends
141    }
142   
143    use_configure   no
144
145    build           { }
146
147    destroot {
148        xinstall -d ${destroot}${texlive_mactex_texbindir}
149
150        set indexlist {"runfiles"}
151        if {[variant_isset "doc"]} { lappend indexlist "docfiles" }
152        if {[variant_isset "src"]} { lappend indexlist "srcfiles" }
153
154        # copy files listed in tlpkginfo/$indexname into destroot
155        foreach indexname $indexlist {           
156            set filelist [open ${worksrcpath}/tlpkginfo/${indexname}]
157            while {[gets $filelist line] >= 0} {
158                # Check if file is excluded
159                set excluded false
160                foreach excludeline ${texlive.exclude} {
161                    if {[string equal -nocase $line $excludeline]} {
162                        # file is specifically excluded
163                        set excluded true
164                        break
165                    }
166                    if {[string equal -nocase -length [expr [string length $excludeline] + 1] $line "$excludeline/"]} {
167                        # this is a file in an excluded directory
168                        set excluded true
169                        break;
170                    }
171                }
172                if {$excluded} {
173                    continue
174                }
175                   
176                set srcfile ${worksrcpath}/${indexname}/$line
177
178                # check for manpages and treat specially
179                if [regexp {^texmf/doc/man/man(\d)/([^/]+)} $line -> section filename] {
180                    if [string match "*.$section" $filename] {
181                        # actually a manpage; install it.  If
182                        # texlive-bin installed a manpage with the
183                        # same name, use it instead to make sure the
184                        # documentation matches the binary.
185                        if [file exists ${texlive_bindir}/man${section}/$filename.gz] {
186                            ln -s ${texlive_bindir}/man${section}/$filename.gz \
187                                ${destroot}${prefix}/share/man/man$section/
188                        } else {
189                            copy $srcfile ${destroot}${prefix}/share/man/man$section/
190                        }
191                    } else {
192                        # not actually a manpage; do nothing
193                        # (e.g. don't install PDF manpages)
194                    }
195                } else {
196                    # not a manpage; install into requested target dir
197                    # translate path in line to destination
198                    set splitline [split $line "/"]
199                    switch [lindex $splitline 0] {
200                        "texmf"      {lset splitline 0 ${texlive_texmfmain}}
201                        "texmf-dist" {lset splitline 0 ${texlive_texmfdist}}
202                        default { ui_msg "warning: unknown file destination" }
203                    }
204                    set dstfile [join $splitline "/"]
205                   
206                    # create directory if necessary, and install file
207                    xinstall -d ${destroot}[file dirname $dstfile]
208                    copy ${srcfile} ${destroot}${dstfile}
209                }
210            }
211        }
212
213        # create symlinks for any binaries activated by the port
214        foreach bin ${texlive.binaries} {
215            ln -s ${texlive_bindir}/$bin ${destroot}${prefix}/bin
216            ln -s ${texlive_bindir}/$bin ${destroot}${texlive_mactex_texbindir}
217        }
218
219        # install a documentation file containing the list of TeX
220        # packages installed. This also ensures that each port
221        # provides at least one file, even if there's nothing to
222        # install (e.g. documentation ports with -doc)
223        xinstall -d ${destroot}${prefix}/share/doc/texlive
224        set docfile [open ${destroot}${prefix}/share/doc/texlive/${name} "w"]
225        puts $docfile "${name} version ${version} (MacPorts revision ${version}_${revision})"
226        puts $docfile "\nTeX Live packages contained in this port:"
227        set pkgfile [open ${worksrcpath}/tlpkginfo/pkgs]
228        while {[gets $pkgfile line] >= 0} {
229            set splitline [split $line]
230            set pkg [lindex $splitline 0]
231            set pkgdesc [join [lrange $splitline 1 end]]
232            puts $docfile "    $pkg: $pkgdesc"
233        }
234        close $pkgfile
235        close $docfile
236
237        # install fmtutil.cnf file
238        if {${texlive.formats} != ""} {
239            xinstall -d ${destroot}${texlive_texmfsysconfig}/fmtutil.d
240            set fmtfilename \
241                ${destroot}${texlive_texmfsysconfig}/fmtutil.d/10${name}.cnf
242            set fmtfile [open $fmtfilename "w"]
243            foreach x ${texlive.formats} {
244                set fmtenabled [lindex $x 0]
245                set fmtname [lindex $x 1]
246                set fmtengine [lindex $x 2]
247                set fmtpatterns [lindex $x 3]
248                set fmtoptions [lindex $x 4]
249                if {!$fmtenabled} {
250                    set fmtprefix "#! "
251                } else {
252                    set fmtprefix ""
253                }
254
255                puts $fmtfile \
256                    "$fmtprefix$fmtname\t$fmtengine\t$fmtpatterns\t$fmtoptions"
257
258                # Simulate texlinks
259                if {($fmtengine != $fmtname) &&
260                    ![file exists ${destroot}${prefix}/bin/$fmtname]} {
261                    ln -s ${prefix}/bin/$fmtengine \
262                        ${destroot}${prefix}/bin/$fmtname
263                    ln -s ${prefix}/bin/$fmtengine \
264                        ${destroot}${texlive_mactex_texbindir}/$fmtname
265                }
266            }
267           
268            close $fmtfile
269        }
270
271        # install updmap.cfg file
272        if {${texlive.maps} != ""} {
273            xinstall -d ${destroot}${texlive_texmfsysconfig}/updmap.d
274            set mapfilename \
275                ${destroot}${texlive_texmfsysconfig}/updmap.d/10${name}.cfg
276            set mapfile [open $mapfilename "w"]
277            foreach x ${texlive.maps} {
278                puts $mapfile $x
279            }
280            close $mapfile
281        }
282
283        # install languages.dat and languages.def files
284        if {${texlive.languages} != ""} {
285            xinstall -d ${destroot}${texlive_texmfsysconfig}/language.d
286            set langdatfilename \
287                ${destroot}${texlive_texmfsysconfig}/language.d/10${name}.dat
288            set langdeffilename \
289                ${destroot}${texlive_texmfsysconfig}/language.d/10${name}.def
290            set langdatfile [open $langdatfilename "w"]
291            set langdeffile [open $langdeffilename "w"]
292            foreach x ${texlive.languages} {
293                set langname [lindex $x 0]
294                set langfile [lindex $x 1]
295                set langlhmin [lindex $x 2]
296                set langrhmin [lindex $x 3]
297                set langsyns [lindex $x 4]
298
299                puts $langdatfile "$langname $langfile"
300                foreach syn $langsyns {
301                    puts $langdatfile "=$syn"
302                }
303
304                foreach syn [concat $langname $langsyns] {
305                    puts $langdeffile "\\addlanguage{$syn}{$langfile}{}{$langlhmin}{$langrhmin}"
306                }
307            }
308            close $langdatfile
309            close $langdeffile
310        }
311    }
312
313    post-activate {
314        system "${texlive_bindir}/mktexlsr"
315        if {${texlive.forceupdatecnf}} {
316            # If force was specified, update all the config files, and
317            # regenerate all maps and formats.
318            system "${prefix}/libexec/texlive-update-cnf language.dat"
319            system "${prefix}/libexec/texlive-update-cnf language.def"
320            system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
321            system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
322            system "${prefix}/bin/updmap-sys"
323            system "${prefix}/bin/fmtutil-sys --all"
324        } else {
325            # Otherwise, only update the config files that are
326            # actually affected, and only generate the needed
327            # formats.
328            if {${texlive.languages} != ""} {
329                system "${prefix}/libexec/texlive-update-cnf language.dat"
330                system "${prefix}/libexec/texlive-update-cnf language.def"
331            }
332            if {${texlive.maps} != ""} {
333                system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
334                system "${prefix}/bin/updmap-sys"
335            }
336            if {${texlive.formats} != ""} {
337                system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
338            }
339
340            # Regenerate formats. If we installed any hyphenation
341            # patterns, then we need to regenerate all
342            # formats. Otherwise, just generate the formats we just
343            # installed.
344            if {${texlive.languages} != ""} {
345                system "${prefix}/bin/fmtutil-sys --all"               
346            } elseif {${texlive.formats} != ""} {
347                foreach x ${texlive.formats} {
348                    set fmtname [lindex $x 1]
349                    system "${prefix}/bin/fmtutil-sys --byfmt $fmtname"
350                }
351            }
352        }
353    }
354
355    post-deactivate {
356        # Update ls-R and any config files to reflect that the package
357        # is now gone
358        system "${texlive_bindir}/mktexlsr"
359        if {${texlive.forceupdatecnf} || ${texlive.languages} != ""} {
360            system "${prefix}/libexec/texlive-update-cnf language.dat"
361            system "${prefix}/libexec/texlive-update-cnf language.def"
362        }
363        if {${texlive.forceupdatecnf} || ${texlive.maps} != ""} {
364            system "${prefix}/libexec/texlive-update-cnf updmap.cfg"
365        }
366        if {${texlive.forceupdatecnf} || ${texlive.formats} != ""} {
367            system "${prefix}/libexec/texlive-update-cnf fmtutil.cnf"
368        }
369       
370        # Remove any generated format files
371        foreach x ${texlive.formats} {
372            set fmtname [lindex $x 1]
373            set fmtengine [lindex $x 2]
374            switch $fmtengine {
375                "mf"       -
376                "mf-nowin" {set fmtengine "metafont"}
377                "mpost"    {set fmtengine "metapost"}
378            }
379           
380            foreach filename [glob -nocomplain ${texlive_texmfsysvar}/web2c/$fmtengine/$fmtname.*] {
381                delete $filename
382            }
383        }
384    }
385}
Note: See TracBrowser for help on using the repository browser.