diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index a3d08f09..79c0a957 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -301,10 +301,10 @@ class Extension // prepare configure args shell()->cd($this->source_dir) ->setEnv($env) - ->execWithEnv(BUILD_BIN_PATH . '/phpize') - ->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') - ->execWithEnv('make clean') - ->execWithEnv('make -j' . $this->builder->concurrency); + ->exec(BUILD_BIN_PATH . '/phpize') + ->exec('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') + ->exec('make clean') + ->exec('make -j' . $this->builder->concurrency); // copy shared library copy($this->source_dir . '/modules/' . $this->getDistName() . '.so', BUILD_LIB_PATH . '/' . $this->getDistName() . '.so'); diff --git a/src/SPC/builder/linux/library/libffi.php b/src/SPC/builder/linux/library/libffi.php index 9d1c2d79..0324f92c 100644 --- a/src/SPC/builder/linux/library/libffi.php +++ b/src/SPC/builder/linux/library/libffi.php @@ -21,8 +21,8 @@ class libffi extends LinuxLibraryBase $arch = getenv('SPC_ARCH'); shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + ->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -31,9 +31,9 @@ class libffi extends LinuxLibraryBase '--prefix= ' . "--libdir={$lib}" ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv("make install DESTDIR={$destdir}"); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) { copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a'); diff --git a/src/SPC/builder/linux/library/libpng.php b/src/SPC/builder/linux/library/libpng.php index 56daee55..fc8c8099 100644 --- a/src/SPC/builder/linux/library/libpng.php +++ b/src/SPC/builder/linux/library/libpng.php @@ -41,15 +41,10 @@ class libpng extends LinuxLibraryBase 'aarch64' => '--enable-arm-neon ', default => '', }; - shell()->cd($this->source_dir) + shell()->cd($this->source_dir)->initLibBuildEnv($this) ->exec('chmod +x ./configure') ->exec('chmod +x ./install-sh') - ->setEnv([ - 'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + ->exec( 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' . './configure ' . '--disable-shared ' . @@ -59,9 +54,9 @@ class libpng extends LinuxLibraryBase $optimizations . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") - ->execWithEnv('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") + ->exec('make install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); $this->cleanLaFiles(); } diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index d57265dd..576396e6 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -64,9 +64,8 @@ class openssl extends LinuxLibraryBase $clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : ''; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( "{$env} ./Configure no-shared {$extra} " . '--prefix=/ ' . '--libdir=lib ' . @@ -76,7 +75,7 @@ class openssl extends LinuxLibraryBase "linux-{$arch}{$clang_postfix}" ) ->exec('make clean') - ->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") + ->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']); // patch for openssl 3.3.0+ diff --git a/src/SPC/builder/macos/library/openssl.php b/src/SPC/builder/macos/library/openssl.php index e0e3919f..f4512871 100644 --- a/src/SPC/builder/macos/library/openssl.php +++ b/src/SPC/builder/macos/library/openssl.php @@ -49,8 +49,7 @@ class openssl extends MacOSLibraryBase } $arch = getenv('SPC_ARCH'); - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + shell()->cd($this->source_dir)->initLibBuildEnv($this) ->exec( "./Configure no-shared {$extra} " . '--prefix=/ ' . // use prefix=/ @@ -59,7 +58,7 @@ class openssl extends MacOSLibraryBase "darwin64-{$arch}-cc" ) ->exec('make clean') - ->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") + ->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']); // patch for openssl 3.3.0+ diff --git a/src/SPC/builder/unix/library/attr.php b/src/SPC/builder/unix/library/attr.php index ce542ddd..26278cb0 100644 --- a/src/SPC/builder/unix/library/attr.php +++ b/src/SPC/builder/unix/library/attr.php @@ -13,16 +13,12 @@ trait attr */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv('libtoolize --force --copy') - ->execWithEnv('./autogen.sh || autoreconf -if') - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls') - ->execWithEnv("make -j {$this->builder->concurrency}") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"]) + ->exec('libtoolize --force --copy') + ->exec('./autogen.sh || autoreconf -if') + ->exec('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls') + ->exec("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX); diff --git a/src/SPC/builder/unix/library/bzip2.php b/src/SPC/builder/unix/library/bzip2.php index 0241fb1b..7315f4e1 100644 --- a/src/SPC/builder/unix/library/bzip2.php +++ b/src/SPC/builder/unix/library/bzip2.php @@ -16,10 +16,9 @@ trait bzip2 protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("make PREFIX='" . BUILD_ROOT_PATH . "' clean") - ->execWithEnv("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean") + ->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} 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/gettext.php b/src/SPC/builder/unix/library/gettext.php index 69736c36..b3800ac5 100644 --- a/src/SPC/builder/unix/library/gettext.php +++ b/src/SPC/builder/unix/library/gettext.php @@ -16,13 +16,9 @@ trait gettext $cflags = $this->builder->getOption('enable-zts') ? '-lpthread -D_REENTRANT' : ''; $ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : ''; - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", - 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags]) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -34,8 +30,8 @@ trait gettext '--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' . '--prefix=' . BUILD_ROOT_PATH ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); } } diff --git a/src/SPC/builder/unix/library/gmp.php b/src/SPC/builder/unix/library/gmp.php index 49b207fb..40cf71d5 100644 --- a/src/SPC/builder/unix/library/gmp.php +++ b/src/SPC/builder/unix/library/gmp.php @@ -15,15 +15,14 @@ trait gmp */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static --disable-shared ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") + ->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/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 56da92e5..6f39385c 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -46,14 +46,9 @@ trait imagemagick // libxml iconv patch $required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : ''; - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, - 'LIBS' => $this->getLibExtraLibs() ?: $required_libs, - 'PKG_CONFIG' => '$PKG_CONFIG --static', - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['LDFLAGS' => $ldflags, 'LIBS' => $required_libs, 'PKG_CONFIG' => '$PKG_CONFIG --static']) + ->exec( './configure ' . '--enable-static --disable-shared ' . $extra . diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 2831f094..0d1b1ad2 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -26,14 +26,9 @@ trait ldap $alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '--enable-argon2=no '; f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config'); f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig'); - $ldflags = '-L' . BUILD_LIB_PATH; - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['LDFLAGS' => "-L{$this->getLibDir()}"]) + ->exec( $this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) . ' ./configure ' . '--enable-static ' . diff --git a/src/SPC/builder/unix/library/libacl.php b/src/SPC/builder/unix/library/libacl.php index 6abfbb5b..0522786f 100644 --- a/src/SPC/builder/unix/library/libacl.php +++ b/src/SPC/builder/unix/library/libacl.php @@ -29,16 +29,12 @@ trait libacl */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), - 'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv('libtoolize --force --copy') - ->execWithEnv('./autogen.sh || autoreconf -if') - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests --disable-nls') - ->execWithEnv("make -j {$this->builder->concurrency}") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"]) + ->exec('libtoolize --force --copy') + ->exec('./autogen.sh || autoreconf -if') + ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --disable-nls') + ->exec("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libacl.pc'], PKGCONF_PATCH_PREFIX); diff --git a/src/SPC/builder/unix/library/libargon2.php b/src/SPC/builder/unix/library/libargon2.php index e91b71f0..e235f575 100644 --- a/src/SPC/builder/unix/library/libargon2.php +++ b/src/SPC/builder/unix/library/libargon2.php @@ -10,11 +10,10 @@ trait libargon2 { protected function build() { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + shell()->cd($this->source_dir)->initLibBuildEnv($this) ->exec("make PREFIX='' clean") - ->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''") - ->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); + ->exec("make -j{$this->builder->concurrency} PREFIX=''") + ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libargon2.pc']); diff --git a/src/SPC/builder/unix/library/libcares.php b/src/SPC/builder/unix/library/libcares.php index d99cc685..3acd9814 100644 --- a/src/SPC/builder/unix/library/libcares.php +++ b/src/SPC/builder/unix/library/libcares.php @@ -24,11 +24,10 @@ trait libcares */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic') - ->execWithEnv("make -j {$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic') + ->exec("make -j {$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libcares.pc'], PKGCONF_PATCH_PREFIX); } diff --git a/src/SPC/builder/unix/library/libiconv.php b/src/SPC/builder/unix/library/libiconv.php index a587c472..6037d5d0 100644 --- a/src/SPC/builder/unix/library/libiconv.php +++ b/src/SPC/builder/unix/library/libiconv.php @@ -10,18 +10,17 @@ trait libiconv { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . '--enable-extra-encodings ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . $destdir); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . $destdir); if (file_exists(BUILD_BIN_PATH . '/iconv')) { unlink(BUILD_BIN_PATH . '/iconv'); diff --git a/src/SPC/builder/unix/library/liblz4.php b/src/SPC/builder/unix/library/liblz4.php index 45e803bf..d5283cbe 100644 --- a/src/SPC/builder/unix/library/liblz4.php +++ b/src/SPC/builder/unix/library/liblz4.php @@ -17,11 +17,10 @@ trait liblz4 protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv("make PREFIX='' clean") - ->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''") - ->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec("make PREFIX='' clean") + ->exec("make -j{$this->builder->concurrency} PREFIX=''") + ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['liblz4.pc']); diff --git a/src/SPC/builder/unix/library/libtiff.php b/src/SPC/builder/unix/library/libtiff.php index 5d2cb4c1..5561adcb 100644 --- a/src/SPC/builder/unix/library/libtiff.php +++ b/src/SPC/builder/unix/library/libtiff.php @@ -22,9 +22,8 @@ trait libtiff // We disabled lzma, zstd, webp, libdeflate by default to reduce the size of the binary $extra_libs .= ' --disable-lzma --disable-zstd --disable-webp --disable-libdeflate'; - $shell = shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + $shell = shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static --disable-shared ' . "{$extra_libs} " . @@ -34,12 +33,12 @@ trait libtiff // TODO: Remove this check when https://gitlab.com/libtiff/libtiff/-/merge_requests/635 will be merged and released if (file_exists($this->source_dir . '/html')) { - $shell->execWithEnv('make clean'); + $shell->exec('make clean'); } $shell - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libtiff-4.pc']); } } diff --git a/src/SPC/builder/unix/library/libxslt.php b/src/SPC/builder/unix/library/libxslt.php index 799c87c2..f0d2592f 100644 --- a/src/SPC/builder/unix/library/libxslt.php +++ b/src/SPC/builder/unix/library/libxslt.php @@ -24,13 +24,13 @@ trait libxslt $required_libs .= ' ' . $dep->getStaticLibFiles(); } } - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => trim($this->getLibExtraCFlags() . ' -I' . BUILD_INCLUDE_PATH), - 'LDFLAGS' => trim($this->getLibExtraLdFlags() . ' -L' . BUILD_LIB_PATH), - 'LIBS' => trim($this->getLibExtraLibs() . "{$required_libs} -lstdc++"), + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv([ + 'CFLAGS' => "-I{$this->getIncludeDir()}", + 'LDFLAGS' => "-L{$this->getLibDir()}", + 'LIBS' => "{$required_libs} -lstdc++", ]) - ->execWithEnv( + ->exec( "{$this->builder->getOption('library_path')} " . "{$this->builder->getOption('ld_library_path')} " . './configure ' . @@ -43,9 +43,9 @@ trait libxslt '--with-libxml-prefix=' . escapeshellarg(BUILD_ROOT_PATH) . ' ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . escapeshellarg(BUILD_ROOT_PATH)); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . escapeshellarg(BUILD_ROOT_PATH)); $this->patchPkgconfPrefix(['libexslt.pc']); } } diff --git a/src/SPC/builder/unix/library/ncurses.php b/src/SPC/builder/unix/library/ncurses.php index a44ac175..42b4f2d3 100644 --- a/src/SPC/builder/unix/library/ncurses.php +++ b/src/SPC/builder/unix/library/ncurses.php @@ -11,9 +11,8 @@ trait ncurses protected function build(): void { $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -33,9 +32,9 @@ trait ncurses '--libdir=' . BUILD_ROOT_PATH . '/lib ' . '--prefix=' . BUILD_ROOT_PATH ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install'); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); $final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); // Remove the new files diff --git a/src/SPC/builder/unix/library/nghttp2.php b/src/SPC/builder/unix/library/nghttp2.php index 202b2959..d8f4dc29 100644 --- a/src/SPC/builder/unix/library/nghttp2.php +++ b/src/SPC/builder/unix/library/nghttp2.php @@ -40,9 +40,8 @@ trait nghttp2 [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -51,9 +50,9 @@ trait nghttp2 $args . ' ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv("make install DESTDIR={$destdir}"); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec("make install DESTDIR={$destdir}"); $this->patchPkgconfPrefix(['libnghttp2.pc']); } } diff --git a/src/SPC/builder/unix/library/nghttp3.php b/src/SPC/builder/unix/library/nghttp3.php index 03d4d481..4c1c8284 100644 --- a/src/SPC/builder/unix/library/nghttp3.php +++ b/src/SPC/builder/unix/library/nghttp3.php @@ -15,13 +15,8 @@ trait nghttp3 */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -29,9 +24,9 @@ trait nghttp3 '--enable-lib-only ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libnghttp3.pc']); } } diff --git a/src/SPC/builder/unix/library/ngtcp2.php b/src/SPC/builder/unix/library/ngtcp2.php index 8ea280a8..66ba1306 100644 --- a/src/SPC/builder/unix/library/ngtcp2.php +++ b/src/SPC/builder/unix/library/ngtcp2.php @@ -30,13 +30,8 @@ trait ngtcp2 $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; } - shell()->cd($this->source_dir) - ->setEnv([ - 'CFLAGS' => $this->getLibExtraCFlags(), - 'LDFLAGS' => $this->getLibExtraLdFlags(), - 'LIBS' => $this->getLibExtraLibs(), - ]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static ' . '--disable-shared ' . @@ -45,9 +40,9 @@ trait ngtcp2 $args . ' ' . '--prefix=' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']); // on macOS, the static library may contain other static libraries? diff --git a/src/SPC/builder/unix/library/onig.php b/src/SPC/builder/unix/library/onig.php index 60ea84fa..380e05b2 100644 --- a/src/SPC/builder/unix/library/onig.php +++ b/src/SPC/builder/unix/library/onig.php @@ -17,11 +17,10 @@ trait onig { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --enable-static --disable-shared --prefix=') - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./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/pkgconfig.php b/src/SPC/builder/unix/library/pkgconfig.php index b489bbba..5fc89113 100644 --- a/src/SPC/builder/unix/library/pkgconfig.php +++ b/src/SPC/builder/unix/library/pkgconfig.php @@ -13,9 +13,9 @@ trait pkgconfig $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $ldflags = !($this instanceof LinuxLibraryBase) || getenv('SPC_LIBC') === 'glibc' ? '' : '--static'; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", 'LDFLAGS' => "{$this->getLibExtraLdFlags()} {$ldflags}", 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags]) + ->exec( './configure ' . '--disable-shared ' . '--enable-static ' . @@ -29,8 +29,8 @@ trait pkgconfig '--without-pc-path' ) ->exec('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install-exec'); + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install-exec'); shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config'); } } diff --git a/src/SPC/builder/unix/library/readline.php b/src/SPC/builder/unix/library/readline.php index d0369c1a..a7339d60 100644 --- a/src/SPC/builder/unix/library/readline.php +++ b/src/SPC/builder/unix/library/readline.php @@ -15,9 +15,8 @@ trait readline */ protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv( + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec( './configure ' . '--enable-static=yes ' . '--enable-shared=no ' . @@ -25,9 +24,9 @@ trait readline '--with-curses ' . '--enable-multibyte=yes' ) - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['readline.pc']); } } diff --git a/src/SPC/builder/unix/library/sqlite.php b/src/SPC/builder/unix/library/sqlite.php index ee814702..42e23679 100644 --- a/src/SPC/builder/unix/library/sqlite.php +++ b/src/SPC/builder/unix/library/sqlite.php @@ -8,12 +8,11 @@ trait sqlite { protected function build(): void { - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --enable-static --disable-shared --prefix=') - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./configure --enable-static --disable-shared --prefix=') + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install DESTDIR=' . BUILD_ROOT_PATH); $this->patchPkgconfPrefix(['sqlite3.pc']); } } diff --git a/src/SPC/builder/unix/library/zlib.php b/src/SPC/builder/unix/library/zlib.php index f764de91..f2490a6c 100644 --- a/src/SPC/builder/unix/library/zlib.php +++ b/src/SPC/builder/unix/library/zlib.php @@ -17,12 +17,11 @@ trait zlib { [,,$destdir] = SEPARATED_PATH; - shell()->cd($this->source_dir) - ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) - ->execWithEnv('./configure --static --prefix=') - ->execWithEnv('make clean') - ->execWithEnv("make -j{$this->builder->concurrency}") - ->execWithEnv("make install DESTDIR={$destdir}"); + shell()->cd($this->source_dir)->initLibBuildEnv($this) + ->exec('./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/util/UnixShell.php b/src/SPC/util/UnixShell.php index 44e97bfe..9dd779a7 100644 --- a/src/SPC/util/UnixShell.php +++ b/src/SPC/util/UnixShell.php @@ -4,6 +4,9 @@ declare(strict_types=1); namespace SPC\util; +use SPC\builder\freebsd\library\BSDLibraryBase; +use SPC\builder\linux\library\LinuxLibraryBase; +use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\RuntimeException; use ZM\Logger\ConsoleColor; @@ -48,7 +51,41 @@ class UnixShell if (!$this->debug) { $cmd .= ' 1>/dev/null 2>&1'; } - f_passthru($cmd); + $env_str = $this->getEnvString(); + if (!empty($env_str)) { + $env_str = "{$env_str} "; + } + f_passthru("{$env_str}{$cmd}"); + return $this; + } + + /** + * Init the environment variable that common build will be used. + * + * @param BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library Library class + */ + public function initLibBuildEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library): UnixShell + { + $this->setEnv([ + 'CFLAGS' => $library->getLibExtraCFlags(), + 'LDFLAGS' => $library->getLibExtraLdFlags(), + 'LIBS' => $library->getLibExtraLibs(), + ]); + return $this; + } + + public function appendEnv(array $env): UnixShell + { + foreach ($env as $k => $v) { + if ($v === '') { + continue; + } + if (!isset($this->env[$k])) { + $this->env[$k] = $v; + } else { + $this->env[$k] = "{$v} {$this->env[$k]}"; + } + } return $this; } @@ -80,14 +117,6 @@ class UnixShell return $this; } - /** - * @throws RuntimeException - */ - public function execWithEnv(string $cmd): UnixShell - { - return $this->exec($this->getEnvString() . ' ' . $cmd); - } - private function getEnvString(): string { $str = ''; diff --git a/src/SPC/util/executor/UnixCMakeExecutor.php b/src/SPC/util/executor/UnixCMakeExecutor.php index 71319fa0..9cb0d52d 100644 --- a/src/SPC/util/executor/UnixCMakeExecutor.php +++ b/src/SPC/util/executor/UnixCMakeExecutor.php @@ -33,24 +33,17 @@ class UnixCMakeExecutor extends Executor FileSystem::resetDir($this->build_dir); } - // prepare environment variables - $env = [ - 'CFLAGS' => $this->library->getLibExtraCFlags(), - 'LDFLAGS' => $this->library->getLibExtraLdFlags(), - 'LIBS' => $this->library->getLibExtraLibs(), - ]; - // prepare shell - $shell = shell()->cd($this->build_dir)->setEnv($env); + $shell = shell()->cd($this->build_dir)->initLibBuildEnv($this->library); // config - $this->steps >= 1 && $shell->execWithEnv("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); + $this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}"); // make - $this->steps >= 2 && $shell->execWithEnv("cmake --build . -j {$this->library->getBuilder()->concurrency}"); + $this->steps >= 2 && $shell->exec("cmake --build . -j {$this->library->getBuilder()->concurrency}"); // install - $this->steps >= 3 && $shell->execWithEnv('make install'); + $this->steps >= 3 && $shell->exec('make install'); } /**