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

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

php-1.0.tcl: prepare for bundled extensions

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