public function compile(CommandInterface $command, $development = false)
{
/**
* Get global namespace
*/
$namespace = str_replace('\\', '_', $this->checkDirectory());
$extensionName = $this->config->get('extension-name');
if (empty($extensionName) || !is_string($extensionName)) {
$extensionName = $namespace;
}
$needConfigure = $this->generate($command);
if ($needConfigure) {
if (Utils::isWindows()) {
exec('cd ext && %PHP_DEVPACK%\\phpize --clean', $output, $exit);
if (file_exists('ext/Release')) {
exec('rd /s /q ext/Release', $output, $exit);
}
$this->logger->output('Preparing for PHP compilation...');
exec('cd ext && %PHP_DEVPACK%\\phpize', $output, $exit);
/* fix until https://github.com/php/php-src/commit/9a3af83ee2aecff25fd4922ef67c1fb4d2af6201 hits all supported PHP builds */
$fixMarker = "/* zephir_phpize_fix */";
$configureFile = file_get_contents("ext/configure.js");
$configureFix = array("var PHP_ANALYZER = 'disabled';", "var PHP_PGO = 'no';", "var PHP_PGI = 'no';");
$hasChanged = false;
if (strpos($configureFile, $fixMarker) === false) {
$configureFile = $fixMarker . PHP_EOL . implode($configureFix, PHP_EOL) . PHP_EOL . $configureFile;
$hasChanged = true;
}
/* fix php's broken phpize pathing ... */
$marker = 'var build_dir = (dirname ? dirname : "").replace(new RegExp("^..\\\\\\\\"), "");';
$pos = strpos($configureFile, $marker);
if ($pos !== false) {
$spMarker = "if (MODE_PHPIZE) {";
$sp = strpos($configureFile, $spMarker, $pos - 200);
if ($sp === false) {
throw new CompilerException("outofdate... phpize seems broken again");
}
$configureFile = substr($configureFile, 0, $sp) . 'if (false) {' . substr($configureFile, $sp + strlen($spMarker));
$hasChanged = true;
}
if ($hasChanged) {
file_put_contents("ext/configure.js", $configureFile);
}
$this->logger->output('Preparing configuration file...');
exec('cd ext && configure --enable-' . $extensionName);
} else {
exec('cd ext && make clean && phpize --clean', $output, $exit);
$this->logger->output('Preparing for PHP compilation...');
exec('cd ext && phpize', $output, $exit);
$this->logger->output('Preparing configuration file...');
$gccFlags = $this->getGccFlags($development);
exec('cd ext && export CC="gcc" && export CFLAGS="' . $gccFlags . '" && ./configure --enable-' . $extensionName);
}
}
$currentDir = getcwd();
$this->logger->output('Compiling...');
if (Utils::isWindows()) {
exec('cd ext && nmake 2>' . $currentDir . '\\compile-errors.log 1>' . $currentDir . '\\compile.log', $output, $exit);
} else {
$this->preCompileHeaders();
exec('cd ext && (make -s -j2 2>' . $currentDir . '/compile-errors.log 1>' . $currentDir . '/compile.log)', $output, $exit);
}
}