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

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

php-1.0.tcl: don't test in stub port either

  • 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 93217 2012-05-17 23:06:33Z 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        # Legacy dist_subdir to match old php5- port layout.
108        if {!${php._bundled}} {
109            if {[lindex [split [lindex [option ${option}] 0] .] 0] == "5"} {
110                dist_subdir php5-${php.rootname}
111            }
112        }
113       
114        # Create subport for each PHP branch.
115        foreach branch [option ${option}] {
116            subport php[php.suffix_from_branch ${branch}]-${php.rootname} {}
117        }
118       
119        # Set up stub port.
120        if {${name} == ${subport}} {
121            supported_archs     noarch
122            depends_run         port:php[php.suffix_from_branch ${php.default_branch}]-${php.rootname}
123            fetch {}
124            checksum {}
125            extract {}
126            patch {}
127            use_configure       no
128            build {}
129            test {}
130            destroot {
131                xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
132                system "echo \"${subport} is a stub port\" > ${destroot}${prefix}/share/doc/${subport}/README"
133            }
134        }
135    }
136}
137
138proc php._set_pecl_livecheck_stable {option action args} {
139    global livecheck.regex
140   
141    if {"set" != ${action}} {
142        return
143    }
144   
145    if {${args}} {
146        livecheck.regex     {>([0-9a-zA-Z.]+)</a></th>\s*<[^>]+>stable<}
147    } else {
148        livecheck.regex     {>([0-9a-zA-Z.]+)</a></th>}
149    }
150}
151
152proc php.setup {extensions version {source ""}} {
153    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
154    global destroot name subport
155   
156    # Use "set" to preserve the list structure.
157    set php.extensions          ${extensions}
158   
159    if {![info exists name]} {
160        name                    php-${php.rootname}
161    }
162    version                     ${version}
163    categories                  php
164   
165    if {${name} != ${subport}} {
166        # Set up distfiles for non-bundled extensions.
167        if {!${php._bundled}} {
168            distname            ${php.rootname}-${version}
169        }
170       
171        depends_lib-append      port:${php}
172       
173        # These are set only for the convenience of subports that want to access
174        # these variables directly, e.g. the ${php}-openssl subport which wants
175        # to move a file in ${build.dir} in a post-extract block.
176        configure.dir           [lindex ${php.build_dirs} 0]
177        build.dir               [lindex ${php.build_dirs} 0]
178        destroot.dir            [lindex ${php.build_dirs} 0]
179       
180        configure.pre_args-append --with-php-config=${php.config}
181       
182        configure.universal_args-delete --disable-dependency-tracking
183       
184        variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {}
185       
186        pre-configure {
187            set php_debug_variant [regexp {/debug-[^/]+$} ${php.extension_dir}]
188            if {${php_debug_variant} && ![variant_isset debug]} {
189                ui_error "${subport} cannot be installed without the debug variant because ${php} is installed with the debug variant."
190                return -code error "incompatible variant selection"
191            } elseif {[variant_isset debug] && !${php_debug_variant}} {
192                ui_error "${subport} cannot be installed with the debug variant because ${php} is installed without the debug variant."
193                return -code error "incompatible variant selection"
194            }
195            foreach dir ${php.build_dirs} {
196                ui_debug "Generating configure script in [file tail ${dir}]"
197                system -W ${dir} "${php.ize}"
198            }
199        }
200       
201        configure {
202            foreach configure.dir ${php.build_dirs} {
203                ui_debug "Configuring in [file tail ${configure.dir}]"
204                portconfigure::configure_main
205            }
206        }
207       
208        build {
209            foreach build.dir ${php.build_dirs} {
210                ui_debug "Building in [file tail ${build.dir}]"
211                portbuild::build_main
212            }
213        }
214       
215        destroot.destdir        INSTALL_ROOT=${destroot}
216       
217        destroot {
218            foreach destroot.dir ${php.build_dirs} {
219                ui_debug "Staging in [file tail ${destroot.dir}]"
220                portdestroot::destroot_main
221            }
222            xinstall -m 755 -d ${destroot}${php.ini_dir}
223            if {"zend" == ${php.type}} {
224                set extension_prefix "zend_extension=${php.extension_dir}/"
225            } else {
226                set extension_prefix "extension="
227            }
228            set fp [open ${destroot}${php.ini_dir}/${php.extension_ini} w]
229            puts $fp "; Do not edit this file; it is automatically generated by MacPorts."
230            puts $fp "; Any changes you make will be lost if you upgrade or uninstall ${subport}."
231            puts $fp "; To configure ${php}, edit ${php.ini}."
232            foreach extension ${php.extensions} {
233                puts $fp "${extension_prefix}${extension}.so"
234            }
235            close $fp
236        }
237       
238        post-install {
239            if {[file exists ${php.ini}]} {
240                set count 0
241                set fp [open ${php.ini} r]
242                while {![eof $fp]} {
243                    set line [gets $fp]
244                    regexp {^extension_dir *= *"?([^\"]*)"?} $line -> php_ini_extension_dir
245                    if {[info exists php_ini_extension_dir]} {
246                        ui_debug "Found extension_dir ${php_ini_extension_dir} in ${php.ini}"
247                        if {${php_ini_extension_dir} != ${php.extension_dir}} {
248                            if {0 == ${count}} {
249                                ui_msg "Your php.ini contains a line that will prevent ${subport}"
250                                ui_msg "and other ${php} extensions from working. To fix this,"
251                                ui_msg "edit ${php.ini} and delete this line:"
252                                ui_msg ""
253                            }
254                            ui_msg ${line}
255                            incr count
256                        }
257                        unset php_ini_extension_dir
258                    }
259                }
260                close $fp
261            }
262        }
263    }
264   
265    if {"pecl" == ${source}} {
266        global php.pecl_livecheck_stable
267       
268        set php.homepage        http://pecl.php.net/package/${php.rootname}
269       
270        homepage                ${php.homepage}
271        master_sites            http://pecl.php.net/get/
272        extract.suffix          .tgz
273       
274        livecheck.type          regexm
275        livecheck.url           ${php.homepage}
276        php.pecl_livecheck_stable yes
277    }
278}
279
280# Return the list of directories we need to phpize / configure / make in.
281proc php.build_dirs_proc {} {
282    global php.extensions php._bundled worksrcpath
283    if {${php._bundled}} {
284        set dirs {}
285        foreach extension ${php.extensions} {
286            lappend dirs ${worksrcpath}/ext/${extension}
287        }
288        return ${dirs}
289    }
290    return ${worksrcpath}
291}
292
293# Calculate suffix from given branch.
294proc php.suffix_from_branch {branch} {
295    return [strsed ${branch} {g/\\.//}]
296}
297
298# Calculate branch from given suffix.
299proc php.branch_from_suffix {suffix} {
300    return [string index ${suffix} 0].[string range ${suffix} 1 end]
301}
302
303# Calculate branch from subport.
304proc php.branch_from_subport {} {
305    global php.default_branch subport
306   
307    # For the subports, get the branch from ${subport}.
308    regexp {^php(\d+)} ${subport} -> suffix
309    if {[info exists suffix]} {
310        return [php.branch_from_suffix ${suffix}]
311    }
312   
313    # For the stub port, use the default branch.
314    return ${php.default_branch}
315}
Note: See TracBrowser for help on using the repository browser.