Skip to content

Commit a613e9a

Browse files
committed
Add spc-config command
1 parent c4b9660 commit a613e9a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\command;
6+
7+
use SPC\exception\RuntimeException;
8+
use SPC\util\SPCConfigUtil;
9+
use Symfony\Component\Console\Attribute\AsCommand;
10+
use Symfony\Component\Console\Input\InputArgument;
11+
use Symfony\Component\Console\Input\InputOption;
12+
13+
#[AsCommand('spc-config', 'Build dependencies')]
14+
class SPCConfigCommand extends BuildCommand
15+
{
16+
protected bool $no_motd = true;
17+
18+
public function configure(): void
19+
{
20+
$this->addArgument('extensions', InputArgument::OPTIONAL, 'The extensions will be compiled, comma separated');
21+
$this->addOption('with-libs', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
22+
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
23+
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
24+
$this->addOption('includes', null, null, 'Add additional include path');
25+
$this->addOption('libs', null, null, 'Add additional libs path');
26+
}
27+
28+
/**
29+
* @throws RuntimeException
30+
*/
31+
public function handle(): int
32+
{
33+
// transform string to array
34+
$libraries = array_map('trim', array_filter(explode(',', $this->getOption('with-libs'))));
35+
// transform string to array
36+
$extensions = $this->getArgument('extensions') ? $this->parseExtensionList($this->getArgument('extensions')) : [];
37+
$include_suggest_ext = $this->getOption('with-suggested-exts');
38+
$include_suggest_lib = $this->getOption('with-suggested-libs');
39+
40+
$util = new SPCConfigUtil(null, $this->input);
41+
$config = $util->config($extensions, $libraries, $include_suggest_ext, $include_suggest_lib);
42+
43+
if ($this->getOption('includes')) {
44+
$this->output->writeln($config['cflags']);
45+
} elseif ($this->getOption('libs')) {
46+
$this->output->writeln("{$config['ldflags']} {$config['libs']}");
47+
} else {
48+
$this->output->writeln("{$config['cflags']} {$config['ldflags']} {$config['libs']}");
49+
}
50+
51+
return 0;
52+
}
53+
}

0 commit comments

Comments
 (0)