1 | # et:ts=4 |
---|
2 | # portdestroot.tcl |
---|
3 | # $Id: portdestroot.tcl 23969 2007-04-14 03:46:37Z jberry@macports.org $ |
---|
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 | |
---|
34 | package provide portdestroot 1.0 |
---|
35 | package require portutil 1.0 |
---|
36 | |
---|
37 | set com.apple.destroot [target_new com.apple.destroot destroot_main] |
---|
38 | target_provides ${com.apple.destroot} destroot |
---|
39 | target_requires ${com.apple.destroot} main fetch extract checksum patch configure build |
---|
40 | target_prerun ${com.apple.destroot} destroot_start |
---|
41 | target_postrun ${com.apple.destroot} destroot_finish |
---|
42 | |
---|
43 | # define options |
---|
44 | options destroot.target destroot.destdir destroot.clean destroot.keepdirs destroot.umask |
---|
45 | options startupitem.create startupitem.requires startupitem.init |
---|
46 | options startupitem.name startupitem.start startupitem.stop startupitem.restart |
---|
47 | options startupitem.type startupitem.executable |
---|
48 | options startupitem.pidfile startupitem.logfile startupitem.logevents |
---|
49 | options startupitem.inetdcompat startupitem.inetdcompat.socketsvcname startupitem.inetdcompat.nowait |
---|
50 | commands destroot |
---|
51 | |
---|
52 | # Set defaults |
---|
53 | default destroot.dir {${build.dir}} |
---|
54 | default destroot.cmd {${build.cmd}} |
---|
55 | default destroot.pre_args {${destroot.target}} |
---|
56 | default destroot.target install |
---|
57 | default destroot.post_args {${destroot.destdir}} |
---|
58 | default destroot.destdir {DESTDIR=${destroot}} |
---|
59 | default destroot.umask {$system_options(destroot_umask)} |
---|
60 | default destroot.clean no |
---|
61 | default destroot.keepdirs "" |
---|
62 | |
---|
63 | default startupitem.name {${portname}} |
---|
64 | default startupitem.init "" |
---|
65 | default startupitem.start "" |
---|
66 | default startupitem.stop "" |
---|
67 | default startupitem.restart "" |
---|
68 | default startupitem.requires "" |
---|
69 | default startupitem.executable "" |
---|
70 | default startupitem.type {$system_options(startupitem_type)} |
---|
71 | default startupitem.pidfile "" |
---|
72 | default startupitem.logfile "" |
---|
73 | default startupitem.logevents no |
---|
74 | default startupitem.inetdcompat "" |
---|
75 | default startupitem.inetdcompat.socketsvcname "" |
---|
76 | default startupitem.inetdcompat.nowait false |
---|
77 | |
---|
78 | set_ui_prefix |
---|
79 | |
---|
80 | namespace eval destroot { |
---|
81 | # Save old umask |
---|
82 | variable oldmask |
---|
83 | } |
---|
84 | |
---|
85 | proc destroot_start {args} { |
---|
86 | global UI_PREFIX prefix portname destroot portresourcepath os.platform destroot.clean |
---|
87 | global destroot::oldmask destroot.umask |
---|
88 | |
---|
89 | ui_msg "$UI_PREFIX [format [msgcat::mc "Staging %s into destroot"] ${portname}]" |
---|
90 | |
---|
91 | set oldmask [umask ${destroot.umask}] |
---|
92 | |
---|
93 | if { ${destroot.clean} == "yes" } { |
---|
94 | system "rm -Rf \"${destroot}\"" |
---|
95 | } |
---|
96 | |
---|
97 | file mkdir "${destroot}" |
---|
98 | if { ${os.platform} == "darwin" } { |
---|
99 | system "cd \"${destroot}\" && mtree -e -U -f ${portresourcepath}/install/macosx.mtree" |
---|
100 | } |
---|
101 | file mkdir "${destroot}/${prefix}" |
---|
102 | system "cd \"${destroot}/${prefix}\" && mtree -e -U -f ${portresourcepath}/install/prefix.mtree" |
---|
103 | } |
---|
104 | |
---|
105 | proc destroot_main {args} { |
---|
106 | command_exec destroot |
---|
107 | return 0 |
---|
108 | } |
---|
109 | |
---|
110 | proc destroot_finish {args} { |
---|
111 | global UI_PREFIX destroot prefix portname startupitem.create destroot::oldmask |
---|
112 | global os.platform os.version |
---|
113 | |
---|
114 | # Create startup-scripts/items |
---|
115 | if {[tbool startupitem.create]} { |
---|
116 | package require portstartupitem 1.0 |
---|
117 | startupitem_create |
---|
118 | } |
---|
119 | |
---|
120 | # Prune empty directories in ${destroot} |
---|
121 | set exclude_dirs [list] |
---|
122 | set exclude_phrase "" |
---|
123 | foreach path [option destroot.keepdirs] { |
---|
124 | if {![file isdirectory ${path}]} { |
---|
125 | xinstall -m 0755 -d ${path} |
---|
126 | } |
---|
127 | if {![file exists ${path}/.turd_${portname}]} { |
---|
128 | xinstall -c -m 0644 /dev/null ${path}/.turd_${portname} |
---|
129 | } |
---|
130 | lappend exclude_dirs "-path \"${path}\"" |
---|
131 | } |
---|
132 | if { [llength ${exclude_dirs}] > 0 } { |
---|
133 | set exclude_phrase "! \\( [join ${exclude_dirs} " -or "] \\)" |
---|
134 | } |
---|
135 | catch {system "find \"${destroot}\" -depth -type d ${exclude_phrase} -exec rmdir -- \{\} \\; 2>/dev/null"} |
---|
136 | |
---|
137 | # Compress all manpages with gzip (instead) |
---|
138 | # but NOT on Jaguar (Darwin 6.x) |
---|
139 | if {![regexp {darwin6} "${os.platform}${os.version}"]} { |
---|
140 | set manpath "${destroot}${prefix}/share/man" |
---|
141 | if {[file isdirectory ${manpath}] && [file type ${manpath}] == "directory"} { |
---|
142 | ui_info "$UI_PREFIX [format [msgcat::mc "Compressing man pages for %s"] ${portname}]" |
---|
143 | set found 0 |
---|
144 | set manlinks [list] |
---|
145 | foreach mandir [readdir "${manpath}"] { |
---|
146 | if {![regexp {^(cat|man)(.)$} ${mandir} match ignore manindex]} { continue } |
---|
147 | set mandirpath [file join ${manpath} ${mandir}] |
---|
148 | if {[file isdirectory ${mandirpath}] && [file type ${mandirpath}] == "directory"} { |
---|
149 | ui_debug "Scanning ${mandir}" |
---|
150 | foreach manfile [readdir ${mandirpath}] { |
---|
151 | set manfilepath [file join ${mandirpath} ${manfile}] |
---|
152 | if {[file isfile ${manfilepath}] && [file type ${manfilepath}] == "file"} { |
---|
153 | if {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]gz\$" ${manfile} gzfile manfile]} { |
---|
154 | set found 1 |
---|
155 | system "cd ${manpath} && \ |
---|
156 | gunzip -f [file join ${mandir} ${gzfile}] && \ |
---|
157 | gzip -9vf [file join ${mandir} ${manfile}]" |
---|
158 | } elseif {[regexp "^(.*\[.\]${manindex}\[a-z\]*)\[.\]bz2\$" ${manfile} bz2file manfile]} { |
---|
159 | set found 1 |
---|
160 | system "cd ${manpath} && \ |
---|
161 | bunzip2 -f [file join ${mandir} ${bz2file}] && \ |
---|
162 | gzip -9vf [file join ${mandir} ${manfile}]" |
---|
163 | } elseif {[regexp "\[.\]${manindex}\[a-z\]*\$" ${manfile}]} { |
---|
164 | set found 1 |
---|
165 | system "cd ${manpath} && \ |
---|
166 | gzip -9vf [file join ${mandir} ${manfile}]" |
---|
167 | } |
---|
168 | set gzmanfile ${manfile}.gz |
---|
169 | set gzmanfilepath [file join ${mandirpath} ${gzmanfile}] |
---|
170 | if {[file exists ${gzmanfilepath}]} { |
---|
171 | set desired 00444 |
---|
172 | set current [file attributes ${gzmanfilepath} -permissions] |
---|
173 | if {$current != $desired} { |
---|
174 | ui_info "[file join ${mandir} ${gzmanfile}]: changing permissions from $current to $desired" |
---|
175 | file attributes ${gzmanfilepath} -permissions $desired |
---|
176 | } |
---|
177 | } |
---|
178 | } elseif {[file type ${manfilepath}] == "link"} { |
---|
179 | lappend manlinks [file join ${mandir} ${manfile}] |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | if {$found == 1} { |
---|
185 | # check man page links and rename/repoint them if necessary |
---|
186 | foreach manlink $manlinks { |
---|
187 | set manlinkpath [file join $manpath $manlink] |
---|
188 | # if link destination is not gzipped, check it |
---|
189 | set manlinksrc [file readlink $manlinkpath] |
---|
190 | if {![regexp "\[.\]gz\$" ${manlinksrc}]} { |
---|
191 | set mandir [file dirname $manlink] |
---|
192 | set mandirpath [file join $manpath $mandir] |
---|
193 | set pwd [pwd] |
---|
194 | if {[catch {cd $mandirpath} err]} { |
---|
195 | puts $err |
---|
196 | return |
---|
197 | } |
---|
198 | # if gzipped destination exists, fix link |
---|
199 | if {[file isfile ${manlinksrc}.gz]} { |
---|
200 | # if actual link name does not end with gz, rename it |
---|
201 | if {![regexp "\[.\]gz\$" ${manlink}]} { |
---|
202 | ui_debug "renaming link: $manlink to ${manlink}.gz" |
---|
203 | file rename $manlinkpath ${manlinkpath}.gz |
---|
204 | set manlink ${manlink}.gz |
---|
205 | set manlinkpath [file join $manpath $manlink] |
---|
206 | } |
---|
207 | # repoint the link |
---|
208 | ui_debug "repointing link: $manlink from $manlinksrc to ${manlinksrc}.gz" |
---|
209 | file delete $manlinkpath |
---|
210 | system "ln -s \"${manlinksrc}.gz\" \"$manlinkpath\"" |
---|
211 | } |
---|
212 | cd $pwd |
---|
213 | } |
---|
214 | } |
---|
215 | } else { |
---|
216 | ui_debug "No man pages found to compress." |
---|
217 | } |
---|
218 | } |
---|
219 | } else { |
---|
220 | ui_debug "No man page compression on ${os.platform}${os.version}." |
---|
221 | } |
---|
222 | |
---|
223 | if [file exists "${destroot}${prefix}/share/info/dir"] { |
---|
224 | ui_debug "Deleting stray info/dir file." |
---|
225 | file delete "${destroot}${prefix}/share/info/dir" |
---|
226 | } |
---|
227 | # Restore umask |
---|
228 | umask $oldmask |
---|
229 | |
---|
230 | return 0 |
---|
231 | } |
---|