mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
add library, extension patches in separate classes
This commit is contained in:
parent
e909dd15b0
commit
51ce2befd8
25
src/SPC/builder/extension/bz2.php
Normal file
25
src/SPC/builder/extension/bz2.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\builder\macos\MacOSBuilder;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
|
#[CustomExt('bz2')]
|
||||||
|
class bz2 extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
$frameworks = $this->builder instanceof MacOSBuilder ? ' ' . $this->builder->getFrameworks(true) . ' ' : '';
|
||||||
|
FileSystem::replaceFile(SOURCE_PATH . '/php-src/configure', REPLACE_FILE_PREG, '/-lbz2/', $this->getLibFilesString() . $frameworks);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
52
src/SPC/builder/extension/curl.php
Normal file
52
src/SPC/builder/extension/curl.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\builder\macos\MacOSBuilder;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
|
#[CustomExt('curl')]
|
||||||
|
class curl extends Extension
|
||||||
|
{
|
||||||
|
public function patchBeforeBuildconf(): bool
|
||||||
|
{
|
||||||
|
logger()->info('patching before-configure for curl checks');
|
||||||
|
$file1 = "AC_DEFUN([PHP_CHECK_LIBRARY], [\n $3\n])";
|
||||||
|
$files = FileSystem::readFile(SOURCE_PATH . '/php-src/ext/curl/config.m4');
|
||||||
|
$file2 = 'AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||||
|
save_old_LDFLAGS=$LDFLAGS
|
||||||
|
ac_stuff="$5"
|
||||||
|
|
||||||
|
save_ext_shared=$ext_shared
|
||||||
|
ext_shared=yes
|
||||||
|
PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
|
||||||
|
AC_CHECK_LIB([$1],[$2],[
|
||||||
|
LDFLAGS=$save_old_LDFLAGS
|
||||||
|
ext_shared=$save_ext_shared
|
||||||
|
$3
|
||||||
|
],[
|
||||||
|
LDFLAGS=$save_old_LDFLAGS
|
||||||
|
ext_shared=$save_ext_shared
|
||||||
|
unset ac_cv_lib_$1[]_$2
|
||||||
|
$4
|
||||||
|
])dnl
|
||||||
|
])';
|
||||||
|
file_put_contents(SOURCE_PATH . '/php-src/ext/curl/config.m4', $file1 . "\n" . $files . "\n" . $file2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
$frameworks = $this->builder instanceof MacOSBuilder ? ' ' . $this->builder->getFrameworks(true) . ' ' : '';
|
||||||
|
FileSystem::replaceFile(SOURCE_PATH . '/php-src/configure', REPLACE_FILE_PREG, '/-lcurl/', $this->getLibFilesString() . $frameworks);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,8 @@ declare(strict_types=1);
|
|||||||
namespace SPC\builder\extension;
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
#[CustomExt('event')]
|
#[CustomExt('event')]
|
||||||
@ -23,4 +25,18 @@ class event extends Extension
|
|||||||
}
|
}
|
||||||
return $arg;
|
return $arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/configure',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/-levent_openssl/',
|
||||||
|
$this->getLibFilesString()
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace SPC\builder\extension;
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
#[CustomExt('memcache')]
|
#[CustomExt('memcache')]
|
||||||
@ -14,4 +15,34 @@ class memcache extends Extension
|
|||||||
{
|
{
|
||||||
return '--enable-memcache --with-zlib-dir=' . BUILD_ROOT_PATH;
|
return '--enable-memcache --with-zlib-dir=' . BUILD_ROOT_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function patchBeforeBuildconf(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/ext/memcache/config9.m4',
|
||||||
|
REPLACE_FILE_STR,
|
||||||
|
'if test -d $abs_srcdir/src ; then',
|
||||||
|
'if test -d $abs_srcdir/main ; then'
|
||||||
|
);
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/ext/memcache/config9.m4',
|
||||||
|
REPLACE_FILE_STR,
|
||||||
|
'export CPPFLAGS="$CPPFLAGS $INCLUDES"',
|
||||||
|
'export CPPFLAGS="$CPPFLAGS $INCLUDES -I$abs_srcdir/main"'
|
||||||
|
);
|
||||||
|
// add for in-tree building
|
||||||
|
file_put_contents(
|
||||||
|
SOURCE_PATH . '/php-src/ext/memcache/php_memcache.h',
|
||||||
|
<<<'EOF'
|
||||||
|
#ifndef PHP_MEMCACHE_H
|
||||||
|
#define PHP_MEMCACHE_H
|
||||||
|
|
||||||
|
extern zend_module_entry memcache_module_entry;
|
||||||
|
#define phpext_memcache_ptr &memcache_module_entry
|
||||||
|
|
||||||
|
#endif
|
||||||
|
EOF
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/SPC/builder/extension/openssl.php
Normal file
25
src/SPC/builder/extension/openssl.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
use SPC\util\Util;
|
||||||
|
|
||||||
|
#[CustomExt('openssl')]
|
||||||
|
class openssl extends Extension
|
||||||
|
{
|
||||||
|
public function patchBeforeMake(): bool
|
||||||
|
{
|
||||||
|
// patch openssl3 with php8.0 bug
|
||||||
|
if (file_exists(SOURCE_PATH . '/openssl/VERSION.dat') && Util::getPHPVersionID() < 80100) {
|
||||||
|
$openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c');
|
||||||
|
$openssl_c = preg_replace('/REGISTER_LONG_CONSTANT\s*\(\s*"OPENSSL_SSLV23_PADDING"\s*.+;/', '', $openssl_c);
|
||||||
|
file_put_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c', $openssl_c);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/SPC/builder/extension/pdo_sqlite.php
Normal file
28
src/SPC/builder/extension/pdo_sqlite.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
|
#[CustomExt('pdo_sqlite')]
|
||||||
|
class pdo_sqlite extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/configure',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/sqlite3_column_table_name=yes/',
|
||||||
|
'sqlite3_column_table_name=no'
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/SPC/builder/extension/pgsql.php
Normal file
28
src/SPC/builder/extension/pgsql.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
|
#[CustomExt('pgsql')]
|
||||||
|
class pgsql extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/configure',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/-lpq/',
|
||||||
|
$this->getLibFilesString()
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/SPC/builder/extension/readline.php
Normal file
28
src/SPC/builder/extension/readline.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
|
#[CustomExt('readline')]
|
||||||
|
class readline extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/configure',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/-lncurses/',
|
||||||
|
$this->getLibFilesString()
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/SPC/builder/extension/ssh2.php
Normal file
28
src/SPC/builder/extension/ssh2.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\builder\extension;
|
||||||
|
|
||||||
|
use SPC\builder\Extension;
|
||||||
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\CustomExt;
|
||||||
|
|
||||||
|
#[CustomExt('ssh2')]
|
||||||
|
class ssh2 extends Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeConfigure(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/php-src/configure',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/-lssh2/',
|
||||||
|
$this->getLibFilesString()
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ namespace SPC\builder\extension;
|
|||||||
|
|
||||||
use SPC\builder\Extension;
|
use SPC\builder\Extension;
|
||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
|
use SPC\util\Util;
|
||||||
|
|
||||||
#[CustomExt('swow')]
|
#[CustomExt('swow')]
|
||||||
class swow extends Extension
|
class swow extends Extension
|
||||||
@ -17,4 +18,17 @@ class swow extends Extension
|
|||||||
$arg .= $this->builder->getLib('curl') ? ' --enable-swow-curl' : ' --disable-swow-curl';
|
$arg .= $this->builder->getLib('curl') ? ' --enable-swow-curl' : ' --disable-swow-curl';
|
||||||
return $arg;
|
return $arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function patchBeforeBuildconf(): bool
|
||||||
|
{
|
||||||
|
if (Util::getPHPVersionID() >= 80000 && !is_link(SOURCE_PATH . '/php-src/ext/swow')) {
|
||||||
|
if (PHP_OS_FAMILY === 'Windows') {
|
||||||
|
f_passthru('cd ' . SOURCE_PATH . '/php-src/ext && mklink /D swow swow-src\ext');
|
||||||
|
} else {
|
||||||
|
f_passthru('cd ' . SOURCE_PATH . '/php-src/ext && ln -s swow-src/ext swow');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,14 +20,34 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder\linux\library;
|
namespace SPC\builder\linux\library;
|
||||||
|
|
||||||
|
use SPC\builder\linux\SystemUtil;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
use SPC\exception\RuntimeException;
|
use SPC\exception\RuntimeException;
|
||||||
use SPC\store\SourcePatcher;
|
use SPC\store\FileSystem;
|
||||||
|
|
||||||
class libpng extends LinuxLibraryBase
|
class libpng extends LinuxLibraryBase
|
||||||
{
|
{
|
||||||
public const NAME = 'libpng';
|
public const NAME = 'libpng';
|
||||||
|
|
||||||
|
public function patchBeforeBuild(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/libpng/configure',
|
||||||
|
REPLACE_FILE_STR,
|
||||||
|
'-lz',
|
||||||
|
BUILD_LIB_PATH . '/libz.a'
|
||||||
|
);
|
||||||
|
if (SystemUtil::getOSRelease()['dist'] === 'alpine') {
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/libpng/configure',
|
||||||
|
REPLACE_FILE_STR,
|
||||||
|
'-lm',
|
||||||
|
'/usr/lib/libm.a'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws RuntimeException
|
* @throws RuntimeException
|
||||||
* @throws FileSystemException
|
* @throws FileSystemException
|
||||||
@ -39,10 +59,6 @@ class libpng extends LinuxLibraryBase
|
|||||||
'arm64' => '--enable-arm-neon ',
|
'arm64' => '--enable-arm-neon ',
|
||||||
default => '',
|
default => '',
|
||||||
};
|
};
|
||||||
|
|
||||||
// patch configure
|
|
||||||
SourcePatcher::patchUnixLibpng();
|
|
||||||
|
|
||||||
shell()->cd($this->source_dir)
|
shell()->cd($this->source_dir)
|
||||||
->exec('chmod +x ./configure')
|
->exec('chmod +x ./configure')
|
||||||
->exec('chmod +x ./install-sh')
|
->exec('chmod +x ./install-sh')
|
||||||
|
|||||||
@ -20,19 +20,32 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder\macos\library;
|
namespace SPC\builder\macos\library;
|
||||||
|
|
||||||
use SPC\store\SourcePatcher;
|
use SPC\exception\FileSystemException;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
|
|
||||||
class curl extends MacOSLibraryBase
|
class curl extends MacOSLibraryBase
|
||||||
{
|
{
|
||||||
use \SPC\builder\unix\library\curl {
|
use \SPC\builder\unix\library\curl;
|
||||||
build as unixBuild;
|
|
||||||
}
|
|
||||||
|
|
||||||
public const NAME = 'curl';
|
public const NAME = 'curl';
|
||||||
|
|
||||||
protected function build()
|
/**
|
||||||
|
* @throws FileSystemException
|
||||||
|
*/
|
||||||
|
public function patchBeforeBuild(): bool
|
||||||
{
|
{
|
||||||
SourcePatcher::patchCurlMacOS();
|
FileSystem::replaceFile(
|
||||||
$this->unixBuild();
|
SOURCE_PATH . '/curl/CMakeLists.txt',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/NOT COREFOUNDATION_FRAMEWORK/m',
|
||||||
|
'FALSE'
|
||||||
|
);
|
||||||
|
FileSystem::replaceFile(
|
||||||
|
SOURCE_PATH . '/curl/CMakeLists.txt',
|
||||||
|
REPLACE_FILE_PREG,
|
||||||
|
'/NOT SYSTEMCONFIGURATION_FRAMEWORK/m',
|
||||||
|
'FALSE'
|
||||||
|
);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user