5 * Check system dependences between php-pear modules.
7 * Paweł Gołaszewski <blues@pld-linux.org> (Perl version)
8 * Michał Moskal <malekith@pld-linux.org> (Perl version)
9 * Elan Ruusamäe <glen@pld-linux.org>
11 * URL: <http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/rpm/rpm-php-requires.php>
13 * Requires: php-pear-PHP_CompatInfo
18 * Produce pear(Path/To/File.php) deps
19 * Ported to PHP from Perl version of rpm-php-requires.
21 * @TODO: use tokenizer to parse php files.
23 function peardeps($files) {
24 // files inside php_pear_dir have this prefix
25 $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR;
26 $length = strlen($prefix);
29 foreach ($files as $f) {
31 if (substr($f, -4) != '.php') {
35 // subdir inside php_pear_dir
36 if (substr($f, 0, $length) == $prefix) {
37 $file_dir = dirname(substr($f, $length));
42 foreach (file($f) as $line) {
43 // skip comments -- not perfect, matches "*" at start of line (very rare altho)
44 if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
48 if (preg_match("/(\W|^)(require|include)(_once)?
50 (\"([^\"]*)\"|'([^']*)')
51 \s* \)? \s* ;/x", $line, $m)) {
61 if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
65 if (substr($x, -4) != '.php') {
72 if (is_null($file_dir)) {
76 if (preg_match("/(\W|^)(require|include)(_once)?
77 \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
78 (\"([^\"]*)\"|'([^']*)')
79 \s* \)? \s* ;/x", $line, $m)) {
89 if (substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
92 if (substr($x, -4) != '.php') {
97 // remove double slashes
98 // TODO: resolve simpletest/test/../socket.php -> simpletest/socket.php
99 $x = str_replace("//", "/", $x);
106 foreach (array_keys($req) as $f) {
108 if (array_key_exists($f, $files)) {
116 * Produce dependencies for extensions using PEAR PHP_CompatInfo package.
118 function extdeps($files) {
119 require_once 'PHP/CompatInfo.php';
121 $info = new PHP_CompatInfo('null');
122 $res = $info->parseData($files);
124 // minimum php version we accept
125 // "%define php_min_version 5.1.2" in spec to minimum version to be 5.1.2
126 $version = max(PHP_MIN_VERSION, $res['version']);
128 if (version_compare($version, '5.0.0', 'ge')) {
129 # force php-<name> only deps when php5
130 # XXX what about php-pecl-<name> virtual provides?
137 echo "php-common >= ", $epoch, ":", $version, "\n";
139 // process extensions
140 foreach ($res['extensions'] as $ext) {
141 // bz2 ext is in php-bzip2 package
145 // libxml ext is in php-xml package
146 if ($ext == 'libxml') {
150 // these need to be lowercased
151 if (in_array($ext, array('SPL', 'PDO', 'SQLite', 'Reflection', 'SimpleXML'))) {
152 $ext = strtolower($ext);
155 printf("$fmt\n", $ext);
159 define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT'));
160 define('PHP_PEAR_DIR', '/usr/share/pear');
161 define('PHP_MIN_VERSION', getenv('PHP_MIN_VERSION'));
164 $files = array_splice($argv, 1);
166 $files = explode(PHP_EOL, trim(file_get_contents('php://stdin')));