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

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

php-1.0.tcl, php5extension-1.0.tcl: add deprecation notices

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