source: trunk/dports/_resources/port1.0/group/php-1.1.tcl @ 93575

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

php-1.1.tcl:

  • "php.setup" is gone; now set name and version manually; this makes it easier to coexist with other portgroups that might want to set "name" themselves
  • subports are created when you set "php.branches", like the python 1.0 portgroup
  • "php.extensions" is now automatically determined for almost all ports
  • "php.type" is gone; Zend extensions should now be listed in "php.extensions.zend"
  • indicating PECL hosting is now done via "php.pecl yes"
  • "php.pecl_livecheck_stable no" is changed to "php.pecl.prerelease yes"
  • "php.pecl_name" is changed to "php.pecl.name"
  • in the comments at the top of the generated extension ini files, indicate that changes will be lost by deactivating the port too (now that we're using registry 2)
  • single-branch extension ports are now supported (e.g. "name php53-foo")
  • "php.create_subports" is added, in the hopes that it could be used to add php extension subports to ports for other software
  • "php.build_dirs_proc" is gone; this functionality is moving to the php port
  • "php._bundled" is gone as it's no longer referenced anywhere
  • every option is now documented with comments
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.3 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.1.tcl 93575 2012-05-27 11:18:37Z 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 builds PHP extensions. Set name and version as for a normal
34# standalone port, then set php.branches and optionally any other php options,
35# described in more detail below.
36
37default categories              php
38
39
40# php.branches: the list of PHP branches for which the extension(s) will be
41# built. For unified extension ports (name begins with "php-") setting
42# php.branches is mandatory; there is no default. Example:
43#
44#   php.branches                5.3 5.4
45#
46# For unified ports, setting php.branches will create the subports.
47#
48# For single-branch extension ports (name begins with e.g. "php54-")
49# php.branches is set automatically based on the port name and should not be
50# changed.
51
52options php.branches
53option_proc php.branches        php._set_branches
54
55proc php._set_branches {option action args} {
56    if {"set" != ${action}} {
57        return
58    }
59   
60    # Sort the values so we can use lindex 0 and end to get the min and max branches respectively.
61    option ${option} [lsort -command vercmp [option ${option}]]
62   
63    global php.default_branch php.rootname name subport
64   
65    if {[regexp {^php\d*-} ${name}]} {
66        # Legacy dist_subdir to match old php5- port layout.
67        if {[lindex [split [lindex [option ${option}] 0] .] 0] == "5"} {
68            dist_subdir php5-${php.rootname}
69        }
70       
71        if {[regexp {^php-} ${name}]} {
72            # Create subport for each PHP branch.
73            php.create_subports
74           
75            # Set up stub port.
76            if {${name} == ${subport}} {
77                supported_archs     noarch
78                depends_run         port:php[php.suffix_from_branch ${php.default_branch}]-${php.rootname}
79                pre-fetch {
80                    distfiles
81                }
82                pre-checksum {
83                    distfiles
84                }
85                pre-extract {
86                    distfiles
87                }
88                patch {}
89                use_configure       no
90                build {}
91                test {}
92                destroot {
93                    xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
94                    system "echo \"${subport} is a stub port\" > ${destroot}${prefix}/share/doc/${subport}/README"
95                }
96            }
97        } else {
98            # Single-branch extension port; add the code to the port directly.
99            php.add_port_code
100        }
101    }
102}
103
104
105# Set php.branches automatically if the port name includes the PHP branch.
106
107option_proc name                php._set_name
108
109proc php._set_name {option action args} {
110    if {"set" != ${action}} {
111        return
112    }
113   
114    if {[regexp {^php\d+-} ${args}]} {
115        php.branches            [php.branch_from_subport]
116    }
117}
118
119
120# php.default_branch: the branch of PHP which should be installed if the user
121# installs the stub port. The default is the largest value in php.branches and
122# most ports should not need to change this.
123
124options php.default_branch
125default php.default_branch      {[lindex ${php.branches} end]}
126option_proc php.default_branch  php._set_default_branch
127
128proc php._set_default_branch {option action args} {
129    if {"set" != ${action}} {
130        return
131    }
132   
133    global name subport php.rootname
134   
135    if {[regexp {^php-} ${name}] && ${name} == ${subport}} {
136        depends_run             port:php[php.suffix_from_branch [option ${option}]]-${php.rootname}
137    }
138}
139
140
141# php.rootname: for normal extension ports, the part of the port name after the
142# "php-" prefix. The default distname is based on this, as are the names of the
143# subports (if any). Extension ports should not need to set this, but other
144# ports calling php.create_subports manually might.
145
146options php.rootname
147default php.rootname            {[php._get_rootname]}
148proc php._get_rootname {} {
149    global name
150    regexp {^php\d*-(.+)$} ${name} -> rootname
151    if {[info exists rootname]} {
152        return ${rootname}
153    }
154    return ${name}
155}
156
157
158# php.create_subports: creates subports for each PHP branch
159#
160# For a normal extension port whose name starts with "php-" this will be called
161# automatically when you set php.branches so you shouldn't need to call it
162# manually unless for example you're adding PHP extension subports to a port
163# that also installs other software.
164
165proc php.create_subports {} {
166    global php.branches php.rootname
167    foreach branch ${php.branches} {
168        subport php[php.suffix_from_branch ${branch}]-${php.rootname} {
169            php.add_port_code
170        }
171    }
172}
173
174
175# php.extension_ini: the name of the automatically-generated ini file that
176# loads the exension(s). There should be no need to change the default.
177
178options php.extension_ini
179default php.extension_ini       {${php.rootname}.ini}
180
181
182# php.extensions: the list of normal extensions that will be listed in the
183# port's ini file, which will cause PHP to load them. The default is to list
184# all installed extensions, and most ports won't need to change this.
185
186options php.extensions
187
188
189# php.extensions.zend: the list of Zend extensions that will be listed in the
190# port's ini file. The default is that none of the extensions are Zend
191# extensions. Most extensions are normal extensions, not Zend extensions. Zend
192# extensions are those that directly interact with the Zend engine, such as PHP
193# accelerators and debuggers.
194
195options php.extensions.zend
196default php.extensions.zend     {}
197
198
199# php.build_dirs: the list of directories we need to phpize, configure, build
200# and destroot in. Most ports only need to phpize, configure, build and destroot
201# in a single directory and so do not need to change this value, and should be
202# setting worksrcdir instead. This option exists primarily so that some subports
203# of the php port can install multiple related extensions at once.
204
205options php.build_dirs
206default php.build_dirs          {${worksrcpath}}
207
208
209# php.pecl: whether this extension is hosted on PECL or not. When set to "yes"
210# the homepage, master_sites, extract.suffix, and livecheck are set according
211# to PECL standards.
212
213options php.pecl
214default php.pecl                no
215option_proc php.pecl            php._set_pecl
216
217proc php._set_pecl {option action args} {
218    if {"set" != ${action}} {
219        return
220    }
221   
222    if {${args}} {
223        global php.rootname
224       
225        php.pecl.name           ${php.rootname}
226        master_sites            http://pecl.php.net/get/
227        extract.suffix          .tgz
228       
229        livecheck.type          regexm
230        php.pecl.prerelease     no
231    }
232}
233
234
235# php.pecl.name: for PECL extensions, the name of the PECL project. The default
236# distname, homepage and livecheck.url are based on this. The default is based
237# on ${php.rootname} which is appropriate for most PECL extensions.
238
239options php.pecl.name
240default php.pecl.name           {${php.rootname}}
241option_proc php.pecl.name       php._set_pecl_name
242
243proc php._set_pecl_name {option action args} {
244    if {"set" != ${action}} {
245        return
246    }
247   
248    global php.pecl
249   
250    if {${php.pecl}} {
251        set pecl_homepage       http://pecl.php.net/package/${args}
252        default distname        {${php.pecl.name}-${version}}
253        homepage                ${pecl_homepage}
254        livecheck.url           ${pecl_homepage}
255    }
256}
257
258
259# php.pecl.prerelease: for PECL extensions, whether to allow livecheck to match
260# pre-release versions or only stable versions. For most PECL extensions the
261# default of "no" is appropriate, but for extensions that have not yet released
262# their first stable version, you can set this to "yes".
263
264options php.pecl.prerelease
265default php.pecl.prerelease     no
266option_proc php.pecl.prerelease php._set_pecl_prerelease
267
268proc php._set_pecl_prerelease {option action args} {
269    if {"set" != ${action}} {
270        return
271    }
272   
273    global php.pecl
274   
275    if {${php.pecl}} {
276        if {${args}} {
277            livecheck.regex     {>([0-9a-zA-Z.]+)</a></th>}
278        } else {
279            livecheck.regex     {>([0-9a-zA-Z.]+)</a></th>\s*<[^>]+>stable<}
280        }
281    }
282}
283
284
285# php: the name of this branch of PHP, e.g. "php53" or "php54".
286
287options php
288default php                     {php${php.suffix}}
289
290
291# php.branch: the version number of this branch of PHP, e.g. "5.3" or "5.4".
292
293options php.branch
294default php.branch              {[php.branch_from_subport]}
295
296
297# php.config: the path to the php-config script for this branch of PHP.
298
299options php.config
300default php.config              {${prefix}/bin/php-config${php.suffix}}
301
302
303# php.extension_dir: the path to the directory extensions will be installed into
304# for this branch of PHP.
305
306options php.extension_dir
307default php.extension_dir       {[exec ${php.config} --extension-dir 2>/dev/null]}
308
309
310# php.ini: the path to the configuration file for this branch of PHP.
311
312options php.ini
313default php.ini                 {${prefix}/etc/${php}/php.ini}
314
315
316# php.ini_dir: the directory the automatically-generated extension ini files
317# will be installed into for this branch of PHP.
318
319options php.ini_dir
320default php.ini_dir             {${prefix}/var/db/${php}}
321
322
323# php.ize: the path to the phpize script for this branch of PHP.
324
325options php.ize
326default php.ize                 {${prefix}/bin/phpize${php.suffix}}
327
328
329# php.suffix: the suffix appended to file and directory names for this branch of
330# PHP, e.g. "53" or "54".
331
332options php.suffix
333default php.suffix              {[php.suffix_from_branch ${php.branch}]}
334
335
336# php.add_port_code: adds the code to the port or subport to do the actual
337# building. For normal extension ports, the portgroup automatically calls this
338# for you when appropriate; the php port's extension subports are a special case
339# and call it manually.
340
341proc php.add_port_code {} {
342    global php php.branch php.branches php.build_dirs php.config php.extension_ini php.extensions php.ini_dir php.rootname php._bundled
343    global destroot name subport version
344   
345    # Set up distfiles default for non-bundled extensions.
346    default distname        {${php.rootname}-${version}}
347   
348    depends_lib-append      port:${php}
349   
350    # These are set only for the convenience of subports that want to access
351    # these variables directly, e.g. the ${php}-openssl subport which wants
352    # to move a file in ${build.dir} in a post-extract block.
353    #configure.dir           [lindex ${php.build_dirs} 0]
354    #build.dir               [lindex ${php.build_dirs} 0]
355    #destroot.dir            [lindex ${php.build_dirs} 0]
356   
357    configure.pre_args-append --with-php-config=${php.config}
358   
359    configure.universal_args-delete --disable-dependency-tracking
360   
361    variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {}
362   
363    pre-configure {
364        set php_debug_variant [regexp {/debug-[^/]+$} ${php.extension_dir}]
365        if {${php_debug_variant} && ![variant_isset debug]} {
366            ui_error "${subport} cannot be installed without the debug variant because ${php} is installed with the debug variant."
367            return -code error "incompatible variant selection"
368        } elseif {[variant_isset debug] && !${php_debug_variant}} {
369            ui_error "${subport} cannot be installed with the debug variant because ${php} is installed without the debug variant."
370            return -code error "incompatible variant selection"
371        }
372        foreach dir ${php.build_dirs} {
373            ui_debug "Generating configure script in [file tail ${dir}]"
374            system -W ${dir} "${php.ize}"
375        }
376    }
377   
378    configure {
379        foreach configure.dir ${php.build_dirs} {
380            ui_debug "Configuring in [file tail ${configure.dir}]"
381            portconfigure::configure_main
382        }
383    }
384   
385    build {
386        foreach build.dir ${php.build_dirs} {
387            ui_debug "Building in [file tail ${build.dir}]"
388            portbuild::build_main
389        }
390    }
391   
392    destroot.destdir        INSTALL_ROOT=${destroot}
393   
394    destroot {
395        foreach destroot.dir ${php.build_dirs} {
396            ui_debug "Staging in [file tail ${destroot.dir}]"
397            portdestroot::destroot_main
398        }
399    }
400   
401    post-destroot {
402        # Get the list of extensions that got installed by the port.
403        set installed_extension_files [lsort [glob -nocomplain -tails -directory ${destroot}${php.extension_dir} *.so]]
404        set installed_extensions {}
405        foreach installed_extension_file ${installed_extension_files} {
406            lappend installed_extensions [file rootname ${installed_extension_file}]
407        }
408       
409        # If the portfile author didn't specify which extensions to load,
410        # load all of them.
411        if {![info exists php.extensions]} {
412            if {0 < [llength ${php.extensions.zend}]} {
413                set php.extensions {}
414            } else {
415                set php.extensions ${installed_extensions}
416            }
417        }
418       
419        foreach extension [concat ${php.extensions} ${php.extensions.zend}] {
420            if {-1 == [lsearch -exact ${installed_extensions} ${extension}]} {
421                ui_error "Cannot list extension \"${extension}\" in ${php.extension_ini} because the port only installed the extensions \"[join ${installed_extensions} "\", \""]\""
422                return -code error "invalid extension name"
423            }
424        }
425       
426        if {0 < [llength ${php.extensions}] || 0 < [llength ${php.extensions.zend}]} {
427            xinstall -m 755 -d ${destroot}${php.ini_dir}
428            set fp [open ${destroot}${php.ini_dir}/${php.extension_ini} w]
429            puts $fp "; Do not edit this file; it is automatically generated by MacPorts. Any changes"
430            puts $fp "; you make will be lost if you upgrade, uninstall or deactivate ${subport}."
431            puts $fp "; To configure ${php}, edit ${php.ini}."
432            foreach extension ${php.extensions.zend} {
433                puts $fp "zend_extension=${php.extension_dir}/${extension}.so"
434            }
435            foreach extension ${php.extensions} {
436                puts $fp "extension=${extension}.so"
437            }
438            close $fp
439        }
440    }
441   
442    post-install {
443        if {[file exists ${php.ini}]} {
444            set count 0
445            set fp [open ${php.ini} r]
446            while {![eof $fp]} {
447                set line [gets $fp]
448                regexp {^extension_dir *= *"?([^\"]*)"?} $line -> php_ini_extension_dir
449                if {[info exists php_ini_extension_dir]} {
450                    ui_debug "Found extension_dir ${php_ini_extension_dir} in ${php.ini}"
451                    if {${php_ini_extension_dir} != ${php.extension_dir}} {
452                        if {0 == ${count}} {
453                            ui_msg "Your php.ini contains a line that will prevent ${subport}"
454                            ui_msg "and other ${php} extensions from working. To fix this,"
455                            ui_msg "edit ${php.ini} and delete this line:"
456                            ui_msg ""
457                        }
458                        ui_msg ${line}
459                        incr count
460                    }
461                    unset php_ini_extension_dir
462                }
463            }
464            close $fp
465        }
466    }
467}
468
469
470# php.suffix_from_branch: calculates the suffix from the given branch.
471
472proc php.suffix_from_branch {branch} {
473    return [strsed ${branch} {g/\\.//}]
474}
475
476
477# php.branch_from_suffix: calculates the branch from the given suffix.
478
479proc php.branch_from_suffix {suffix} {
480    return [string index ${suffix} 0].[string range ${suffix} 1 end]
481}
482
483
484# php.branch_from_subport: calculates the branch from the subport.
485
486proc php.branch_from_subport {} {
487    global php.default_branch subport
488   
489    # For the subports, get the branch from ${subport}.
490    regexp {^php(\d+)} ${subport} -> suffix
491    if {[info exists suffix]} {
492        return [php.branch_from_suffix ${suffix}]
493    }
494   
495    # For the stub port, use the default branch.
496    return ${php.default_branch}
497}
Note: See TracBrowser for help on using the repository browser.