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

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

php port:

  • use php portgroup always, not just in extension subports
  • move some procs from php port to php portgroup and rename them

php portgroup:

  • rename "version(s)" to "branch(es)" for consistency with php port and perl5 portgroup
  • setting php.branches in extension ports is now mandatory, like in the python portgroup; there is no longer a default
  • branches are now set in dotted decimal format, like in the perl5 portgroup
  • subports are now created in an option proc attached to php.branches, like in the python portgroup
  • remove unnecessary php.source option
  • add php.suffix option
  • replace ${name} with ${subport} and PHP with ${php} in some user-facing messages
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.1 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 92727 2012-05-05 01:46:25Z 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
58options php.build_dirs
59default php.build_dirs          {[php.build_dirs_proc]}
60options php.default_branch
61default php.default_branch      {[lindex ${php.branches} end]}
62options php.extension_ini
63default php.extension_ini       {${php.rootname}.ini}
64options php.extensions
65options php.rootname
66default php.rootname            {[lindex ${php.extensions} 0]}
67options php.type
68default php.type                php
69option_proc php.branches        php._set_branches
70
71# Options that relate to the branch of PHP being used by a subport.
72options php
73default php                     {php${php.suffix}}
74options php.branch
75default php.branch              {[php.branch_from_subport]}
76options php.config
77default php.config              {${prefix}/bin/php-config${php.suffix}}
78options php.extension_dir
79default php.extension_dir       {[exec ${php.config} --extension-dir 2>/dev/null]}
80options php.ini
81default php.ini                 {${prefix}/etc/${php}/php.ini}
82options php.ini_dir
83default php.ini_dir             {${prefix}/var/db/${php}}
84options php.ize
85default php.ize                 {${prefix}/bin/phpize${php.suffix}}
86options php.suffix
87default php.suffix              {[php.suffix_from_branch ${php.branch}]}
88
89# Private options you don't need to worry about.
90options php._bundled
91default php._bundled            {[string equal ${name} "php"]}
92
93
94proc php._set_branches {option action args} {
95    if {"set" != ${action}} {
96        return
97    }
98   
99    # Sort the values so we can use lindex 0 and end to get the min and max branches respectively.
100    option ${option} [lsort -command vercmp [option ${option}]]
101   
102    global php.default_branch php.rootname php._bundled name subport
103    if {[regexp {^php-} ${name}]} {
104        # Create subport for each PHP branch.
105        foreach branch [option ${option}] {
106            subport php[php.suffix_from_branch ${branch}]-${php.rootname} {
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        }
115       
116        # Set up stub port.
117        if {${name} == ${subport}} {
118            supported_archs     noarch
119            distfiles
120            depends_run         port:php[php.suffix_from_branch ${php.default_branch}]-${php.rootname}
121            patch {}
122            use_configure       no
123            build {}
124            destroot {
125                xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
126                system "echo \"${subport} is a stub port\" > ${destroot}${prefix}/share/doc/${subport}/README"
127            }
128        }
129    }
130}
131
132proc php.setup {extensions version {source ""}} {
133    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
134    global destroot name subport
135   
136    # Use "set" to preserve the list structure.
137    set php.extensions          ${extensions}
138   
139    if {![info exists name]} {
140        name                    php-${php.rootname}
141    }
142    version                     ${version}
143    categories                  php
144   
145    if {${name} != ${subport}} {
146        # Set up distfiles for non-bundled extensions.
147        if {!${php._bundled}} {
148            distname            ${php.rootname}-${version}
149        }
150       
151        depends_lib-append      port:${php}
152       
153        # These are set only for the convenience of subports that want to access
154        # these variables directly, e.g. the ${php}-openssl subport which wants
155        # to move a file in ${build.dir} in a post-extract block.
156        configure.dir           [lindex ${php.build_dirs} 0]
157        build.dir               [lindex ${php.build_dirs} 0]
158        destroot.dir            [lindex ${php.build_dirs} 0]
159       
160        configure.pre_args-append --with-php-config=${php.config}
161       
162        configure.universal_args-delete --disable-dependency-tracking
163       
164        variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {}
165       
166        pre-configure {
167            set php_debug_variant [regexp {/debug-[^/]+$} ${php.extension_dir}]
168            if {${php_debug_variant} && ![variant_isset debug]} {
169                ui_error "${subport} cannot be installed without the debug variant because ${php} is installed with the debug variant."
170                return -code error "incompatible variant selection"
171            } elseif {[variant_isset debug] && !${php_debug_variant}} {
172                ui_error "${subport} cannot be installed with the debug variant because ${php} is installed without the debug variant."
173                return -code error "incompatible variant selection"
174            }
175            foreach dir ${php.build_dirs} {
176                ui_debug "Generating configure script in [file tail ${dir}]"
177                system -W ${dir} "${php.ize}"
178            }
179        }
180       
181        configure {
182            foreach configure.dir ${php.build_dirs} {
183                ui_debug "Configuring in [file tail ${configure.dir}]"
184                portconfigure::configure_main
185            }
186        }
187       
188        build {
189            foreach build.dir ${php.build_dirs} {
190                ui_debug "Building in [file tail ${build.dir}]"
191                portbuild::build_main
192            }
193        }
194       
195        destroot.destdir        INSTALL_ROOT=${destroot}
196       
197        destroot {
198            foreach destroot.dir ${php.build_dirs} {
199                ui_debug "Staging in [file tail ${destroot.dir}]"
200                portdestroot::destroot_main
201            }
202            xinstall -m 755 -d ${destroot}${php.ini_dir}
203            if {"zend" == ${php.type}} {
204                set extension_prefix "zend_extension=${php.extension_dir}/"
205            } else {
206                set extension_prefix "extension="
207            }
208            set fp [open ${destroot}${php.ini_dir}/${php.extension_ini} w]
209            puts $fp "; Do not edit this file; it is automatically generated by MacPorts."
210            puts $fp "; Any changes you make will be lost if you upgrade or uninstall ${subport}."
211            puts $fp "; To configure ${php}, edit ${php.ini}."
212            foreach extension ${php.extensions} {
213                puts $fp "${extension_prefix}${extension}.so"
214            }
215            close $fp
216        }
217       
218        post-install {
219            if {[file exists ${php.ini}]} {
220                set count 0
221                set fp [open ${php.ini} r]
222                while {![eof $fp]} {
223                    set line [gets $fp]
224                    regexp {^extension_dir *= *"?([^\"]*)"?} $line -> php_ini_extension_dir
225                    if {[info exists php_ini_extension_dir]} {
226                        ui_debug "Found extension_dir ${php_ini_extension_dir} in ${php.ini}"
227                        if {${php_ini_extension_dir} != ${php.extension_dir}} {
228                            if {0 == ${count}} {
229                                ui_msg "Your php.ini contains a line that will prevent ${subport}"
230                                ui_msg "and other ${php} extensions from working. To fix this,"
231                                ui_msg "edit ${php.ini} and delete this line:"
232                                ui_msg ""
233                            }
234                            ui_msg ${line}
235                            incr count
236                        }
237                        unset php_ini_extension_dir
238                    }
239                }
240                close $fp
241            }
242        }
243    }
244   
245    if {"pecl" == ${source}} {
246        set php.homepage        http://pecl.php.net/package/${php.rootname}/
247       
248        homepage                ${php.homepage}
249        master_sites            http://pecl.php.net/get/
250        extract.suffix          .tgz
251       
252        livecheck.type          regexm
253        livecheck.url           ${php.homepage}
254        livecheck.regex         {>([0-9.]+)</a></th>\s*<[^>]+>stable<}
255    }
256   
257    if {${php._bundled}} {
258        homepage                http://www.php.net/${php.rootname}
259       
260        pre-extract {
261            # Speed up extraction by extracting only the modules we're going to be building.
262            foreach extension ${php.extensions} {
263                extract.post_args-append ${worksrcdir}/ext/${extension}
264            }
265        }
266       
267        pre-configure {
268            set php_version [exec ${php.config} --version 2>/dev/null]
269            if {${version} != ${php_version}} {
270                ui_error "${subport} @${version} requires ${php} @${version} but you have ${php} @${php_version}."
271                return -code error "incompatible ${php} installation"
272            }
273        }
274       
275        destroot.target         install-modules install-headers
276    }
277}
278
279# Return the list of directories we need to phpize / configure / make in.
280proc php.build_dirs_proc {} {
281    global php.extensions php._bundled worksrcpath
282    if {${php._bundled}} {
283        set dirs {}
284        foreach extension ${php.extensions} {
285            lappend dirs ${worksrcpath}/ext/${extension}
286        }
287        return ${dirs}
288    }
289    return ${worksrcpath}
290}
291
292# Calculate suffix from given branch.
293proc php.suffix_from_branch {branch} {
294    return [strsed ${branch} {g/\\.//}]
295}
296
297# Calculate branch from given suffix.
298proc php.branch_from_suffix {suffix} {
299    return [string index ${suffix} 0].[string range ${suffix} 1 end]
300}
301
302# Calculate branch from subport.
303proc php.branch_from_subport {} {
304    global php.default_branch subport
305   
306    # For the subports, get the branch from ${subport}.
307    regexp {^php(\d+)} ${subport} -> suffix
308    if {[info exists suffix]} {
309        return [php.branch_from_suffix ${suffix}]
310    }
311   
312    # For the stub port, use the default branch.
313    return ${php.default_branch}
314}
Note: See TracBrowser for help on using the repository browser.