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

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

php-1.1.tcl: add autoconf build dep (#34644)

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