mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-05 15:55:39 +08:00
Add gnu based static binary support
This commit is contained in:
@@ -15,6 +15,8 @@ use SPC\util\GlobalEnvManager;
|
||||
|
||||
class LinuxBuilder extends UnixBuilderBase
|
||||
{
|
||||
public string $libc;
|
||||
|
||||
/** @var bool Micro patch phar flag */
|
||||
private bool $phar_patched = false;
|
||||
|
||||
@@ -25,13 +27,18 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = $options;
|
||||
SystemUtil::initLibcVar($this->options['libc'] ?? null);
|
||||
|
||||
$this->libc = getenv('SPC_LIBC') ?: LIBC_MUSL_WRAPPER;
|
||||
|
||||
// check musl-cross make installed if we use musl-cross-make
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
|
||||
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
||||
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
|
||||
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
|
||||
if ($this->libc !== LIBC_GLIBC) {
|
||||
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
||||
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
|
||||
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
|
||||
}
|
||||
|
||||
GlobalEnvManager::init($this);
|
||||
|
||||
|
||||
@@ -182,4 +182,12 @@ class SystemUtil
|
||||
'arch', 'manjaro',
|
||||
];
|
||||
}
|
||||
|
||||
public static function initLibcVar(?string $libc = null): void
|
||||
{
|
||||
if ($libc === null) {
|
||||
$libc = self::isMuslDist() ? 'musl' : 'musl-wrapper';
|
||||
}
|
||||
f_putenv('SPC_LIBC=' . $libc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,8 @@ class libpng extends LinuxLibraryBase
|
||||
shell()->cd($this->source_dir)
|
||||
->exec('chmod +x ./configure')
|
||||
->exec('chmod +x ./install-sh')
|
||||
->exec(
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
|
||||
'./configure ' .
|
||||
'--disable-shared ' .
|
||||
@@ -54,9 +55,9 @@ class libpng extends LinuxLibraryBase
|
||||
$optimizations .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la")
|
||||
->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH);
|
||||
->execWithEnv('make clean')
|
||||
->execWithEnv("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la")
|
||||
->execWithEnv('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX);
|
||||
$this->cleanLaFiles();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class openssl extends LinuxLibraryBase
|
||||
$extra = '';
|
||||
$ex_lib = '-ldl -pthread';
|
||||
|
||||
$env = "CC='" . getenv('CC') . ' -static -idirafter ' . BUILD_INCLUDE_PATH .
|
||||
$env = "CC='" . getenv('CC') . ' -idirafter ' . BUILD_INCLUDE_PATH .
|
||||
' -idirafter /usr/include/ ' .
|
||||
' -idirafter /usr/include/' . $this->builder->getOption('arch') . '-linux-gnu/ ' .
|
||||
"' ";
|
||||
@@ -70,7 +70,6 @@ class openssl extends LinuxLibraryBase
|
||||
'--prefix=/ ' .
|
||||
'--libdir=lib ' .
|
||||
'--openssldir=/etc/ssl ' .
|
||||
'-static ' .
|
||||
"{$zlib_extra}" .
|
||||
'no-legacy ' .
|
||||
"linux-{$this->builder->getOption('arch')}{$clang_postfix}"
|
||||
|
||||
Reference in New Issue
Block a user