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

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

php-1.0.tcl: Group and separate options into those that relate to the extension vs. those that relate to the version of PHP

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.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.0.tcl 90670 2012-03-12 01:32:10Z 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#
41# where extension is the name of the extension (e.g. APC), version is its
42# version, and if the extension is hosted at PECL, source is "pecl"; otherwise
43# don't use source.
44#
45# If this is a Zend extension, use
46#
47#   php.type                    zend
48
49### This portgroup is not ready to be used yet ###
50
51
52# Options that relate to the PHP extension.
53default build.dir               {[lindex ${php.build_dirs} 0]}
54default configure.dir           {[lindex ${php.build_dirs} 0]}
55default destroot.dir            {[lindex ${php.build_dirs} 0]}
56options php.build_dirs
57default php.build_dirs          {[php.build_dirs_proc]}
58options php.bundled
59options php.extensions
60options php.ini
61default php.ini                 {${php.rootname}.ini}
62options php.rootname
63default php.rootname            {[lindex ${php.extensions} 0]}
64options php.source
65default php.source              standalone
66options php.type
67default php.type                php
68options php.versions
69default php.versions            {{54}}
70
71# Options that relate to the version of PHP.
72options php
73default php                     {php${php.version}}
74options php.config
75default php.config              {${prefix}/bin/php-config${php.version}}
76options php.extension_dir
77default php.extension_dir       {[exec ${php.config} --extension-dir 2>/dev/null]}
78options php.inidir
79default php.inidir              {${prefix}/var/db/${php}}
80options php.php_ini
81default php.php_ini             {${prefix}/etc/${php}/php.ini}
82options php.phpize
83default php.phpize              {${prefix}/bin/phpize${php.version}}
84options php.version
85
86
87proc php.setup {extensions version {source ""}} {
88    global php php.build_dirs php.bundled php.config php.extensions php.homepage php.ini php.inidir php.rootname php.source php.version php.versions
89    global destroot name subport
90   
91    # Use "set" to preserve the list structure.
92    set php.extensions          ${extensions}
93   
94    php.source                  ${source}
95   
96    # Sort versions so we can use lindex 0 and end to get the min and max versions respectively.
97    set php.versions            [lsort ${php.versions}]
98   
99    if {![info exists name]} {
100        name                    php-${php.rootname}
101    }
102    version                     ${version}
103    categories                  php
104   
105    if {[regexp {^php-} ${name}]} {
106        foreach v ${php.versions} {
107            subport php${v}-${php.rootname} {}
108        }
109    }
110   
111    regexp {^php(\d+)} ${subport} -> php.version
112   
113    php.bundled                 [regexp {^php\d+$} ${name}]
114   
115    if {${name} == ${subport}} {
116        supported_archs         noarch
117        distfiles
118        depends_lib-append      port:php[lindex ${php.versions} end]-${php.rootname}
119        use_configure           no
120        build {}
121        destroot {
122            xinstall -d -m 755 ${destroot}${prefix}/share/doc/${subport}
123            system "echo \"${name} is a stub port\" > ${destroot}${prefix}/share/doc/${subport}/README"
124        }
125    } else {
126        # Set up distfiles for non-bundled extensions.
127        if {!${php.bundled}} {
128            distname            ${php.rootname}-${version}
129            # Legacy dist_subdir to match old php5- port layout.
130            if {[string index [lindex ${php.versions} 0] 0] == "5"} {
131                dist_subdir     php5-${php.rootname}
132            }
133        }
134       
135        depends_lib-append      port:${php}
136       
137        configure.args-append   --with-php-config=${php.config}
138       
139        configure.universal_args-delete --disable-dependency-tracking
140       
141        variant debug description {Enable debug support (useful to analyze a PHP-related core dump)} {}
142       
143        pre-configure {
144            set php_debug_variant [regexp {/debug-[^/]+$} ${php.extension_dir}]
145            if {${php_debug_variant} && ![variant_isset debug]} {
146                ui_error "${name} cannot be installed without the debug variant because PHP is installed with the debug variant."
147                return -code error "incompatible variant selection"
148            } elseif {[variant_isset debug] && !${php_debug_variant}} {
149                ui_error "${name} cannot be installed with the debug variant because PHP is installed without the debug variant."
150                return -code error "incompatible variant selection"
151            }
152            foreach dir ${php.build_dirs} {
153                ui_debug "Generating configure script in [file tail ${dir}]"
154                system "cd ${dir} && ${php.phpize}"
155            }
156        }
157       
158        configure {
159            foreach configure.dir ${php.build_dirs} {
160                ui_debug "Configuring in [file tail ${configure.dir}]"
161                portconfigure::configure_main
162            }
163        }
164       
165        build {
166            foreach build.dir ${php.build_dirs} {
167                ui_debug "Building in [file tail ${build.dir}]"
168                portbuild::build_main
169            }
170        }
171       
172        destroot.destdir        INSTALL_ROOT=${destroot}
173       
174        destroot {
175            foreach destroot.dir ${php.build_dirs} {
176                ui_debug "Staging in [file tail ${destroot.dir}]"
177                portdestroot::destroot_main
178            }
179            xinstall -m 755 -d ${destroot}${php.inidir}
180            if {"zend" == ${php.type}} {
181                set extension_prefix "zend_extension=${php.extension_dir}/"
182            } else {
183                set extension_prefix "extension="
184            }
185            set fp [open ${destroot}${php.inidir}/${php.ini} w]
186            puts $fp "; Do not edit this file; it is automatically generated by MacPorts."
187            puts $fp "; Any changes you make will be lost if you upgrade or uninstall ${name}."
188            puts $fp "; To configure PHP, edit ${php.php_ini}."
189            foreach extension ${php.extensions} {
190                puts $fp "${extension_prefix}${extension}.so"
191            }
192            close $fp
193        }
194       
195        post-install {
196            if {[file exists ${php.php_ini}]} {
197                set count 0
198                set fp [open ${php.php_ini} r]
199                while {![eof $fp]} {
200                    set line [gets $fp]
201                    regexp {^extension_dir *= *"?([^\"]*)"?} $line -> phpiniextensiondir
202                    if {[info exists phpiniextensiondir]} {
203                        ui_debug "Found extension_dir ${phpiniextensiondir} in ${php.php_ini}"
204                        if {${phpiniextensiondir} != ${php.extension_dir}} {
205                            if {0 == ${count}} {
206                                ui_msg "Your php.ini contains a line that will prevent ${name}"
207                                ui_msg "and other PHP extensions from working. To fix this,"
208                                ui_msg "edit ${php.php_ini} and delete this line:"
209                                ui_msg ""
210                            }
211                            ui_msg ${line}
212                            incr count
213                        }
214                        unset phpiniextensiondir
215                    }
216                }
217                close $fp
218            }
219        }
220    }
221   
222    if {"pecl" == ${source}} {
223        set php.homepage        http://pecl.php.net/package/${php.rootname}/
224       
225        homepage                ${php.homepage}
226        master_sites            http://pecl.php.net/get/
227        extract.suffix          .tgz
228       
229        livecheck.type          regexm
230        livecheck.url           ${php.homepage}
231        livecheck.regex         {>([0-9.]+)</a></th>\s*<[^>]+>stable<}
232    }
233   
234    if {${php.bundled}} {
235        homepage                http://www.php.net/${php.rootname}
236       
237        pre-extract {
238            foreach extension ${php.extensions} {
239                extract.post_args-append ${worksrcdir}/ext/${extension}
240            }
241        }
242       
243        pre-configure {
244            set php_version [exec ${php.config} --version 2>/dev/null]
245            if {${version} != ${php_version}} {
246                ui_error "${name} ${version} requires PHP ${version} but you have PHP ${php_version}."
247                return -code error "incompatible PHP installation"
248            }
249        }
250       
251        destroot.target         install-modules install-headers
252    }
253}
254
255proc php.build_dirs_proc {} {
256    global php.extensions php.bundled worksrcpath
257    if {${php.bundled}} {
258        set dirs {}
259        foreach extension ${php.extensions} {
260            lappend dirs ${worksrcpath}/ext/${extension}
261        }
262        return ${dirs}
263    }
264    return ${worksrcpath}
265}
Note: See TracBrowser for help on using the repository browser.