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

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

make sure to only add pre-build and post-destroot code once

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.6 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 89024 2012-01-18 06:24:05Z 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
62# py-foo historically meant python24
63default python.default_version {24}
64default python.version {[python_get_version]}
65
66proc python_get_version {} {
67    if {[string match py-* [option name]]} {
68        return [string range [option subport] 2 3]
69    } else {
70        return [option python.default_version]
71    }
72}
73
74proc python_set_versions {option action args} {
75    if {$action != "set"} {
76        return
77    }
78    global name subport python._addedcode
79    if {[string match py-* $name]} {
80        foreach v [option $option] {
81            subport py${v}[string trimleft $name py] { depends_lib port:python${v} }
82        }
83        if {$subport == $name || $subport == ""} {
84            # set up py-foo as a stub port that depends on the default pyXY-foo
85            distfiles
86            supported_archs noarch
87            global python.default_version
88            if {${python.default_version} == "24"} {
89                replaced_by py24[string trimleft $name py]
90            }
91            global python.version
92            unset python.version
93            depends_lib port:py${python.default_version}[string trimleft $name py]
94            build {}
95            destroot {
96                system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README"
97            }
98        } else {
99            set addcode 1
100        }
101    } else {
102        set addcode 1
103    }
104    if {[info exists addcode] && ![info exists python._addedcode]} {
105        pre-build {
106            if {${python.add_archflags}} {
107                if {[variant_exists universal] && [variant_isset universal]} {
108                    build.env-append CFLAGS="${configure.universal_cflags}" \
109                                     OBJCFLAGS="${configure.universal_cflags}" \
110                                     CXXFLAGS="${configure.universal_cxxflags}" \
111                                     LDFLAGS="${configure.universal_ldflags}"
112                } else {
113                    build.env-append CFLAGS="${configure.cc_archflags}" \
114                                     OBJCFLAGS="${configure.objc_archflags}" \
115                                     CXXFLAGS="${configure.cxx_archflags}" \
116                                     FFLAGS="${configure.f77_archflags}" \
117                                     F90FLAGS="${configure.f90_archflags}" \
118                                     FCFLAGS="${configure.fc_archflags}" \
119                                     LDFLAGS="${configure.ld_archflags}"
120                }
121            }
122            if {${python.set_compiler}} {
123                foreach var {cc objc cxx fc f77 f90} {
124                    if {[set configure.${var}] != ""} {
125                        build.env-append [string toupper $var]="[set configure.${var}]"
126                    }
127                }
128            }
129        }
130        post-destroot {
131            if {${python.link_binaries}} {
132                foreach bin [glob -nocomplain -tails -directory "${destroot}${python.prefix}/bin" *] {
133                    if {[catch {file type "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"}]} {
134                        ln -s "${python.prefix}/bin/${bin}" "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"
135                    }
136                }
137            }
138        }
139        set python._addedcode 1
140    }
141}
142
143option_proc python.default_version python_set_default_version
144proc python_set_default_version {option action args} {
145    if {$action != "set"} {
146        return
147    }
148    global name subport python.default_version
149    if {[string match py-* $name]} {
150        if {$subport == $name || $subport == ""} {
151            if {${python.default_version} == "24"} {
152                replaced_by py24[string trimleft $name py]
153            } else {
154                global replaced_by
155                unset -nocomplain replaced_by
156            }
157            depends_lib port:py${python.default_version}[string trimleft $name py]
158        }
159    } else {
160        python.versions ${python.default_version}
161        depends_lib-append port:python[option python.default_version]
162    }
163}
164
165
166options python.branch python.prefix python.bin python.lib python.libdir \
167        python.include python.pkgd
168# for pythonXY, python.branch is X.Y
169default python.branch {[string range ${python.version} 0 end-1].[string index ${python.version} end]}
170default python.prefix {[python_get_defaults prefix]}
171default python.bin  {[python_get_defaults bin]}
172default python.lib  {[python_get_defaults lib]}
173default python.pkgd {[python_get_defaults pkgd]}
174default python.libdir {${python.prefix}/lib/python${python.branch}}
175default python.include  {${python.prefix}/include/python${python.branch}}
176
177default build.cmd       {"${python.bin} setup.py [python_get_defaults setup_args]"}
178default destroot.cmd    {"${python.bin} setup.py [python_get_defaults setup_args]"}
179default destroot.destdir {"--prefix=[python_get_defaults setup_prefix] --root=${destroot}"}
180
181proc python_get_defaults {var} {
182    global python.version python.branch prefix python.prefix
183    switch -- $var {
184        prefix {
185            global build_arch frameworks_dir
186            set ret "${frameworks_dir}/Python.framework/Versions/${python.branch}"
187            if {${python.version} == 25 || (${python.version} == 24 && 
188                ![file isfile ${ret}/include/python${python.branch}/Python.h] &&
189                ([file isfile ${prefix}/include/python${python.branch}/Python.h]
190                || [string match *64* $build_arch]))} {
191                set ret $prefix
192            }
193            return $ret
194        }
195        bin {
196            if {${python.version} != 24} {
197                return "${python.prefix}/bin/python${python.branch}"
198            } else {
199                return "${prefix}/bin/python${python.branch}"
200            }
201        }
202        lib {
203            if {${python.version} != 24 && ${python.version} != 25} {
204                return "${python.prefix}/Python"
205            } else {
206                return "${prefix}/lib/lib${python.branch}.dylib"
207            }
208        }
209        pkgd {
210            if {${python.version} != 24} {
211                return "${python.prefix}/lib/python${python.branch}/site-packages"
212            } else {
213                return "${prefix}/lib/python${python.branch}/site-packages"
214            }
215        }
216        setup_args {
217            if {${python.version} != 24} {
218                return "--no-user-cfg"
219            } else {
220                return ""
221            }
222        }
223        setup_prefix {
224            if {${python.version} != 24} {
225                return "${python.prefix}"
226            } else {
227                return "${prefix}"
228            }
229        }
230        link_binaries {
231            if {${python.version} != 24 && ${python.version} != 25} {
232                return yes
233            } else {
234                return no
235            }
236        }
237        default {
238            error "unknown option $var"
239        }
240    }
241}
242
243options python.add_archflags
244default python.add_archflags yes
245options python.set_compiler
246default python.set_compiler yes
247
248options python.link_binaries python.link_binaries_suffix
249default python.link_binaries {[python_get_defaults link_binaries]}
250default python.link_binaries_suffix {-${python.branch}}
Note: See TracBrowser for help on using the repository browser.