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

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

php-1.0.tcl: update for new unified php port

  • 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 92545 2012-05-01 04:33:14Z 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
59default php.bundled             {[string equal ${name} "php"]}
60options php.extension_ini
61default php.extension_ini       {${php.rootname}.ini}
62options php.extensions
63options php.rootname
64default php.rootname            {[lindex ${php.extensions} 0]}
65options php.source
66default php.source              standalone
67options php.type
68default php.type                php
69options php.versions
70default php.versions            {{54}}
71
72# Options that relate to the version of PHP.
73options php
74default php                     {php${php.version}}
75options php.config
76default php.config              {${prefix}/bin/php-config${php.version}}
77options php.extension_dir
78default php.extension_dir       {[exec ${php.config} --extension-dir 2>/dev/null]}
79options php.ini
80default php.ini                 {${prefix}/etc/${php}/php.ini}
81options php.ini_dir
82default php.ini_dir             {${prefix}/var/db/${php}}
83options php.ize
84default php.ize                 {${prefix}/bin/phpize${php.version}}
85options php.version
86
87
88proc php.setup {extensions version {source ""}} {
89    global php php.build_dirs php.bundled php.config php.extension_ini php.extensions php.homepage php.ini_dir php.rootname php.source php.version php.versions
90    global destroot name subport
91   
92    # Use "set" to preserve the list structure.
93    set php.extensions          ${extensions}
94   
95    php.source                  ${source}
96   
97    # Sort versions so we can use lindex 0 and end to get the min and max versions respectively.
98    set php.versions            [lsort ${php.versions}]
99   
100    if {![info exists name]} {
101        name                    php-${php.rootname}
102    }
103    version                     ${version}
104    categories                  php
105   
106    if {[regexp {^php-} ${name}]} {
107        foreach v ${php.versions} {
108            subport php${v}-${php.rootname} {}
109        }
110    }
111   
112    regexp {^php(\d+)} ${subport} -> php.version
113   
114    if {${name} == ${subport}} {
115        supported_archs         noarch
116        distfiles
117        depends_lib-append      port:php[lindex ${php.versions} end]-${php.rootname}
118        patch {}
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.pre_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 -W ${dir} "${php.ize}"
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.ini_dir}
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.ini_dir}/${php.extension_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.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.ini}]} {
197                set count 0
198                set fp [open ${php.ini} r]
199                while {![eof $fp]} {
200                    set line [gets $fp]
201                    regexp {^extension_dir *= *"?([^\"]*)"?} $line -> php_ini_extension_dir
202                    if {[info exists php_ini_extension_dir]} {
203                        ui_debug "Found extension_dir ${php_ini_extension_dir} in ${php.ini}"
204                        if {${php_ini_extension_dir} != ${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.ini} and delete this line:"
209                                ui_msg ""
210                            }
211                            ui_msg ${line}
212                            incr count
213                        }
214                        unset php_ini_extension_dir
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.