Skip to content

Commit

Permalink
重新支持 bin 项目
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 12, 2019
1 parent 7557760 commit db4285a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions console/src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Builder
protected $projectType;
protected $target;
protected $installTargetDir;
protected $phpRoot;

const DIR_SRC = 'src';
const DIR_INCLUDE = 'include';
Expand All @@ -37,7 +38,6 @@ class Builder
protected $debug;
protected $verbose;


protected $configFile;
protected $config;

Expand All @@ -46,17 +46,22 @@ function __construct($debug = false, $verbose = false)
$this->debug = $debug;
$this->verbose = $verbose;
$this->root = getcwd() . '/';
$this->phpRoot = trim(`php-config --prefix`);

$this->loadConfig();
$this->projectName = $this->getConfigValue('project', 'name');
$this->projectType = $this->getConfigValue('project', 'type');
$this->cxxflags .= ' ' . $this->getConfigValue('build', 'cxxflags');
$this->cflags .= ' ' . $this->getConfigValue('build', 'cflags');
$this->ldflags .= ' ' . $this->getConfigValue('build', 'ldflags');
$this->target = $this->root . '/lib/' . $this->projectName . '.so';

if ($this->isExtension()) {
$php_extension_dir = trim(`php-config --extension-dir`);
$this->installTargetDir = $php_extension_dir;
$this->target = $this->root . '/lib/' . $this->projectName . '.so';
} else {
$this->installTargetDir = $this->phpRoot . '/bin';
$this->target = $this->root . '/bin/' . $this->projectName;
}
}

Expand Down Expand Up @@ -226,18 +231,24 @@ public function link()
if (!is_dir(dirname($this->target))) {
@mkdir(dirname($this->target));
}
$link_option = '';

$link_option = ' -L./lib';
$libs = trim(`php-config --libs`);
$ldflags = trim(`php-config --ldflags`);

/**
* PHP 的 library 路径
*/
$link_option .= ' -L' . $this->phpRoot . '/lib';

if ($this->isExtension()) {
$link_option .= ' -shared';
$libs .= " ".self::PHPX_LFLAGS;
} else {
$libs .= " ".self::PHPX_LFLAGS;
$libs .= " ".self::PHPX_LFLAGS.' -lphp7';
}

$this->exec(self::CXX . " $objects {$ldflags} {$libs} {$this->ldflags} {$link_option} -L./lib -o {$this->target}");
$this->exec(self::CXX . " $objects {$ldflags} {$libs} {$this->ldflags} {$link_option} -o {$this->target}");
}

function clean()
Expand Down

0 comments on commit db4285a

Please sign in to comment.