source: trunk/dports/_resources/port1.0/group/perl5-1.0.tcl @ 149129

Last change on this file since 149129 was 149129, checked in by mojca@…, 3 years ago

perl5 portgroup: switch to livecheck from api.metacpan.org (see also #51535)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.9 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
2# $Id: perl5-1.0.tcl 149129 2016-06-01 07:15:20Z mojca@macports.org $
3#
4# Copyright (c) 2004 Robert Shaw <rshaw@opendarwin.org>,
5#                    Toby Peterson <toby@opendarwin.org>
6# Copyright (c) 2002 Apple Computer, Inc.
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# portfile configuration options
36# perl5.branches: the major perl versions supported by this module. A
37#   subport will be created for each. e.g. p5.12-foo, p5.10-foo, ...
38# perl5.branches must be set in the portfile
39# perl5.default_branch: the branch used when you request p5-foo
40options perl5.default_branch perl5.branches
41default perl5.default_branch {[perl5_get_default_branch]}
42
43proc perl5_get_default_branch {} {
44    global prefix perl5.branches
45    # use whatever ${prefix}/bin/perl5 was chosen, and if none, fall back to 5.22
46    if {![catch {set val [lindex [split [exec ${prefix}/bin/perl5 -V:version] {'}] 1]}]} {
47        set ret [join [lrange [split $val .] 0 1] .]
48    } else {
49        set ret 5.22
50    }
51    # if the above default is not supported by this module, use the latest it does support
52    if {[info exists perl5.branches] && [lsearch -exact ${perl5.branches} $ret] == -1} {
53        set ret [lindex ${perl5.branches} end]
54    }
55    return $ret
56}
57
58proc perl5.extract_config {var {default ""}} {
59    global perl5.bin
60
61    if {[catch {set val [lindex [split [exec ${perl5.bin} -V:${var}] {'}] 1]}]} {
62        set val ${default}
63    }
64
65    return $val
66}
67
68# Create perl subports
69proc perl5.create_subports {branches rootname} {
70    foreach v ${branches} {
71        subport p${v}-${rootname} {
72            depends_lib-append port:perl${v}
73            perl5.major ${v}
74        }
75    }
76}
77
78# Set perl variant options and defaults
79options perl5.default_variant perl5.variant perl5.set_default_variant perl5.conflict_variants perl5.require_variant
80# The default variant derived from perl5.default_branch if not set in Portfile.
81default perl5.default_variant {[string map {. _} perl${perl5.default_branch}]}
82# The name of the selected variant or empty if there is not one.
83default perl5.variant {}
84# Control whether to set a default perl variant or not.
85default perl5.set_default_variant {true}
86# Control whether to conflict the perl variants or not. Probably almost always true.
87default perl5.conflict_variants {true}
88# Control whether a perl variant is required and if true produce an error if a perl variant is not set.
89default perl5.require_variant {false}
90# Get variant names from branches
91proc perl5.get_variant_names {branches} {
92    set ret {}
93    foreach branch ${branches} {
94        lappend ret "perl[string map {. _} ${branch}]"
95    }
96    return $ret
97}
98# Create perl variants
99proc perl5.create_variants {branches} {
100    global name perl5.major perl5.default_variant perl5.variant perl5.set_default_variant perl5.conflict_variants perl5.require_variant perl5.variants
101    set perl5.variants [perl5.get_variant_names ${branches}]
102    foreach branch ${branches} {
103        set index [lsearch ${branches} ${branch}]
104        set variant [lindex ${perl5.variants} ${index}]
105# Add conflicts
106        set conflicts {}
107        if {${perl5.conflict_variants}} {
108            set conflicts "conflicts {[lreplace ${perl5.variants} ${index} ${index}]}"
109        }
110        eval "variant ${variant} ${conflicts} description Use MacPorts perl${branch} {}"
111        if {[variant_isset ${variant}]} {
112            perl5.variant ${variant}
113        }
114    }
115# Set default perl variant
116    if {${perl5.variant} eq {} && ${perl5.set_default_variant}} {
117        default_variants-append +${perl5.default_variant}
118        if {[variant_isset ${perl5.default_variant}]} {
119            perl5.variant ${perl5.default_variant}
120        }
121    }
122# Set perl version and deps
123    foreach branch ${branches} {
124        set index [lsearch ${branches} ${branch}]
125        set variant [lindex ${perl5.variants} ${index}]
126        if {[variant_isset ${variant}]} {
127            perl5.major ${branch}
128            depends_lib-append port:perl${branch}
129        }
130    }
131# Require perl variant
132    pre-fetch {
133        if {![variant_isset ${perl5.variant}] && ${perl5.require_variant}} {
134            ui_error "${name} requires one of these variants: ${perl5.variants}"
135            return -code error "absence of required perl variant"
136        }
137    }
138}
139
140# Set some variables.
141options perl5.version perl5.major perl5.arch perl5.lib perl5.bindir perl5.archlib perl5.bin
142default perl5.version {[perl5.extract_config version]}
143default perl5.major {${perl5.default_branch}}
144default perl5.arch {[perl5.extract_config archname ${os.platform}]}
145default perl5.bin {${prefix}/bin/perl${perl5.major}}
146
147# define installation libraries as vendor location
148default perl5.lib {[perl5.extract_config vendorlib]}
149default perl5.bindir {${prefix}/libexec/perl${perl5.major}}
150default perl5.archlib {${perl5.lib}/${perl5.arch}}
151
152default configure.universal_args {}
153
154options perl5.link_binaries perl5.link_binaries_suffix
155default perl5.link_binaries yes
156default perl5.link_binaries_suffix {-${perl5.major}}
157
158# define these empty initially, they are set by perl5.setup arguments
159set perl5.module ""
160set perl5.moduleversion ""
161set perl5.cpandir ""
162
163# perl5 group setup procedure
164proc perl5.setup {module vers {cpandir ""}} {
165    global perl5.branches perl5.default_branch perl5.bin perl5.lib \
166           perl5.module perl5.moduleversion perl5.cpandir \
167           prefix subport name
168
169    # define perl5.module
170    set perl5.module ${module}
171    set perl5.moduleversion $vers
172
173    # define perl5.cpandir
174    # check if optional CPAN dir specified to perl5.setup
175    if {[string length ${cpandir}] == 0} {
176        # if not, default to the first word (before a dash) from the
177        # module name, this is the normal convention on CPAN
178        set perl5.cpandir [lindex [split ${perl5.module} {-}] 0]
179    } else {
180        # else, use what was passed
181        set perl5.cpandir ${cpandir}
182    }
183
184    if {![info exists name]} {
185        name            p5-[string tolower ${perl5.module}]
186    }
187    version             [perl5_convert_version ${perl5.moduleversion}]
188    categories          perl
189    homepage            http://search.cpan.org/dist/${perl5.module}/
190
191    master_sites        perl_cpan:${perl5.cpandir}
192    distname            ${perl5.module}-${perl5.moduleversion}
193    dist_subdir         perl5
194
195    if {[string match p5-* $name]} {
196        set rootname        [string range $name 3 end]
197        perl5.create_subports ${perl5.branches} ${rootname}
198
199        if {$subport eq $name} {
200            perl5.major
201            distfiles
202            supported_archs noarch
203            replaced_by p[option perl5.default_branch]-${rootname}
204            depends_lib-append port:p[option perl5.default_branch]-${rootname}
205            use_configure no
206            build {}
207            destroot {
208                xinstall -d -m 755 ${destroot}${prefix}/share/doc/${name}
209                system "echo $name is a stub port > ${destroot}${prefix}/share/doc/${name}/README"
210            }
211        }
212    } else {
213        depends_lib-append port:perl${perl5.default_branch}
214    }
215    if {![string match p5-* $name] || $subport ne $name} {
216        configure.cmd       ${perl5.bin}
217        configure.env       PERL_AUTOINSTALL=--skipdeps
218        configure.pre_args  Makefile.PL
219        default configure.args {"INSTALLDIRS=vendor CC=\"${configure.cc}\" LD=\"${configure.cc}\""}
220
221        # CCFLAGS can be passed in to "configure" but it's not necessarily inherited.
222        # LDFLAGS can't be passed in (or if it can, it's not easy to figure out how).
223        post-configure {
224            fs-traverse file ${configure.dir} {
225                if {[file isfile ${file}] && [file tail ${file}] eq "Makefile"} {
226                    ui_info "Fixing flags in [string map "${configure.dir}/ {}" ${file}]"
227                    reinplace -locale C "/^CCFLAGS *=/s/$/ [get_canonical_archflags cc]/" ${file}
228                    reinplace -locale C "/^OTHERLDFLAGS *=/s/$/ [get_canonical_archflags ld]/" ${file}
229                }
230            }
231        }
232
233        test.run            yes
234
235        destroot.target     pure_install
236
237        post-destroot {
238            fs-traverse file ${destroot}${perl5.lib} {
239                if {[file isfile ${file}] && [file tail ${file}] eq ".packlist"} {
240                    ui_info "Fixing paths in [string map "${destroot}${perl5.lib}/ {}" ${file}]"
241                    reinplace -n "s|${destroot}||p" ${file}
242                }
243            }
244            if {${perl5.link_binaries}} {
245                foreach bin [glob -nocomplain -tails -directory "${destroot}${perl5.bindir}" *] {
246                    if {[catch {file type "${destroot}${prefix}/bin/${bin}${perl5.link_binaries_suffix}"}]} {
247                        ln -s "${perl5.bindir}/${bin}" "${destroot}${prefix}/bin/${bin}${perl5.link_binaries_suffix}"
248                    }
249                }
250            }
251        }
252    }
253
254    livecheck.type      regexm
255    livecheck.url       http://api.metacpan.org/release/${perl5.module}/
256    livecheck.regex     \"name\" : \"[quotemeta ${perl5.module}]-(\[^"\]+?)\"
257    default livecheck.version {${perl5.moduleversion}}
258}
259
260# Switch from default MakeMaker-style routine to Module::Build-style.
261proc perl5.use_module_build {} {
262    global perl5.bin destroot perl5.major
263
264    if {${perl5.major} eq ""} {
265        return
266    }
267
268    depends_lib-append  port:p${perl5.major}-module-build
269
270    configure.pre_args  Build.PL
271    default configure.args {"--installdirs=vendor --config cc=\"${configure.cc}\" --config ld=\"${configure.cc}\""}
272
273    build.cmd           ${perl5.bin}
274    build.pre_args      Build
275    build.args          build
276
277    test.pre_args       Build
278    test.args           test
279
280    destroot.cmd        ${perl5.bin}
281    destroot.pre_args   Build
282    destroot.args       install
283    destroot.destdir    --destdir=${destroot}
284}
285
286# Convert a floating-point version to a dotted-integer one.
287proc perl5_convert_version {vers} {
288    set index [string first . $vers]
289    set other_dot [string first . [string range $vers [expr {$index + 1}] end]]
290    if {$index == -1 || $other_dot != -1} {
291        return $vers
292    }
293    set ret [string range $vers 0 [expr {$index - 1}]]
294    incr index
295    set fractional [string range $vers $index end]
296    set index 0
297    while {$index < [string length $fractional] || $index < 6} {
298        set sub [string range $fractional $index [expr {$index + 2}]]
299        if {[string length $sub] < 3} {
300            append sub [string repeat "0" [expr {3 - [string length $sub]}]]
301        }
302        append ret ".[scan $sub %u]"
303        incr index 3
304    }
305    return $ret
306}
Note: See TracBrowser for help on using the repository browser.