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 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 | |
---|
48 | categories python |
---|
49 | |
---|
50 | use_configure no |
---|
51 | # we want the default universal variant added despite not using configure |
---|
52 | universal_variant yes |
---|
53 | |
---|
54 | build.target build |
---|
55 | |
---|
56 | pre-destroot { |
---|
57 | xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}/examples |
---|
58 | } |
---|
59 | |
---|
60 | options python.versions python.version python.default_version |
---|
61 | option_proc python.versions python_set_versions |
---|
62 | # py-foo historically meant python24 |
---|
63 | default python.default_version {24} |
---|
64 | default python.version {[python_get_version]} |
---|
65 | |
---|
66 | proc 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 | |
---|
74 | proc python_set_versions {option action args} { |
---|
75 | if {$action != "set"} { |
---|
76 | return |
---|
77 | } |
---|
78 | if {[string match py-* [option name]]} { |
---|
79 | foreach v [option $option] { |
---|
80 | subport py${v}[string trimleft [option name] py] { depends_lib port:python${v} } |
---|
81 | } |
---|
82 | if {![exists depends_lib]} { |
---|
83 | depends_lib port:py[option python.default_version][string trimleft [option name] py] |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | option_proc python.default_version python_set_default_version |
---|
89 | proc python_set_default_version {option action args} { |
---|
90 | if {$action != "set"} { |
---|
91 | return |
---|
92 | } |
---|
93 | global name subport |
---|
94 | if {[string match py-* $name]} { |
---|
95 | if {$subport == "" || $subport == $name} { |
---|
96 | depends_lib port:py[option python.default_version][string trimleft $name py] |
---|
97 | } |
---|
98 | } else { |
---|
99 | depends_lib-append port:python[option python.default_version] |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | option_proc name python_set_name |
---|
104 | # set up py-foo as a stub port that depends on the default pyXY-foo |
---|
105 | proc python_set_name {option action args} { |
---|
106 | if {$action != "set"} { |
---|
107 | return |
---|
108 | } |
---|
109 | global name subport |
---|
110 | if {[string match py-* $name] && ($subport == "" || $subport == $name)} { |
---|
111 | supported_archs noarch |
---|
112 | build {} |
---|
113 | destroot { |
---|
114 | system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README" |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | options python.branch python.prefix python.bin python.lib python.libdir \ |
---|
120 | python.include python.pkgd |
---|
121 | # for pythonXY, python.branch is X.Y |
---|
122 | default python.branch {[string range ${python.version} 0 end-1].[string index ${python.version} end]} |
---|
123 | default python.prefix {[python_get_defaults prefix]} |
---|
124 | default python.bin {[python_get_defaults bin]} |
---|
125 | default python.lib {[python_get_defaults lib]} |
---|
126 | default python.pkgd {[python_get_defaults pkgd]} |
---|
127 | default python.libdir {${python.prefix}/lib/python${python.branch}} |
---|
128 | default python.include {${python.prefix}/include/python${python.branch}} |
---|
129 | |
---|
130 | default build.cmd {"${python.bin} setup.py [python_get_defaults setup_args]"} |
---|
131 | default destroot.cmd {"${python.bin} setup.py [python_get_defaults setup_args]"} |
---|
132 | default destroot.destdir {"--prefix=[python_get_defaults setup_prefix] --root=${destroot}"} |
---|
133 | |
---|
134 | proc python_get_defaults {var} { |
---|
135 | global python.version python.branch prefix python.prefix |
---|
136 | switch -- $var { |
---|
137 | prefix { |
---|
138 | global build_arch frameworks_dir |
---|
139 | set ret "${frameworks_dir}/Python.framework/Versions/${python.branch}" |
---|
140 | if {${python.version} == 25 || (${python.version} == 24 && |
---|
141 | ![file isfile ${ret}/include/python${python.branch}/Python.h] && |
---|
142 | ([file isfile ${prefix}/include/python${python.branch}/Python.h] |
---|
143 | || [string match *64* $build_arch]))} { |
---|
144 | set ret $prefix |
---|
145 | } |
---|
146 | return $ret |
---|
147 | } |
---|
148 | bin { |
---|
149 | if {${python.version} != 24} { |
---|
150 | return "${python.prefix}/bin/python${python.branch}" |
---|
151 | } else { |
---|
152 | return "${prefix}/bin/python${python.branch}" |
---|
153 | } |
---|
154 | } |
---|
155 | lib { |
---|
156 | if {${python.version} != 24 && ${python.version} != 25} { |
---|
157 | return "${python.prefix}/Python" |
---|
158 | } else { |
---|
159 | return "${prefix}/lib/lib${python.branch}.dylib" |
---|
160 | } |
---|
161 | } |
---|
162 | pkgd { |
---|
163 | if {${python.version} != 24} { |
---|
164 | return "${python.prefix}/lib/python${python.branch}/site-packages" |
---|
165 | } else { |
---|
166 | return "${prefix}/lib/python${python.branch}/site-packages" |
---|
167 | } |
---|
168 | } |
---|
169 | setup_args { |
---|
170 | if {${python.version} != 24} { |
---|
171 | return "--no-user-cfg" |
---|
172 | } else { |
---|
173 | return "" |
---|
174 | } |
---|
175 | } |
---|
176 | setup_prefix { |
---|
177 | if {${python.version} != 24} { |
---|
178 | return "${python.prefix}" |
---|
179 | } else { |
---|
180 | return "${prefix}" |
---|
181 | } |
---|
182 | } |
---|
183 | link_binaries { |
---|
184 | if {${python.version} != 24 && ${python.version} != 25} { |
---|
185 | return yes |
---|
186 | } else { |
---|
187 | return no |
---|
188 | } |
---|
189 | } |
---|
190 | default { |
---|
191 | error "unknown option $var" |
---|
192 | } |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | options python.add_archflags |
---|
197 | default python.add_archflags yes |
---|
198 | |
---|
199 | pre-build { |
---|
200 | if {${python.add_archflags}} { |
---|
201 | if {[variant_exists universal] && [variant_isset universal]} { |
---|
202 | build.env-append CFLAGS="${configure.universal_cflags}" \ |
---|
203 | OBJCFLAGS="${configure.universal_cflags}" \ |
---|
204 | CXXFLAGS="${configure.universal_cxxflags}" \ |
---|
205 | LDFLAGS="${configure.universal_ldflags}" |
---|
206 | } else { |
---|
207 | build.env-append CFLAGS="${configure.cc_archflags}" \ |
---|
208 | OBJCFLAGS="${configure.objc_archflags}" \ |
---|
209 | CXXFLAGS="${configure.cxx_archflags}" \ |
---|
210 | FFLAGS="${configure.f77_archflags}" \ |
---|
211 | F90FLAGS="${configure.f90_archflags}" \ |
---|
212 | FCFLAGS="${configure.fc_archflags}" \ |
---|
213 | LDFLAGS="${configure.ld_archflags}" |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | options python.link_binaries python.link_binaries_suffix |
---|
219 | default python.link_binaries {[python_get_defaults link_binaries]} |
---|
220 | default python.link_binaries_suffix {-${python.branch}} |
---|
221 | post-destroot { |
---|
222 | if {${python.link_binaries}} { |
---|
223 | foreach bin [glob -nocomplain -tails -directory "${destroot}${python.prefix}/bin" *] { |
---|
224 | if {[catch {file type "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}"}]} { |
---|
225 | ln -s "${python.prefix}/bin/${bin}" "${destroot}${prefix}/bin/${bin}${python.link_binaries_suffix}" |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | } |
---|