Merge from vendor branch TNF:
[pkgsrcv2.git] / lang / php / phpversion.mk
1 # $NetBSD: phpversion.mk,v 1.15 2011/09/14 16:44:26 taca Exp $
2 #
3 # This file selects a PHP version, based on the user's preferences and
4 # the installed packages. It does not add a dependency on the PHP
5 # package.
6 #
7 # === User-settable variables ===
8 #
9 # PHP_VERSION_DEFAULT
10 #       The PHP version to choose when more than one is acceptable to
11 #       the package. '5' means any 5.*, 52 only 5.2.*, 53 only 5.3.*
12 #
13 #       Possible: 5 52 53
14 #       Default: 5
15 #
16 # === Package-settable variables ===
17 #
18 # PHP_VERSIONS_ACCEPTED
19 #       The PHP versions that are accepted by the package.
20 #
21 #       Possible: 5 52 53
22 #       Default: 5
23 #
24 # PHP_VERSION_REQD
25 #       If the package works only with a specific PHP version, this
26 #       variable can be used to force it.
27 #
28 #       Possible: (undefined) 5 52 53
29 #       Default: (undefined)
30 #
31 # === Variables defined by this file ===
32 #
33 # PKG_PHP_VERSION
34 #       The selected PHP version.
35 #
36 #       Possible: 5 53
37 #       Default: ${PHP_VERSION_DEFAULT}
38 #
39 # PKG_PHP_MAJOR_VERS
40 #       The selected PHP's major version.
41 #
42 #       Possible: 5
43 #       Default: 5
44 #
45 # PKG_PHP
46 #       The same as ${PKG_PHP_VERSION}, prefixed with "php-".
47 #
48 # PHPPKGSRCDIR
49 #       The directory of the PHP implementation, relative to the
50 #       package directory.
51 #
52 #       Example: ../../lang/php5
53 #
54 # PHP_PKG_PREFIX
55 #       The prefix that is prepended to the package name.
56 #
57 #       Example: php5, php53
58 #
59 # Keywords: php
60 #
61
62 .if !defined(PHPVERSION_MK)
63 PHPVERSION_MK=  defined
64
65 _VARGROUPS+=    php
66 _USER_VARS.php= PHP_VERSION_DEFAULT
67 _PKG_VARS.php=  PHP_VERSIONS_ACCEPTED PHP_VERSION_REQD
68 _SYS_VARS.php=  PKG_PHP_VERSION PKG_PHP PHPPKGSRCDIR PHP_PKG_PREFIX \
69                 PKG_PHP_MAJOR_VERS
70
71 .include "../../mk/bsd.prefs.mk"
72
73 PHP_VERSION_DEFAULT?=           53
74 PHP_VERSIONS_ACCEPTED?=         5 53
75
76 # transform the list into individual variables
77 .for pv in ${PHP_VERSIONS_ACCEPTED}
78 _PHP_VERSION_${pv}_OK=  yes
79 .endfor
80
81 # check what is installed
82 .if exists(${LOCALBASE}/lib/php/20040412)
83 _PHP_VERSION_5_INSTALLED=       yes
84 _PHP_VERSION_52_INSTALLED=      yes
85 _PHP_INSTALLED=         yes
86 .endif
87 .if exists(${LOCALBASE}/lib/php/20090626) || exists(${LOCALBASE}/include/php/Zend/zend_gc.h)
88 _PHP_VERSION_53_INSTALLED=      yes
89 _PHP_INSTALLED=         yes
90 .endif
91
92 # if a version is explicitely required, take it
93 .if defined(PHP_VERSION_REQD)
94 _PHP_VERSION=   ${PHP_VERSION_REQD}
95 .endif
96 # if the default is already installed, it is first choice
97 .if !defined(_PHP_VERSION)
98 .if defined(_PHP_VERSION_${PHP_VERSION_DEFAULT}_OK)
99 .if defined(_PHP_VERSION_${PHP_VERSION_DEFAULT}_INSTALLED)
100 _PHP_VERSION=   ${PHP_VERSION_DEFAULT}
101 .endif
102 .endif
103 .endif
104 # prefer an already installed version, in order of "accepted"
105 .if !defined(_PHP_VERSION)
106 .for pv in ${PHP_VERSIONS_ACCEPTED}
107 .if defined(_PHP_VERSION_${pv}_INSTALLED)
108 _PHP_VERSION?=  ${pv}
109 .else
110 # keep information as last resort - see below
111 _PHP_VERSION_FIRSTACCEPTED?=    ${pv}
112 .endif
113 .endfor
114 .endif
115 # if the default is OK for the addon pkg, take this
116 .if !defined(_PHP_VERSION)
117 .if defined(_PHP_VERSION_${PHP_VERSION_DEFAULT}_OK)
118 _PHP_VERSION=   ${PHP_VERSION_DEFAULT}
119 .endif
120 .endif
121 # take the first one accepted by the package
122 .if !defined(_PHP_VERSION)
123 _PHP_VERSION=   ${_PHP_VERSION_FIRSTACCEPTED}
124 .endif
125
126 #
127 # Variable assignment for multi-PHP packages
128 MULTI+= PHP_VERSION_REQD=${_PHP_VERSION}
129
130 # export some of internal variables
131 PKG_PHP_VERSION:=       ${_PHP_VERSION:C/\.[0-9]//}
132 PKG_PHP:=               PHP${_PHP_VERSION:C/([0-9])([0-9])/\1.\2/}
133
134 # currently we have only PHP 5.x packages.
135 PKG_PHP_MAJOR_VERS:=    5
136
137 # if installed PHP isn't compatible with required PHP, bail out
138 .if defined(_PHP_INSTALLED) && !defined(_PHP_VERSION_${_PHP_VERSION}_INSTALLED)
139 PKG_SKIP_REASON+=       "Package accepts ${PKG_PHP}, but different version is installed"
140 .endif
141
142 MESSAGE_SUBST+=         PKG_PHP_VERSION=${PKG_PHP_VERSION} \
143                         PKG_PHP=${PKG_PHP}
144 PLIST_SUBST+=           PKG_PHP_VERSION=${PKG_PHP_VERSION} \
145                         PKG_PHP_MAJOR_VERS=${PKG_PHP_MAJOR_VERS}
146
147 # force the selected PHP version for recursive builds
148 PHP_VERSION_REQD:=      ${PKG_PHP_VERSION}
149
150 #
151 # set variables for the version we decided to use:
152 #
153 .if ${_PHP_VERSION} == "5" || ${_PHP_VERSION} == "52"
154 PHPPKGSRCDIR=           ../../lang/php5
155 PHP_PKG_PREFIX=         php5
156 .elif ${_PHP_VERSION} == "53"
157 PHPPKGSRCDIR=           ../../lang/php53
158 PHP_PKG_PREFIX=         php53
159 .else
160 # force an error
161 PKG_SKIP_REASON+=       "${PKG_PHP} is not a valid package"
162 .endif
163
164 #
165 # check installed version aginst required:
166 #
167 .if defined(_PHP_VERSION_INSTALLED)
168 .if ${_PHP_VERSION} != ${_PHP_VERSION_INSTALLED}
169 PKG_SKIP_REASON+=       "${PKGBASE} requires ${PKG_PHP}, but php-${_PHP_VERSION_INSTALLED} is already installed."
170 .endif
171 .endif
172
173 .endif  # PHPVERSION_MK