]> TLD Linux GIT Repositories - packages/rpm-tld-macros.git/blob - macros.php
- merged 2.029 from PLD
[packages/rpm-tld-macros.git] / macros.php
1 # PHP specific macro definitions.
2
3 # name of php package
4 %php_name               php%{?php_suffix}
5
6 # use rpmbuild -D 'php_suffix 54' to build php extension for php 5.4
7 # NOTE: error output must be empty. otherwise can't build pecl packages if no php*-devel is installed
8 %php_suffix             %{expand:%%global php_suffix %(c=$(php-config --sysconfdir 2>/dev/null) || echo '' && echo ${c#/etc/php})%%{nil}}%php_suffix
9
10 # phpXY, version always present for using current php version (in regards of php*-devel package)
11 %php_versuffix          %{expand:%%global php_versuffix %((IFS=.; set -- $(php-config --version); echo $1$2))%%{nil}}%php_versuffix
12
13 # php cli. version that php headers are installed for
14 %__php                  /usr/bin/php%{php_versuffix}
15
16 %php_pear_dir           /usr/share/pear
17 %php_data_dir           /usr/share/php
18 %php_extensiondir       %{expand:%%global php_extensiondir %(php-config%{?php_suffix} --extension-dir 2>/dev/null || echo ERROR)}%php_extensiondir
19 %php_sysconfdir         %{expand:%%global php_sysconfdir %(php-config%{?php_suffix} --sysconfdir 2>/dev/null || echo ERROR)}%php_sysconfdir
20 %php_includedir         %{expand:%%global php_includedir %(php-config%{?php_suffix} --include-dir 2>/dev/null || echo ERROR)}%php_includedir
21
22 # extract php/zend api versions
23 %php_major_version      %{expand:%%global php_major_version %(awk '/#define PHP_MAJOR_VERSION/{print $3}' %{php_includedir}/main/php_version.h 2>/dev/null || echo ERROR)}%php_major_version
24 %php_minor_version      %{expand:%%global php_minor_version %(awk '/#define PHP_MINOR_VERSION/{print $3}' %{php_includedir}/main/php_version.h 2>/dev/null || echo ERROR)}%php_minor_version
25 %php_api_version        %{expand:%%global php_api_version %(awk '/#define PHP_API_VERSION/{print $3}' %{php_includedir}/main/php.h 2>/dev/null || echo ERROR)}%php_api_version
26 %php_pdo_api_version    %{expand:%%global php_pdo_api_version %(awk '/#define PDO_DRIVER_API/{print $3}' %{php_includedir}/ext/pdo/php_pdo_driver.h 2>/dev/null || echo ERROR)}%php_pdo_api_version
27 %php_debug              %{expand:%%global php_debug %(awk '/#define ZEND_DEBUG/{print $3}' %{php_includedir}/main/php_config.h 2>/dev/null || echo ERROR)}%php_debug
28 %zend_module_api        %{expand:%%global zend_module_api %(awk '/#define ZEND_MODULE_API_NO/{print $3}' %{php_includedir}/Zend/zend_modules.h 2>/dev/null || echo ERROR)}%zend_module_api
29 %zend_extension_api     %{expand:%%global zend_extension_api %(awk '/#define ZEND_EXTENSION_API_NO/{print $3}' %{php_includedir}/Zend/zend_extensions.h 2>/dev/null || echo ERROR)}%zend_extension_api
30 %_zend_zts              %{expand:%%global _zend_zts %(Z=$(grep -sc '^#define ZTS 1' %{php_includedir}/main/php_config.h); echo ${Z:-ERROR})}%_zend_zts
31 # "_ts" if ZTS enabled, empty otherwise
32 %zend_zts               %{expand:%%global _zend_zts_%{?_zend_zts} 1}%{?_zend_zts_1:_ts}
33
34 # helper macro
35 %__php_api_requires() Requires: %{php_name}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
36
37 # macros for public use
38 # for php extensions (php-pecl)
39 %requires_php_extension %{__php_api_requires modules_api php_api_version} \
40 %{__php_api_requires zend_module_api} \
41 %{__php_api_requires debug php_debug} \
42 %{__php_api_requires thread-safety _zend_zts}
43
44 # for zend extensions
45 %requires_zend_extension %{__php_api_requires zend_module_api} \
46 %{__php_api_requires zend_extension_api} \
47 %{__php_api_requires debug php_debug} \
48 %{__php_api_requires thread-safety _zend_zts}
49
50 # for php pdo modules (php-pecl-PDO_*)
51 %requires_php_pdo_module %{__php_api_requires PDO_API php_pdo_api_version}
52
53 # for using PHP post scripts. for PHP >= 5.0
54 %php_webserver_restart \
55 [ ! -f /etc/apache/conf.d/??_mod_php.conf ] || %service -q apache restart \
56 [ ! -f /etc/httpd/conf.d/??_mod_php.conf ] || %service -q httpd restart \
57 if [ -x /etc/rc.d/init.d/php-fcgi ]; then \
58         PHP_FCGI_BINARY=; . /etc/sysconfig/php-fcgi 2>/dev/null \
59         if [[ ${PHP_FCGI_BINARY:-php.fcgi} = *php.fcgi* ]]; then \
60                 %service -q php-fcgi restart \
61         fi \
62 fi \
63 if [ -x /etc/rc.d/init.d/%{php_name}-fpm ]; then \
64         %service -q %{php_name}-fpm restart \
65 fi \
66 %{nil}
67
68 # for using php post scripts. for PHP >= 4.0 && PHP < 5.0
69 %php4_webserver_restart \
70 [ ! -f /etc/apache/conf.d/??_mod_php4.conf ] || %service -q apache restart \
71 [ ! -f /etc/httpd/conf.d/??_mod_php4.conf ] || %service -q httpd restart \
72 if [ -x /etc/rc.d/init.d/php-fcgi ]; then \
73         PHP_FCGI_BINARY=; . /etc/sysconfig/php-fcgi 2>/dev/null \
74         if [[ ${PHP_FCGI_BINARY:-php.fcgi} = *php4.fcgi* ]]; then \
75                 %service -q php-fcgi restart \
76         fi \
77 fi \
78 %{nil}
79
80 # PEAR install macros
81 # Author: Elan Ruusamäe <glen@pld-linux.org>
82 #
83 # Usage:
84 #       %%pear_package_setup ...
85 #
86 # -a #   - also unpack SOURCE#. for PEAR bootstrapping
87 # -n FMT - create builddir with FMT, instead of default %%{pearname}-%%{version}
88 # -z     - unpack pear package and let pear use package.xml (not tarball) for install. for PEAR bootstrapping
89 # -D     - pass -D to %setup (so the build dir is not removed)
90 # -c     - register channel from local channel.xml file
91 # -d     - pass -d arg to pearcmd
92 #
93 # unpack PEAR package to %%{_builddir}/FMT. package is extracted with already
94 # destination hierarchy. you should copy the tree to buildroot after
95 # patching/reorganizing with %%pear_package_install.
96 #
97 # additionally BUILDROOT is stripped from files and files are converted to UNIX
98 # line endings.
99 #
100 # the pear install process output is recorded to install.log, you should put it
101 # to %%doc for later debug or just for information.
102 #
103 # additionally additional-packages.txt is produced if it was detected that the
104 # package has optional dependencies. the file format is suitable of displaying
105 # in %%post of a package. you should put this file to %%doc. noautocompressdoc is
106 # automatically added for this file.
107
108
109 # records install.log and transforms PEAR names to TLD Linux rpm package names.
110 %__pear_install_log \
111 tee install.log \
112 # make post message of optional packages \
113 grep -E 'can optionally use|Optional feature' install.log | sed -e 's,package "pear/,package "php-pear-,g;s,^pear/,php-pear-,;s,^pear/,php-pear-,' > optional-packages.txt \
114 if [ -s optional-packages.txt ]; then \
115         awk -F'"' '/use package/{print $2}' optional-packages.txt | sed -e "s,_,/,g;s,php-pear-, 'pear(,;s,$,.*)'," | tr -d '\\\n' > _noautoreq \
116 else \
117         rm -f optional-packages.txt \
118 fi \
119 %{nil}
120
121 # Command invoking PEAR CLI
122 # Same as /usr/bin/pear, except we force GMT timezone
123 %__pear %__php -doutput_buffering=1 -dopen_basedir="" -dmemory_limit=-1 -ddate.timezone=GMT /usr/share/pear/pearcmd.php
124
125 %pear_install(a:d:n:zD) \
126 %__pear \\\
127         -c %{builddir}/pearrc \\\
128         -d doc_dir=/docs \\\
129         -d temp_dir=/tmp \\\
130         -d php_dir=%{-c:%{builddir}/}%{php_pear_dir} \\\
131         -d bin_dir=%{_bindir} \\\
132         -d data_dir=%{php_pear_dir}/data \\\
133         -d test_dir=%{php_pear_dir}/tests \\\
134         %{-d:%(echo "%{-d*}" | awk 'BEGIN{RS=","}{printf("-d %%s \\\\\\n\\t", $1)}')} \\\
135         install \\\
136         --packagingroot=%{builddir} \\\
137         --offline \\\
138         --nodeps \\\
139         %{-f:--force} \\\
140         %{!-z:%{S:%{-a*}%{!-a:0}}}%{-z:$_P} > .install.log || { c=$?; cat .install.log; exit $c; }; \
141         %{-c:cp -a %{builddir}/%{builddir}/%{php_pear_dir} %{builddir}/%(dirname %{php_pear_dir}); rm -rf %{builddir}/%{builddir}; } \
142 %{nil}
143
144 # The main macro.
145 # using this macro will append optional-packages.txt to the nocompressdoc list
146 # as it's displayed to user after package install. and adding additional gzip
147 # dep is just waste ;)
148 %pear_package_setup(a:d:n:zDc:) \
149 %define srcdir %{-n*}%{!-n:%{?_pearname}%{!?_pearname:%{pearname}}-%{version}} \
150 %define builddir %{_builddir}/%{srcdir} \
151 %setup -q -c -T %{-D:-D} -n %{srcdir} \
152 %{-z:%{__tar} zxf %{S:0}; %{-a:%{__tar} zxf %{S:%{-a*}}}} \
153 %{-z:_P=package2.xml; [ -f $_P ] || _P=package.xml; _N=%{srcdir}; mv $_P $_N; cd $_N} \
154 %{-c:%{__pear} -c pearrc config-set php_dir %{builddir}/%{php_pear_dir}; %__pear -c %{builddir}/pearrc channel-add %{-c*}} \
155 %pear_install \
156 %{-z:cd ..} \
157 %{__tar} --wildcards -zvxf %{S:0} package*.xml \
158 cat %{-z:$_N/}.install.log | %__pear_install_log \
159 %undos -f php,html,js,xml \
160 %{!?_noautocompressdoc:%global _noautocompressdoc %{nil}}%{expand:%%global _noautocompressdoc %{_noautocompressdoc} optional-packages.txt} \
161 %{!?_noautoprov:%global _noautoprov %{nil}}%{expand:%%global _noautoprov %{_noautoprov} 'pear(tests/.*)'} \
162 %{nil}
163
164 # Copies extracted PEAR package structure and PEAR registry to buildroot.
165 # Author: Elan Ruusamäe <glen@pld-linux.org>
166 %pear_package_install() \
167 cp -a ./%{php_pear_dir}/{.registry,*} $RPM_BUILD_ROOT%{php_pear_dir} \
168 # tests should not be packaged \
169 %{__rm} -rf $RPM_BUILD_ROOT%{php_pear_dir}/tests \
170 # cleanup backups \
171 find $RPM_BUILD_ROOT%{php_pear_dir} '(' -name '*~' -o -name '*.orig' ')' | xargs -r rm -v \
172 # help the developer out a little: \
173 if [ -f _noautoreq ]; then \
174         echo "AutoReqdep detected:" \
175         echo "_noautoreq $(cat _noautoreq)" \
176 fi \
177 %{nil}
178
179 # Print optional package info for pear packages
180 # Author: Elan Ruusamäe <glen@pld-linux.org>
181 # Usage:
182 #   %post -p <lua>
183 #       %%pear_package_print_optionalpackages
184 #
185 # Requirements:
186 # BuildRequires:        rpmbuild(macros) >= 1.571
187 %pear_package_print_optionalpackages \
188 f = io.open("%{_docdir}/%{name}-%{version}/optional-packages.txt", "r") \
189 if f then \
190         for l in f:lines() do print(l); end \
191         f:close() \
192 end \
193 %{nil}