Ticket #16723: python-1.0.3.tcl

File python-1.0.3.tcl, 7.8 KB (added by jmroot (Joshua Root), 13 years ago)

now with subports

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$
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 Apple Computer, Inc. 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
34# subports pyXY-foo are declared for each XY in python.versions
35
36# options:
37# python.versions: which versions this module supports, e.g. "26 27 31"
38#   always set this (even if you have your own subport blocks)
39# python.default_version: which version will be installed if the user asks
40#   for py-foo rather than pyXY-foo
41#
42# Note: setting these options requires name to be set beforehand
43
44categories      python
45
46use_configure   no
47
48build.target    build
49
50pre-destroot    {
51    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}/examples
52}
53
54options python.versions python.version python.default_version
55option_proc python.versions python_set_versions
56# py-foo historically meant python24
57default python.default_version {24}
58default python.version {[string range $subport 2 3]}
59
60proc python_set_versions {option action args} {
61    if {$action != "set"} {
62        return
63    }
64    foreach v [option $option] {
65        subport py${v}[string trimleft [option name] py] { depends_lib port:python${v} }
66    }
67    if {![exists depends_lib]} {
68        depends_lib port:py[option python.default_version][string trimleft [option name] py]
69    }
70}
71
72option_proc python.default_version python_set_default_version
73proc python_set_default_version {option action args} {
74    if {$action != "set"} {
75        return
76    }
77    global name subport
78    if {$subport == "" || $subport == $name} {
79        depends_lib port:py[option python.default_version][string trimleft $name py]
80    }
81}
82
83option_proc name python_set_name
84# set up py-foo as a stub port that depends on the default pyXY-foo
85proc python_set_name {option action args} {
86    if {$action != "set"} {
87        return
88    }
89    global name subport
90    if {![string match py-* $name]} {
91        ui_warn "name should be of the form py-*"
92    }
93    if {$subport == "" || $subport == $name} {
94        supported_archs noarch
95        build {}
96        destroot {
97            system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README"
98        }
99    }
100}
101
102options python.branch python.prefix python.bin python.lib python.libdir \
103        python.include python.pkgd
104# for pythonXY, python.branch is X.Y
105default python.branch {[string range ${python.version} 0 end-1].[string index ${python.version} end]}
106default python.prefix {[python_get_defaults prefix]}
107default python.bin  {[python_get_defaults bin]}
108default python.lib  {[python_get_defaults lib]}
109default python.pkgd {[python_get_defaults pkgd]}
110default python.libdir {${python.prefix}/lib/python${python.branch}}
111default python.include  {${python.prefix}/include/python${python.branch}}
112
113if {${python.version} != 24} {
114    set python.setup_args --no-user-cfg
115    default destroot.destdir {"--prefix=${python.prefix} --root=${destroot}"}
116} else {
117    set python.setup_args ""
118    default destroot.destdir {"--prefix=${prefix} --root=${destroot}"}
119}
120default build.cmd       {"${python.bin} setup.py ${python.setup_args}"}
121default destroot.cmd    {"${python.bin} setup.py ${python.setup_args}"}
122
123proc python_get_defaults {var} {
124    global python.version python.branch prefix python.prefix
125    switch -- $var {
126        prefix {
127            global build_arch frameworks_dir
128            set ret "${frameworks_dir}/Python.framework/Versions/${python.branch}"
129            if {${python.version} == 25 || (${python.version} == 24 && 
130                ![file isfile ${ret}/include/python${python.branch}/Python.h] &&
131                ([file isfile ${prefix}/include/python${python.branch}/Python.h]
132                || [string match *64* $build_arch]))} {
133                set ret $prefix
134            }
135            return $ret
136        }
137        bin {
138            if {${python.version} != 24} {
139                return "${python.prefix}/bin/python${python.branch}"
140            } else {
141                return "${prefix}/bin/python${python.branch}"
142            }
143        }
144        lib {
145            if {${python.version} != 24 && ${python.version} != 25} {
146                return "${python.prefix}/Python"
147            } else {
148                return "${prefix}/lib/lib${python.branch}.dylib"
149            }
150        }
151        pkgd {
152            if {${python.version} != 24} {
153                return "${python.prefix}/lib/python${python.branch}/site-packages"
154            } else {
155                return "${prefix}/lib/python${python.branch}/site-packages"
156            }
157        }
158        default {
159            error "unknown option $var"
160        }
161    }
162}
163
164options python.add_archflags
165if {${python.version} != 24 && ${python.version} != 25} {
166    # we want the default universal variant added despite not using configure
167    universal_variant yes
168    default python.add_archflags yes
169} else {
170    default python.add_archflags no
171}
172
173pre-build {
174    if {${python.add_archflags}} {
175        if {[variant_exists universal] && [variant_isset universal]} {
176            build.env-append CFLAGS="${configure.universal_cflags}" \
177                             OBJCFLAGS="${configure.universal_cflags}" \
178                             CXXFLAGS="${configure.universal_cxxflags}" \
179                             LDFLAGS="${configure.universal_ldflags}"
180        } else {
181            build.env-append CFLAGS="${configure.cc_archflags}" \
182                             OBJCFLAGS="${configure.objc_archflags}" \
183                             CXXFLAGS="${configure.cxx_archflags}" \
184                             FFLAGS="${configure.f77_archflags}" \
185                             F90FLAGS="${configure.f90_archflags}" \
186                             FCFLAGS="${configure.fc_archflags}" \
187                             LDFLAGS="${configure.ld_archflags}"
188        }
189    }
190}
191
192options python.link_binaries python.link_binaries_suffix
193if {${python.version} != 24 && ${python.version} != 25} {
194    default python.link_binaries yes
195} else {
196    default python.link_binaries no
197}
198default python.link_binaries_suffix {-${python.branch}}
199post-destroot {
200    if {${python.link_binaries}} {
201        foreach bin [glob -nocomplain -tails -directory "${destroot}${python.prefix}/bin" *] {
202            if {[catch {file type "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"}]} {
203                ln -s "${python.prefix}/bin/${bin}" "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"
204            }
205        }
206    }
207}