Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/**
2
/**
3
 * PEAR_Builder for building PHP extensions (PECL packages)
3
 * PEAR_Builder for building PHP extensions (PECL packages)
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
10
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2006 The PHP Group
11
 * @copyright  1997-2009 The Authors
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
12
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
19
 * @version    CVS: $Id: Builder.php,v 1.31 2007/01/10 05:32:51 cellog Exp $
-
 
20
 * @link       http://pear.php.net/package/PEAR
13
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
14
 * @since      File available since Release 0.1
22
 * 
15
 *
23
 * TODO: log output parameters in PECL command line
16
 * TODO: log output parameters in PECL command line
24
 * TODO: msdev path in configuration
17
 * TODO: msdev path in configuration
25
 */
18
 */
26
 
19
 
27
/**
20
/**
28
 * Needed for extending PEAR_Builder
21
 * Needed for extending PEAR_Builder
29
 */
22
 */
30
require_once 'PEAR/Common.php';
23
require_once 'PEAR/Common.php';
31
require_once 'PEAR/PackageFile.php';
24
require_once 'PEAR/PackageFile.php';
-
 
25
require_once 'System.php';
-
 
26
 
32
/**
27
/**
33
 * Class to handle building (compiling) extensions.
28
 * Class to handle building (compiling) extensions.
34
 *
29
 *
35
 * @category   pear
30
 * @category   pear
36
 * @package    PEAR
31
 * @package    PEAR
37
 * @author     Stig Bakken <ssb@php.net>
32
 * @author     Stig Bakken <ssb@php.net>
38
 * @author     Greg Beaver <cellog@php.net>
33
 * @author     Greg Beaver <cellog@php.net>
39
 * @copyright  1997-2006 The PHP Group
34
 * @copyright  1997-2009 The Authors
40
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
35
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
41
 * @version    Release: 1.5.1
36
 * @version    Release: 1.10.1
42
 * @link       http://pear.php.net/package/PEAR
37
 * @link       http://pear.php.net/package/PEAR
43
 * @since      Class available since PHP 4.0.2
38
 * @since      Class available since PHP 4.0.2
44
 * @see        http://pear.php.net/manual/en/core.ppm.pear-builder.php
39
 * @see        http://pear.php.net/manual/en/core.ppm.pear-builder.php
45
 */
40
 */
46
class PEAR_Builder extends PEAR_Common
41
class PEAR_Builder extends PEAR_Common
47
{
42
{
48
    // {{{ properties
-
 
49
 
-
 
50
    var $php_api_version = 0;
43
    var $php_api_version = 0;
51
    var $zend_module_api_no = 0;
44
    var $zend_module_api_no = 0;
52
    var $zend_extension_api_no = 0;
45
    var $zend_extension_api_no = 0;
53
 
46
 
54
    var $extensions_built = array();
47
    var $extensions_built = array();
55
 
48
 
56
    /**
49
    /**
57
     * @var string Used for reporting when it is not possible to pass function
50
     * @var string Used for reporting when it is not possible to pass function
58
     *             via extra parameter, e.g. log, msdevCallback
51
     *             via extra parameter, e.g. log, msdevCallback
59
     */
52
     */
60
    var $current_callback = null;
53
    var $current_callback = null;
61
 
54
 
62
    // used for msdev builds
55
    // used for msdev builds
63
    var $_lastline = null;
56
    var $_lastline = null;
64
    var $_firstline = null;
57
    var $_firstline = null;
65
    // }}}
-
 
66
    // {{{ constructor
-
 
67
 
58
 
68
    /**
59
    /**
69
     * PEAR_Builder constructor.
60
     * PEAR_Builder constructor.
70
     *
61
     *
71
     * @param object $ui user interface object (instance of PEAR_Frontend_*)
62
     * @param object $ui user interface object (instance of PEAR_Frontend_*)
72
     *
63
     *
73
     * @access public
64
     * @access public
74
     */
65
     */
75
    function PEAR_Builder(&$ui)
66
    function __construct(&$ui)
76
    {
67
    {
77
        parent::PEAR_Common();
68
        parent::__construct();
78
        $this->setFrontendObject($ui);
69
        $this->setFrontendObject($ui);
79
    }
70
    }
80
 
-
 
81
    // }}}
-
 
82
 
-
 
83
    // {{{ _build_win32()
-
 
84
 
71
 
85
    /**
72
    /**
86
     * Build an extension from source on windows.
73
     * Build an extension from source on windows.
87
     * requires msdev
74
     * requires msdev
88
     */
75
     */
89
    function _build_win32($descfile, $callback = null)
76
    function _build_win32($descfile, $callback = null)
90
    {
77
    {
91
        if (is_object($descfile)) {
78
        if (is_object($descfile)) {
92
            $pkg = $descfile;
79
            $pkg = $descfile;
93
            $descfile = $pkg->getPackageFile();
80
            $descfile = $pkg->getPackageFile();
94
        } else {
81
        } else {
95
            $pf = &new PEAR_PackageFile($this->config, $this->debug);
82
            $pf = new PEAR_PackageFile($this->config, $this->debug);
96
            $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
83
            $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
97
            if (PEAR::isError($pkg)) {
84
            if (PEAR::isError($pkg)) {
98
                return $pkg;
85
                return $pkg;
99
            }
86
            }
100
        }
87
        }
101
        $dir = dirname($descfile);
88
        $dir = dirname($descfile);
102
        $old_cwd = getcwd();
89
        $old_cwd = getcwd();
103
 
90
 
104
        if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
91
        if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
105
            return $this->raiseError("could not chdir to $dir");
92
            return $this->raiseError("could not chdir to $dir");
106
        }
93
        }
-
 
94
 
107
        // packages that were in a .tar have the packagefile in this directory
95
        // packages that were in a .tar have the packagefile in this directory
108
        $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
96
        $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
109
        if (file_exists($dir) && is_dir($vdir)) {
97
        if (file_exists($dir) && is_dir($vdir)) {
110
            if (chdir($vdir)) {
98
            if (!chdir($vdir)) {
111
                $dir = getcwd();
-
 
112
            } else {
-
 
113
                return $this->raiseError("could not chdir to " . realpath($vdir));
99
                return $this->raiseError("could not chdir to " . realpath($vdir));
114
            }
100
            }
-
 
101
 
-
 
102
            $dir = getcwd();
115
        }
103
        }
116
 
104
 
117
        $this->log(2, "building in $dir");
105
        $this->log(2, "building in $dir");
118
 
106
 
119
        $dsp = $pkg->getPackage().'.dsp';
107
        $dsp = $pkg->getPackage().'.dsp';
120
        if (!file_exists("$dir/$dsp")) {
108
        if (!file_exists("$dir/$dsp")) {
121
            return $this->raiseError("The DSP $dsp does not exist.");
109
            return $this->raiseError("The DSP $dsp does not exist.");
122
        }
110
        }
123
        // XXX TODO: make release build type configurable
111
        // XXX TODO: make release build type configurable
124
        $command = 'msdev '.$dsp.' /MAKE "'.$pkg->getPackage(). ' - Release"';
112
        $command = 'msdev '.$dsp.' /MAKE "'.$pkg->getPackage(). ' - Release"';
125
 
113
 
126
        $err = $this->_runCommand($command, array(&$this, 'msdevCallback'));
114
        $err = $this->_runCommand($command, array(&$this, 'msdevCallback'));
127
        if (PEAR::isError($err)) {
115
        if (PEAR::isError($err)) {
128
            return $err;
116
            return $err;
129
        }
117
        }
130
 
118
 
131
        // figure out the build platform and type
119
        // figure out the build platform and type
132
        $platform = 'Win32';
120
        $platform = 'Win32';
133
        $buildtype = 'Release';
121
        $buildtype = 'Release';
134
        if (preg_match('/.*?'.$pkg->getPackage().'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
122
        if (preg_match('/.*?'.$pkg->getPackage().'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
135
            $platform = $matches[1];
123
            $platform = $matches[1];
136
            $buildtype = $matches[2];
124
            $buildtype = $matches[2];
137
        }
125
        }
138
 
126
 
139
        if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/',$this->_lastline,$matches)) {
127
        if (preg_match('/(.*)?\s-\s(\d+).*?(\d+)/', $this->_lastline, $matches)) {
140
            if ($matches[2]) {
128
            if ($matches[2]) {
141
                // there were errors in the build
129
                // there were errors in the build
142
                return $this->raiseError("There were errors during compilation.");
130
                return $this->raiseError("There were errors during compilation.");
143
            }
131
            }
144
            $out = $matches[1];
132
            $out = $matches[1];
145
        } else {
133
        } else {
146
            return $this->raiseError("Did not understand the completion status returned from msdev.exe.");
134
            return $this->raiseError("Did not understand the completion status returned from msdev.exe.");
147
        }
135
        }
148
 
136
 
149
        // msdev doesn't tell us the output directory :/
137
        // msdev doesn't tell us the output directory :/
150
        // open the dsp, find /out and use that directory
138
        // open the dsp, find /out and use that directory
151
        $dsptext = join(file($dsp),'');
139
        $dsptext = join(file($dsp),'');
152
 
140
 
153
        // this regex depends on the build platform and type having been
141
        // this regex depends on the build platform and type having been
154
        // correctly identified above.
142
        // correctly identified above.
155
        $regex ='/.*?!IF\s+"\$\(CFG\)"\s+==\s+("'.
143
        $regex ='/.*?!IF\s+"\$\(CFG\)"\s+==\s+("'.
156
                    $pkg->getPackage().'\s-\s'.
144
                    $pkg->getPackage().'\s-\s'.
157
                    $platform.'\s'.
145
                    $platform.'\s'.
158
                    $buildtype.'").*?'.
146
                    $buildtype.'").*?'.
159
                    '\/out:"(.*?)"/is';
147
                    '\/out:"(.*?)"/is';
160
 
148
 
161
        if ($dsptext && preg_match($regex,$dsptext,$matches)) {
149
        if ($dsptext && preg_match($regex, $dsptext, $matches)) {
162
            // what we get back is a relative path to the output file itself.
150
            // what we get back is a relative path to the output file itself.
163
            $outfile = realpath($matches[2]);
151
            $outfile = realpath($matches[2]);
164
        } else {
152
        } else {
165
            return $this->raiseError("Could not retrieve output information from $dsp.");
153
            return $this->raiseError("Could not retrieve output information from $dsp.");
166
        }
154
        }
167
        // realpath returns false if the file doesn't exist
155
        // realpath returns false if the file doesn't exist
168
        if ($outfile && copy($outfile, "$dir/$out")) {
156
        if ($outfile && copy($outfile, "$dir/$out")) {
169
            $outfile = "$dir/$out";
157
            $outfile = "$dir/$out";
170
        }
158
        }
171
 
159
 
172
        $built_files[] = array(
160
        $built_files[] = array(
173
            'file' => "$outfile",
161
            'file' => "$outfile",
174
            'php_api' => $this->php_api_version,
162
            'php_api' => $this->php_api_version,
175
            'zend_mod_api' => $this->zend_module_api_no,
163
            'zend_mod_api' => $this->zend_module_api_no,
176
            'zend_ext_api' => $this->zend_extension_api_no,
164
            'zend_ext_api' => $this->zend_extension_api_no,
177
            );
165
            );
178
 
166
 
179
        return $built_files;
167
        return $built_files;
180
    }
168
    }
181
    // }}}
169
    // }}}
182
 
170
 
183
    // {{{ msdevCallback()
171
    // {{{ msdevCallback()
184
    function msdevCallback($what, $data)
172
    function msdevCallback($what, $data)
185
    {
173
    {
186
        if (!$this->_firstline)
174
        if (!$this->_firstline)
187
            $this->_firstline = $data;
175
            $this->_firstline = $data;
188
        $this->_lastline = $data;
176
        $this->_lastline = $data;
189
        call_user_func($this->current_callback, $what, $data);
177
        call_user_func($this->current_callback, $what, $data);
190
    }
178
    }
191
    // }}}
-
 
192
 
-
 
193
    // {{{ _harventInstDir
179
 
194
    /**
180
    /**
195
     * @param string
181
     * @param string
196
     * @param string
182
     * @param string
197
     * @param array
183
     * @param array
198
     * @access private
184
     * @access private
199
     */
185
     */
200
    function _harvestInstDir($dest_prefix, $dirname, &$built_files)
186
    function _harvestInstDir($dest_prefix, $dirname, &$built_files)
201
    {
187
    {
202
        $d = opendir($dirname);
188
        $d = opendir($dirname);
203
        if (!$d)
189
        if (!$d)
204
            return false;
190
            return false;
205
 
191
 
206
        $ret = true;
192
        $ret = true;
207
        while (($ent = readdir($d)) !== false) {
193
        while (($ent = readdir($d)) !== false) {
208
            if ($ent{0} == '.')
194
            if ($ent{0} == '.')
209
                continue;
195
                continue;
210
 
196
 
211
            $full = $dirname . DIRECTORY_SEPARATOR . $ent;
197
            $full = $dirname . DIRECTORY_SEPARATOR . $ent;
212
            if (is_dir($full)) {
198
            if (is_dir($full)) {
213
                if (!$this->_harvestInstDir(
199
                if (!$this->_harvestInstDir(
214
                        $dest_prefix . DIRECTORY_SEPARATOR . $ent,
200
                        $dest_prefix . DIRECTORY_SEPARATOR . $ent,
215
                        $full, $built_files)) {
201
                        $full, $built_files)) {
216
                    $ret = false;
202
                    $ret = false;
217
                    break;
203
                    break;
218
                }
204
                }
219
            } else {
205
            } else {
220
                $dest = $dest_prefix . DIRECTORY_SEPARATOR . $ent;
206
                $dest = $dest_prefix . DIRECTORY_SEPARATOR . $ent;
221
                $built_files[] = array(
207
                $built_files[] = array(
222
                        'file' => $full,
208
                        'file' => $full,
223
                        'dest' => $dest,
209
                        'dest' => $dest,
224
                        'php_api' => $this->php_api_version,
210
                        'php_api' => $this->php_api_version,
225
                        'zend_mod_api' => $this->zend_module_api_no,
211
                        'zend_mod_api' => $this->zend_module_api_no,
226
                        'zend_ext_api' => $this->zend_extension_api_no,
212
                        'zend_ext_api' => $this->zend_extension_api_no,
227
                        );
213
                        );
228
            }
214
            }
229
        }
215
        }
230
        closedir($d);
216
        closedir($d);
231
        return $ret;
217
        return $ret;
232
    }
218
    }
233
 
-
 
234
    // }}}
-
 
235
 
-
 
236
    // {{{ build()
-
 
237
 
219
 
238
    /**
220
    /**
239
     * Build an extension from source.  Runs "phpize" in the source
221
     * Build an extension from source.  Runs "phpize" in the source
240
     * directory, but compiles in a temporary directory
222
     * directory, but compiles in a temporary directory
241
     * (/var/tmp/pear-build-USER/PACKAGE-VERSION).
223
     * (TMPDIR/pear-build-USER/PACKAGE-VERSION).
242
     *
224
     *
243
     * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or
225
     * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or
244
     *               a PEAR_PackageFile object
226
     *               a PEAR_PackageFile object
245
     *
227
     *
246
     * @param mixed $callback callback function used to report output,
228
     * @param mixed $callback callback function used to report output,
247
     * see PEAR_Builder::_runCommand for details
229
     * see PEAR_Builder::_runCommand for details
248
     *
230
     *
249
     * @return array an array of associative arrays with built files,
231
     * @return array an array of associative arrays with built files,
250
     * format:
232
     * format:
251
     * array( array( 'file' => '/path/to/ext.so',
233
     * array( array( 'file' => '/path/to/ext.so',
252
     *               'php_api' => YYYYMMDD,
234
     *               'php_api' => YYYYMMDD,
253
     *               'zend_mod_api' => YYYYMMDD,
235
     *               'zend_mod_api' => YYYYMMDD,
254
     *               'zend_ext_api' => YYYYMMDD ),
236
     *               'zend_ext_api' => YYYYMMDD ),
255
     *        ... )
237
     *        ... )
256
     *
238
     *
257
     * @access public
239
     * @access public
258
     *
240
     *
259
     * @see PEAR_Builder::_runCommand
241
     * @see PEAR_Builder::_runCommand
260
     */
242
     */
261
    function build($descfile, $callback = null)
243
    function build($descfile, $callback = null)
262
    {
244
    {
-
 
245
        if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php([^\\/\\\\]+)?$/',
-
 
246
                       $this->config->get('php_bin'), $matches)) {
-
 
247
            if (isset($matches[2]) && strlen($matches[2]) &&
-
 
248
                trim($matches[2]) != trim($this->config->get('php_prefix'))) {
-
 
249
                $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
-
 
250
                           ' appears to have a prefix ' . $matches[2] . ', but' .
-
 
251
                           ' config variable php_prefix does not match');
-
 
252
            }
-
 
253
 
-
 
254
            if (isset($matches[3]) && strlen($matches[3]) &&
-
 
255
                trim($matches[3]) != trim($this->config->get('php_suffix'))) {
-
 
256
                $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') .
-
 
257
                           ' appears to have a suffix ' . $matches[3] . ', but' .
-
 
258
                           ' config variable php_suffix does not match');
-
 
259
            }
-
 
260
        }
-
 
261
 
263
        $this->current_callback = $callback;
262
        $this->current_callback = $callback;
264
        if (PEAR_OS == "Windows") {
263
        if (PEAR_OS == "Windows") {
265
            return $this->_build_win32($descfile,$callback);
264
            return $this->_build_win32($descfile, $callback);
266
        }
265
        }
-
 
266
 
267
        if (PEAR_OS != 'Unix') {
267
        if (PEAR_OS != 'Unix') {
268
            return $this->raiseError("building extensions not supported on this platform");
268
            return $this->raiseError("building extensions not supported on this platform");
269
        }
269
        }
-
 
270
 
270
        if (is_object($descfile)) {
271
        if (is_object($descfile)) {
271
            $pkg = $descfile;
272
            $pkg = $descfile;
272
            $descfile = $pkg->getPackageFile();
273
            $descfile = $pkg->getPackageFile();
-
 
274
            if (is_a($pkg, 'PEAR_PackageFile_v1')) {
-
 
275
                $dir = dirname($descfile);
-
 
276
            } else {
-
 
277
                $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName();
-
 
278
                // automatically delete at session end
-
 
279
                $this->addTempFile($dir);
-
 
280
            }
273
        } else {
281
        } else {
274
            $pf = &new PEAR_PackageFile($this->config);
282
            $pf = new PEAR_PackageFile($this->config);
275
            $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
283
            $pkg = &$pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL);
276
            if (PEAR::isError($pkg)) {
284
            if (PEAR::isError($pkg)) {
277
                return $pkg;
285
                return $pkg;
278
            }
286
            }
-
 
287
            $dir = dirname($descfile);
279
        }
288
        }
-
 
289
 
-
 
290
        // Find config. outside of normal path - e.g. config.m4
-
 
291
        foreach (array_keys($pkg->getInstallationFileList()) as $item) {
-
 
292
          if (stristr(basename($item), 'config.m4') && dirname($item) != '.') {
280
        $dir = dirname($descfile);
293
            $dir .= DIRECTORY_SEPARATOR . dirname($item);
-
 
294
            break;
-
 
295
          }
-
 
296
        }
-
 
297
 
281
        $old_cwd = getcwd();
298
        $old_cwd = getcwd();
282
        if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
299
        if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
283
            return $this->raiseError("could not chdir to $dir");
300
            return $this->raiseError("could not chdir to $dir");
284
        }
301
        }
-
 
302
 
285
        $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
303
        $vdir = $pkg->getPackage() . '-' . $pkg->getVersion();
286
        if (is_dir($vdir)) {
304
        if (is_dir($vdir)) {
287
            chdir($vdir);
305
            chdir($vdir);
288
        }
306
        }
-
 
307
 
289
        $dir = getcwd();
308
        $dir = getcwd();
290
        $this->log(2, "building in $dir");
309
        $this->log(2, "building in $dir");
291
        putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
310
        putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH'));
-
 
311
        $err = $this->_runCommand($this->config->get('php_prefix')
-
 
312
                                . "phpize" .
-
 
313
                                $this->config->get('php_suffix'),
292
        $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback'));
314
                                array(&$this, 'phpizeCallback'));
293
        if (PEAR::isError($err)) {
315
        if (PEAR::isError($err)) {
294
            return $err;
316
            return $err;
295
        }
317
        }
-
 
318
 
296
        if (!$err) {
319
        if (!$err) {
297
            return $this->raiseError("`phpize' failed");
320
            return $this->raiseError("`phpize' failed");
298
        }
321
        }
299
 
322
 
300
        // {{{ start of interactive part
323
        // {{{ start of interactive part
301
        $configure_command = "$dir/configure";
324
        $configure_command = "$dir/configure";
-
 
325
 
-
 
326
        $phpConfigName = $this->config->get('php_prefix')
-
 
327
            . 'php-config'
-
 
328
            . $this->config->get('php_suffix');
-
 
329
        $phpConfigPath = System::which($phpConfigName);
-
 
330
        if ($phpConfigPath !== false) {
-
 
331
            $configure_command .= ' --with-php-config='
-
 
332
                . $phpConfigPath;
-
 
333
        }
-
 
334
 
302
        $configure_options = $pkg->getConfigureOptions();
335
        $configure_options = $pkg->getConfigureOptions();
303
        if ($configure_options) {
336
        if ($configure_options) {
304
            foreach ($configure_options as $o) {
337
            foreach ($configure_options as $o) {
305
                $default = array_key_exists('default', $o) ? $o['default'] : null;
338
                $default = array_key_exists('default', $o) ? $o['default'] : null;
306
                list($r) = $this->ui->userDialog('build',
339
                list($r) = $this->ui->userDialog('build',
307
                                                 array($o['prompt']),
340
                                                 array($o['prompt']),
308
                                                 array('text'),
341
                                                 array('text'),
309
                                                 array($default));
342
                                                 array($default));
310
                if (substr($o['name'], 0, 5) == 'with-' &&
343
                if (substr($o['name'], 0, 5) == 'with-' &&
311
                    ($r == 'yes' || $r == 'autodetect')) {
344
                    ($r == 'yes' || $r == 'autodetect')) {
312
                    $configure_command .= " --$o[name]";
345
                    $configure_command .= " --$o[name]";
313
                } else {
346
                } else {
314
                    $configure_command .= " --$o[name]=".trim($r);
347
                    $configure_command .= " --$o[name]=".trim($r);
315
                }
348
                }
316
            }
349
            }
317
        }
350
        }
318
        // }}} end of interactive part
351
        // }}} end of interactive part
319
 
352
 
320
        // FIXME make configurable
353
        // FIXME make configurable
321
        if(!$user=getenv('USER')){
354
        if (!$user=getenv('USER')) {
322
            $user='defaultuser';
355
            $user='defaultuser';
323
        }
356
        }
-
 
357
 
-
 
358
        $tmpdir = $this->config->get('temp_dir');
324
        $build_basedir = "/var/tmp/pear-build-$user";
359
        $build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"');
325
        $build_dir = "$build_basedir/$vdir";
360
        $build_dir = "$build_basedir/$vdir";
326
        $inst_dir = "$build_basedir/install-$vdir";
361
        $inst_dir = "$build_basedir/install-$vdir";
327
        $this->log(1, "building in $build_dir");
362
        $this->log(1, "building in $build_dir");
328
        if (is_dir($build_dir)) {
363
        if (is_dir($build_dir)) {
329
            System::rm(array('-rf', $build_dir));
364
            System::rm(array('-rf', $build_dir));
330
        }
365
        }
-
 
366
 
331
        if (!System::mkDir(array('-p', $build_dir))) {
367
        if (!System::mkDir(array('-p', $build_dir))) {
332
            return $this->raiseError("could not create build dir: $build_dir");
368
            return $this->raiseError("could not create build dir: $build_dir");
333
        }
369
        }
-
 
370
 
334
        $this->addTempFile($build_dir);
371
        $this->addTempFile($build_dir);
335
        if (!System::mkDir(array('-p', $inst_dir))) {
372
        if (!System::mkDir(array('-p', $inst_dir))) {
336
            return $this->raiseError("could not create temporary install dir: $inst_dir");
373
            return $this->raiseError("could not create temporary install dir: $inst_dir");
337
        }
374
        }
338
        $this->addTempFile($inst_dir);
375
        $this->addTempFile($inst_dir);
339
 
-
 
340
        if (getenv('MAKE')) {
376
 
341
            $make_command = getenv('MAKE');
-
 
342
        } else {
-
 
343
            $make_command = 'make';
377
        $make_command = getenv('MAKE') ? getenv('MAKE') : 'make';
344
        }
378
 
345
        $to_run = array(
379
        $to_run = array(
346
            $configure_command,
380
            $configure_command,
347
            $make_command,
381
            $make_command,
348
            "$make_command INSTALL_ROOT=\"$inst_dir\" install",
382
            "$make_command INSTALL_ROOT=\"$inst_dir\" install",
349
            "find \"$inst_dir\" -ls"
383
            "find \"$inst_dir\" | xargs ls -dils"
350
            );
384
            );
351
        if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
385
        if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
352
            return $this->raiseError("could not chdir to $build_dir");
386
            return $this->raiseError("could not chdir to $build_dir");
353
        }
387
        }
354
        putenv('PHP_PEAR_VERSION=1.5.1');
388
        putenv('PHP_PEAR_VERSION=1.10.1');
355
        foreach ($to_run as $cmd) {
389
        foreach ($to_run as $cmd) {
356
            $err = $this->_runCommand($cmd, $callback);
390
            $err = $this->_runCommand($cmd, $callback);
357
            if (PEAR::isError($err)) {
391
            if (PEAR::isError($err)) {
358
                chdir($old_cwd);
392
                chdir($old_cwd);
359
                return $err;
393
                return $err;
360
            }
394
            }
361
            if (!$err) {
395
            if (!$err) {
362
                chdir($old_cwd);
396
                chdir($old_cwd);
363
                return $this->raiseError("`$cmd' failed");
397
                return $this->raiseError("`$cmd' failed");
364
            }
398
            }
365
        }
399
        }
366
        if (!($dp = opendir("modules"))) {
400
        if (!($dp = opendir("modules"))) {
367
            chdir($old_cwd);
401
            chdir($old_cwd);
368
            return $this->raiseError("no `modules' directory found");
402
            return $this->raiseError("no `modules' directory found");
369
        }
403
        }
370
        $built_files = array();
404
        $built_files = array();
371
        $prefix = exec("php-config --prefix");
405
        $prefix = exec($this->config->get('php_prefix')
-
 
406
                        . "php-config" .
-
 
407
                       $this->config->get('php_suffix') . " --prefix");
372
        $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
408
        $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
373
        chdir($old_cwd);
409
        chdir($old_cwd);
374
        return $built_files;
410
        return $built_files;
375
    }
411
    }
376
 
-
 
377
    // }}}
-
 
378
    // {{{ phpizeCallback()
-
 
379
 
412
 
380
    /**
413
    /**
381
     * Message callback function used when running the "phpize"
414
     * Message callback function used when running the "phpize"
382
     * program.  Extracts the API numbers used.  Ignores other message
415
     * program.  Extracts the API numbers used.  Ignores other message
383
     * types than "cmdoutput".
416
     * types than "cmdoutput".
384
     *
417
     *
385
     * @param string $what the type of message
418
     * @param string $what the type of message
386
     * @param mixed $data the message
419
     * @param mixed $data the message
387
     *
420
     *
388
     * @return void
421
     * @return void
389
     *
422
     *
390
     * @access public
423
     * @access public
391
     */
424
     */
392
    function phpizeCallback($what, $data)
425
    function phpizeCallback($what, $data)
393
    {
426
    {
394
        if ($what != 'cmdoutput') {
427
        if ($what != 'cmdoutput') {
395
            return;
428
            return;
396
        }
429
        }
397
        $this->log(1, rtrim($data));
430
        $this->log(1, rtrim($data));
398
        if (preg_match('/You should update your .aclocal.m4/', $data)) {
431
        if (preg_match('/You should update your .aclocal.m4/', $data)) {
399
            return;
432
            return;
400
        }
433
        }
401
        $matches = array();
434
        $matches = array();
402
        if (preg_match('/^\s+(\S[^:]+):\s+(\d{8})/', $data, $matches)) {
435
        if (preg_match('/^\s+(\S[^:]+):\s+(\d{8})/', $data, $matches)) {
403
            $member = preg_replace('/[^a-z]/', '_', strtolower($matches[1]));
436
            $member = preg_replace('/[^a-z]/', '_', strtolower($matches[1]));
404
            $apino = (int)$matches[2];
437
            $apino = (int)$matches[2];
405
            if (isset($this->$member)) {
438
            if (isset($this->$member)) {
406
                $this->$member = $apino;
439
                $this->$member = $apino;
407
                //$msg = sprintf("%-22s : %d", $matches[1], $apino);
440
                //$msg = sprintf("%-22s : %d", $matches[1], $apino);
408
                //$this->log(1, $msg);
441
                //$this->log(1, $msg);
409
            }
442
            }
410
        }
443
        }
411
    }
444
    }
412
 
-
 
413
    // }}}
-
 
414
    // {{{ _runCommand()
-
 
415
 
445
 
416
    /**
446
    /**
417
     * Run an external command, using a message callback to report
447
     * Run an external command, using a message callback to report
418
     * output.  The command will be run through popen and output is
448
     * output.  The command will be run through popen and output is
419
     * reported for every line with a "cmdoutput" message with the
449
     * reported for every line with a "cmdoutput" message with the
420
     * line string, including newlines, as payload.
450
     * line string, including newlines, as payload.
421
     *
451
     *
422
     * @param string $command the command to run
452
     * @param string $command the command to run
423
     *
453
     *
424
     * @param mixed $callback (optional) function to use as message
454
     * @param mixed $callback (optional) function to use as message
425
     * callback
455
     * callback
426
     *
456
     *
427
     * @return bool whether the command was successful (exit code 0
457
     * @return bool whether the command was successful (exit code 0
428
     * means success, any other means failure)
458
     * means success, any other means failure)
429
     *
459
     *
430
     * @access private
460
     * @access private
431
     */
461
     */
432
    function _runCommand($command, $callback = null)
462
    function _runCommand($command, $callback = null)
433
    {
463
    {
434
        $this->log(1, "running: $command");
464
        $this->log(1, "running: $command");
435
        $pp = popen("$command 2>&1", "r");
465
        $pp = popen("$command 2>&1", "r");
436
        if (!$pp) {
466
        if (!$pp) {
437
            return $this->raiseError("failed to run `$command'");
467
            return $this->raiseError("failed to run `$command'");
438
        }
468
        }
439
        if ($callback && $callback[0]->debug == 1) {
469
        if ($callback && $callback[0]->debug == 1) {
440
            $olddbg = $callback[0]->debug;
470
            $olddbg = $callback[0]->debug;
441
            $callback[0]->debug = 2;
471
            $callback[0]->debug = 2;
442
        }
472
        }
443
 
473
 
444
        while ($line = fgets($pp, 1024)) {
474
        while ($line = fgets($pp, 1024)) {
445
            if ($callback) {
475
            if ($callback) {
446
                call_user_func($callback, 'cmdoutput', $line);
476
                call_user_func($callback, 'cmdoutput', $line);
447
            } else {
477
            } else {
448
                $this->log(2, rtrim($line));
478
                $this->log(2, rtrim($line));
449
            }
479
            }
450
        }
480
        }
451
        if ($callback && isset($olddbg)) {
481
        if ($callback && isset($olddbg)) {
452
            $callback[0]->debug = $olddbg;
482
            $callback[0]->debug = $olddbg;
453
        }
483
        }
454
        if (is_resource($pp)) {
-
 
-
 
484
 
455
            $exitcode = pclose($pp);
485
        $exitcode = is_resource($pp) ? pclose($pp) : -1;
456
        } else {
-
 
457
            $exitcode = -1;
-
 
458
        }
-
 
459
        return ($exitcode == 0);
486
        return ($exitcode == 0);
460
    }
487
    }
461
 
-
 
462
    // }}}
-
 
463
    // {{{ log()
-
 
464
 
488
 
465
    function log($level, $msg)
489
    function log($level, $msg, $append_crlf = true)
466
    {
490
    {
467
        if ($this->current_callback) {
491
        if ($this->current_callback) {
468
            if ($this->debug >= $level) {
492
            if ($this->debug >= $level) {
469
                call_user_func($this->current_callback, 'output', $msg);
493
                call_user_func($this->current_callback, 'output', $msg);
470
            }
494
            }
471
            return;
495
            return;
472
        }
496
        }
473
        return PEAR_Common::log($level, $msg);
497
        return parent::log($level, $msg, $append_crlf);
474
    }
498
    }
475
 
-
 
476
    // }}}
-
 
477
}
499
}
478
 
-
 
479
?>
-