From cfa89e30034968f526b02d06396c5167e0025675 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 18 Mar 2023 18:46:10 +0800 Subject: [PATCH] add gmp extension for macOS --- config/ext.json | 2 +- config/lib.json | 12 ++++++++ config/source.json | 9 ++++++ src/SPC/builder/Extension.php | 3 ++ src/SPC/builder/macos/library/gmp.php | 42 +++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/SPC/builder/macos/library/gmp.php diff --git a/config/ext.json b/config/ext.json index a91c323d..a67abd14 100644 --- a/config/ext.json +++ b/config/ext.json @@ -100,7 +100,7 @@ }, "gmp": { "type": "builtin", - "arg-type": "with", + "arg-type": "none", "lib-depends": [ "gmp" ] diff --git a/config/lib.json b/config/lib.json index 967c31f9..a4f03670 100644 --- a/config/lib.json +++ b/config/lib.json @@ -68,6 +68,18 @@ "SystemConfiguration" ] }, + "gmp": { + "source": "gmp", + "static-libs-unix": [ + "libgmp.a" + ], + "static-libs-windows": [ + "libgmp.lib" + ], + "headers": [ + "gmp.h" + ] + }, "libffi": { "source": "libffi", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index 0a31cd5f..929711f6 100644 --- a/config/source.json +++ b/config/source.json @@ -35,6 +35,15 @@ "path": "LICENSE" } }, + "gmp": { + "type": "filelist", + "url": "https://gmplib.org/download/gmp/", + "regex": "/href=\"(?gmp-(?[^\"]+)\\.tar\\.xz)\"/", + "license": { + "type": "text", + "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." + } + }, "libffi": { "type": "ghrel", "repo": "libffi/libffi", diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index 1e864317..ec4c0777 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -182,6 +182,9 @@ class Extension $arg .= ' --with-event-openssl --with-openssl-dir="' . BUILD_ROOT_PATH . '"'; } break;*/ + case 'gmp': + $arg = ' --with-gmp="' . BUILD_ROOT_PATH . '" '; + break; case 'sqlite3': $arg = ' --with-sqlite3="' . BUILD_ROOT_PATH . '" ' . 'SQLITE_CFLAGS=-I"' . BUILD_INCLUDE_PATH . '" ' . diff --git a/src/SPC/builder/macos/library/gmp.php b/src/SPC/builder/macos/library/gmp.php new file mode 100644 index 00000000..ee72ce87 --- /dev/null +++ b/src/SPC/builder/macos/library/gmp.php @@ -0,0 +1,42 @@ + + * + * 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 gmp extends MacOSLibraryBase +{ + public const NAME = 'gmp'; + + protected function build() + { + [,,$destdir] = SEPARATED_PATH; + + f_passthru( + $this->builder->set_x . ' && ' . + "cd {$this->source_dir} && " . + "{$this->builder->configure_env} ./configure " . + '--enable-static --disable-shared ' . + '--prefix= && ' . // use prefix=/ + 'make clean && ' . + "make -j{$this->builder->concurrency} && " . + 'make install DESTDIR=' . $destdir + ); + } +}