mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-10 02:15:36 +08:00
Add preliminary MacPorts support
This commit is contained in:
@@ -20,8 +20,8 @@ class unixodbc extends LibraryPackage
|
|||||||
{
|
{
|
||||||
$sysconf_selector = match ($os = SystemTarget::getTargetOS()) {
|
$sysconf_selector = match ($os = SystemTarget::getTargetOS()) {
|
||||||
'Darwin' => match (SystemTarget::getTargetArch()) {
|
'Darwin' => match (SystemTarget::getTargetArch()) {
|
||||||
'x86_64' => '/usr/local/etc',
|
'x86_64' => is_dir('/usr/local/etc') ? '/usr/local/etc' : '/opt/local/etc',
|
||||||
'aarch64' => '/opt/homebrew/etc',
|
'aarch64' => is_dir('/opt/homebrew/etc') ? '/opt/homebrew/etc' : '/opt/local/etc',
|
||||||
default => throw new WrongUsageException('Unsupported architecture: ' . GNU_ARCH),
|
default => throw new WrongUsageException('Unsupported architecture: ' . GNU_ARCH),
|
||||||
},
|
},
|
||||||
'Linux' => '/etc',
|
'Linux' => '/etc',
|
||||||
|
|||||||
@@ -45,6 +45,18 @@ class MacOSToolCheck
|
|||||||
return CheckResult::ok();
|
return CheckResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[CheckItem('if macports has installed', limit_os: 'Darwin', level: 998)]
|
||||||
|
public function checkPorts(): ?CheckResult
|
||||||
|
{
|
||||||
|
if (($path = MacOSUtil::findCommand('port')) === null) {
|
||||||
|
return CheckResult::fail('MacPorts is not installed', 'port');
|
||||||
|
}
|
||||||
|
if ($path !== '/opt/local/bin/port' && getenv('GNU_ARCH') === 'aarch64') {
|
||||||
|
return CheckResult::fail('Current macports (/opt/local/bin/port) is not installed for M1 Mac, please re-install macports!');
|
||||||
|
}
|
||||||
|
return CheckResult::ok();
|
||||||
|
}
|
||||||
|
|
||||||
#[CheckItem('if necessary tools are installed', limit_os: 'Darwin')]
|
#[CheckItem('if necessary tools are installed', limit_os: 'Darwin')]
|
||||||
public function checkCliTools(): ?CheckResult
|
public function checkCliTools(): ?CheckResult
|
||||||
{
|
{
|
||||||
@@ -74,6 +86,20 @@ class MacOSToolCheck
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[CheckItem('if macports llvm are installed', limit_os: 'Darwin')]
|
||||||
|
public function checkPortsLLVM(): ?CheckResult
|
||||||
|
{
|
||||||
|
if (getenv('SPC_USE_LLVM') === 'port') {
|
||||||
|
$macports_prefix = getenv('MACPORTS_PREFIX') ?: '/opt/local';
|
||||||
|
|
||||||
|
if (($path = MacOSUtil::findCommand('clang', ["{$macports_prefix}/bin"])) === null) {
|
||||||
|
return CheckResult::fail('MacPorts llvm is not installed', 'build-tools', ['missing' => ['llvm']]);
|
||||||
|
}
|
||||||
|
return CheckResult::ok($path);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
#[CheckItem('if bison version is 3.0 or later', limit_os: 'Darwin')]
|
#[CheckItem('if bison version is 3.0 or later', limit_os: 'Darwin')]
|
||||||
public function checkBisonVersion(array $command_path = []): ?CheckResult
|
public function checkBisonVersion(array $command_path = []): ?CheckResult
|
||||||
{
|
{
|
||||||
@@ -91,7 +117,7 @@ class MacOSToolCheck
|
|||||||
if ($command_path !== []) {
|
if ($command_path !== []) {
|
||||||
return CheckResult::fail("Current {$bison} version is too old: " . $matches[0]);
|
return CheckResult::fail("Current {$bison} version is too old: " . $matches[0]);
|
||||||
}
|
}
|
||||||
return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin']);
|
return $this->checkBisonVersion(['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin']);
|
||||||
}
|
}
|
||||||
return CheckResult::ok($matches[0]);
|
return CheckResult::ok($matches[0]);
|
||||||
}
|
}
|
||||||
@@ -108,6 +134,9 @@ class MacOSToolCheck
|
|||||||
#[FixItem('build-tools')]
|
#[FixItem('build-tools')]
|
||||||
public function fixBuildTools(array $missing): bool
|
public function fixBuildTools(array $missing): bool
|
||||||
{
|
{
|
||||||
|
$hasBrew = $this->checkBrew()?->isOK();
|
||||||
|
$hasMacports = $this->checkPorts()?->isOK();
|
||||||
|
|
||||||
$replacement = [
|
$replacement = [
|
||||||
'glibtoolize' => 'libtool',
|
'glibtoolize' => 'libtool',
|
||||||
];
|
];
|
||||||
@@ -115,7 +144,18 @@ class MacOSToolCheck
|
|||||||
if (isset($replacement[$cmd])) {
|
if (isset($replacement[$cmd])) {
|
||||||
$cmd = $replacement[$cmd];
|
$cmd = $replacement[$cmd];
|
||||||
}
|
}
|
||||||
shell()->exec('brew install --formula ' . escapeshellarg($cmd));
|
|
||||||
|
if ($hasBrew) {
|
||||||
|
shell()->exec('brew install --formula ' . escapeshellarg($cmd));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hasMacports) {
|
||||||
|
shell()->exec('port install ' . escapeshellarg($cmd));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/StaticPHP/Toolchain/ClangPortsToolchain.php
Normal file
20
src/StaticPHP/Toolchain/ClangPortsToolchain.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace StaticPHP\Toolchain;
|
||||||
|
|
||||||
|
use StaticPHP\Util\GlobalEnvManager;
|
||||||
|
|
||||||
|
class ClangPortsToolchain extends ClangNativeToolchain
|
||||||
|
{
|
||||||
|
public function initEnv(): void
|
||||||
|
{
|
||||||
|
$macports_prefix = getenv('MACPORTS_PREFIX') ?: '/opt/local';
|
||||||
|
GlobalEnvManager::putenv("SPC_DEFAULT_CC={$macports_prefix}/bin/clang");
|
||||||
|
GlobalEnvManager::putenv("SPC_DEFAULT_CXX={$macports_prefix}/bin/clang++");
|
||||||
|
GlobalEnvManager::putenv("SPC_DEFAULT_AR={$macports_prefix}/bin/llvm-ar");
|
||||||
|
GlobalEnvManager::putenv('SPC_DEFAULT_LD=ld');
|
||||||
|
GlobalEnvManager::addPathIfNotExists("{$macports_prefix}/bin");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,10 +134,10 @@ class GlobalEnvManager
|
|||||||
}
|
}
|
||||||
// test bison
|
// test bison
|
||||||
if (PHP_OS_FAMILY === 'Darwin') {
|
if (PHP_OS_FAMILY === 'Darwin') {
|
||||||
if ($bison = MacOSUtil::findCommand('bison', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin'])) {
|
if ($bison = MacOSUtil::findCommand('bison', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin/bison'])) {
|
||||||
self::putenv("BISON={$bison}");
|
self::putenv("BISON={$bison}");
|
||||||
}
|
}
|
||||||
if ($yacc = MacOSUtil::findCommand('yacc', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin'])) {
|
if ($yacc = MacOSUtil::findCommand('yacc', ['/opt/homebrew/opt/bison/bin', '/usr/local/opt/bison/bin', '/opt/local/bin/yacc'])) {
|
||||||
self::putenv("YACC={$yacc}");
|
self::putenv("YACC={$yacc}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user