From 8df4ade7541a0e781d291a15e48b9bbf5cc7a1a2 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 29 Apr 2023 18:59:47 +0800 Subject: [PATCH] refactor to pkg-config and add some add-on libs for gd --- config/ext.json | 34 ++--- config/lib.json | 58 ++++--- config/source.json | 72 ++++++--- ext-support.md | 44 ++++-- src/SPC/builder/extension/curl.php | 18 --- src/SPC/builder/extension/gd.php | 11 +- src/SPC/builder/extension/mbstring.php | 2 +- src/SPC/builder/extension/mongodb.php | 17 +++ src/SPC/builder/extension/openssl.php | 18 --- src/SPC/builder/extension/sqlite3.php | 19 --- src/SPC/builder/extension/xml.php | 4 +- src/SPC/builder/extension/zip.php | 18 --- src/SPC/builder/extension/zlib.php | 18 --- src/SPC/builder/extension/zstd.php | 2 +- src/SPC/builder/linux/LinuxBuilder.php | 42 +---- src/SPC/builder/linux/library/brotli.php | 51 +------ src/SPC/builder/linux/library/bzip2.php | 35 +---- src/SPC/builder/linux/library/curl.php | 143 +----------------- src/SPC/builder/linux/library/freetype.php | 12 ++ src/SPC/builder/linux/library/gmp.php | 17 +-- src/SPC/builder/linux/library/libavif.php | 12 ++ src/SPC/builder/linux/library/libiconv.php | 41 +---- src/SPC/builder/linux/library/libjpeg.php | 12 ++ src/SPC/builder/linux/library/libpng.php | 4 +- src/SPC/builder/linux/library/libssh2.php | 52 +------ src/SPC/builder/linux/library/libwebp.php | 28 ++++ src/SPC/builder/linux/library/libxml2.php | 31 +--- src/SPC/builder/linux/library/libyaml.php | 85 +---------- src/SPC/builder/linux/library/libzip.php | 98 +----------- src/SPC/builder/linux/library/nghttp2.php | 41 +---- src/SPC/builder/linux/library/onig.php | 40 +---- src/SPC/builder/linux/library/openssl.php | 1 + src/SPC/builder/linux/library/sqlite.php | 39 +---- src/SPC/builder/linux/library/xz.php | 48 +----- src/SPC/builder/linux/library/zlib.php | 38 +---- src/SPC/builder/linux/library/zstd.php | 37 +---- src/SPC/builder/macos/MacOSBuilder.php | 2 +- src/SPC/builder/macos/library/brotli.php | 23 +-- src/SPC/builder/macos/library/bzip2.php | 11 +- src/SPC/builder/macos/library/curl.php | 92 +---------- src/SPC/builder/macos/library/freetype.php | 25 +-- src/SPC/builder/macos/library/gmp.php | 17 +-- src/SPC/builder/macos/library/libavif.php | 28 ++++ src/SPC/builder/macos/library/libiconv.php | 23 +-- src/SPC/builder/macos/library/libjpeg.php | 12 ++ src/SPC/builder/macos/library/libpng.php | 6 +- src/SPC/builder/macos/library/libssh2.php | 46 +----- src/SPC/builder/macos/library/libwebp.php | 28 ++++ src/SPC/builder/macos/library/libxml2.php | 23 +-- src/SPC/builder/macos/library/libyaml.php | 86 +---------- src/SPC/builder/macos/library/libzip.php | 92 +---------- src/SPC/builder/macos/library/nghttp2.php | 1 + src/SPC/builder/macos/library/onig.php | 35 +---- src/SPC/builder/macos/library/openssl.php | 1 + src/SPC/builder/macos/library/sqlite.php | 12 +- src/SPC/builder/macos/library/xz.php | 27 +--- src/SPC/builder/macos/library/zlib.php | 13 +- src/SPC/builder/macos/library/zstd.php | 32 +--- src/SPC/builder/traits/UnixBuilderTrait.php | 15 ++ src/SPC/builder/traits/UnixLibraryTrait.php | 26 ++++ .../builder/traits/UnixSystemUtilTrait.php | 6 + src/SPC/builder/unix/library/brotli.php | 34 +++++ src/SPC/builder/unix/library/bzip2.php | 17 +++ src/SPC/builder/unix/library/curl.php | 54 +++++++ src/SPC/builder/unix/library/freetype.php | 29 ++++ src/SPC/builder/unix/library/gmp.php | 22 +++ src/SPC/builder/unix/library/libavif.php | 28 ++++ src/SPC/builder/unix/library/libiconv.php | 24 +++ src/SPC/builder/unix/library/libjpeg.php | 28 ++++ src/SPC/builder/unix/library/libssh2.php | 30 ++++ src/SPC/builder/unix/library/libwebp.php | 32 ++++ src/SPC/builder/unix/library/libyaml.php | 75 +++++++++ src/SPC/builder/unix/library/libzip.php | 42 +++++ src/SPC/builder/unix/library/onig.php | 25 +++ src/SPC/builder/unix/library/sqlite.php | 17 +++ src/SPC/builder/unix/library/xz.php | 27 ++++ src/SPC/builder/unix/library/zlib.php | 20 +++ src/SPC/builder/unix/library/zstd.php | 26 ++++ src/SPC/store/FileSystem.php | 17 ++- src/SPC/util/ConfigValidator.php | 2 +- src/SPC/util/Patcher.php | 19 ++- src/SPC/util/UnixShell.php | 22 +++ src/globals/defines.php | 7 + 83 files changed, 1001 insertions(+), 1520 deletions(-) delete mode 100644 src/SPC/builder/extension/curl.php create mode 100644 src/SPC/builder/extension/mongodb.php delete mode 100644 src/SPC/builder/extension/openssl.php delete mode 100644 src/SPC/builder/extension/sqlite3.php delete mode 100644 src/SPC/builder/extension/zip.php delete mode 100644 src/SPC/builder/extension/zlib.php create mode 100644 src/SPC/builder/linux/library/freetype.php create mode 100644 src/SPC/builder/linux/library/libavif.php create mode 100644 src/SPC/builder/linux/library/libjpeg.php create mode 100644 src/SPC/builder/linux/library/libwebp.php create mode 100644 src/SPC/builder/macos/library/libavif.php create mode 100644 src/SPC/builder/macos/library/libjpeg.php create mode 100644 src/SPC/builder/macos/library/libwebp.php create mode 100644 src/SPC/builder/unix/library/brotli.php create mode 100644 src/SPC/builder/unix/library/bzip2.php create mode 100644 src/SPC/builder/unix/library/curl.php create mode 100644 src/SPC/builder/unix/library/freetype.php create mode 100644 src/SPC/builder/unix/library/gmp.php create mode 100644 src/SPC/builder/unix/library/libavif.php create mode 100644 src/SPC/builder/unix/library/libiconv.php create mode 100644 src/SPC/builder/unix/library/libjpeg.php create mode 100644 src/SPC/builder/unix/library/libssh2.php create mode 100644 src/SPC/builder/unix/library/libwebp.php create mode 100644 src/SPC/builder/unix/library/libyaml.php create mode 100644 src/SPC/builder/unix/library/libzip.php create mode 100644 src/SPC/builder/unix/library/onig.php create mode 100644 src/SPC/builder/unix/library/sqlite.php create mode 100644 src/SPC/builder/unix/library/xz.php create mode 100644 src/SPC/builder/unix/library/zlib.php create mode 100644 src/SPC/builder/unix/library/zstd.php diff --git a/config/ext.json b/config/ext.json index ceb1ee09..a48c8542 100644 --- a/config/ext.json +++ b/config/ext.json @@ -17,7 +17,7 @@ }, "curl": { "type": "builtin", - "arg-type": "custom", + "arg-type": "with", "lib-depends": [ "curl" ] @@ -69,25 +69,10 @@ "zlib" ], "lib-suggests": [ - "gd", "libavif", "libwebp", "libjpeg", - "xpm", "freetype" - ], - "lib-depends-windows": [ - "libiconv", - "freetype", - "libjpeg", - "zlib", - "libpng", - "xpm" - ], - "lib-suggests-windows": [ - "gd", - "libavif", - "libwebp" ] }, "gettext": { @@ -121,6 +106,10 @@ "kerberos" ] }, + "inotify": { + "type": "external", + "source": "inotify" + }, "intl": { "type": "builtin", "lib-depends": [ @@ -149,7 +138,8 @@ }, "mongodb": { "type": "external", - "source": "mongodb" + "source": "mongodb", + "arg-type": "custom" }, "mysqli": { "type": "builtin", @@ -167,7 +157,7 @@ }, "openssl": { "type": "builtin", - "arg-type": "custom", + "arg-type": "with", "lib-depends": [ "openssl" ] @@ -285,7 +275,7 @@ }, "sqlite3": { "type": "builtin", - "arg-type": "custom", + "arg-type": "with-prefix", "lib-depends": [ "sqlite" ] @@ -305,10 +295,6 @@ ], "unix-only": true }, - "inotify": { - "type": "external", - "source": "inotify" - }, "swow": { "type": "external", "source": "swow", @@ -383,7 +369,7 @@ }, "zip": { "type": "builtin", - "arg-type": "custom", + "arg-type": "with-prefix", "arg-type-windows": "enable", "lib-depends": [ "libzip" diff --git a/config/lib.json b/config/lib.json index 41aa9567..3f5d3a0b 100644 --- a/config/lib.json +++ b/config/lib.json @@ -66,12 +66,6 @@ "SystemConfiguration" ] }, - "postgresql": { - "source": "postgresql", - "static-libs-unix": [ - "libpg.a" - ] - }, "freetype": { "source": "freetype", "static-libs-unix": [ @@ -80,6 +74,14 @@ "headers-unix": [ "freetype2/freetype/freetype.h", "freetype2/ft2build.h" + ], + "lib-depends": [ + "zlib" + ], + "lib-suggests": [ + "libpng", + "bzip2", + "brotli" ] }, "gmp": { @@ -94,6 +96,12 @@ "gmp.h" ] }, + "libavif": { + "source": "libavif", + "static-libs-unix": [ + "libavif.a" + ] + }, "libffi": { "source": "libffi", "static-libs-unix": [ @@ -115,7 +123,8 @@ "libiconv": { "source": "libiconv", "static-libs-unix": [ - "libiconv.a" + "libiconv.a", + "libcharset.a" ], "headers": [ "iconv.h", @@ -123,6 +132,13 @@ "localcharset.h" ] }, + "libjpeg": { + "source": "libjpeg", + "static-libs-unix": [ + "libjpeg.a", + "libturbojpeg.a" + ] + }, "libmcrypt": { "source": "libmcrypt", "static-libs-unix": [ @@ -170,6 +186,16 @@ "zlib" ] }, + "libwebp": { + "source": "libwebp", + "static-libs-unix": [ + "libwebp.a", + "libwebpdecoder.a", + "libwebpdemux.a", + "libwebpmux.a", + "libsharpyuv.a" + ] + }, "libxml2": { "source": "libxml2", "static-libs-unix": [ @@ -257,17 +283,7 @@ "openssl" ], "lib-suggests": [ - "libxml2", - "libev", - "libcares", - "libngtcp2", - "libnghttp3", - "libbpf", - "libevent-openssl", - "jansson", - "jemalloc", - "systemd", - "cunit" + "libxml2" ] }, "onig": { @@ -303,6 +319,12 @@ "zlib" ] }, + "postgresql": { + "source": "postgresql", + "static-libs-unix": [ + "libpg.a" + ] + }, "pthreads4w": { "source": "pthreads4w", "static-libs-windows": [ diff --git a/config/source.json b/config/source.json index 2212c110..58e6adef 100644 --- a/config/source.json +++ b/config/source.json @@ -44,13 +44,6 @@ "path": "LICENSE.TXT" } }, - "postgresql": { - "type": "custom", - "license": { - "type": "file", - "path": "COPYRIGHT" - } - }, "gmp": { "type": "filelist", "url": "https://gmplib.org/download/gmp/", @@ -60,6 +53,24 @@ "text": "Since version 6, GMP is distributed under the dual licenses, GNU LGPL v3 and GNU GPL v2. These licenses make the library free to use, share, and improve, and allow you to pass on the result. The GNU licenses give freedoms, but also set firm restrictions on the use with non-free programs." } }, + "inotify": { + "type": "url", + "url": "http://pecl.php.net/get/inotify", + "path": "php-src/ext/inotify", + "filename": "inotify.tgz", + "license": { + "type": "file", + "path": "LICENSE" + } + }, + "libavif": { + "type": "ghtar", + "repo": "AOMediaCodec/libavif", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "libffi": { "type": "ghrel", "repo": "libffi/libffi", @@ -78,6 +89,14 @@ "path": "COPYING" } }, + "libjpeg": { + "type": "ghtar", + "repo": "libjpeg-turbo/libjpeg-turbo", + "license": { + "type": "file", + "path": "LICENSE.md" + } + }, "libmcrypt": { "type": "url", "url": "https://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz", @@ -121,6 +140,14 @@ "path": "LICENSE" } }, + "libwebp": { + "type": "ghtagtar", + "repo": "webmproject/libwebp", + "license": { + "type": "file", + "path": "COPYING" + } + }, "libxml2": { "type": "url", "url": "https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.9.14/libxml2-v2.9.14.tar.gz", @@ -202,6 +229,20 @@ "path": "LICENSE.txt" } }, + "php-src": { + "type": "custom", + "license": { + "type": "file", + "path": "LICENSE" + } + }, + "postgresql": { + "type": "custom", + "license": { + "type": "file", + "path": "COPYRIGHT" + } + }, "protobuf": { "type": "url", "url": "http://pecl.php.net/get/protobuf", @@ -212,16 +253,6 @@ "path": "LICENSE" } }, - "inotify": { - "type": "url", - "url": "http://pecl.php.net/get/inotify", - "path": "php-src/ext/inotify", - "filename": "inotify.tgz", - "license": { - "type": "file", - "path": "LICENSE" - } - }, "pthreads4w": { "type": "git", "rev": "master", @@ -231,13 +262,6 @@ "path": "LICENSE" } }, - "php-src": { - "type": "custom", - "license": { - "type": "file", - "path": "LICENSE" - } - }, "redis": { "type": "git", "path": "php-src/ext/redis", diff --git a/ext-support.md b/ext-support.md index 5613457a..1f783ae6 100644 --- a/ext-support.md +++ b/ext-support.md @@ -19,35 +19,36 @@ | event | | | | | exif | yes | yes | | | filter | yes | yes | | -| fileinfo | yes | | | +| fileinfo | yes | yes | | | ftp | yes | yes | | -| gd | yes, untested | yes | | +| gd | yes | yes | | | gettext | | | | -| gmp | yes, untested | yes, untested | | -| iconv | yes | | | +| gmp | yes | yes | | +| iconv | yes | yes | | | inotify | yes | yes | | | mbstring | yes | yes | | +| mbregex | yes | yes | | | mcrypt | | [faulty](https://github.com/crazywhalecc/static-php-cli/issues/32) | | -| mongodb | yes, untested | | | -| mysqli | | | | +| mongodb | yes | yes | | +| mysqli | yes | yes | | | mysqlnd | yes | yes | | | openssl | yes | yes | | -| pcntl | yes, untested | yes | | +| pcntl | yes | yes | | | pdo | yes | yes | | | pdo_mysql | yes | yes | | | pdo_sqlite | yes | yes | | | pdo_pgsql | | | | | phar | yes | yes | | | posix | yes | yes | | -| protobuf | yes, untested | | | +| protobuf | yes | yes | | | readline | | | | | redis | yes | yes | | | session | yes | yes | | -| shmop | yes, untested | | | -| simplexml | yes, untested | yes, untested | | -| soap | yes, untested | | | +| shmop | yes | yes | | +| simplexml | yes | yes | | +| soap | yes | yes | | | sockets | yes | yes | | -| sqlite3 | yes, untested | yes, untested | | +| sqlite3 | yes | yes | | | swow | yes | [no](https://github.com/crazywhalecc/static-php-cli/issues/32) | | | swoole | [no](https://github.com/crazywhalecc/static-php-cli/issues/32) | [partial](https://github.com/crazywhalecc/static-php-cli/issues/32) | | | tokenizer | yes | yes | | @@ -56,6 +57,7 @@ | xmlwriter | yes, untested | yes, untested | | | zip | yes, untested | yes | | | zlib | yes | yes | | +| zstd | yes | yes | | ## Additional Requirements @@ -72,6 +74,24 @@ Here are some extension list example for different use. - For static-php-cli self (with dev dependencies): `"posix,pcntl,phar,tokenizer,iconv,zlib,xml,dom,xmlwriter,xmlreader,fileinfo"` - Minimum, with no extension: `""` +Compile with all supported extensions (exclude `swow`, `swoole` due to c++ extension): + +```bash +bin/spc build --build-all bcmath,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,mbregex,mbstring,mongodb,mysqli,mysqlnd,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,protobuf,redis,session,shmop,simplexml,soap,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,yaml,zip,zlib,zstd --with-libs=libjpeg,freetype,libwebp,libavif --debug +``` + +## Additional Libraries + +Some extensions have soft dependencies, you can enable extra features by adding these libs using `--with-libs`. + +For example, to compile with gd extension, with `libwebp, libgif, libavif, libjpeg, freetype` extra features: + +```bash +bin/spc build gd --with-libs=libjpeg,freetype,libwebp,libavif --build-cli +``` + +> If you don't add them, your compilation will not enable these features. + ## Limitations - swow and swoole cannot be compiled at the same time. diff --git a/src/SPC/builder/extension/curl.php b/src/SPC/builder/extension/curl.php deleted file mode 100644 index e7805ff3..00000000 --- a/src/SPC/builder/extension/curl.php +++ /dev/null @@ -1,18 +0,0 @@ -getLibFilesString() . '"'; - } -} diff --git a/src/SPC/builder/extension/gd.php b/src/SPC/builder/extension/gd.php index b1efe170..707a898f 100644 --- a/src/SPC/builder/extension/gd.php +++ b/src/SPC/builder/extension/gd.php @@ -13,13 +13,10 @@ class gd extends Extension public function getUnixConfigureArg(): string { $arg = '--enable-gd'; - if ($this->builder->getLib('freetype')) { - $arg .= ' --with-freetype ' . - 'FREETYPE2_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '/freetype2" ' . - 'FREETYPE2_LIBS="' . $this->getLibFilesString() . '"'; - } - $arg .= ' PNG_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' . - 'PNG_LIBS="' . $this->getLibFilesString() . '"'; + $arg .= $this->builder->getLib('freetype') ? ' --with-freetype' : ''; + $arg .= $this->builder->getLib('libjpeg') ? ' --with-jpeg' : ''; + $arg .= $this->builder->getLib('libwebp') ? ' --with-webp' : ''; + $arg .= $this->builder->getLib('libavif') ? ' --with-avif' : ''; return $arg; } } diff --git a/src/SPC/builder/extension/mbstring.php b/src/SPC/builder/extension/mbstring.php index 72614830..058483a5 100644 --- a/src/SPC/builder/extension/mbstring.php +++ b/src/SPC/builder/extension/mbstring.php @@ -16,6 +16,6 @@ class mbstring extends Extension if ($this->builder->getExt('mbregex') === null) { $arg .= ' --disable-mbregex'; } - return $arg . ' ONIG_CFLAGS=-I"' . BUILD_ROOT_PATH . '" ONIG_LIBS="' . $this->getLibFilesString() . '"'; + return $arg; } } diff --git a/src/SPC/builder/extension/mongodb.php b/src/SPC/builder/extension/mongodb.php new file mode 100644 index 00000000..843ee39b --- /dev/null +++ b/src/SPC/builder/extension/mongodb.php @@ -0,0 +1,17 @@ +getLibFilesString() . '" '; - } -} diff --git a/src/SPC/builder/extension/sqlite3.php b/src/SPC/builder/extension/sqlite3.php deleted file mode 100644 index c4623f63..00000000 --- a/src/SPC/builder/extension/sqlite3.php +++ /dev/null @@ -1,19 +0,0 @@ -getLibFilesString() . '"'; - } -} diff --git a/src/SPC/builder/extension/xml.php b/src/SPC/builder/extension/xml.php index 1110d783..adac92c8 100644 --- a/src/SPC/builder/extension/xml.php +++ b/src/SPC/builder/extension/xml.php @@ -30,9 +30,7 @@ class xml extends Extension 'simplexml' => '--enable-simplexml', default => throw new RuntimeException('Not accept non-xml extension'), }; - $arg .= ' --with-libxml="' . BUILD_ROOT_PATH . '" ' . - 'LIBXML_CFLAGS=-I"' . realpath('include/libxml2') . '" ' . - 'LIBXML_LIBS="' . $this->getLibFilesString() . '" '; + $arg .= ' --with-libxml="' . BUILD_ROOT_PATH . '"'; return $arg; } } diff --git a/src/SPC/builder/extension/zip.php b/src/SPC/builder/extension/zip.php deleted file mode 100644 index d259441f..00000000 --- a/src/SPC/builder/extension/zip.php +++ /dev/null @@ -1,18 +0,0 @@ -getLibFilesString() . '"'; - } -} diff --git a/src/SPC/builder/extension/zlib.php b/src/SPC/builder/extension/zlib.php deleted file mode 100644 index ed0ff4f1..00000000 --- a/src/SPC/builder/extension/zlib.php +++ /dev/null @@ -1,18 +0,0 @@ -getLibFilesString() . '"'; - } -} diff --git a/src/SPC/builder/extension/zstd.php b/src/SPC/builder/extension/zstd.php index 6ea6ee65..13311979 100644 --- a/src/SPC/builder/extension/zstd.php +++ b/src/SPC/builder/extension/zstd.php @@ -12,6 +12,6 @@ class zstd extends Extension { public function getUnixConfigureArg(): string { - return '--with-libzstd'; + return '--enable-zstd --with-libzstd="' . BUILD_ROOT_PATH . '"'; } } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index a70e324d..12e458c7 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -183,8 +183,6 @@ class LinuxBuilder extends BuilderBase $envs ); - $extra_libs .= $this->generateExtraLibs(); - file_put_contents('/tmp/comment', $this->note_section); // 清理 @@ -274,7 +272,9 @@ class LinuxBuilder extends BuilderBase } /** - * @throws RuntimeException + * 构建 fpm + * + * @throws FileSystemException|RuntimeException */ public function buildFpm(string $extra_libs, string $use_lld): void { @@ -295,40 +295,4 @@ class LinuxBuilder extends BuilderBase ->exec("{$this->cross_compile_prefix}objcopy --update-section .comment=/tmp/comment --add-gnu-debuglink=php-fpm.debug --remove-section=.note php-fpm"); $this->deployBinary(BUILD_TARGET_FPM); } - - /** - * @throws RuntimeException - */ - private function generateExtraLibs(): string - { - if ($this->libc === 'glibc') { - $glibc_libs = [ - 'rt', - 'm', - 'c', - 'pthread', - 'dl', - 'nsl', - 'anl', - // 'crypt', - 'resolv', - 'util', - ]; - $makefile = file_get_contents(SOURCE_PATH . '/php-src/Makefile'); - preg_match('/^EXTRA_LIBS\s*=\s*(.*)$/m', $makefile, $matches); - if (!$matches) { - throw new RuntimeException('failed to find EXTRA_LIBS in Makefile'); - } - $_extra_libs = []; - foreach (array_filter(explode(' ', $matches[1])) as $used) { - foreach ($glibc_libs as $libName) { - if ("-l{$libName}" === $used && !in_array("-l{$libName}", $_extra_libs, true)) { - array_unshift($_extra_libs, "-l{$libName}"); - } - } - } - return ' ' . implode(' ', $_extra_libs); - } - return ''; - } } diff --git a/src/SPC/builder/linux/library/brotli.php b/src/SPC/builder/linux/library/brotli.php index 44338f60..ff93913d 100644 --- a/src/SPC/builder/linux/library/brotli.php +++ b/src/SPC/builder/linux/library/brotli.php @@ -1,59 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class brotli extends LinuxLibraryBase { - public const NAME = 'brotli'; + use \SPC\builder\unix\library\brotli; - /** - * @throws RuntimeException - */ - public function build() - { - [$lib, $include, $destdir] = SEPARATED_PATH; - // 清理旧的编译文件 - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build'); - // 使用 cmake 编译 - shell()->cd($this->source_dir . '/build') - ->exec( - $this->builder->configure_env . ' cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency} --target brotlicommon-static") - ->exec("cmake --build . -j {$this->builder->concurrency} --target brotlidec-static") - ->exec("cmake --build . -j {$this->builder->concurrency} --target brotlienc-static") - ->exec('cp libbrotlidec-static.a ' . BUILD_LIB_PATH) - ->exec('cp libbrotlienc-static.a ' . BUILD_LIB_PATH) - ->exec('cp libbrotlicommon-static.a ' . BUILD_LIB_PATH) - ->exec('cp -r ../c/include/brotli ' . BUILD_INCLUDE_PATH); - } + public const NAME = 'brotli'; } diff --git a/src/SPC/builder/linux/library/bzip2.php b/src/SPC/builder/linux/library/bzip2.php index b6c6acf9..14385512 100644 --- a/src/SPC/builder/linux/library/bzip2.php +++ b/src/SPC/builder/linux/library/bzip2.php @@ -1,43 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class bzip2 extends LinuxLibraryBase { + use \SPC\builder\unix\library\bzip2; + public const NAME = 'bzip2'; - - protected array $dep_names = []; - - /** - * @throws RuntimeException - */ - public function build() - { - shell() - ->cd($this->source_dir) - ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->exec("make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") - ->exec('cp libbz2.a ' . BUILD_LIB_PATH) - ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); - } } diff --git a/src/SPC/builder/linux/library/curl.php b/src/SPC/builder/linux/library/curl.php index 22bdca6f..d45492c4 100644 --- a/src/SPC/builder/linux/library/curl.php +++ b/src/SPC/builder/linux/library/curl.php @@ -1,64 +1,15 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class curl extends LinuxLibraryBase { + use \SPC\builder\unix\library\curl; + public const NAME = 'curl'; - protected array $static_libs = ['libcurl.a']; - - protected array $headers = ['curl']; - - protected array $pkgconfs = [ - 'libcurl.pc' => <<<'EOF' -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include -supported_protocols="DICT FILE FTP FTPS GOPHER GOPHERS HTTP HTTPS IMAP IMAPS MQTT POP3 POP3S RTSP SCP SFTP SMB SMBS SMTP SMTPS TELNET TFTP" -supported_features="AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets alt-svc brotli libz zstd" - -Name: libcurl -URL: https://curl.se/ -Description: Library to transfer files with ftp, http, etc. -Version: 7.83.0 -Libs: -L${libdir} -lcurl -Libs.private: -lnghttp2 -lidn2 -lssh2 -lssh2 -lpsl -lssl -lcrypto -lssl -lcrypto -lgssapi_krb5 -lzstd -lbrotlidec -lz -Cflags: -I${includedir} -EOF - ]; - - protected array $dep_names = [ - 'zlib' => false, - 'libssh2' => true, - 'brotli' => true, - 'nghttp2' => true, - 'zstd' => true, - 'openssl' => true, - 'idn2' => true, - 'psl' => true, - ]; - public function getStaticLibFiles(string $style = 'autoconf', bool $recursive = true): string { $libs = parent::getStaticLibFiles($style, $recursive); @@ -67,94 +18,4 @@ EOF } return $libs; } - - /** - * @throws RuntimeException - */ - public function build() - { - $extra = ''; - // lib:openssl - $openssl = $this->builder->getLib('openssl'); - $use_openssl = $openssl instanceof LinuxLibraryBase ? 'ON' : 'OFF'; - $extra .= "-DCURL_USE_OPENSSL={$use_openssl} -DCURL_ENABLE_SSL={$use_openssl} "; - // lib:zlib - $zlib = $this->builder->getLib('zlib'); - if ($zlib instanceof LinuxLibraryBase) { - $extra .= '-DZLIB_LIBRARY="' . $zlib->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZLIB_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } - // lib:libssh2 - $libssh2 = $this->builder->getLib('libssh2'); - if ($libssh2 instanceof LinuxLibraryBase) { - $extra .= '-DLIBSSH2_LIBRARY="' . $libssh2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DLIBSSH2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_USE_LIBSSH2=OFF '; - } - // lib:brotli - $brotli = $this->builder->getLib('brotli'); - if ($brotli) { - $extra .= '-DCURL_BROTLI=ON ' . - '-DBROTLIDEC_LIBRARY="' . realpath(BUILD_LIB_PATH . '/libbrotlidec-static.a') . ';' . realpath(BUILD_LIB_PATH . '/libbrotlicommon-static.a') . '" ' . - '-DBROTLICOMMON_LIBRARY="' . realpath(BUILD_LIB_PATH . '/libbrotlicommon-static.a') . '" ' . - '-DBROTLI_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_BROTLI=OFF '; - } - // lib:nghttp2 - $nghttp2 = $this->builder->getLib('nghttp2'); - if ($nghttp2 instanceof LinuxLibraryBase) { - $extra .= '-DUSE_NGHTTP2=ON ' . - '-DNGHTTP2_LIBRARY="' . $nghttp2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DNGHTTP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DUSE_NGHTTP2=OFF '; - } - // lib:ldap - $ldap = $this->builder->getLib('ldap'); - if ($ldap instanceof LinuxLibraryBase) { - // $extra .= '-DCURL_DISABLE_LDAP=OFF '; - // TODO: LDAP support - throw new RuntimeException('LDAP support is not implemented yet'); - } - $extra .= '-DCURL_DISABLE_LDAP=ON '; - // lib:zstd - $zstd = $this->builder->getLib('zstd'); - if ($zstd instanceof LinuxLibraryBase) { - $extra .= '-DCURL_ZSTD=ON ' . - '-DZstd_LIBRARY="' . $zstd->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZstd_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_ZSTD=OFF '; - } - // lib:idn2 - $idn2 = $this->builder->getLib('idn2'); - $extra .= $idn2 instanceof LinuxLibraryBase ? '-DUSE_LIBIDN2=ON ' : '-DUSE_LIBIDN2=OFF '; - // lib:psl - $libpsl = $this->builder->getLib('psl'); - $extra .= $libpsl instanceof LinuxLibraryBase ? '-DCURL_USE_LIBPSL=ON ' : '-DCURL_USE_LIBPSL=OFF '; - - [$lib, $include, $destdir] = SEPARATED_PATH; - // compile! - shell() - ->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec("{$this->builder->configure_env} cmake " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_CURL_EXE=OFF ' . - $extra . - "-DCMAKE_INSTALL_PREFIX={$destdir} " . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR='{$destdir}'"); - shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/') - ->exec("sed -ie 's|\"/lib/libcurl.a\"|\"" . BUILD_LIB_PATH . "/libcurl.a\"|g' CURLTargets-release.cmake"); - } } diff --git a/src/SPC/builder/linux/library/freetype.php b/src/SPC/builder/linux/library/freetype.php new file mode 100644 index 00000000..a653d247 --- /dev/null +++ b/src/SPC/builder/linux/library/freetype.php @@ -0,0 +1,12 @@ +cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static --disable-shared ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/linux/library/libavif.php b/src/SPC/builder/linux/library/libavif.php new file mode 100644 index 00000000..410d549d --- /dev/null +++ b/src/SPC/builder/linux/library/libavif.php @@ -0,0 +1,12 @@ + - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class libiconv extends LinuxLibraryBase { + use \SPC\builder\unix\library\libiconv; + public const NAME = 'libiconv'; - - protected array $dep_names = []; - - /** - * @throws RuntimeException - */ - public function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static ' . - '--disable-shared ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec('make install DESTDIR=' . $destdir); - } } diff --git a/src/SPC/builder/linux/library/libjpeg.php b/src/SPC/builder/linux/library/libjpeg.php new file mode 100644 index 00000000..110bdeb9 --- /dev/null +++ b/src/SPC/builder/linux/library/libjpeg.php @@ -0,0 +1,12 @@ +builder->arch) { 'x86_64' => '--enable-intel-sse ', 'arm64' => '--enable-arm-neon ', @@ -52,7 +51,7 @@ class libpng extends LinuxLibraryBase '--disable-shared ' . '--enable-static ' . '--enable-hardware-optimizations ' . - '--with-zlib-prefix=' . BUILD_ROOT_PATH . ' ' . + '--with-zlib-prefix="' . BUILD_ROOT_PATH . '" ' . $optimizations . '--prefix=' ) @@ -61,5 +60,6 @@ class libpng extends LinuxLibraryBase ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH) ->cd(BUILD_LIB_PATH) ->exec('ln -sf libpng16.a libpng.a'); + $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/linux/library/libssh2.php b/src/SPC/builder/linux/library/libssh2.php index eb912c48..cec5ab9f 100644 --- a/src/SPC/builder/linux/library/libssh2.php +++ b/src/SPC/builder/linux/library/libssh2.php @@ -1,60 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class libssh2 extends LinuxLibraryBase { + use \SPC\builder\unix\library\libssh2; + public const NAME = 'libssh2'; - - /** - * @throws RuntimeException - */ - public function build() - { - // lib:zlib - $enable_zlib = $this->builder->getLib('zlib') !== null ? 'ON' : 'OFF'; - - [$lib, $include, $destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - "{$this->builder->configure_env} " . ' cmake ' . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_EXAMPLES=OFF ' . - '-DBUILD_TESTING=OFF ' . - "-DENABLE_ZLIB_COMPRESSION={$enable_zlib} " . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency} --target libssh2") - ->exec('make install DESTDIR="' . $destdir . '"'); - } } diff --git a/src/SPC/builder/linux/library/libwebp.php b/src/SPC/builder/linux/library/libwebp.php new file mode 100644 index 00000000..d376e341 --- /dev/null +++ b/src/SPC/builder/linux/library/libwebp.php @@ -0,0 +1,28 @@ + + * + * lwmbs is licensed under Mulan PSL v2. You can use this + * software according to the terms and conditions of the + * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +declare(strict_types=1); + +namespace SPC\builder\linux\library; + +class libwebp extends LinuxLibraryBase +{ + use \SPC\builder\unix\library\libwebp; + + public const NAME = 'libwebp'; +} diff --git a/src/SPC/builder/linux/library/libxml2.php b/src/SPC/builder/linux/library/libxml2.php index 28183892..0389b3ea 100644 --- a/src/SPC/builder/linux/library/libxml2.php +++ b/src/SPC/builder/linux/library/libxml2.php @@ -1,20 +1,4 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); @@ -38,14 +22,11 @@ class libxml2 extends LinuxLibraryBase [$lib, $include, $destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') + FileSystem::resetDir($this->source_dir . '/build'); + shell()->cd($this->source_dir . '/build') ->exec( "{$this->builder->configure_env} " . ' cmake ' . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . + "{$this->builder->makeCmakeArgs()} " . '-DBUILD_SHARED_LIBS=OFF ' . '-DLIBXML2_WITH_ICONV=ON ' . '-DIconv_IS_BUILT_IN=OFF ' . @@ -55,14 +36,10 @@ class libxml2 extends LinuxLibraryBase '-DLIBXML2_WITH_PYTHON=OFF ' . '-DLIBXML2_WITH_PROGRAMS=OFF ' . '-DLIBXML2_WITH_TESTS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . '..' ) ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec('make install DESTDIR="' . $destdir . '"'); + ->exec("make install DESTDIR={$destdir}"); if (is_dir(BUILD_INCLUDE_PATH . '/libxml2/libxml')) { if (is_dir(BUILD_INCLUDE_PATH . '/libxml')) { diff --git a/src/SPC/builder/linux/library/libyaml.php b/src/SPC/builder/linux/library/libyaml.php index 7679bac0..a17cabc6 100644 --- a/src/SPC/builder/linux/library/libyaml.php +++ b/src/SPC/builder/linux/library/libyaml.php @@ -1,93 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class libyaml extends LinuxLibraryBase { + use \SPC\builder\unix\library\libyaml; + public const NAME = 'libyaml'; - - /** - * @throws RuntimeException - */ - public function build() - { - // prepare cmake/config.h.in - if (!is_file(SOURCE_PATH . '/libyaml/cmake/config.h.in')) { - f_mkdir(SOURCE_PATH . '/libyaml/cmake'); - file_put_contents( - SOURCE_PATH . '/libyaml/cmake/config.h.in', - <<<'EOF' -#define YAML_VERSION_MAJOR @YAML_VERSION_MAJOR@ -#define YAML_VERSION_MINOR @YAML_VERSION_MINOR@ -#define YAML_VERSION_PATCH @YAML_VERSION_PATCH@ -#define YAML_VERSION_STRING "@YAML_VERSION_STRING@" -EOF - ); - } - - // prepare yamlConfig.cmake.in - if (!is_file(SOURCE_PATH . '/libyaml/yamlConfig.cmake.in')) { - file_put_contents( - SOURCE_PATH . '/libyaml/yamlConfig.cmake.in', - <<<'EOF' -# Config file for the yaml library. -# -# It defines the following variables: -# yaml_LIBRARIES - libraries to link against - -@PACKAGE_INIT@ - -set_and_check(yaml_TARGETS "@PACKAGE_CONFIG_DIR_CONFIG@/yamlTargets.cmake") - -if(NOT yaml_TARGETS_IMPORTED) - set(yaml_TARGETS_IMPORTED 1) - include(${yaml_TARGETS}) -endif() - -set(yaml_LIBRARIES yaml) - -EOF - ); - } - - [$lib, $include, $destdir] = SEPARATED_PATH; - - shell() - ->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec("{$this->builder->configure_env} cmake " . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_TESTING=OFF ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/linux/library/libzip.php b/src/SPC/builder/linux/library/libzip.php index 650f9e83..13f2e857 100644 --- a/src/SPC/builder/linux/library/libzip.php +++ b/src/SPC/builder/linux/library/libzip.php @@ -1,106 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\FileSystemException; -use SPC\exception\RuntimeException; - class libzip extends LinuxLibraryBase { + use \SPC\builder\unix\library\libzip; + public const NAME = 'libzip'; - - /** - * @throws FileSystemException|RuntimeException - */ - public function build() - { - $extra = ''; - // lib:zlib - $zlib = $this->builder->getLib('zlib'); - if ($zlib instanceof LinuxLibraryBase) { - $extra .= '-DZLIB_LIBRARY="' . $zlib->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZLIB_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } - // lib:bzip2 - $libbzip2 = $this->builder->getLib('bzip2'); - if ($libbzip2 instanceof LinuxLibraryBase) { - $extra .= '-DENABLE_BZIP2=ON ' . - '-DBZIP2_LIBRARIES="' . $libbzip2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DBZIP2_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } else { - $extra .= '-DENABLE_BZIP2=OFF '; - } - // lib:xz - $xz = $this->builder->getLib('xz'); - if ($xz instanceof LinuxLibraryBase) { - $extra .= '-DENABLE_LZMA=ON ' . - '-DLIBLZMA_LIBRARY="' . $xz->getStaticLibFiles(style: 'cmake') . '" ' . - '-DLIBLZMA_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } else { - $extra .= '-DENABLE_LZMA=OFF '; - } - // lib:zstd - $libzstd = $this->builder->getLib('zstd'); - if ($libzstd instanceof LinuxLibraryBase) { - $extra .= '-DENABLE_ZSTD=ON ' . - '-DZstd_LIBRARY="' . $libzstd->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZstd_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DENABLE_ZSTD=OFF '; - } - // lib:openssl - $libopenssl = $this->builder->getLib('openssl'); - if ($libopenssl instanceof LinuxLibraryBase) { - $extra .= '-DENABLE_OPENSSL=ON ' . - '-DOpenSSL_LIBRARY="' . $libopenssl->getStaticLibFiles(style: 'cmake') . '" ' . - '-DOpenSSL_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DENABLE_OPENSSL=OFF '; - } - - [$lib, $include, $destdir] = SEPARATED_PATH; - - shell() - ->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - $this->builder->configure_env . ' cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DENABLE_GNUTLS=OFF ' . - '-DENABLE_MBEDTLS=OFF ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_DOC=OFF ' . - '-DBUILD_EXAMPLES=OFF ' . - '-DBUILD_REGRESS=OFF ' . - '-DBUILD_TOOLS=OFF ' . - $extra . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("make -j{$this->builder->concurrency}") - ->exec('make install DESTDIR=' . $destdir); - } } diff --git a/src/SPC/builder/linux/library/nghttp2.php b/src/SPC/builder/linux/library/nghttp2.php index badba1d6..733b562d 100644 --- a/src/SPC/builder/linux/library/nghttp2.php +++ b/src/SPC/builder/linux/library/nghttp2.php @@ -20,50 +20,10 @@ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class nghttp2 extends LinuxLibraryBase { public const NAME = 'nghttp2'; - protected array $static_libs = ['libnghttp2.a']; - - protected array $headers = ['nghttp2']; - - protected array $pkgconfs = [ - 'libnghttp2.pc' => <<<'EOF' -exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${prefix}/include - -Name: libnghttp2 -Description: HTTP/2 C library -URL: https://github.com/tatsuhiro-t/nghttp2 -Version: 1.47.0 -Libs: -L${libdir} -lnghttp2 -Cflags: -I${includedir} -EOF - ]; - - protected array $dep_names = [ - 'zlib' => false, - 'openssl' => false, - 'libxml2' => true, - 'libev' => true, - 'libcares' => true, - 'libngtcp2' => true, - 'libnghttp3' => true, - 'libbpf' => true, - 'libevent-openssl' => true, - 'jansson' => true, - 'jemalloc' => true, - 'systemd' => true, - 'cunit' => true, - ]; - - /** - * @throws RuntimeException - */ public function build() { $args = $this->builder->makeAutoconfArgs(static::NAME, [ @@ -98,5 +58,6 @@ EOF ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec("make install DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['libnghttp2.pc']); } } diff --git a/src/SPC/builder/linux/library/onig.php b/src/SPC/builder/linux/library/onig.php index 45cf3d63..1c2b45e0 100644 --- a/src/SPC/builder/linux/library/onig.php +++ b/src/SPC/builder/linux/library/onig.php @@ -1,48 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class onig extends LinuxLibraryBase { + use \SPC\builder\unix\library\onig; + public const NAME = 'onig'; - - /** - * @throws RuntimeException - */ - public function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static ' . - '--disable-shared ' . - "--host={$this->builder->arch}-unknown-linux " . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index 4296e11e..d5cfa7cb 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -73,5 +73,6 @@ class openssl extends LinuxLibraryBase ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make install_sw DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); } } diff --git a/src/SPC/builder/linux/library/sqlite.php b/src/SPC/builder/linux/library/sqlite.php index 44afc7ac..65b65072 100644 --- a/src/SPC/builder/linux/library/sqlite.php +++ b/src/SPC/builder/linux/library/sqlite.php @@ -1,47 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class sqlite extends LinuxLibraryBase { + use \SPC\builder\unix\library\sqlite; + public const NAME = 'sqlite'; - - /** - * @throws RuntimeException - */ - public function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static ' . - '--disable-shared ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/linux/library/xz.php b/src/SPC/builder/linux/library/xz.php index 552ad078..11f57233 100644 --- a/src/SPC/builder/linux/library/xz.php +++ b/src/SPC/builder/linux/library/xz.php @@ -1,56 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class xz extends LinuxLibraryBase { + use \SPC\builder\unix\library\xz; + public const NAME = 'xz'; - - /** - * @throws RuntimeException - */ - public function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - // ->exec('autoreconf -i --force') - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static ' . - '--disable-shared ' . - "--host={$this->builder->gnu_arch}-unknown-linux " . - '--disable-xz ' . - '--disable-xzdec ' . - '--disable-lzmadec ' . - '--disable-lzmainfo ' . - '--disable-scripts ' . - '--disable-doc ' . - '--with-libiconv ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/linux/library/zlib.php b/src/SPC/builder/linux/library/zlib.php index fcc32c05..6b7d76a2 100644 --- a/src/SPC/builder/linux/library/zlib.php +++ b/src/SPC/builder/linux/library/zlib.php @@ -1,46 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class zlib extends LinuxLibraryBase { + use \SPC\builder\unix\library\zlib; + public const NAME = 'zlib'; - - /** - * @throws RuntimeException - */ - public function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--static ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/linux/library/zstd.php b/src/SPC/builder/linux/library/zstd.php index e5a8dad5..f1787a84 100644 --- a/src/SPC/builder/linux/library/zstd.php +++ b/src/SPC/builder/linux/library/zstd.php @@ -1,45 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\linux\library; -use SPC\exception\RuntimeException; - class zstd extends LinuxLibraryBase { - public const NAME = 'zstd'; + use \SPC\builder\unix\library\zstd; - /** - * @throws RuntimeException - */ - public function build() - { - shell()->cd($this->source_dir) - ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->exec( - "make -j{$this->builder->concurrency} " . - "{$this->builder->configure_env} " . - "PREFIX='" . BUILD_ROOT_PATH . "' " . - '-C lib libzstd.a CPPFLAGS_STATLIB=-DZSTD_MULTITHREAD' - ) - ->exec('cp lib/libzstd.a ' . BUILD_LIB_PATH) - ->exec('cp lib/zdict.h lib/zstd_errors.h lib/zstd.h ' . BUILD_INCLUDE_PATH); - } + public const NAME = 'zstd'; } diff --git a/src/SPC/builder/macos/MacOSBuilder.php b/src/SPC/builder/macos/MacOSBuilder.php index 3c29f00d..05eee63f 100644 --- a/src/SPC/builder/macos/MacOSBuilder.php +++ b/src/SPC/builder/macos/MacOSBuilder.php @@ -77,7 +77,7 @@ class MacOSBuilder extends BuilderBase $prefix = $arr[1] ?? null; if ($lib instanceof MacOSLibraryBase) { logger()->info("{$name} \033[32;1mwith\033[0;1m {$libName} support"); - $ret .= $lib->makeAutoconfEnv($prefix) . ' '; + $ret .= '--with-' . $libName . '=yes '; } else { logger()->info("{$name} \033[31;1mwithout\033[0;1m {$libName} support"); $ret .= ($disableArgs ?? "--with-{$libName}=no") . ' '; diff --git a/src/SPC/builder/macos/library/brotli.php b/src/SPC/builder/macos/library/brotli.php index 1ff7efeb..75b68fbc 100644 --- a/src/SPC/builder/macos/library/brotli.php +++ b/src/SPC/builder/macos/library/brotli.php @@ -22,26 +22,7 @@ namespace SPC\builder\macos\library; class brotli extends MacOSLibraryBase { - public const NAME = 'brotli'; + use \SPC\builder\unix\library\brotli; - protected function build() - { - [$lib, $include, $destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - "{$this->builder->configure_env} cmake " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } + public const NAME = 'brotli'; } diff --git a/src/SPC/builder/macos/library/bzip2.php b/src/SPC/builder/macos/library/bzip2.php index 824cc6df..bd44e0bc 100644 --- a/src/SPC/builder/macos/library/bzip2.php +++ b/src/SPC/builder/macos/library/bzip2.php @@ -22,14 +22,7 @@ namespace SPC\builder\macos\library; class bzip2 extends MacOSLibraryBase { - public const NAME = 'bzip2'; + use \SPC\builder\unix\library\bzip2; - protected function build() - { - shell()->cd($this->source_dir) - ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->exec("make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") - ->exec('cp libbz2.a ' . BUILD_LIB_PATH) - ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); - } + public const NAME = 'bzip2'; } diff --git a/src/SPC/builder/macos/library/curl.php b/src/SPC/builder/macos/library/curl.php index 45ec30e4..9c63fdc5 100644 --- a/src/SPC/builder/macos/library/curl.php +++ b/src/SPC/builder/macos/library/curl.php @@ -20,97 +20,19 @@ declare(strict_types=1); namespace SPC\builder\macos\library; -use SPC\exception\RuntimeException; +use SPC\util\Patcher; class curl extends MacOSLibraryBase { + use \SPC\builder\unix\library\curl { + build as unixBuild; + } + public const NAME = 'curl'; protected function build() { - $extra = ''; - // lib:openssl - $openssl = $this->getBuilder()->getLib('openssl'); - if ($openssl instanceof MacOSLibraryBase) { - $extra .= '-DCURL_USE_OPENSSL=ON '; - } else { - $extra .= '-DCURL_USE_OPENSSL=OFF -DCURL_ENABLE_SSL=OFF '; - } - // lib:zlib - $zlib = $this->getBuilder()->getLib('zlib'); - if ($zlib instanceof MacOSLibraryBase) { - $extra .= '-DZLIB_LIBRARY="' . $zlib->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZLIB_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } - // lib:libssh2 - $libssh2 = $this->builder->getLib('libssh2'); - if ($libssh2 instanceof MacOSLibraryBase) { - $extra .= '-DLIBSSH2_LIBRARY="' . $libssh2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DLIBSSH2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_USE_LIBSSH2=OFF '; - } - // lib:brotli - $brotli = $this->builder->getLib('brotli'); - if ($brotli) { - $extra .= '-DCURL_BROTLI=ON ' . - '-DBROTLIDEC_LIBRARY="' . realpath(BUILD_LIB_PATH . '/libbrotlidec-static.a') . ';' . realpath(BUILD_LIB_PATH . '/libbrotlicommon-static.a') . '" ' . - '-DBROTLICOMMON_LIBRARY="' . realpath(BUILD_LIB_PATH . '/libbrotlicommon-static.a') . '" ' . - '-DBROTLI_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_BROTLI=OFF '; - } - // lib:nghttp2 - $nghttp2 = $this->builder->getLib('nghttp2'); - if ($nghttp2 instanceof MacOSLibraryBase) { - $extra .= '-DUSE_NGHTTP2=ON ' . - '-DNGHTTP2_LIBRARY="' . $nghttp2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DNGHTTP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DUSE_NGHTTP2=OFF '; - } - // lib:ldap - $ldap = $this->builder->getLib('ldap'); - if ($ldap instanceof MacOSLibraryBase) { - // $extra .= '-DCURL_DISABLE_LDAP=OFF '; - // TODO: LDAP support - throw new RuntimeException('LDAP support is not implemented yet'); - } - $extra .= '-DCURL_DISABLE_LDAP=ON '; - // lib:zstd - $zstd = $this->builder->getLib('zstd'); - if ($zstd instanceof MacOSLibraryBase) { - $extra .= '-DCURL_ZSTD=ON ' . - '-DZstd_LIBRARY="' . $zstd->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZstd_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DCURL_ZSTD=OFF '; - } - // lib:idn2 - $idn2 = $this->builder->getLib('idn2'); - $extra .= $idn2 instanceof MacOSLibraryBase ? '-DUSE_LIBIDN2=ON ' : '-DUSE_LIBIDN2=OFF '; - // lib:psl - $libpsl = $this->builder->getLib('psl'); - $extra .= $libpsl instanceof MacOSLibraryBase ? '-DCURL_USE_LIBPSL=ON ' : '-DCURL_USE_LIBPSL=OFF '; - - [$lib, $include, $destdir] = SEPARATED_PATH; - // compile! - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - "{$this->builder->configure_env} cmake " . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - $extra . - '-DCMAKE_INSTALL_PREFIX= ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); + Patcher::patchCurlMacOS(); + $this->unixBuild(); } } diff --git a/src/SPC/builder/macos/library/freetype.php b/src/SPC/builder/macos/library/freetype.php index 45da3140..ee1600ec 100644 --- a/src/SPC/builder/macos/library/freetype.php +++ b/src/SPC/builder/macos/library/freetype.php @@ -9,28 +9,7 @@ namespace SPC\builder\macos\library; */ class freetype extends MacOSLibraryBase { + use \SPC\builder\unix\library\freetype; + public const NAME = 'freetype'; - - protected function build() - { - [,,$destdir] = SEPARATED_PATH; - - $suggested = ''; - $suggested .= ($this->builder->getLib('libpng') instanceof MacOSLibraryBase) ? ('--with-png=' . BUILD_ROOT_PATH) : '--without-png'; - $suggested .= ' '; - $suggested .= ($this->builder->getLib('bzip2') instanceof MacOSLibraryBase) ? ('--with-bzip2=' . BUILD_ROOT_PATH) : '--without-bzip2'; - $suggested .= ' '; - $suggested .= ($this->builder->getLib('brotli') instanceof MacOSLibraryBase) ? ('--with-brotli=' . BUILD_ROOT_PATH) : '--without-brotli'; - $suggested .= ' '; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static --disable-shared --without-harfbuzz --prefix= ' . - $suggested - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/gmp.php b/src/SPC/builder/macos/library/gmp.php index edef5560..f75d0bbd 100644 --- a/src/SPC/builder/macos/library/gmp.php +++ b/src/SPC/builder/macos/library/gmp.php @@ -9,20 +9,7 @@ namespace SPC\builder\macos\library; */ class gmp extends MacOSLibraryBase { + use \SPC\builder\unix\library\gmp; + public const NAME = 'gmp'; - - protected function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static --disable-shared ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/libavif.php b/src/SPC/builder/macos/library/libavif.php new file mode 100644 index 00000000..74b84b6a --- /dev/null +++ b/src/SPC/builder/macos/library/libavif.php @@ -0,0 +1,28 @@ + + * + * lwmbs is licensed under Mulan PSL v2. You can use this + * software according to the terms and conditions of the + * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +declare(strict_types=1); + +namespace SPC\builder\macos\library; + +class libavif extends MacOSLibraryBase +{ + use \SPC\builder\unix\library\libavif; + + public const NAME = 'libavif'; +} diff --git a/src/SPC/builder/macos/library/libiconv.php b/src/SPC/builder/macos/library/libiconv.php index f8e603f3..d5c2b693 100644 --- a/src/SPC/builder/macos/library/libiconv.php +++ b/src/SPC/builder/macos/library/libiconv.php @@ -20,28 +20,9 @@ declare(strict_types=1); namespace SPC\builder\macos\library; -use SPC\exception\RuntimeException; - class libiconv extends MacOSLibraryBase { + use \SPC\builder\unix\library\libiconv; + public const NAME = 'libiconv'; - - /** - * @throws RuntimeException - */ - public function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static ' . - '--disable-shared ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec('make install DESTDIR=' . $destdir); - } } diff --git a/src/SPC/builder/macos/library/libjpeg.php b/src/SPC/builder/macos/library/libjpeg.php new file mode 100644 index 00000000..6b86baae --- /dev/null +++ b/src/SPC/builder/macos/library/libjpeg.php @@ -0,0 +1,12 @@ +builder->arch) { 'x86_64' => '--enable-intel-sse ', 'arm64' => '--enable-arm-neon ', default => '', }; - - // patch configure - Patcher::patchUnixLibpng(); shell()->cd($this->source_dir) ->exec('chmod +x ./configure') ->exec( @@ -59,5 +54,6 @@ class libpng extends MacOSLibraryBase ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH) ->cd(BUILD_LIB_PATH) ->exec('ln -sf libpng16.a libpng.a'); + $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); } } diff --git a/src/SPC/builder/macos/library/libssh2.php b/src/SPC/builder/macos/library/libssh2.php index e129a6e6..888ac407 100644 --- a/src/SPC/builder/macos/library/libssh2.php +++ b/src/SPC/builder/macos/library/libssh2.php @@ -1,20 +1,4 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); @@ -22,33 +6,7 @@ namespace SPC\builder\macos\library; class libssh2 extends MacOSLibraryBase { + use \SPC\builder\unix\library\libssh2; + public const NAME = 'libssh2'; - - protected function build() - { - // lib:zlib - $enable_zlib = $this->builder->getLib('zlib') !== null ? 'ON' : 'OFF'; - - [$lib, $include, $destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - "{$this->builder->configure_env} " . ' cmake ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_EXAMPLES=OFF ' . - '-DBUILD_TESTING=OFF ' . - "-DENABLE_ZLIB_COMPRESSION={$enable_zlib} " . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("cmake --build . -j {$this->builder->concurrency} --target libssh2") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/libwebp.php b/src/SPC/builder/macos/library/libwebp.php new file mode 100644 index 00000000..1b2a2ee8 --- /dev/null +++ b/src/SPC/builder/macos/library/libwebp.php @@ -0,0 +1,28 @@ + + * + * lwmbs is licensed under Mulan PSL v2. You can use this + * software according to the terms and conditions of the + * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, + * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * + * See the Mulan PSL v2 for more details. + */ + +declare(strict_types=1); + +namespace SPC\builder\macos\library; + +class libwebp extends MacOSLibraryBase +{ + use \SPC\builder\unix\library\libwebp; + + public const NAME = 'libwebp'; +} diff --git a/src/SPC/builder/macos/library/libxml2.php b/src/SPC/builder/macos/library/libxml2.php index 43c48ae0..1333c89f 100644 --- a/src/SPC/builder/macos/library/libxml2.php +++ b/src/SPC/builder/macos/library/libxml2.php @@ -1,26 +1,11 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\macos\library; use SPC\exception\RuntimeException; +use SPC\store\FileSystem; class libxml2 extends MacOSLibraryBase { @@ -37,10 +22,8 @@ class libxml2 extends MacOSLibraryBase [$lib, $include, $destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') + FileSystem::resetDir($this->source_dir . '/build'); + shell()->cd($this->source_dir . '/build') ->exec( "{$this->builder->configure_env} " . ' cmake ' . // '--debug-find ' . diff --git a/src/SPC/builder/macos/library/libyaml.php b/src/SPC/builder/macos/library/libyaml.php index 79eff2f6..ab0b1351 100644 --- a/src/SPC/builder/macos/library/libyaml.php +++ b/src/SPC/builder/macos/library/libyaml.php @@ -1,94 +1,12 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); namespace SPC\builder\macos\library; -use SPC\exception\RuntimeException; - class libyaml extends MacOSLibraryBase { + use \SPC\builder\unix\library\libyaml; + public const NAME = 'libyaml'; - - /** - * @throws RuntimeException - */ - public function build() - { - // prepare cmake/config.h.in - if (!is_file(SOURCE_PATH . '/libyaml/cmake/config.h.in')) { - f_mkdir(SOURCE_PATH . '/libyaml/cmake'); - file_put_contents( - SOURCE_PATH . '/libyaml/cmake/config.h.in', - <<<'EOF' -#define YAML_VERSION_MAJOR @YAML_VERSION_MAJOR@ -#define YAML_VERSION_MINOR @YAML_VERSION_MINOR@ -#define YAML_VERSION_PATCH @YAML_VERSION_PATCH@ -#define YAML_VERSION_STRING "@YAML_VERSION_STRING@" -EOF - ); - } - - // prepare yamlConfig.cmake.in - if (!is_file(SOURCE_PATH . '/libyaml/yamlConfig.cmake.in')) { - file_put_contents( - SOURCE_PATH . '/libyaml/yamlConfig.cmake.in', - <<<'EOF' -# Config file for the yaml library. -# -# It defines the following variables: -# yaml_LIBRARIES - libraries to link against - -@PACKAGE_INIT@ - -set_and_check(yaml_TARGETS "@PACKAGE_CONFIG_DIR_CONFIG@/yamlTargets.cmake") - -if(NOT yaml_TARGETS_IMPORTED) - set(yaml_TARGETS_IMPORTED 1) - include(${yaml_TARGETS}) -endif() - -set(yaml_LIBRARIES yaml) - -EOF - ); - } - - [$lib, $include, $destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - "{$this->builder->configure_env} " . ' cmake ' . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DBUILD_TESTING=OFF ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/libzip.php b/src/SPC/builder/macos/library/libzip.php index 0951d9e5..18824fa3 100644 --- a/src/SPC/builder/macos/library/libzip.php +++ b/src/SPC/builder/macos/library/libzip.php @@ -1,20 +1,4 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); @@ -22,79 +6,7 @@ namespace SPC\builder\macos\library; class libzip extends MacOSLibraryBase { + use \SPC\builder\unix\library\libzip; + public const NAME = 'libzip'; - - protected function build() - { - $extra = ''; - // lib:zlib - $zlib = $this->builder->getLib('zlib'); - if ($zlib instanceof MacOSLibraryBase) { - $extra .= '-DZLIB_LIBRARY="' . $zlib->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZLIB_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } - // lib:bzip2 - $libbzip2 = $this->builder->getLib('bzip2'); - if ($libbzip2 instanceof MacOSLibraryBase) { - $extra .= '-DENABLE_BZIP2=ON ' . - '-DBZIP2_LIBRARIES="' . $libbzip2->getStaticLibFiles(style: 'cmake') . '" ' . - '-DBZIP2_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } else { - $extra .= '-DENABLE_BZIP2=OFF '; - } - // lib:xz - $xz = $this->builder->getLib('xz'); - if ($xz instanceof MacOSLibraryBase) { - $extra .= '-DENABLE_LZMA=ON ' . - '-DLIBLZMA_LIBRARY="' . $xz->getStaticLibFiles(style: 'cmake') . '" ' . - '-DLIBLZMA_INCLUDE_DIR=' . BUILD_INCLUDE_PATH . ' '; - } else { - $extra .= '-DENABLE_LZMA=OFF '; - } - // lib:zstd - $libzstd = $this->builder->getLib('zstd'); - if ($libzstd instanceof MacOSLibraryBase) { - $extra .= '-DENABLE_ZSTD=ON ' . - '-DZstd_LIBRARY="' . $libzstd->getStaticLibFiles(style: 'cmake') . '" ' . - '-DZstd_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DENABLE_ZSTD=OFF '; - } - // lib:openssl - $libopenssl = $this->builder->getLib('openssl'); - if ($libopenssl instanceof MacOSLibraryBase) { - $extra .= '-DENABLE_OPENSSL=ON ' . - '-DOpenSSL_LIBRARY="' . $libopenssl->getStaticLibFiles(style: 'cmake') . '" ' . - '-DOpenSSL_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; - } else { - $extra .= '-DENABLE_OPENSSL=OFF '; - } - - [$lib, $include, $destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec('rm -rf build') - ->exec('mkdir -p build') - ->cd($this->source_dir . '/build') - ->exec( - "{$this->builder->configure_env} " . ' cmake ' . - // '--debug-find ' . - '-DCMAKE_BUILD_TYPE=Release ' . - '-DENABLE_GNUTLS=OFF ' . - '-DENABLE_MBEDTLS=OFF ' . - '-DBUILD_SHARED_LIBS=OFF ' . - '-DBUILD_DOC=OFF ' . - '-DBUILD_EXAMPLES=OFF ' . - '-DBUILD_REGRESS=OFF ' . - '-DBUILD_TOOLS=OFF ' . - $extra . - '-DCMAKE_INSTALL_PREFIX=/ ' . - "-DCMAKE_INSTALL_LIBDIR={$lib} " . - "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . - "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . - '..' - ) - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/nghttp2.php b/src/SPC/builder/macos/library/nghttp2.php index c9d2f04d..62518c24 100644 --- a/src/SPC/builder/macos/library/nghttp2.php +++ b/src/SPC/builder/macos/library/nghttp2.php @@ -58,5 +58,6 @@ class nghttp2 extends MacOSLibraryBase ->exec('make clean') ->exec("make -j{$this->builder->concurrency}") ->exec("make install DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['libnghttp2.pc']); } } diff --git a/src/SPC/builder/macos/library/onig.php b/src/SPC/builder/macos/library/onig.php index 47111351..25563203 100644 --- a/src/SPC/builder/macos/library/onig.php +++ b/src/SPC/builder/macos/library/onig.php @@ -1,20 +1,4 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); @@ -22,22 +6,7 @@ namespace SPC\builder\macos\library; class onig extends MacOSLibraryBase { + use \SPC\builder\unix\library\onig; + public const NAME = 'onig'; - - protected function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec( - "{$this->builder->configure_env} " . ' ./configure ' . - '--enable-static ' . - '--disable-shared ' . - "--host={$this->builder->arch}-apple-darwin " . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index 07f71d49..7349e9ee 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -47,5 +47,6 @@ class openssl extends MacOSLibraryBase ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make install_sw DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); } } diff --git a/src/SPC/builder/macos/library/sqlite.php b/src/SPC/builder/macos/library/sqlite.php index 9c3e023e..016f0d32 100644 --- a/src/SPC/builder/macos/library/sqlite.php +++ b/src/SPC/builder/macos/library/sqlite.php @@ -6,15 +6,7 @@ namespace SPC\builder\macos\library; class sqlite extends MacOSLibraryBase { - public const NAME = 'sqlite'; + use \SPC\builder\unix\library\sqlite; - protected function build() - { - [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix=") - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } + public const NAME = 'sqlite'; } diff --git a/src/SPC/builder/macos/library/xz.php b/src/SPC/builder/macos/library/xz.php index 7f9abda3..d656e35e 100644 --- a/src/SPC/builder/macos/library/xz.php +++ b/src/SPC/builder/macos/library/xz.php @@ -22,30 +22,7 @@ namespace SPC\builder\macos\library; class xz extends MacOSLibraryBase { + use \SPC\builder\unix\library\xz; + public const NAME = 'xz'; - - protected function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec('autoreconf -i --force') - ->exec( - "{$this->builder->configure_env} ./configure " . - '--enable-static ' . - '--disable-shared ' . - "--host={$this->builder->gnu_arch}-apple-darwin " . - '--disable-xz ' . - '--disable-xzdec ' . - '--disable-lzmadec ' . - '--disable-lzmainfo ' . - '--disable-scripts ' . - '--disable-doc ' . - '--with-libiconv ' . - '--prefix=' - ) - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/zlib.php b/src/SPC/builder/macos/library/zlib.php index 11dab8eb..2f451c10 100644 --- a/src/SPC/builder/macos/library/zlib.php +++ b/src/SPC/builder/macos/library/zlib.php @@ -22,16 +22,7 @@ namespace SPC\builder\macos\library; class zlib extends MacOSLibraryBase { + use \SPC\builder\unix\library\zlib; + public const NAME = 'zlib'; - - protected function build() - { - [,,$destdir] = SEPARATED_PATH; - - shell()->cd($this->source_dir) - ->exec("{$this->builder->configure_env} ./configure --static --prefix=") - ->exec('make clean') - ->exec("make -j{$this->builder->concurrency}") - ->exec("make install DESTDIR={$destdir}"); - } } diff --git a/src/SPC/builder/macos/library/zstd.php b/src/SPC/builder/macos/library/zstd.php index f645a8f8..251d6e4f 100644 --- a/src/SPC/builder/macos/library/zstd.php +++ b/src/SPC/builder/macos/library/zstd.php @@ -1,20 +1,4 @@ - * - * lwmbs is licensed under Mulan PSL v2. You can use this - * software according to the terms and conditions of the - * Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at: - * - * http://license.coscl.org.cn/MulanPSL2 - * - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, - * WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * - * See the Mulan PSL v2 for more details. - */ declare(strict_types=1); @@ -22,19 +6,7 @@ namespace SPC\builder\macos\library; class zstd extends MacOSLibraryBase { - public const NAME = 'zstd'; + use \SPC\builder\unix\library\zstd; - protected function build() - { - shell()->cd($this->source_dir) - ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->exec( - "make -j{$this->builder->concurrency} " . - "{$this->builder->configure_env} " . - "PREFIX='" . BUILD_ROOT_PATH . "' " . - '-C lib libzstd.a CPPFLAGS_STATLIB=-DZSTD_MULTITHREAD' - ) - ->exec('cp lib/libzstd.a ' . BUILD_LIB_PATH) - ->exec('cp lib/zdict.h lib/zstd_errors.h lib/zstd.h ' . BUILD_INCLUDE_PATH); - } + public const NAME = 'zstd'; } diff --git a/src/SPC/builder/traits/UnixBuilderTrait.php b/src/SPC/builder/traits/UnixBuilderTrait.php index 81f0371e..da37cc15 100644 --- a/src/SPC/builder/traits/UnixBuilderTrait.php +++ b/src/SPC/builder/traits/UnixBuilderTrait.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace SPC\builder\traits; +use SPC\builder\linux\LinuxBuilder; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -133,4 +134,18 @@ trait UnixBuilderTrait logger()->info('cleaning up'); shell()->cd(SOURCE_PATH . '/php-src')->exec('make clean'); } + + /** + * Return generic cmake options when configuring cmake projects + */ + public function makeCmakeArgs(): string + { + [$lib, $include] = SEPARATED_PATH; + $extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . $this->cc . ' ' : ''; + return $extra . '-DCMAKE_BUILD_TYPE=Release ' . + '-DCMAKE_INSTALL_PREFIX=/ ' . + "-DCMAKE_INSTALL_LIBDIR={$lib} " . + "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . + "-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}"; + } } diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index efdbedb1..494b3ab8 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -51,4 +51,30 @@ trait UnixLibraryTrait return $prefix . '_CFLAGS="-I' . BUILD_INCLUDE_PATH . '" ' . $prefix . '_LIBS="' . $this->getStaticLibFiles() . '"'; } + + /** + * Patch pkgconfig file prefix + * + * @param array $files file list + * @throws FileSystemException + * @throws RuntimeException + */ + public function patchPkgconfPrefix(array $files, int $patch_option = PKGCONF_PATCH_ALL): void + { + logger()->info('Patching library [' . static::NAME . '] pkgconfig'); + foreach ($files as $name) { + $realpath = realpath(BUILD_ROOT_PATH . '/lib/pkgconfig/' . $name); + if ($realpath === false) { + throw new RuntimeException('Cannot find library [' . static::NAME . '] pkgconfig file [' . $name . '] !'); + } + logger()->debug('Patching ' . $realpath); + // replace prefix + $file = FileSystem::readFile($realpath); + $file = ($patch_option & PKGCONF_PATCH_PREFIX) === PKGCONF_PATCH_PREFIX ? preg_replace('/^prefix=.*$/m', 'prefix=' . BUILD_ROOT_PATH, $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_EXEC_PREFIX) === PKGCONF_PATCH_EXEC_PREFIX ? preg_replace('/^exec_prefix=.*$/m', 'exec_prefix=${prefix}', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_LIBDIR) === PKGCONF_PATCH_LIBDIR ? preg_replace('/^libdir=.*$/m', 'libdir=${prefix}/lib', $file) : $file; + $file = ($patch_option & PKGCONF_PATCH_INCLUDEDIR) === PKGCONF_PATCH_INCLUDEDIR ? preg_replace('/^includedir=.*$/m', 'includedir=${prefix}/include', $file) : $file; + FileSystem::writeFile($realpath, $file); + } + } } diff --git a/src/SPC/builder/traits/UnixSystemUtilTrait.php b/src/SPC/builder/traits/UnixSystemUtilTrait.php index 6695f243..adc25a5f 100644 --- a/src/SPC/builder/traits/UnixSystemUtilTrait.php +++ b/src/SPC/builder/traits/UnixSystemUtilTrait.php @@ -45,6 +45,12 @@ SET(CMAKE_SYSTEM_PROCESSOR {$target_arch}) SET(CMAKE_C_FLAGS "{$cflags}") SET(CMAKE_CXX_FLAGS "{$cflags}") SET(CMAKE_FIND_ROOT_PATH "{$root}") +SET(CMAKE_PREFIX_PATH "{$root}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) CMAKE; // 有时候系统的 cmake 找不到 ar 命令,真奇怪 if (PHP_OS_FAMILY === 'Linux') { diff --git a/src/SPC/builder/unix/library/brotli.php b/src/SPC/builder/unix/library/brotli.php new file mode 100644 index 00000000..21869601 --- /dev/null +++ b/src/SPC/builder/unix/library/brotli.php @@ -0,0 +1,34 @@ +source_dir . '/build-dir'); + shell()->cd($this->source_dir . '/build-dir') + ->exec( + $this->builder->configure_env . ' cmake ' . + "{$this->builder->makeCmakeArgs()} " . + '-DBUILD_SHARED_LIBS=OFF ' . + '..' + ) + ->exec("cmake --build . -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); + shell()->cd(BUILD_ROOT_PATH . '/lib') + ->exec('ln -s libbrotlicommon-static.a libbrotlicommon.a') + ->exec('ln -s libbrotlidec-static.a libbrotlidec.a') + ->exec('ln -s libbrotlienc-static.a libbrotlienc.a'); + foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) { + if (str_starts_with($filename, 'libbrotli') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) { + unlink(BUILD_ROOT_PATH . '/lib/' . $filename); + } + } + } +} diff --git a/src/SPC/builder/unix/library/bzip2.php b/src/SPC/builder/unix/library/bzip2.php new file mode 100644 index 00000000..bb4f0d9e --- /dev/null +++ b/src/SPC/builder/unix/library/bzip2.php @@ -0,0 +1,17 @@ +cd($this->source_dir) + ->exec("make {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' clean") + ->exec("make -j{$this->builder->concurrency} {$this->builder->configure_env} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") + ->exec('cp libbz2.a ' . BUILD_LIB_PATH) + ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); + } +} diff --git a/src/SPC/builder/unix/library/curl.php b/src/SPC/builder/unix/library/curl.php new file mode 100644 index 00000000..1e96e68e --- /dev/null +++ b/src/SPC/builder/unix/library/curl.php @@ -0,0 +1,54 @@ +builder->getLib('openssl') ? '-DCURL_USE_OPENSSL=ON ' : '-DCURL_USE_OPENSSL=OFF -DCURL_ENABLE_SSL=OFF '; + // lib:brotli + $extra .= $this->builder->getLib('brotli') ? '-DCURL_BROTLI=ON ' : '-DCURL_BROTLI=OFF '; + // lib:libssh2 + $libssh2 = $this->builder->getLib('libssh2'); + if ($this->builder->getLib('libssh2')) { + $extra .= '-DLIBSSH2_LIBRARY="' . $libssh2->getStaticLibFiles(style: 'cmake') . '" ' . + '-DLIBSSH2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; + } else { + $extra .= '-DCURL_USE_LIBSSH2=OFF '; + } + // lib:nghttp2 + if ($nghttp2 = $this->builder->getLib('nghttp2')) { + $extra .= '-DUSE_NGHTTP2=ON ' . + '-DNGHTTP2_LIBRARY="' . $nghttp2->getStaticLibFiles(style: 'cmake') . '" ' . + '-DNGHTTP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" '; + } else { + $extra .= '-DUSE_NGHTTP2=OFF '; + } + // TODO: ldap is not supported yet + $extra .= '-DCURL_DISABLE_LDAP=ON '; + // lib:zstd + $extra .= $this->builder->getLib('zstd') ? '-DCURL_ZSTD=ON ' : '-DCURL_ZSTD=OFF '; + // lib:idn2 + $extra .= $this->builder->getLib('idn2') ? '-DUSE_LIBIDN2=ON ' : '-DUSE_LIBIDN2=OFF '; + // lib:psl + $extra .= $this->builder->getLib('psl') ? '-DCURL_USE_LIBPSL=ON ' : '-DCURL_USE_LIBPSL=OFF '; + + FileSystem::resetDir($this->source_dir . '/build'); + // compile! + shell()->cd($this->source_dir . '/build') + ->exec("{$this->builder->configure_env} cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF {$extra} ..") + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + // patch pkgconf + $this->patchPkgconfPrefix(['libcurl.pc']); + shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/') + ->exec("sed -ie 's|\"/lib/libcurl.a\"|\"" . BUILD_LIB_PATH . "/libcurl.a\"|g' CURLTargets-release.cmake"); + } +} diff --git a/src/SPC/builder/unix/library/freetype.php b/src/SPC/builder/unix/library/freetype.php new file mode 100644 index 00000000..750622c3 --- /dev/null +++ b/src/SPC/builder/unix/library/freetype.php @@ -0,0 +1,29 @@ +builder->getLib('libpng') ? '--with-png' : '--without-png'; + $suggested .= ' '; + $suggested .= $this->builder->getLib('bzip2') ? ('--with-bzip2=' . BUILD_ROOT_PATH) : '--without-bzip2'; + $suggested .= ' '; + $suggested .= $this->builder->getLib('brotli') ? ('--with-brotli=' . BUILD_ROOT_PATH) : '--without-brotli'; + $suggested .= ' '; + + shell()->cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static --disable-shared --without-harfbuzz --prefix= ' . + $suggested + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['freetype2.pc']); + } +} diff --git a/src/SPC/builder/unix/library/gmp.php b/src/SPC/builder/unix/library/gmp.php new file mode 100644 index 00000000..934e9b02 --- /dev/null +++ b/src/SPC/builder/unix/library/gmp.php @@ -0,0 +1,22 @@ +cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static --disable-shared ' . + '--prefix=' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['gmp.pc']); + } +} diff --git a/src/SPC/builder/unix/library/libavif.php b/src/SPC/builder/unix/library/libavif.php new file mode 100644 index 00000000..413b471d --- /dev/null +++ b/src/SPC/builder/unix/library/libavif.php @@ -0,0 +1,28 @@ +source_dir . '/build'); + // Start build + shell()->cd($this->source_dir . '/build') + ->exec( + "{$this->builder->configure_env} cmake " . + $this->builder->makeCmakeArgs() . ' ' . + '-DBUILD_SHARED_LIBS=OFF ' . + '..' + ) + ->exec("cmake --build . -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + // patch pkgconfig + $this->patchPkgconfPrefix(['libavif.pc']); + } +} diff --git a/src/SPC/builder/unix/library/libiconv.php b/src/SPC/builder/unix/library/libiconv.php new file mode 100644 index 00000000..12ca1ada --- /dev/null +++ b/src/SPC/builder/unix/library/libiconv.php @@ -0,0 +1,24 @@ +cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static ' . + '--disable-shared ' . + '--prefix=' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . $destdir); + } +} diff --git a/src/SPC/builder/unix/library/libjpeg.php b/src/SPC/builder/unix/library/libjpeg.php new file mode 100644 index 00000000..08c51d85 --- /dev/null +++ b/src/SPC/builder/unix/library/libjpeg.php @@ -0,0 +1,28 @@ +source_dir . '/build'); + // Start build + shell()->cd($this->source_dir . '/build') + ->exec( + "{$this->builder->configure_env} cmake {$this->builder->makeCmakeArgs()} " . + '-DENABLE_STATIC=ON ' . + '-DENABLE_SHARED=OFF ' . + '..' + ) + ->exec("cmake --build . -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + // patch pkgconfig + $this->patchPkgconfPrefix(['libjpeg.pc', 'libturbojpeg.pc']); + } +} diff --git a/src/SPC/builder/unix/library/libssh2.php b/src/SPC/builder/unix/library/libssh2.php new file mode 100644 index 00000000..c0dccdf2 --- /dev/null +++ b/src/SPC/builder/unix/library/libssh2.php @@ -0,0 +1,30 @@ +builder->getLib('zlib') !== null ? 'ON' : 'OFF'; + + FileSystem::resetDir($this->source_dir . '/build'); + shell()->cd($this->source_dir . '/build') + ->exec( + "{$this->builder->configure_env} " . ' cmake ' . + "{$this->builder->makeCmakeArgs()} " . + '-DBUILD_SHARED_LIBS=OFF ' . + '-DBUILD_EXAMPLES=OFF ' . + '-DBUILD_TESTING=OFF ' . + "-DENABLE_ZLIB_COMPRESSION={$enable_zlib} " . + '..' + ) + ->exec("cmake --build . -j {$this->builder->concurrency} --target libssh2") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['libssh2.pc']); + } +} diff --git a/src/SPC/builder/unix/library/libwebp.php b/src/SPC/builder/unix/library/libwebp.php new file mode 100644 index 00000000..9d06842d --- /dev/null +++ b/src/SPC/builder/unix/library/libwebp.php @@ -0,0 +1,32 @@ +cd($this->source_dir) + ->exec('./autogen.sh') + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static ' . + '--disable-shared ' . + '--prefix= ' . + '--enable-libwebpdecoder ' . + '--enable-libwebpextras ' . + '--disable-tiff ' . + '--disable-gl ' . + '--disable-sdl ' . + '--disable-wic' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . $destdir); + $this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX); + } +} diff --git a/src/SPC/builder/unix/library/libyaml.php b/src/SPC/builder/unix/library/libyaml.php new file mode 100644 index 00000000..58ea9fe3 --- /dev/null +++ b/src/SPC/builder/unix/library/libyaml.php @@ -0,0 +1,75 @@ +source_dir . '/build'); + shell()->cd($this->source_dir . '/build') + ->exec( + "{$this->builder->configure_env} cmake " . + // '--debug-find ' . + '-DCMAKE_BUILD_TYPE=Release ' . + '-DBUILD_TESTING=OFF ' . + '-DBUILD_SHARED_LIBS=OFF ' . + '-DCMAKE_INSTALL_PREFIX=/ ' . + "-DCMAKE_INSTALL_LIBDIR={$lib} " . + "-DCMAKE_INSTALL_INCLUDEDIR={$include} " . + "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . + '..' + ) + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); + } +} diff --git a/src/SPC/builder/unix/library/libzip.php b/src/SPC/builder/unix/library/libzip.php new file mode 100644 index 00000000..f50a6144 --- /dev/null +++ b/src/SPC/builder/unix/library/libzip.php @@ -0,0 +1,42 @@ +builder->getLib('bzip2') ? '-DENABLE_BZIP2=ON ' : '-DENABLE_BZIP2=OFF '; + // lib:xz + $extra .= $this->builder->getLib('xz') ? '-DENABLE_LZMA=ON ' : '-DENABLE_LZMA=OFF '; + // lib:zstd + $extra .= $this->builder->getLib('zstd') ? '-DENABLE_ZSTD=ON ' : '-DENABLE_ZSTD=OFF '; + // lib:openssl + $extra .= $this->builder->getLib('openssl') ? '-DENABLE_OPENSSL=ON ' : '-DENABLE_OPENSSL=OFF '; + + FileSystem::resetDir($this->source_dir . '/build'); + shell()->cd($this->source_dir . '/build') + ->exec( + "{$this->builder->configure_env} " . ' cmake ' . + "{$this->builder->makeCmakeArgs()} " . + '-DENABLE_GNUTLS=OFF ' . + '-DENABLE_MBEDTLS=OFF ' . + '-DBUILD_SHARED_LIBS=OFF ' . + '-DBUILD_DOC=OFF ' . + '-DBUILD_EXAMPLES=OFF ' . + '-DBUILD_REGRESS=OFF ' . + '-DBUILD_TOOLS=OFF ' . + $extra . + '..' + ) + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX); + } +} diff --git a/src/SPC/builder/unix/library/onig.php b/src/SPC/builder/unix/library/onig.php new file mode 100644 index 00000000..72969d79 --- /dev/null +++ b/src/SPC/builder/unix/library/onig.php @@ -0,0 +1,25 @@ +cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} " . ' ./configure ' . + '--enable-static ' . + '--disable-shared ' . + '--prefix=' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['oniguruma.pc']); + } +} diff --git a/src/SPC/builder/unix/library/sqlite.php b/src/SPC/builder/unix/library/sqlite.php new file mode 100644 index 00000000..add31e53 --- /dev/null +++ b/src/SPC/builder/unix/library/sqlite.php @@ -0,0 +1,17 @@ +cd($this->source_dir) + ->exec("{$this->builder->configure_env} ./configure --enable-static --disable-shared --prefix=") + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + } +} diff --git a/src/SPC/builder/unix/library/xz.php b/src/SPC/builder/unix/library/xz.php new file mode 100644 index 00000000..006ed6c2 --- /dev/null +++ b/src/SPC/builder/unix/library/xz.php @@ -0,0 +1,27 @@ +cd($this->source_dir) + ->exec( + "{$this->builder->configure_env} ./configure " . + '--enable-static ' . + '--disable-shared ' . + "--host={$this->builder->gnu_arch}-unknown-linux " . + '--disable-scripts ' . + '--disable-doc ' . + '--with-libiconv ' . + '--prefix=' + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['liblzma.pc']); + } +} diff --git a/src/SPC/builder/unix/library/zlib.php b/src/SPC/builder/unix/library/zlib.php new file mode 100644 index 00000000..542d918d --- /dev/null +++ b/src/SPC/builder/unix/library/zlib.php @@ -0,0 +1,20 @@ +cd($this->source_dir) + ->exec("{$this->builder->configure_env} ./configure --static --prefix=") + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); + $this->patchPkgconfPrefix(['zlib.pc']); + } +} diff --git a/src/SPC/builder/unix/library/zstd.php b/src/SPC/builder/unix/library/zstd.php new file mode 100644 index 00000000..f6b4ea32 --- /dev/null +++ b/src/SPC/builder/unix/library/zstd.php @@ -0,0 +1,26 @@ +source_dir . '/build/cmake/build'); + shell()->cd($this->source_dir . '/build/cmake/build') + ->exec( + "{$this->builder->configure_env} cmake " . + "{$this->builder->makeCmakeArgs()} " . + '-DZSTD_BUILD_STATIC=ON ' . + '-DZSTD_BUILD_SHARED=OFF ' . + '..' + ) + ->exec("cmake --build . -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); + $this->patchPkgconfPrefix(['libzstd.pc']); + } +} diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 20b052ae..786e4e4f 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -169,8 +169,8 @@ class FileSystem break; // case 'zstd': // case 'zst': - // passthru('cat ' . $filename . ' | zstd -d | tar -x -C ".SOURCE_PATH . "/' . $name . ' --strip-components 1', $ret); - // break; + // passthru('cat ' . $filename . ' | zstd -d | tar -x -C ".SOURCE_PATH . "/' . $name . ' --strip-components 1', $ret); + // break; case 'tar': f_passthru("tar -xf {$filename} -C " . SOURCE_PATH . "/{$name} --strip-components 1"); break; @@ -408,4 +408,17 @@ class FileSystem } return file_put_contents($path, $content, ...$args); } + + /** + * Reset (remove recursively and create again) dir + * + * @throws FileSystemException + */ + public static function resetDir(string $dir_name): void + { + if (is_dir($dir_name)) { + self::removeDir($dir_name); + } + self::createDir($dir_name); + } } diff --git a/src/SPC/util/ConfigValidator.php b/src/SPC/util/ConfigValidator.php index 3d129071..9b818fb7 100644 --- a/src/SPC/util/ConfigValidator.php +++ b/src/SPC/util/ConfigValidator.php @@ -19,7 +19,7 @@ class ConfigValidator foreach ($data as $name => $src) { isset($src['type']) || throw new ValidationException("source {$name} must have prop: [type]"); is_string($src['type']) || throw new ValidationException("source {$name} type prop must be string"); - in_array($src['type'], ['filelist', 'git', 'ghtagtar', 'ghtar', 'ghrel', 'url']) || throw new ValidationException("source {$name} type [{$src['type']}] is invalid"); + in_array($src['type'], ['filelist', 'git', 'ghtagtar', 'ghtar', 'ghrel', 'url', 'custom']) || throw new ValidationException("source {$name} type [{$src['type']}] is invalid"); switch ($src['type']) { case 'filelist': isset($src['url'], $src['regex']) || throw new ValidationException("source {$name} needs [url] and [regex] props"); diff --git a/src/SPC/util/Patcher.php b/src/SPC/util/Patcher.php index e24ffc3f..3d7a7625 100644 --- a/src/SPC/util/Patcher.php +++ b/src/SPC/util/Patcher.php @@ -204,9 +204,6 @@ class Patcher } } - /** - * @throws FileSystemException - */ public static function patchUnixLibpng(): void { FileSystem::replaceFile( @@ -217,6 +214,22 @@ class Patcher ); } + public static function patchCurlMacOS(): void + { + FileSystem::replaceFile( + 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' + ); + } + /** * @throws FileSystemException */ diff --git a/src/SPC/util/UnixShell.php b/src/SPC/util/UnixShell.php index 90203ec1..565182ea 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -13,6 +13,8 @@ class UnixShell private bool $debug; + private array $env = []; + public function __construct(?bool $debug = null) { $this->debug = $debug ?? defined('DEBUG_MODE'); @@ -54,4 +56,24 @@ class UnixShell exec($cmd, $out, $code); return [$code, $out]; } + + public function setEnv(array $env): UnixShell + { + $this->env = array_merge($this->env, $env); + return $this; + } + + public function execWithEnv(string $cmd): UnixShell + { + return $this->exec($this->getEnvString() . ' ' . $cmd); + } + + private function getEnvString(): string + { + $str = ''; + foreach ($this->env as $k => $v) { + $str .= ' ' . $k . '="' . $v . '"'; + } + return trim($str); + } } diff --git a/src/globals/defines.php b/src/globals/defines.php index 2ea31c34..7297a04f 100644 --- a/src/globals/defines.php +++ b/src/globals/defines.php @@ -50,4 +50,11 @@ const FIX_POLICY_DIE = 1; // die directly const FIX_POLICY_PROMPT = 2; // if it can be fixed, ask fix or not const FIX_POLICY_AUTOFIX = 3; // if it can be fixed, just fix automatically +// pkgconf patch policy +const PKGCONF_PATCH_PREFIX = 1; +const PKGCONF_PATCH_EXEC_PREFIX = 2; +const PKGCONF_PATCH_LIBDIR = 4; +const PKGCONF_PATCH_INCLUDEDIR = 8; +const PKGCONF_PATCH_ALL = 15; + ConsoleLogger::$date_format = 'H:i:s';