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>
13 * Produce pear(Path/To/File.php) deps
14 * Ported to PHP from Perl version of rpm-php-requires.
16 * @TODO: use tokenizer to parse php files.
18 function peardeps($files) {
19 // files inside php_pear_dir have this prefix
20 $prefix = RPM_BUILD_ROOT. PHP_PEAR_DIR . DIRECTORY_SEPARATOR;
21 $length = strlen($prefix);
24 foreach ($files as $f) {
26 if (substr($f, -4) != '.php') {
30 // subdir inside php_pear_dir
31 if (substr($f, 0, $length) == $prefix) {
32 $file_dir = dirname(substr($f, $length));
37 foreach (explode(PHP_EOL, file_get_contents($f)) as $line) {
39 if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
43 while (preg_match("/(\W|^)(require|include)(_once)?
45 (\"([^\"]*)\"|'([^']*)')
46 \s* \)? \s* ;/x", $line, $m)) {
50 } else if ($m[6] != "") {
56 if (substr($x, 0, 2) == './' || substr($x, -1) == '$') {
60 if (substr($x, -4) != '.php') {
67 if (is_null($file_dir)) {
71 while (preg_match("/(\W|^)(require|include)(_once)?
72 \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
73 (\"([^\"]*)\"|'([^']*)')
74 \s* \)? \s* ;/x", $line, $m)) {
78 } else if ($m[6] != "") {
84 if (substr($x, -1) == '$') {
87 if (substr($x, -4) != '.php') {
98 foreach (array_keys($req) as $f) {
100 if (array_key_exists($f, $files)) {
108 * Produce dependencies for extensions using PEAR PHP_CompatInfo package.
110 function extdeps($files) {
111 require_once 'PHP/CompatInfo.php';
113 $info = new PHP_CompatInfo('null');
114 $res = $info->parseData($files);
116 if (version_compare($res['version'], '5.0.0', 'ge')) {
118 // session, pcre are statically compiled in
119 // date, SPL, SimpleXML are internal for php
121 $staticmods = array('standard', 'ereg', 'session', 'pcre', 'date', 'spl', 'simplexml');
124 // session has always been compiled in
125 $staticmods = array('standard', 'ereg', 'session');
127 echo "php-common >= ", $epoch, ":", $res['version'], "\n";
129 // process extensions
130 foreach ($res['extensions'] as $ext) {
131 if (in_array($ext, $staticmods)) {
135 echo "php(", $ext, ")\n";
139 define('RPM_BUILD_ROOT', getenv('RPM_BUILD_ROOT'));
140 define('PHP_PEAR_DIR', '/usr/share/pear');
143 $files = array_splice($argv, 1);
145 $files = explode(PHP_EOL, trim(file_get_contents('php://stdin')));