source: trunk/dports/_resources/port1.0/group/python-1.0.tcl @ 94386

Last change on this file since 94386 was 94386, checked in by jmr@…, 7 years ago

add smart python.default_version autoselection

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2# $Id: python-1.0.tcl 94386 2012-06-17 20:28:22Z jmr@macports.org $
3#
4# Copyright (c) 2011 The MacPorts Project
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# Usage:
33# name should be of the form py-foo for modules
34# subports pyXY-foo are declared for each XY in python.versions
35
36# for apps (i.e. not named py-foo), no subports will be defined
37# only the python.default_version will be used
38# you can change that in variants if you want
39
40# options:
41# python.versions: which versions this module supports, e.g. "26 27 31"
42#   always set this (even if you have your own subport blocks)
43# python.default_version: which version will be installed if the user asks
44#   for py-foo rather than pyXY-foo
45#
46# Note: setting these options requires name to be set beforehand
47
48categories      python
49
50use_configure   no
51# we want the default universal variant added despite not using configure
52universal_variant yes
53
54build.target    build
55
56pre-destroot    {
57    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}/examples
58}
59
60options python.versions python.version python.default_version
61option_proc python.versions python_set_versions
62default python.default_version {[python_get_default_version]}
63default python.version {[python_get_version]}
64
65proc python_get_version {} {
66    if {[string match py-* [option name]]} {
67        return [string range [option subport] 2 3]
68    } else {
69        return [option python.default_version]
70    }
71}
72proc python_get_default_version {} {
73    global python.versions
74    # py-foo historically meant python24, so we default to that if present
75    if {[info exists python.versions]} {
76        if {[lsearch -exact ${python.versions} 24] != -1} {
77            return 24
78        } elseif {[lsearch -exact ${python.versions} 27] != -1} {
79            # this is the actual preferred version
80            return 27
81        } else {
82            return [lindex ${python.versions} end]
83        }
84    } else {
85        return 24
86    }
87}
88
89proc python_set_versions {option action args} {
90    if {$action != "set"} {
91        return
92    }
93    global name subport python._addedcode
94    if {[string match py-* $name]} {
95        foreach v [option $option] {
96            subport py${v}[string trimleft $name py] { depends_lib port:python${v} }
97        }
98        if {$subport == $name || $subport == ""} {
99            # set up py-foo as a stub port that depends on the default pyXY-foo
100            distfiles
101            supported_archs noarch
102            global python.default_version
103            if {${python.default_version} == "24"} {
104                replaced_by py24[string trimleft $name py]
105            }
106            global python.version
107            unset python.version
108            depends_lib port:py${python.default_version}[string trimleft $name py]
109            patch {}
110            build {}
111            destroot {
112                system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README"
113            }
114        } else {
115            set addcode 1
116        }
117    } else {
118        set addcode 1
119    }
120    if {[info exists addcode] && ![info exists python._addedcode]} {
121        pre-build {
122            if {${python.add_archflags}} {
123                if {[variant_exists universal] && [variant_isset universal]} {
124                    build.env-append CFLAGS="${configure.universal_cflags}" \
125                                     OBJCFLAGS="${configure.universal_cflags}" \
126                                     CXXFLAGS="${configure.universal_cxxflags}" \
127                                     LDFLAGS="${configure.universal_ldflags}"
128                } else {
129                    build.env-append CFLAGS="${configure.cc_archflags}" \
130                                     OBJCFLAGS="${configure.objc_archflags}" \
131                                     CXXFLAGS="${configure.cxx_archflags}" \
132                                     FFLAGS="${configure.f77_archflags}" \
133                                     F90FLAGS="${configure.f90_archflags}" \
134                                     FCFLAGS="${configure.fc_archflags}" \
135                                     LDFLAGS="${configure.ld_archflags}"
136                }
137            }
138            if {${python.set_compiler}} {
139                foreach var {cc objc cxx fc f77 f90} {
140                    if {[set configure.${var}] != ""} {
141                        build.env-append [string toupper $var]="[set configure.${var}]"
142                    }
143                }
144            }
145        }
146        post-destroot {
147            if {${python.link_binaries}} {
148                foreach bin [glob -nocomplain -tails -directory "${destroot}${python.prefix}/bin" *] {
149                    if {[catch {file type "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"}]} {
150                        ln -s "${python.prefix}/bin/${bin}" "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"
151                    }
152                }
153            }
154        }
155        set python._addedcode 1
156    }
157}
158
159option_proc python.default_version python_set_default_version
160proc python_set_default_version {option action args} {
161    if {$action != "set"} {
162        return
163    }
164    global name subport python.default_version
165    if {[string match py-* $name]} {
166        if {$subport == $name || $subport == ""} {
167            # Mark stub as replaced_by py24 subport if that's the
168            # default version, for backwards compatibility.  If the
169            # default version isn't 24, clear replaced_by -- it might
170            # have already been set by python_set_versions. (But make
171            # sure we've set it first, or unset might complain.)
172            replaced_by py24[string trimleft $name py]
173            if {${python.default_version} != "24"} {
174                global replaced_by
175                unset replaced_by
176            }
177            depends_lib port:py${python.default_version}[string trimleft $name py]
178        }
179    } else {
180        python.versions ${python.default_version}
181        depends_lib-append port:python[option python.default_version]
182    }
183}
184
185
186options python.branch python.prefix python.bin python.lib python.libdir \
187        python.include python.pkgd
188# for pythonXY, python.branch is X.Y
189default python.branch {[string range ${python.version} 0 end-1].[string index ${python.version} end]}
190default python.prefix {[python_get_defaults prefix]}
191default python.bin  {[python_get_defaults bin]}
192default python.lib  {[python_get_defaults lib]}
193default python.pkgd {[python_get_defaults pkgd]}
194default python.libdir {${python.prefix}/lib/python${python.branch}}
195default python.include  {${python.prefix}/include/python${python.branch}}
196
197default build.cmd       {"${python.bin} setup.py [python_get_defaults setup_args]"}
198default destroot.cmd    {"${python.bin} setup.py [python_get_defaults setup_args]"}
199default destroot.destdir {"--prefix=[python_get_defaults setup_prefix] --root=${destroot}"}
200
201proc python_get_defaults {var} {
202    global python.version python.branch prefix python.prefix
203    switch -- $var {
204        prefix {
205            global build_arch frameworks_dir
206            set ret "${frameworks_dir}/Python.framework/Versions/${python.branch}"
207            if {${python.version} == 25 || (${python.version} == 24 && 
208                ![file isfile ${ret}/include/python${python.branch}/Python.h] &&
209                ([file isfile ${prefix}/include/python${python.branch}/Python.h]
210                || [string match *64* $build_arch]))} {
211                set ret $prefix
212            }
213            return $ret
214        }
215        bin {
216            if {${python.version} != 24} {
217                return "${python.prefix}/bin/python${python.branch}"
218            } else {
219                return "${prefix}/bin/python${python.branch}"
220            }
221        }
222        lib {
223            if {${python.version} != 24 && ${python.version} != 25} {
224                return "${python.prefix}/Python"
225            } else {
226                return "${prefix}/lib/lib${python.branch}.dylib"
227            }
228        }
229        pkgd {
230            if {${python.version} != 24} {
231                return "${python.prefix}/lib/python${python.branch}/site-packages"
232            } else {
233                return "${prefix}/lib/python${python.branch}/site-packages"
234            }
235        }
236        setup_args {
237            if {${python.version} != 24} {
238                return "--no-user-cfg"
239            } else {
240                return ""
241            }
242        }
243        setup_prefix {
244            if {${python.version} != 24} {
245                return "${python.prefix}"
246            } else {
247                return "${prefix}"
248            }
249        }
250        link_binaries {
251            if {${python.version} != 24 && ${python.version} != 25} {
252                return yes
253            } else {
254                return no
255            }
256        }
257        default {
258            error "unknown option $var"
259        }
260    }
261}
262
263options python.add_archflags
264default python.add_archflags yes
265options python.set_compiler
266default python.set_compiler yes
267
268options python.link_binaries python.link_binaries_suffix
269default python.link_binaries {[python_get_defaults link_binaries]}
270default python.link_binaries_suffix {-${python.branch}}
Note: See TracBrowser for help on using the repository browser.