source: trunk/base/src/port1.0/portdestroot.tcl @ 14485

Last change on this file since 14485 was 14485, checked in by jberry, 15 years ago

Add a global switch in ports.conf which controls what kind of startupitem
will be generated by default. This may be overridden in particular portfiles
by the startupitem.type key. Legal values are "default", "systemstarter", or "launchd".
In the event of "default", a type appropriate to the platform will be chosen.

  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
1# et:ts=4
2# portdestroot.tcl
3# $Id: portdestroot.tcl,v 1.28 2005/10/08 21:29:35 jberry Exp $
4#
5# Copyright (c) 2002 - 2003 Apple Computer, Inc.
6# Copyright (c) 2004 - 2005 Robert Shaw <rshaw@opendarwin.org>
7# All rights reserved.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17# 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
18#    may be used to endorse or promote products derived from this software
19#    without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33
34package provide portdestroot 1.0
35package require portutil 1.0
36
37set com.apple.destroot [target_new com.apple.destroot destroot_main]
38target_provides ${com.apple.destroot} destroot
39target_requires ${com.apple.destroot} main fetch extract checksum patch configure build
40target_prerun ${com.apple.destroot} destroot_start
41target_postrun ${com.apple.destroot} destroot_finish
42
43# define options
44options destroot.target destroot.destdir destroot.clean destroot.keepdirs destroot.umask
45options startupitem.create startupitem.requires startupitem.init
46options startupitem.name startupitem.start startupitem.stop startupitem.restart
47options startupitem.type startupitem.executable
48options startupitem.pidfile startupitem.logfile startupitem.logevents
49commands destroot
50
51# Set defaults
52default destroot.dir {${build.dir}}
53default destroot.cmd {${build.cmd}}
54default destroot.pre_args {${destroot.target}}
55default destroot.target install
56default destroot.post_args {${destroot.destdir}}
57default destroot.destdir {DESTDIR=${destroot}}
58default destroot.umask {$system_options(destroot_umask)}
59default destroot.clean no
60default destroot.keepdirs ""
61
62default startupitem.name                {${portname}}
63default startupitem.init                ""
64default startupitem.start               ""
65default startupitem.stop                ""
66default startupitem.restart             ""
67default startupitem.requires    ""
68default startupitem.executable  ""
69default startupitem.type                {$system_options(startupitem_type)}
70default startupitem.pidfile             ""
71default startupitem.logfile             ""
72default startupitem.logevents   no
73
74set_ui_prefix
75
76namespace eval destroot {
77        # Save old umask
78        variable oldmask
79}
80
81proc destroot_start {args} {
82    global UI_PREFIX prefix portname destroot portresourcepath os.platform destroot.clean
83    global destroot::oldmask destroot.umask
84   
85    ui_msg "$UI_PREFIX [format [msgcat::mc "Staging %s into destroot"] ${portname}]"
86
87    set oldmask [umask ${destroot.umask}]
88   
89    if { ${destroot.clean} == "yes" } {
90        system "rm -Rf \"${destroot}\""
91    }
92   
93    file mkdir "${destroot}"
94    if { ${os.platform} == "darwin" } {
95        system "cd \"${destroot}\" && mtree -e -U -f ${portresourcepath}/install/macosx.mtree"
96    }
97    file mkdir "${destroot}/${prefix}"
98    system "cd \"${destroot}/${prefix}\" && mtree -e -U -f ${portresourcepath}/install/prefix.mtree"
99}
100
101proc destroot_main {args} {
102    system "[command destroot]"
103    return 0
104}
105
106proc destroot_finish {args} {
107    global UI_PREFIX destroot prefix portname startupitem.create destroot::oldmask
108        global os.platform os.version
109
110    # Create startup-scripts/items
111    if {[tbool startupitem.create]} {
112        package require portstartupitem 1.0
113        startupitem_create
114    }
115
116    # Prune empty directories in ${destroot}
117    set exclude_dirs [list]
118    set exclude_phrase ""
119    foreach path [option destroot.keepdirs] {
120                if {![file isdirectory ${path}]} {
121                        xinstall -m 0755 -d ${path}
122                }
123                if {![file exists ${path}/.turd_${portname}]} {
124                        xinstall -c -m 0644 /dev/null ${path}/.turd_${portname}
125                }
126        lappend exclude_dirs "-path \"${path}\""
127    }
128    if { [llength ${exclude_dirs}] > 0 } {
129        set exclude_phrase "! \\( [join ${exclude_dirs} " -or "] \\)"
130    }
131    catch {system "find \"${destroot}\" -depth -type d ${exclude_phrase} -exec rmdir -- \{\} \\; 2>/dev/null"}
132
133    # Compress all manpages with gzip (instead)
134        # but NOT on Jaguar (Darwin 6.x)
135        if {![regexp {darwin6} "${os.platform}${os.version}"]} {
136    set manpath "${destroot}${prefix}/share/man"
137    if {[file isdirectory ${manpath}] && [file type ${manpath}] == "directory"} {
138        ui_info "$UI_PREFIX [format [msgcat::mc "Compressing man pages for %s"] ${portname}]"
139        set found 0
140        set manlinks [list]
141        foreach mandir [readdir "${manpath}"] {
142            if {![regexp {^man(.)$} ${mandir} match manindex]} { continue }
143            set mandirpath [file join ${manpath} ${mandir}]
144            if {[file isdirectory ${mandirpath}] && [file type ${mandirpath}] == "directory"} {
145                ui_debug "Scanning ${mandir}"
146                foreach manfile [readdir ${mandirpath}] {
147                    set manfilepath [file join ${mandirpath} ${manfile}]
148                    if {[file isfile ${manfilepath}] && [file type ${manfilepath}] == "file"} {
149                        if {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]gz\$" ${manfile} gzfile manfile]} {
150                            set found 1
151                            system "cd ${manpath} && \
152                                                                gunzip -f [file join ${mandir} ${gzfile}] && \
153                                                                gzip -9vf [file join ${mandir} ${manfile}]"
154                        } elseif {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]bz2\$" ${manfile} bz2file manfile]} {
155                            set found 1
156                            system "cd ${manpath} && \
157                                                                bunzip2 -f [file join ${mandir} ${bz2file}] && \
158                                                                gzip -9vf [file join ${mandir} ${manfile}]"
159                        } elseif {[regexp "\[.\]${manindex}\[a-z\]*\$" ${manfile}]} {
160                            set found 1
161                            system "cd ${manpath} && \
162                                                                gzip -9vf [file join ${mandir} ${manfile}]"
163                        }
164                        set gzmanfile ${manfile}.gz
165                        set gzmanfilepath [file join ${mandirpath} ${gzmanfile}]
166                        if {[file exists ${gzmanfilepath}]} {
167                            set desired 00444
168                            set current [file attributes ${gzmanfilepath} -permissions]
169                            if {$current != $desired} {
170                                ui_info "[file join ${mandir} ${gzmanfile}]: changing permissions from $current to $desired"
171                                file attributes ${gzmanfilepath} -permissions $desired
172                            }
173                        }
174                    } elseif {[file type ${manfilepath}] == "link"} {
175                        lappend manlinks [file join ${mandir} ${manfile}]
176                    }
177                }
178            }
179        }
180        if {$found == 1} {
181            # check man page links and rename/repoint them if necessary
182            foreach manlink $manlinks {
183                set manlinkpath [file join $manpath $manlink]
184                # if link destination is not gzipped, check it
185                set manlinksrc [file readlink $manlinkpath]
186                if {![regexp "\[.\]gz\$" ${manlinksrc}]} {
187                    set mandir [file dirname $manlink]
188                    set mandirpath [file join $manpath $mandir]
189                    set pwd [pwd]
190                    if {[catch {cd $mandirpath} err]} {
191                        puts $err
192                        return
193                    }
194                    # if gzipped destination exists, fix link
195                    if {[file isfile ${manlinksrc}.gz]} {
196                        # if actual link name does not end with gz, rename it
197                        if {![regexp "\[.\]gz\$" ${manlink}]} {
198                            ui_debug "renaming link: $manlink to ${manlink}.gz"
199                            file rename $manlinkpath ${manlinkpath}.gz
200                            set manlink ${manlink}.gz
201                            set manlinkpath [file join $manpath $manlink]
202                        }
203                        # repoint the link
204                        ui_debug "repointing link: $manlink from $manlinksrc to ${manlinksrc}.gz"
205                        file delete $manlinkpath
206                        system "ln -s \"${manlinksrc}.gz\" \"$manlinkpath\""
207                    }
208                    cd $pwd
209                }
210            }
211        } else {
212            ui_debug "No man pages found to compress."
213        }
214    }
215        } else {
216            ui_debug "No man page compression on ${os.platform}${os.version}."
217    }
218
219        if [file exists "${destroot}${prefix}/share/info/dir"] {
220                ui_debug "Deleting stray info/dir file."
221            file delete "${destroot}${prefix}/share/info/dir"
222        }
223    # Restore umask
224    umask $oldmask
225
226    return 0
227}
Note: See TracBrowser for help on using the repository browser.