Ticket #16723: python-1.0.2.tcl

File python-1.0.2.tcl, 8.8 KB (added by MarcusCalhoun-Lopez (Marcus Calhoun-Lopez), 15 years ago)
Line 
1# et:ts=4
2# python24-1.0.tcl
3#
4# $Id: python24-1.0.tcl 26177 2007-06-15 10:11:22Z jmpp@macports.org $
5#
6# Copyright (c) 2004 Markus W. Weissman <mww@macports.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 are
11# met:
12#
13# 1. Redistributions of source code must retain the above copyright
14#    notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16#    notice, this list of conditions and the following disclaimer in the
17#    documentation and/or other materials provided with the distribution.
18# 3. Neither the name of Apple Computer, Inc. nor the names of its
19#    contributors may be used to endorse or promote products derived from
20#    this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34
35# arbitrary 'reasonable' defaults
36set python.versions {python24 python25 python26}
37set python.default_version python26
38
39# Can be removed once MacPorts 1.7.0 is released
40if {![info exists frameworks_dir]} {
41    set frameworks_dir ${prefix}/Library/Frameworks
42}
43
44# Python versions 2.6 and above have different prefix locations (see #16933).
45set python24.prefix  ${prefix}
46set python25.prefix  ${prefix}
47set python26.prefix  ${frameworks_dir}/Python.framework/Versions/2.6
48
49proc python.versions {versions} {
50    global python.versions
51    set python.versions $versions
52}
53
54categories      python
55dist_subdir     python
56
57use_configure   no
58
59build.target    build
60
61pre-destroot    {
62    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}/examples
63}
64
65# select a default version if none set
66foreach v ${python.versions} {
67    if {[variant_isset $v]} {
68        set python.version_chosen ${v}
69    }
70}
71if {![info exists python.version_chosen]} {
72    variant_set ${python.default_version}
73    set python.primary_version ${python.default_version}
74} else {
75    set python.primary_version python.version_chosen
76}
77
78foreach v ${python.versions} {
79    # pythonx.y
80    set python.dotversion [string range $v 0 end-1].[string index $v end]
81
82    set ${v}.bin        [set ${v}.prefix]/bin/${python.dotversion}
83    set ${v}.libdir     [set ${v}.prefix]/lib/${python.dotversion}
84    set ${v}.pkgd       [set ${v}.prefix]/lib/${python.dotversion}/site-packages
85    set ${v}.include    [set ${v}.prefix]/include/${python.dotversion}
86    set ${v}.version    [string range ${v} end-1 end-1].[string range ${v} end end]
87    set ${v}.framework  ${frameworks_dir}/Python.framework/Versions/[set ${v}.version]
88
89    # Each python variant gets its own worksrcpath, but they aren't split until after post-patch.
90    # Patches applied to all variants can be done in pre-patch, patch, and post-patch.
91    # Patches applied to individual variants must be done in pre-build.
92    #
93    # Each python variant get its own destroot directory.
94    # They aren't combined until after post-destroot.
95    variant $v "post-patch { copy \${worksrcpath} \${worksrcpath}-${v} }\n  post-destroot { private_python_post_destroot ${v} } "
96
97    # Python versions 2.6 and above have different library locations (see #16933).
98    # Python versions 2.6 and above support the --no-user-cfg option (see #16765).
99    if { [set ${v}.version] <= 2.5 } {
100        set ${v}.lib    [set ${v}.prefix]/lib/lib[set ${v}.version].dylib
101        set ${v}.setup  setup.py
102    } else {
103        set ${v}.lib    [set ${v}.prefix]/Python
104        set ${v}.setup  {setup.py --no-user-cfg}
105    }
106
107    if {[variant_isset $v]} {
108        depends_lib-append      port:${v}
109    }
110}
111
112build {
113    foreach v ${python.versions} {
114        if {[variant_isset $v]} {
115            set buildcmd "[set ${v}.bin] [set ${v}.setup]"
116            system "cd ${worksrcpath}-${v} && ${buildcmd} ${build.target}"
117        }
118    }
119}
120
121destroot {
122    # Each python variant has its own destroot.
123    # This makes appending version numbers to binary files easier.
124    foreach v ${python.versions} {
125        if {[variant_isset $v]} {
126            copy ${destroot} ${destroot}-${v}
127        }
128    }
129
130    foreach v ${python.versions} {
131        if {[variant_isset ${v}]} {
132            destroot.destdir    --prefix=[set ${v}.prefix] --root=${destroot}-${v}
133            set destrootcmd "[set ${v}.bin] [set ${v}.setup]"
134
135            system "cd ${worksrcpath}-${v} && ${destrootcmd} ${destroot.target} ${destroot.destdir}"
136
137            # Avoid conflicts by moving everything out of ${prefix}/[bin, share/man, ...]
138            foreach dir {bin lib/pkgconfig share/pkgconfig} {
139                xinstall -d -m 755 ${destroot}-${v}[set ${v}.framework]/${dir}
140                foreach file [glob -nocomplain -directory ${destroot}-${v}${prefix}/${dir} *] {
141                    move ${file} ${destroot}-${v}[set ${v}.framework]/${dir}/
142                }
143            }
144            foreach mani [glob -nocomplain -directory ${destroot}-${v}${prefix}/share/man *] {
145                foreach man [glob -nocomplain -directory ${mani} *] {
146                    xinstall -d -m 755 ${destroot}-${v}[set ${v}.framework]/share/man/[file tail ${mani}]
147                    move ${man} ${destroot}-${v}[set ${v}.framework]/share/man/[file tail ${mani}]/
148                }
149            }
150
151            # Link program files back to ${prefix}/bin with version number appended
152            foreach file [glob -nocomplain -tails -directory ${destroot}-${v}[set ${v}.framework]/bin *] {
153                if { [string range ${file} end-2 end] != [set ${v}.version] } {
154                    # Don't create link if file ends in version number already
155                    ln -s [set ${v}.framework]/bin/${file} ${destroot}${prefix}/bin/${file}-[set ${v}.version]
156                }
157            }
158        }
159    }
160}
161
162########################################################################################################################
163# Each python variant has its own destroot directory.
164# This function combines them.
165# Conflicts cause errors
166########################################################################################################################
167proc private_rename_recur {olddir newdir} {
168    foreach fl [glob -nocomplain -tails -directory ${olddir} *] {
169        if { [file isdirectory ${olddir}/${fl}] && [file type ${olddir}/${fl}] != "link" } {
170            xinstall -d ${newdir}/${fl}
171            private_rename_recur ${olddir}/${fl} ${newdir}/${fl}
172        } else {
173            move ${olddir}/${fl} ${newdir}/${fl}
174        }
175    }
176}
177
178########################################################################################################################
179# Called by post-destroot for each variant (v is the python version)
180########################################################################################################################
181proc private_python_post_destroot {v} {
182    global destroot frameworks_dir destroot python.versions prefix
183    foreach vv ${python.versions} {
184        global ${vv}.version ${vv}.framework
185    }
186
187    private_rename_recur ${destroot}-${v} ${destroot}
188
189    # Create links to the 'Current' python version as defined by python_select
190    foreach file [glob -nocomplain -tails -directory ${destroot}[set ${v}.framework]/bin *] {
191        if { [string range ${file} end-2 end] ne [set ${v}.version] } {
192            # Don't create link if file ends in the version number
193            ln -sf ${frameworks_dir}/Python.framework/Versions/Current/bin/${file} ${destroot}${prefix}/bin/${file} 
194        }
195    }
196    foreach dir {lib/pkgconfig share/pkgconfig} {
197        foreach file [glob -nocomplain -tails -directory ${destroot}[set ${v}.framework]/${dir} *] {
198            ln -sf ${frameworks_dir}/Python.framework/Versions/Current/${dir}/${file} ${destroot}${prefix}/${dir}/${file} 
199        }
200    }
201    foreach mani [glob -nocomplain -tails -directory ${destroot}[set ${v}.framework]/share/man *] {
202        foreach man [glob -nocomplain -tails -directory ${destroot}[set ${v}.framework]/share/man/${mani} *] {
203            ln -sf ${frameworks_dir}/Python.framework/Versions/Current/share/man/${mani}/${man} ${destroot}${prefix}/share/man/${mani}
204        }
205    }
206}
207
208test {
209    foreach v ${python.versions} {
210        if {[variant_isset $v]} {
211            set destrootcmd "[set ${v}.bin] [set ${v}.setup]"
212            system "cd ${worksrcpath}-${v} && ${destrootcmd} test"
213        }
214    }
215}
216# Othere possibe test procedures are:
217#test {
218#    foreach v ${python.versions} {
219#        if {[variant_isset $v]} {
220#            system "cd ${worksrcpath}-${v} && make check PYTHONPATH=[glob -nocomplain ${worksrcpath}-${v}/build/lib*]"
221#        }
222#    }
223#}