88 $data =
'<XML><PROPERTIES ' .
$options .
' /></XML>';
89 $parser = xml_parser_create(
'ISO-8859-1');
90 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
91 xml_set_element_handler(
92 $parser, array($this,
'_parseConfigureOptionsStartElement'),
93 array($this,
'_parseConfigureOptionsEndElement'));
94 xml_parse($parser, $data,
true);
95 xml_parser_free($parser);
133 if (is_object($descfile)) {
135 $descfile = $pkg->getPackageFile();
143 $dir = dirname($descfile);
146 if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
147 return $this->raiseError(
"could not chdir to $dir");
151 $vdir = $pkg->getPackage() .
'-' . $pkg->getVersion();
152 if (file_exists($dir) && is_dir($vdir)) {
154 return $this->raiseError(
"could not chdir to " . realpath($vdir));
160 $this->
log(2,
"building in $dir");
162 $dsp = $pkg->getPackage().
'.dsp';
163 if (!file_exists(
"$dir/$dsp")) {
164 return $this->raiseError(
"The DSP $dsp does not exist.");
167 $command =
'msdev '.$dsp.
' /MAKE "'.$pkg->getPackage().
' - Release"';
176 $buildtype =
'Release';
177 if (preg_match(
'/.*?'.$pkg->getPackage().
'\s-\s(\w+)\s(.*?)-+/i',$this->_firstline,$matches)) {
178 $platform = $matches[1];
179 $buildtype = $matches[2];
182 if (preg_match(
'/(.*)?\s-\s(\d+).*?(\d+)/', $this->_lastline, $matches)) {
185 return $this->raiseError(
"There were errors during compilation.");
189 return $this->raiseError(
"Did not understand the completion status returned from msdev.exe.");
194 $dsptext = join(
'', file($dsp));
198 $regex =
'/.*?!IF\s+"\$\(CFG\)"\s+==\s+("'.
199 $pkg->getPackage().
'\s-\s'.
204 if ($dsptext && preg_match($regex, $dsptext, $matches)) {
206 $outfile = realpath($matches[2]);
208 return $this->raiseError(
"Could not retrieve output information from $dsp.");
211 if ($outfile && copy($outfile,
"$dir/$out")) {
212 $outfile =
"$dir/$out";
215 $built_files[] = array(
216 'file' =>
"$outfile",
217 'php_api' => $this->php_api_version,
218 'zend_mod_api' => $this->zend_module_api_no,
219 'zend_ext_api' => $this->zend_extension_api_no,
243 $d = opendir($dirname);
248 while (($ent = readdir($d)) !==
false) {
252 $full = $dirname . DIRECTORY_SEPARATOR . $ent;
255 $dest_prefix . DIRECTORY_SEPARATOR . $ent,
256 $full, $built_files)) {
261 $dest = $dest_prefix . DIRECTORY_SEPARATOR . $ent;
262 $built_files[] = array(
265 'php_api' => $this->php_api_version,
266 'zend_mod_api' => $this->zend_module_api_no,
267 'zend_ext_api' => $this->zend_extension_api_no,
298 function build($descfile, $callback =
null)
300 if (preg_match(
'/(\\/|\\\\|^)([^\\/\\\\]+)?php([^\\/\\\\]+)?$/',
301 $this->config->get(
'php_bin'), $matches)) {
302 if (isset($matches[2]) && strlen($matches[2]) &&
303 trim($matches[2]) != trim($this->config->get(
'php_prefix'))) {
304 $this->
log(0,
'WARNING: php_bin ' . $this->config->get(
'php_bin') .
305 ' appears to have a prefix ' . $matches[2] .
', but' .
306 ' config variable php_prefix does not match');
309 if (isset($matches[3]) && strlen($matches[3]) &&
310 trim($matches[3]) != trim($this->config->get(
'php_suffix'))) {
311 $this->
log(0,
'WARNING: php_bin ' . $this->config->get(
'php_bin') .
312 ' appears to have a suffix ' . $matches[3] .
', but' .
313 ' config variable php_suffix does not match');
317 $this->current_callback = $callback;
323 return $this->raiseError(
"building extensions not supported on this platform");
326 if (is_object($descfile)) {
328 $descfile = $pkg->getPackageFile();
329 if (is_a($pkg,
'PEAR_PackageFile_v1')) {
330 $dir = dirname($descfile);
332 $dir = $pkg->_config->get(
'temp_dir') .
'/' . $pkg->getName();
342 $dir = dirname($descfile);
346 foreach (array_keys($pkg->getInstallationFileList()) as $item) {
347 if (stristr(basename($item),
'config.m4') && dirname($item) !=
'.') {
348 $dir .= DIRECTORY_SEPARATOR . dirname($item);
354 if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) {
355 return $this->raiseError(
"could not chdir to $dir");
358 $vdir = $pkg->getPackage() .
'-' . $pkg->getVersion();
364 $this->
log(2,
"building in $dir");
365 $binDir = $this->config->get(
'bin_dir');
366 if (!preg_match(
'@(^|:)' . preg_quote($binDir,
'@') .
'(:|$)@', getenv(
'PATH'))) {
367 putenv(
'PATH=' . $binDir .
':' . getenv(
'PATH'));
369 $err = $this->
_runCommand($this->config->get(
'php_prefix')
371 $this->config->get(
'php_suffix'),
372 array(&$this,
'phpizeCallback'));
378 return $this->raiseError(
"`phpize' failed");
382 $configure_command =
"$dir/configure";
384 $phpConfigName = $this->config->get(
'php_prefix')
386 . $this->config->get(
'php_suffix');
387 $phpConfigPath = System::which($phpConfigName);
388 if ($phpConfigPath !==
false) {
389 $configure_command .=
' --with-php-config='
393 $configure_options = $pkg->getConfigureOptions();
394 if ($configure_options) {
395 foreach ($configure_options as $option) {
396 $default = array_key_exists(
'default', $option) ? $option[
'default'] :
null;
397 if (array_key_exists($option[
'name'], $this->_parsed_configure_options)) {
398 $response = $this->_parsed_configure_options[$option[
'name']];
401 'build', [$option[
'prompt']], [
'text'], [$default]);
403 if (substr($option[
'name'], 0, 5) ===
'with-' &&
405 $configure_command .=
" --{$option['name']}";
407 $configure_command .=
" --{$option['name']}=".trim(
$response);
414 if (!$user=getenv(
'USER')) {
418 $tmpdir = $this->config->get(
'temp_dir');
419 $build_basedir = System::mktemp(
' -t "' . $tmpdir .
'" -d "pear-build-' . $user .
'"');
420 $build_dir =
"$build_basedir/$vdir";
421 $inst_dir =
"$build_basedir/install-$vdir";
422 $this->
log(1,
"building in $build_dir");
423 if (is_dir($build_dir)) {
424 System::rm(array(
'-rf', $build_dir));
427 if (!System::mkDir(array(
'-p', $build_dir))) {
428 return $this->raiseError(
"could not create build dir: $build_dir");
432 if (!System::mkDir(array(
'-p', $inst_dir))) {
433 return $this->raiseError(
"could not create temporary install dir: $inst_dir");
437 $make_command = getenv(
'MAKE') ? getenv(
'MAKE') :
'make';
442 "$make_command INSTALL_ROOT=\"$inst_dir\" install",
443 "find \"$inst_dir\" | xargs ls -dils"
445 if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) {
446 return $this->raiseError(
"could not chdir to $build_dir");
448 putenv(
'PHP_PEAR_VERSION=1.10.18');
449 foreach ($to_run as $cmd) {
457 return $this->raiseError(
"`$cmd' failed");
460 if (!($dp = opendir(
"modules"))) {
462 return $this->raiseError(
"no `modules' directory found");
464 $built_files = array();
465 $prefix = exec($this->config->get(
'php_prefix')
467 $this->config->get(
'php_suffix') .
" --prefix");
468 $this->
_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files);
524 $this->
log(1,
"running: $command");
525 $pp = popen(
"$command 2>&1",
"r");
527 return $this->raiseError(
"failed to run `$command'");
529 if ($callback && $callback[0]->debug == 1) {
530 $olddbg = $callback[0]->debug;
531 $callback[0]->debug = 2;
534 while ($line = fgets($pp, 1024)) {
536 call_user_func($callback,
'cmdoutput', $line);
538 $this->
log(2, rtrim($line));
541 if ($callback && isset($olddbg)) {
542 $callback[0]->debug = $olddbg;
545 $exitcode = is_resource($pp) ? pclose($pp) : -1;
546 return ($exitcode == 0);
549 function log($level, $msg, $append_crlf =
true)
551 if ($this->current_callback) {
552 if ($this->debug >= $level) {
553 call_user_func($this->current_callback,
'output', $msg);
557 return parent::log($level, $msg, $append_crlf);