source: trunk/dports/_resources/port1.0/group/php-1.0.tcl @ 93030

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

php-1.0.tcl: improve PECL livecheck

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.8 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: php-1.0.tcl 93030 2012-05-14 07:10:15Z ryandesign@macports.org $
3#
4# Copyright (c) 2009-2012 The MacPorts Project
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10#
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of The MacPorts Project nor the names of its
17#    contributors may be used to endorse or promote products derived from
18#    this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32#
33# This PortGroup automatically sets up the standard environment for building
34# a PHP extension.
35#
36# Usage:
37#
38#   PortGroup                   php 1.0
39#   php.setup                   extension version source
40#   php.branches                5.3 5.4
41#
42# where extension is the name of the extension (e.g. APC), version is its
43# version, and if the extension is hosted at PECL, source is "pecl"; otherwise
44# don't use source.
45#
46# php.branches must be set to the list of PHP branches for which this extension
47# should be made available.
48#
49# If this is a Zend extension, use
50#
51#   php.type                    zend
52
53### This portgroup is not ready to be used yet ###
54
55
56# Options that relate to the PHP extension.
57options php.branches
58option_proc php.branches        php._set_branches
59options php.build_dirs
60default php.build_dirs          {[php.build_dirs_proc]}
61options php.default_branch
62default php.default_branch      {[lindex ${php.branches} end]}
63options php.extension_ini
64default php.extension_ini       {${php.rootname}.ini}
65options php.extensions
66options php.pecl_livecheck_stable
67default php.pecl_livecheck_stable yes
68option_proc php.pecl_livecheck_stable php._set_pecl_livecheck_stable
69options php.rootname
70default php.rootname            {[lindex ${php.extensions} 0]}
71options php.type
72default php.type                php
73
74# Options that relate to the branch of PHP being used by a subport.
75options php
76default php                     {php${php.suffix}}
77options php.branch
78default php.branch              {[php.branch_from_subport]}
79options php.config
80default php.config              {${prefix}/bin/php-config${php.suffix}}
81options php.extension_dir
82default php.extension_dir       {[exec ${php.config} --extension-dir 2>/dev/null]}
83options php.ini
84default php.ini                 {${prefix}/etc/${php}/php.ini}
85options php.ini_dir
86default php.ini_dir             {${prefix}/var/db/${php}}
87options php.ize
88default php.ize                 {${prefix}/bin/phpize${php.suffix}}
89options php.suffix
90default php.suffix              {[php.suffix_from_branch ${php.branch}]}
91
92# Private options you don't need to worry about.
93options php._bundled
94default php._bundled            {[string equal ${name} "php"]}
95
96
97proc php._set_branches {option action args} {
98    if {"set" != ${action}} {
99        return
100    }
101   
102    # Sort the values so we can use lindex 0 and end to get the min and max branches respectively.
103    option ${option} [lsort -command vercmp [option ${option}]]
104   
105    global php.default_branch php.rootname php._bundled name subport
106    if {[regexp {^php-} ${name}]} {
107        # Create subport for each PHP branch.
108        foreach branch [option ${option}] {
109            subport php[php.suffix_from_branch ${branch}]-${php.rootname} {
110                # Legacy dist_subdir to match old php5- port layout.
111                if {!${php._bundled}} {
112                    if {[lindex [split [lindex [option ${option}] 0] .] 0] == "5"} {
113                        dist_subdir php5-${php.rootname}
114                    }
115                }
116            }
117        }
118       
119        # Set up stub port.
120        if {${name} == ${subport}} {
121            supported_archs     noarch
122            distfiles
123            depends_run         port:php[php.suffix_from_branch ${php.default_branch}]-${php.rootname}
124            patch {}
125            use_configure       no
126            build {}
127            destroot {
128                xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
129                system "echo \"${subport} is a stub port\" > ${destroot}${prefix}/share/doc/${subport}/README"
130            }
131        }
132    }
133}
134
135proc php._set_pecl_livecheck_stable {option action args} {
136    global livecheck.regex
137   
138    if {"set" != ${action}} {
139        return
140    }
141   
142    if {${args}} {
143        livecheck.regex     {>([0-9a-z.]+)</a></th>\s*<[^>]+>stable<}
144    } else {
145        livecheck.regex     {>([0-9a-z.]+)</a></th>}
146    }
147}
148
149proc php.setup {extensions version {source ""}} {
150    global php php.branch php.branches php.build_dirs php.config php.extension_ini php.extensions php.homepage php.ini_dir php.rootname php._bundled
151    global destroot name subport
152   
153    # Use "set" to preserve the list structure.
154    set php.extensions          ${extensions}
155   
156    if {![info exists name]} {
157        name                    php-${php.rootname}
158    }
159    version                     ${version}
160    categories                  php
161   
162    if {${name} != ${subport}} {
163        # Set up distfiles for non-bundled extensions.
164        if {!${php._bundled}} {
165            distname            ${php.rootname}-${version}
166        }
167       
168        depends_lib-append      port:${php}
169       
170        # These are set only for the convenience of subports that want to access
171        # these variables directly, e.g. the ${php}-openssl subport which wants
172        # to move a file in ${build.dir} in a post-extract block.
173        configure.dir           [lindex ${php.build_dirs} 0]
174        build.dir               [lindex ${php.build_dirs} 0]
175        destroot.dir            [lindex ${php.build_dirs} 0]
176       
177        configure.pre_args-append --with-php-config=${php.config}
178       
179        configure.universal_args-delete --disable-dependency-tracking
180       
181        variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {}
182       
183        pre-configure {
184            set php_debug_variant [regexp {/debug-[^/]+$} ${php.extension_dir}]
185            if {${php_debug_variant} && ![variant_isset debug]} {
186                ui_error "${subport} cannot be installed without the debug variant because ${php} is installed with the debug variant."
187                return -code error "incompatible variant selection"
188            } elseif {[variant_isset debug] && !${php_debug_variant}} {
189                ui_error "${subport} cannot be installed with the debug variant because ${php} is installed without the debug variant."
190                return -code error "incompatible variant selection"
191            }
192            foreach dir ${php.build_dirs} {
193                ui_debug "Generating configure script in [file tail ${dir}]"
194                system -W ${dir} "${php.ize}"
195            }
196        }
197       
198        configure {
199            foreach configure.dir ${php.build_dirs} {
200                ui_debug "Configuring in [file tail ${configure.dir}]"
201                portconfigure::configure_main
202            }
203        }
204       
205        build {
206            foreach build.dir ${php.build_dirs} {
207                ui_debug "Building in [file tail ${build.dir}]"
208                portbuild::build_main
209            }
210        }
211       
212        destroot.destdir        INSTALL_ROOT=${destroot}
213       
214        destroot {
215            foreach destroot.dir ${php.build_dirs} {
216                ui_debug "Staging in [file tail ${destroot.dir}]"
217                portdestroot::destroot_main
218            }
219            xinstall -m 755 -d ${destroot}${php.ini_dir}
220            if {"zend" == ${php.type}} {
221                set extension_prefix "zend_extension=${php.extension_dir}/"
222            } else {
223                set extension_prefix "extension="
224            }
225            set fp [open ${destroot}${php.ini_dir}/${php.extension_ini} w]
226            puts $fp "; Do not edit this file; it is automatically generated by MacPorts."
227            puts $fp "; Any changes you make will be lost if you upgrade or uninstall ${subport}."
228            puts $fp "; To configure ${php}, edit ${php.ini}."
229            foreach extension ${php.extensions} {
230                puts $fp "${extension_prefix}${extension}.so"
231            }
232            close $fp
233        }
234       
235        post-install {
236            if {[file exists ${php.ini}]} {
237                set count 0
238                set fp [open ${php.ini} r]
239                while {![eof $fp]} {
240                    set line [gets $fp]
241                    regexp {^extension_dir *= *"?([^\"]*)"?} $line -> php_ini_extension_dir
242                    if {[info exists php_ini_extension_dir]} {
243                        ui_debug "Found extension_dir ${php_ini_extension_dir} in ${php.ini}"
244                        if {${php_ini_extension_dir} != ${php.extension_dir}} {
245                            if {0 == ${count}} {
246                                ui_msg "Your php.ini contains a line that will prevent ${subport}"
247                                ui_msg "and other ${php} extensions from working. To fix this,"
248                                ui_msg "edit ${php.ini} and delete this line:"
249                                ui_msg ""
250                            }
251                            ui_msg ${line}
252                            incr count
253                        }
254                        unset php_ini_extension_dir
255                    }
256                }
257                close $fp
258            }
259        }
260    }
261   
262    if {"pecl" == ${source}} {
263        global php.pecl_livecheck_stable
264       
265        set php.homepage        http://pecl.php.net/package/${php.rootname}
266       
267        homepage                ${php.homepage}
268        master_sites            http://pecl.php.net/get/
269        extract.suffix          .tgz
270       
271        livecheck.type          regexm
272        livecheck.url           ${php.homepage}
273        php.pecl_livecheck_stable yes
274    }
275}
276
277# Return the list of directories we need to phpize / configure / make in.
278proc php.build_dirs_proc {} {
279    global php.extensions php._bundled worksrcpath
280    if {${php._bundled}} {
281        set dirs {}
282        foreach extension ${php.extensions} {
283            lappend dirs ${worksrcpath}/ext/${extension}
284        }
285        return ${dirs}
286    }
287    return ${worksrcpath}
288}
289
290# Calculate suffix from given branch.
291proc php.suffix_from_branch {branch} {
292    return [strsed ${branch} {g/\\.//}]
293}
294
295# Calculate branch from given suffix.
296proc php.branch_from_suffix {suffix} {
297    return [string index ${suffix} 0].[string range ${suffix} 1 end]
298}
299
300# Calculate branch from subport.
301proc php.branch_from_subport {} {
302    global php.default_branch subport
303   
304    # For the subports, get the branch from ${subport}.
305    regexp {^php(\d+)} ${subport} -> suffix
306    if {[info exists suffix]} {
307        return [php.branch_from_suffix ${suffix}]
308    }
309   
310    # For the stub port, use the default branch.
311    return ${php.default_branch}
312}
Note: See TracBrowser for help on using the repository browser.