Skip to content

Commit

Permalink
optimize [2] 不要使用字符串替换,conf.d支持子目录
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Feb 17, 2023
1 parent d274ce0 commit 875ec69
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 128 deletions.
2 changes: 1 addition & 1 deletion conf.d/curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
->withPrefix(CURL_PREFIX)
->withConfigure(
'autoreconf -fi && ./configure --prefix=' . CURL_PREFIX .
' --enable-static --disable-shared --with-openssl=/usr/openssl ' .
' --enable-static --disable-shared --with-openssl=' . OPENSSL_PREFIX . ' ' .
'--without-librtmp --without-brotli --without-libidn2 --disable-ldap --disable-rtsp --without-zstd --without-nghttp2 --without-nghttp3'
)
->withPkgName('libcurl')
Expand Down
23 changes: 15 additions & 8 deletions conf.d/gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
->withConfigure('cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=' . JPEG_PREFIX . ' .')
->withPkgName('libjpeg');

// linux 系统中是保存在 lib64 目录下的,而 macos 是放在 /usr/libjpeg/lib 目录中的,不清楚这里是什么原因?
// linux 系统中是保存在 /usr/lib64 目录下的,而 macos 是放在 /usr/lib 目录中的,不清楚这里是什么原因?
$jpeg_lib_dir = JPEG_PREFIX . '/' . ($p->getOsType() === 'macos' ? 'lib' : 'lib64');
$gif_prefix = GIF_PREFIX;
$lib->withLdflags('-L' . $jpeg_lib_dir)
->withPkgConfig($jpeg_lib_dir . '/pkgconfig');
if ($p->getOsType() === 'macos') {
Expand Down Expand Up @@ -43,11 +44,17 @@
->withPrefix(GIF_PREFIX)
->withMakeOptions('libgif.a')
->withMakeInstallCommand('')
->withScriptBeforeInstall('test -d ' . GIF_PREFIX . ' && rm -rf ' . GIF_PREFIX .
'mkdir -p ' . GIF_PREFIX . '/lib
mkdir -p ' . GIF_PREFIX . '/include'
->withScriptAfterInstall(<<<EOF
if [ ! -d {$gif_prefix}/lib ]; then
mkdir -p {$gif_prefix}/lib
fi
if [ ! -d {$gif_prefix}/include ]; then
mkdir -p {$gif_prefix}/include
fi
cp libgif.a {$gif_prefix}/lib/libgif.a
cp gif_lib.h {$gif_prefix}/include/gif_lib.h
EOF
)
->withScriptAfterInstall('cp libgif.a ' . GIF_PREFIX . '/lib && cp gif_lib.h ' . GIF_PREFIX . '/include')
->withLdflags('-L' . GIF_PREFIX . '/lib')
->withPkgName('')
->withPkgConfig('')
Expand Down Expand Up @@ -77,9 +84,9 @@
->withPrefix(FREETYPE_PREFIX)
->withUrl('https://download.savannah.gnu.org/releases/freetype/freetype-2.10.4.tar.gz')
->withLicense('https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT', Library::LICENSE_SPEC)
->withConfigure('BZIP2_CFLAGS="-I/usr/bzip2/include" & \\' .
'BZIP2_LIBS="-L/usr/bzip2/lib -lbz2" & \\' .
'PATH="' . PNG_PREFIX .'/bin:$PATH" & \\' .
->withConfigure('BZIP2_CFLAGS="-I' . BZIP2_PREFIX . '/include" & \\' .
'BZIP2_LIBS="-L' . BZIP2_PREFIX . '/lib -lbz2" & \\' .
'PATH="' . PNG_PREFIX . '/bin:$PATH" & \\' .
'./configure --prefix=' . FREETYPE_PREFIX . ' \\' . PHP_EOL .
'--enable-static \\' . PHP_EOL .
'--disable-shared \\' . PHP_EOL .
Expand Down
5 changes: 3 additions & 2 deletions conf.d/intl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use SwooleCli\Extension;

return function (Preprocessor $p) {
$icu_prefix = ICU_PREFIX;
$p->addLibrary(
(new Library('icu'))
->withUrl('https://github.com/unicode-org/icu/releases/download/release-60-3/icu4c-60_3-src.tgz')
->withPrefix('/usr/icu')
->withPrefix(ICU_PREFIX)
->withConfigure(<<<EOF
export CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"
source/runConfigureICU Linux --prefix=/usr/icu \
./configure --prefix={$icu_prefix} \
--enable-icu-config=yes \
--enable-static=yes \
--enable-shared=no \
Expand Down
4 changes: 2 additions & 2 deletions conf.d/mbstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
$p->addLibrary(
(new Library('oniguruma'))
->withUrl('https://codeload.github.com/kkos/oniguruma/tar.gz/refs/tags/v6.9.7')
->withPrefix('/usr/oniguruma')
->withConfigure('./autogen.sh && ./configure --prefix=/usr/oniguruma --enable-static --disable-shared')
->withPrefix(ONIGURUMA_PREFIX)
->withConfigure('./autogen.sh && ./configure --prefix=' . ONIGURUMA_PREFIX . ' --enable-static --disable-shared')
->withFile('oniguruma-6.9.7.tar.gz')
->withLicense('https://github.com/kkos/oniguruma/blob/master/COPYING', Library::LICENSE_SPEC)
->withPkgName('oniguruma')
Expand Down
6 changes: 3 additions & 3 deletions conf.d/mimalloc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
(new Library('mimalloc'))
->withUrl('https://github.com/microsoft/mimalloc/archive/refs/tags/v2.0.7.tar.gz')
->withFile('mimalloc-2.0.7.tar.gz')
->withPrefix('/usr/mimalloc')
->withConfigure("cmake . -DMI_BUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=/usr/mimalloc -DMI_INSTALL_TOPLEVEL=ON -DMI_PADDING=OFF -DMI_SKIP_COLLECT_ON_EXIT=ON -DMI_BUILD_TESTS=OFF")
->withPrefix(MIMALLOC_PREFIX)
->withConfigure('cmake . -DMI_BUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=' . MIMALLOC_PREFIX . ' -DMI_INSTALL_TOPLEVEL=ON -DMI_PADDING=OFF -DMI_SKIP_COLLECT_ON_EXIT=ON -DMI_BUILD_TESTS=OFF')
->withPkgName('libmimalloc')
->withLicense('https://github.com/microsoft/mimalloc/blob/master/LICENSE', Library::LICENSE_MIT)
->withHomePage('https://microsoft.github.io/mimalloc/')
->withLdflags('-L/usr/mimalloc/lib -lmimalloc')
->withLdflags('-L' . MIMALLOC_PREFIX . '/lib -lmimalloc')
);
};

49 changes: 25 additions & 24 deletions conf.d/readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
use SwooleCli\Library;

return function (Preprocessor $p) {
$ncurses_prefix = NCURSES_PREFIX;
$p->addLibrary(
(new Library('ncurses'))
->withUrl('https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.3.tar.gz')
->withPrefix('/usr/ncurses/')
->withPrefix(NCURSES_PREFIX)
->withConfigure(<<<EOF
mkdir -p /usr/ncurses/lib/pkgconfig
mkdir -p {$ncurses_prefix}/lib/pkgconfig
./configure \
--prefix=/usr/ncurses \
--prefix={$ncurses_prefix} \
--enable-static \
--disable-shared \
--enable-pc-files \
--with-pkg-config=/usr/ncurses/lib/pkgconfig \
--with-pkg-config-libdir=/usr/ncurses/lib/pkgconfig \
--with-pkg-config={$ncurses_prefix}/lib/pkgconfig \
--with-pkg-config-libdir={$ncurses_prefix}/lib/pkgconfig \
--with-normal \
--enable-widec \
--enable-echo \
Expand All @@ -36,21 +37,20 @@
--enable-symlinks
EOF
)

->withScriptBeforeInstall('
ln -s /usr/ncurses/lib/pkgconfig/formw.pc /usr/ncurses/lib/pkgconfig/form.pc ;
ln -s /usr/ncurses/lib/pkgconfig/menuw.pc /usr/ncurses/lib/pkgconfig/menu.pc ;
ln -s /usr/ncurses/lib/pkgconfig/ncurses++w.pc /usr/ncurses/lib/pkgconfig/ncurses++.pc ;
ln -s /usr/ncurses/lib/pkgconfig/ncursesw.pc /usr/ncurses/lib/pkgconfig/ncurses.pc ;
ln -s /usr/ncurses/lib/pkgconfig/panelw.pc /usr/ncurses/lib/pkgconfig/panel.pc ;
ln -s /usr/ncurses/lib/pkgconfig/ticw.pc /usr/ncurses/lib/pkgconfig/tic.pc ;
ln -s ' . NCURSES_PREFIX . '/lib/pkgconfig/formw.pc ' . NCURSES_PREFIX . '/lib/pkgconfig/form.pc ;
ln -s ' . NCURSES_PREFIX . '/lib/pkgconfig/menuw.pc ' . NCURSES_PREFIX . '/lib/pkgconfig/menu.pc ;
ln -s ' . NCURSES_PREFIX . '/lib/pkgconfig/ncurses++w.pc ' . NCURSES_PREFIX . '/lib/pkgconfig/ncurses++.pc ;
ln -s ' . NCURSES_PREFIX . '/lib/pkgconfig/ncursesw.pc ' . NCURSES_PREFIX . '/lib/pkgconfig/ncurses.pc ;
ln -s ' . NCURSES_PREFIX . '/lib/pkgconfig/panelw.pc ' . NCURSES_PREFIX . '/lib/pkgconfig/panel.pc ;
ln -s ' . NCURSES_PREFIX . '/lib/pkgconfig/ticw.pc ' . NCURSES_PREFIX . '/lib/pkgconfig/tic.pc ;
ln -s /usr/ncurses/lib/libformw.a /usr/ncurses/lib/libform.a ;
ln -s /usr/ncurses/lib/libmenuw.a /usr/ncurses/lib/libmenu.a ;
ln -s /usr/ncurses/lib/libncurses++w.a /usr/ncurses/lib/libncurses++.a ;
ln -s /usr/ncurses/lib/libncursesw.a /usr/ncurses/lib/libncurses.a ;
ln -s /usr/ncurses/lib/libpanelw.a /usr/ncurses/lib/libpanel.a ;
ln -s /usr/ncurses/lib/libticw.a /usr/ncurses/lib/libtic.a ;
ln -s ' . NCURSES_PREFIX . '/lib/libformw.a ' . NCURSES_PREFIX . '/lib/libform.a ;
ln -s ' . NCURSES_PREFIX . '/lib/libmenuw.a ' . NCURSES_PREFIX . '/lib/libmenu.a ;
ln -s ' . NCURSES_PREFIX . '/lib/libncurses++w.a ' . NCURSES_PREFIX . '/lib/libncurses++.a ;
ln -s ' . NCURSES_PREFIX . '/lib/libncursesw.a ' . NCURSES_PREFIX . '/lib/libncurses.a ;
ln -s ' . NCURSES_PREFIX . '/lib/libpanelw.a ' . NCURSES_PREFIX . '/lib/libpanel.a ;
ln -s ' . NCURSES_PREFIX . '/lib/libticw.a ' . NCURSES_PREFIX . '/lib/libtic.a ;
')
->withPkgName('ncursesw')
->withLicense('https://github.com/projectceladon/libncurses/blob/master/README', Library::LICENSE_MIT)
Expand All @@ -60,35 +60,36 @@
$p->addLibrary(
(new Library('libedit'))
->withUrl('https://thrysoee.dk/editline/libedit-20210910-3.1.tar.gz')
->withPrefix('/usr/libedit')
->withConfigure('./configure --prefix=/usr/libedit --enable-static --disable-shared')
->withPrefix(LIBEDIT_PREFIX)
->withConfigure('./configure --prefix=' . LIBEDIT_PREFIX . ' --enable-static --disable-shared')
->withLdflags('')
->withLicense('http://www.netbsd.org/Goals/redistribution.html', Library::LICENSE_BSD)
->withHomePage('https://thrysoee.dk/editline/')
);
} else {
$readline_prefix = READLINE_PREFIX;
$p->addLibrary(
(new Library('readline'))
->withUrl('https://ftp.gnu.org/gnu/readline/readline-8.2.tar.gz')
->withPrefix('/usr/readline')
->withPrefix(READLINE_PREFIX)
->withConfigure(<<<EOF
./configure \
--prefix=/usr/readline \
--prefix={$readline_prefix} \
--enable-static \
--disable-shared \
--with-curses \
--enable-multibyte
EOF
)
->withPkgName('readline')
->withLdflags('-L/usr/readline/lib')
->withLdflags('-L' . READLINE_PREFIX . '/lib')
->withLicense('https://www.gnu.org/licenses/gpl.html', Library::LICENSE_GPL)
->withHomePage('https://tiswww.case.edu/php/chet/readline/rltop.html')
->depends('ncurses')
);
}
$p->addExtension((new Extension('readline'))
->withOptions('--with-readline=/usr/readline')
->withOptions('--with-readline=' . READLINE_PREFIX)
->depends('ncurses', 'readline')
);
};
4 changes: 2 additions & 2 deletions conf.d/sodium.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
->withLicense('https://en.wikipedia.org/wiki/ISC_license', Library::LICENSE_SPEC)
->withHomePage('https://doc.libsodium.org/')
->withUrl('https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz')
->withPrefix('/usr/libsodium')
->withConfigure('./configure --prefix=/usr/libsodium --enable-static --disable-shared')
->withPrefix(LIBSODIUM_PREFIX)
->withConfigure('./configure --prefix=' . LIBSODIUM_PREFIX . ' --enable-static --disable-shared')
->withPkgName('libsodium')
);
$p->addExtension((new Extension('sodium'))->withOptions('--with-sodium'));
Expand Down
4 changes: 2 additions & 2 deletions conf.d/sqlite3.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
$p->addLibrary(
(new Library('sqlite3'))
->withUrl('https://www.sqlite.org/2021/sqlite-autoconf-3370000.tar.gz')
->withPrefix('/usr/sqlite3')
->withConfigure('./configure --prefix=/usr/sqlite3 --enable-static --disable-shared')
->withPrefix(SQLITE3_PREFIX)
->withConfigure('./configure --prefix=' . SQLITE3_PREFIX . ' --enable-static --disable-shared')
->withHomePage('https://www.sqlite.org/index.html')
->withLicense('https://www.sqlite.org/copyright.html', Library::LICENSE_SPEC)
->withPkgName('sqlite3')
Expand Down
18 changes: 9 additions & 9 deletions conf.d/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
(new Library('brotli'))
->withUrl('https://github.com/google/brotli/archive/refs/tags/v1.0.9.tar.gz')
->withFile('brotli-1.0.9.tar.gz')
->withPrefix('/usr/brotli')
->withConfigure("cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr/brotli .")
->withPrefix(BROTLI_PREFIX)
->withConfigure('cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=' . BROTLI_PREFIX . ' .')
->withScriptAfterInstall(
implode(PHP_EOL, [
'rm -rf /usr/brotli/lib/*.so.*',
'rm -rf /usr/brotli/lib/*.so',
'rm -rf /usr/brotli/lib/*.dylib',
'mv /usr/brotli/lib/libbrotlicommon-static.a /usr/brotli/lib/libbrotli.a',
'mv /usr/brotli/lib/libbrotlienc-static.a /usr/brotli/lib/libbrotlienc.a',
'mv /usr/brotli/lib/libbrotlidec-static.a /usr/brotli/lib/libbrotlidec.a',
'rm -rf ' . BROTLI_PREFIX . '/lib/*.so.*',
'rm -rf ' . BROTLI_PREFIX . '/lib/*.so',
'rm -rf ' . BROTLI_PREFIX . '/lib/*.dylib',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotli.a',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlienc-static.a ' . BROTLI_PREFIX . '/lib/libbrotlienc.a',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlidec-static.a ' . BROTLI_PREFIX . '/lib/libbrotlidec.a',
]))
->withPkgName('libbrotlicommon libbrotlidec libbrotlienc')
->withLicense('https://github.com/google/brotli/blob/master/LICENSE', Library::LICENSE_MIT)
->withHomePage('https://github.com/google/brotli')
);
$options .= ' --with-brotli-dir=/usr/brotli';
$options .= ' --with-brotli-dir=' . BROTLI_PREFIX;
}

$p->addExtension((new Extension('swoole'))
Expand Down
7 changes: 4 additions & 3 deletions conf.d/xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use SwooleCli\Extension;

return function (Preprocessor $p) {
$libxml2_prefix = LIBXML2_PREFIX;
$iconv_prefix = ICONV_PREFIX;
$p->addLibrary(
// MUST be in the /usr directory
(new Library('libxml2'))
->withUrl('https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.9.10/libxml2-v2.9.10.tar.gz')
->withPrefix('/usr/libxml2')
->withPrefix(LIBXML2_PREFIX)
->withConfigure(<<<EOF
./autogen.sh && ./configure --prefix=/usr/libxml2 --with-iconv=/usr/libiconv --enable-static=yes --enable-shared=no --without-python
./autogen.sh && ./configure --prefix=$libxml2_prefix --with-iconv=$iconv_prefix --enable-static=yes --enable-shared=no --without-python
EOF
)
->withPkgName('libxml-2.0')
Expand Down
6 changes: 3 additions & 3 deletions conf.d/xsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
$p->addLibrary(
(new Library('libxslt'))
->withUrl('https://gitlab.gnome.org/GNOME/libxslt/-/archive/v1.1.34/libxslt-v1.1.34.tar.gz')
->withPrefix('/usr/libxslt')
->withConfigure('./autogen.sh && ./configure --prefix=/usr/libxslt --enable-static=yes --enable-shared=no')
->withPrefix(LIBXSLT_PREFIX)
->withConfigure('./autogen.sh && ./configure --prefix=' . LIBXSLT_PREFIX . '--enable-static=yes --enable-shared=no')
->withLicense('http://www.opensource.org/licenses/mit-license.html', Library::LICENSE_MIT)
->withPkgName('libexslt libxslt')
->depends('libxml2','libiconv')
->depends('libxml2', 'libiconv')
);
$p->addExtension((new Extension('xsl'))->withOptions('--with-xsl')->depends('libxslt'));
};
6 changes: 3 additions & 3 deletions conf.d/yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
$p->addLibrary(
(new Library('libyaml'))
->withUrl('https://pyyaml.org/download/libyaml/yaml-0.2.5.tar.gz')
->withPrefix('/usr/libyaml')
->withConfigure('./configure --prefix=/usr/libyaml --enable-static --disable-shared')
->withPrefix(LIBYAML_PREFIX)
->withConfigure('./configure --prefix=' . LIBYAML_PREFIX . ' --enable-static --disable-shared')
->withPkgName('yaml-0.1')
->withLicense('https://pyyaml.org/wiki/LibYAML', Library::LICENSE_MIT)
->withHomePage('https://pyyaml.org/wiki/LibYAML')
);
$p->addExtension((new Extension('yaml'))
->withOptions('--with-yaml=/usr/libyaml')
->withOptions('--with-yaml=' . LIBYAML_PREFIX)
->withPeclVersion('2.2.2')
->withHomePage('https://github.com/php/pecl-file_formats-yaml')
->withLicense('https://github.com/php/pecl-file_formats-yaml/blob/php7/LICENSE', Extension::LICENSE_MIT)
Expand Down
2 changes: 1 addition & 1 deletion conf.d/zlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
->withPkgName('zlib')
->depends('libxml2', 'bzip2')
);
$p->addExtension((new Extension('zlib'))->withOptions('--with-zlib --with-zlib-dir=/usr/zlib'));
$p->addExtension((new Extension('zlib'))->withOptions('--with-zlib --with-zlib-dir=' . ZLIB_PREFIX));
};
21 changes: 9 additions & 12 deletions prepare.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/sapi/constants.php';

use SwooleCli\Preprocessor;

$homeDir = getenv('HOME');

$p = new Preprocessor(__DIR__);
$p->setPhpSrcDir($homeDir . '/.phpbrew/build/php-8.1.12');
$p->parseArguments($argc, $argv);
$p->setPhpSrcDir(getenv('HOME') . '/.phpbrew/build/php-8.1.12');
if ($p->getOsType() == 'macos') {
$p->setWorkDir(__DIR__);
$p->setBuildDir(__DIR__ . '/thirdparty');
$p->setExtraLdflags('-framework CoreFoundation -framework SystemConfiguration -undefined dynamic_lookup -lwebp -lwebpdemux -lwebpmux -licudata -licui18n -licuio');
$p->addEndCallback(function () use ($p, $homeDir) {
$libDir = $homeDir . '/.swoole-cli';
if (!is_dir($libDir)) {
mkdir($libDir);
define('GLOBAL_PREFIX', $homeDir . '/.swoole-cli');
$p->setExtraLdflags('-framework CoreFoundation -framework SystemConfiguration -undefined dynamic_lookup');
$p->addEndCallback(function () use ($p) {
if (!is_dir(GLOBAL_PREFIX)) {
mkdir(GLOBAL_PREFIX);
}
// The lib directory MUST not be in the current directory, otherwise the php make clean script will delete librarys
file_put_contents(__DIR__ . '/make.sh', str_replace('/usr', $homeDir . '/.swoole-cli', file_get_contents(__DIR__ . '/make.sh')));
});
} else {
define('GLOBAL_PREFIX', '/usr');
}
$p->gen();
$p->info();
$p->execute();
Loading

0 comments on commit 875ec69

Please sign in to comment.