Merge pull request #751 from crazywhalecc/shell-improvement

Extract default build env to unix shell
This commit is contained in:
Jerry Ma 2025-06-09 13:37:12 +08:00 committed by GitHub
commit bed5b9d4ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 186 additions and 202 deletions

12
.gitignore vendored
View File

@ -5,22 +5,22 @@ docker/extensions/
docker/source/ docker/source/
# Vendor files # Vendor files
/vendor/ /vendor/**
# default source extract directory # default source extract directory
/source/ /source/**
# default source download directory # default source download directory
/downloads/ /downloads/**
# default source build root directory # default source build root directory
/buildroot/ /buildroot/**
# default package root directory # default package root directory
/pkgroot/ /pkgroot/**
# default pack:lib and release directory # default pack:lib and release directory
/dist/ /dist/**
packlib_files.txt packlib_files.txt
# tools cache files # tools cache files

View File

@ -301,10 +301,10 @@ class Extension
// prepare configure args // prepare configure args
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv($env) ->setEnv($env)
->execWithEnv(BUILD_BIN_PATH . '/phpize') ->exec(BUILD_BIN_PATH . '/phpize')
->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') ->exec('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static')
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv('make -j' . $this->builder->concurrency); ->exec('make -j' . $this->builder->concurrency);
// copy shared library // copy shared library
copy($this->source_dir . '/modules/' . $this->getDistName() . '.so', BUILD_LIB_PATH . '/' . $this->getDistName() . '.so'); copy($this->source_dir . '/modules/' . $this->getDistName() . '.so', BUILD_LIB_PATH . '/' . $this->getDistName() . '.so');

View File

@ -21,8 +21,8 @@ class libffi extends LinuxLibraryBase
$arch = getenv('SPC_ARCH'); $arch = getenv('SPC_ARCH');
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->initializeEnv($this)
->execWithEnv( ->exec(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -31,9 +31,9 @@ class libffi extends LinuxLibraryBase
'--prefix= ' . '--prefix= ' .
"--libdir={$lib}" "--libdir={$lib}"
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv("make install DESTDIR={$destdir}"); ->exec("make install DESTDIR={$destdir}");
if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) { if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) {
copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a'); copy(BUILD_ROOT_PATH . '/lib64/libffi.a', BUILD_ROOT_PATH . '/lib/libffi.a');

View File

@ -41,15 +41,10 @@ class libpng extends LinuxLibraryBase
'aarch64' => '--enable-arm-neon ', 'aarch64' => '--enable-arm-neon ',
default => '', default => '',
}; };
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->exec('chmod +x ./configure') ->exec('chmod +x ./configure')
->exec('chmod +x ./install-sh') ->exec('chmod +x ./install-sh')
->setEnv([ ->exec(
'CFLAGS' => trim($this->getLibExtraCFlags() . ' ' . $this->builder->arch_c_flags),
'LDFLAGS' => $this->getLibExtraLdFlags(),
'LIBS' => $this->getLibExtraLibs(),
])
->execWithEnv(
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' . 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
'./configure ' . './configure ' .
'--disable-shared ' . '--disable-shared ' .
@ -59,9 +54,9 @@ class libpng extends LinuxLibraryBase
$optimizations . $optimizations .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency} DEFAULT_INCLUDES='-I{$this->source_dir} -I" . BUILD_INCLUDE_PATH . "' LIBS= libpng16.la") ->exec("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 install-libLTLIBRARIES install-data-am DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX); $this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX);
$this->cleanLaFiles(); $this->cleanLaFiles();
} }

View File

@ -64,9 +64,8 @@ class openssl extends LinuxLibraryBase
$clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : ''; $clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : '';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
"{$env} ./Configure no-shared {$extra} " . "{$env} ./Configure no-shared {$extra} " .
'--prefix=/ ' . '--prefix=/ ' .
'--libdir=lib ' . '--libdir=lib ' .
@ -76,7 +75,7 @@ class openssl extends LinuxLibraryBase
"linux-{$arch}{$clang_postfix}" "linux-{$arch}{$clang_postfix}"
) )
->exec('make clean') ->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}"); ->exec("make install_sw DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
// patch for openssl 3.3.0+ // patch for openssl 3.3.0+

View File

@ -49,8 +49,7 @@ class openssl extends MacOSLibraryBase
} }
$arch = getenv('SPC_ARCH'); $arch = getenv('SPC_ARCH');
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec( ->exec(
"./Configure no-shared {$extra} " . "./Configure no-shared {$extra} " .
'--prefix=/ ' . // use prefix=/ '--prefix=/ ' . // use prefix=/
@ -59,7 +58,7 @@ class openssl extends MacOSLibraryBase
"darwin64-{$arch}-cc" "darwin64-{$arch}-cc"
) )
->exec('make clean') ->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}"); ->exec("make install_sw DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
// patch for openssl 3.3.0+ // patch for openssl 3.3.0+

View File

@ -118,4 +118,13 @@ trait UnixLibraryTrait
{ {
return getenv($this->getSnakeCaseName() . '_LIBS') ?: ''; return getenv($this->getSnakeCaseName() . '_LIBS') ?: '';
} }
public function getLibExtraCXXFlags(): string
{
$env = getenv($this->getSnakeCaseName() . '_CXXFLAGS') ?: '';
if (!str_contains($env, $this->builder->arch_cxx_flags)) {
$env .= $this->builder->arch_cxx_flags;
}
return $env;
}
} }

View File

@ -13,16 +13,12 @@ trait attr
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"])
'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), ->exec('libtoolize --force --copy')
'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), ->exec('./autogen.sh || autoreconf -if')
'LIBS' => $this->getLibExtraLibs(), ->exec('./configure --prefix= --enable-static --disable-shared --with-pic --disable-nls')
]) ->exec("make -j {$this->builder->concurrency}")
->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}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX); $this->patchPkgconfPrefix(['libattr.pc'], PKGCONF_PATCH_PREFIX);

View File

@ -19,6 +19,7 @@ trait brotli
{ {
UnixCMakeExecutor::create($this) UnixCMakeExecutor::create($this)
->setBuildDir("{$this->getSourceDir()}/build-dir") ->setBuildDir("{$this->getSourceDir()}/build-dir")
->addConfigureArgs("-DSHARE_INSTALL_PREFIX={$this->getBuildRootPath()}")
->build(); ->build();
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);

View File

@ -16,10 +16,9 @@ trait bzip2
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean")
->execWithEnv("make PREFIX='" . BUILD_ROOT_PATH . "' clean") ->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
->execWithEnv("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
->exec('cp libbz2.a ' . BUILD_LIB_PATH) ->exec('cp libbz2.a ' . BUILD_LIB_PATH)
->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH);
} }

View File

@ -16,13 +16,9 @@ trait gettext
$cflags = $this->builder->getOption('enable-zts') ? '-lpthread -D_REENTRANT' : ''; $cflags = $this->builder->getOption('enable-zts') ? '-lpthread -D_REENTRANT' : '';
$ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : ''; $ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : '';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags])
'CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", ->exec(
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
'LIBS' => $this->getLibExtraLibs(),
])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -34,8 +30,8 @@ trait gettext
'--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' . '--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' .
'--prefix=' . BUILD_ROOT_PATH '--prefix=' . BUILD_ROOT_PATH
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install'); ->exec('make install');
} }
} }

View File

@ -15,15 +15,14 @@ trait gmp
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared ' . '--enable-static --disable-shared ' .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['gmp.pc']); $this->patchPkgconfPrefix(['gmp.pc']);
} }

View File

@ -46,14 +46,9 @@ trait imagemagick
// libxml iconv patch // libxml iconv patch
$required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : ''; $required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : '';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->appendEnv(['LDFLAGS' => $ldflags, 'LIBS' => $required_libs, 'PKG_CONFIG' => '$PKG_CONFIG --static'])
'CFLAGS' => $this->getLibExtraCFlags(), ->exec(
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
'LIBS' => $this->getLibExtraLibs() ?: $required_libs,
'PKG_CONFIG' => '$PKG_CONFIG --static',
])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared ' . '--enable-static --disable-shared ' .
$extra . $extra .

View File

@ -26,14 +26,9 @@ trait ldap
$alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '--enable-argon2=no '; $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=' . BUILD_ROOT_PATH . '/bin/pkg-config');
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig'); f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
$ldflags = '-L' . BUILD_LIB_PATH; shell()->cd($this->source_dir)->initializeEnv($this)
shell()->cd($this->source_dir) ->appendEnv(['LDFLAGS' => "-L{$this->getLibDir()}"])
->setEnv([ ->exec(
'CFLAGS' => $this->getLibExtraCFlags(),
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
'LIBS' => $this->getLibExtraLibs(),
])
->execWithEnv(
$this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) . $this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) .
' ./configure ' . ' ./configure ' .
'--enable-static ' . '--enable-static ' .

View File

@ -29,16 +29,12 @@ trait libacl
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->appendEnv(['CFLAGS' => "-I{$this->getIncludeDir()}", 'LDFLAGS' => "-L{$this->getLibDir()}"])
'CFLAGS' => trim('-I' . BUILD_INCLUDE_PATH . ' ' . $this->getLibExtraCFlags()), ->exec('libtoolize --force --copy')
'LDFLAGS' => trim('-L' . BUILD_LIB_PATH . ' ' . $this->getLibExtraLdFlags()), ->exec('./autogen.sh || autoreconf -if')
'LIBS' => $this->getLibExtraLibs(), ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --disable-nls')
]) ->exec("make -j {$this->builder->concurrency}")
->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}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libacl.pc'], PKGCONF_PATCH_PREFIX); $this->patchPkgconfPrefix(['libacl.pc'], PKGCONF_PATCH_PREFIX);

View File

@ -10,11 +10,10 @@ trait libargon2
{ {
protected function build() protected function build()
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec("make PREFIX='' clean") ->exec("make PREFIX='' clean")
->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''") ->exec("make -j{$this->builder->concurrency} PREFIX=''")
->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libargon2.pc']); $this->patchPkgconfPrefix(['libargon2.pc']);

View File

@ -24,11 +24,10 @@ trait libcares
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic')
->execWithEnv('./configure --prefix= --enable-static --disable-shared --disable-tests --with-pic') ->exec("make -j {$this->builder->concurrency}")
->execWithEnv("make -j {$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libcares.pc'], PKGCONF_PATCH_PREFIX); $this->patchPkgconfPrefix(['libcares.pc'], PKGCONF_PATCH_PREFIX);
} }

View File

@ -10,18 +10,17 @@ trait libiconv
{ {
[,,$destdir] = SEPARATED_PATH; [,,$destdir] = SEPARATED_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
'--enable-extra-encodings ' . '--enable-extra-encodings ' .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . $destdir); ->exec('make install DESTDIR=' . $destdir);
if (file_exists(BUILD_BIN_PATH . '/iconv')) { if (file_exists(BUILD_BIN_PATH . '/iconv')) {
unlink(BUILD_BIN_PATH . '/iconv'); unlink(BUILD_BIN_PATH . '/iconv');

View File

@ -17,11 +17,10 @@ trait liblz4
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec("make PREFIX='' clean")
->execWithEnv("make PREFIX='' clean") ->exec("make -j{$this->builder->concurrency} PREFIX=''")
->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''") ->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['liblz4.pc']); $this->patchPkgconfPrefix(['liblz4.pc']);

View File

@ -22,9 +22,8 @@ trait libtiff
// We disabled lzma, zstd, webp, libdeflate by default to reduce the size of the binary // 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'; $extra_libs .= ' --disable-lzma --disable-zstd --disable-webp --disable-libdeflate';
$shell = shell()->cd($this->source_dir) $shell = shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared ' . '--enable-static --disable-shared ' .
"{$extra_libs} " . "{$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 // 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')) { if (file_exists($this->source_dir . '/html')) {
$shell->execWithEnv('make clean'); $shell->exec('make clean');
} }
$shell $shell
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libtiff-4.pc']); $this->patchPkgconfPrefix(['libtiff-4.pc']);
} }
} }

View File

@ -24,13 +24,13 @@ trait libxslt
$required_libs .= ' ' . $dep->getStaticLibFiles(); $required_libs .= ' ' . $dep->getStaticLibFiles();
} }
} }
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->appendEnv([
'CFLAGS' => trim($this->getLibExtraCFlags() . ' -I' . BUILD_INCLUDE_PATH), 'CFLAGS' => "-I{$this->getIncludeDir()}",
'LDFLAGS' => trim($this->getLibExtraLdFlags() . ' -L' . BUILD_LIB_PATH), 'LDFLAGS' => "-L{$this->getLibDir()}",
'LIBS' => trim($this->getLibExtraLibs() . "{$required_libs} -lstdc++"), 'LIBS' => "{$required_libs} -lstdc++",
]) ])
->execWithEnv( ->exec(
"{$this->builder->getOption('library_path')} " . "{$this->builder->getOption('library_path')} " .
"{$this->builder->getOption('ld_library_path')} " . "{$this->builder->getOption('ld_library_path')} " .
'./configure ' . './configure ' .
@ -43,9 +43,9 @@ trait libxslt
'--with-libxml-prefix=' . escapeshellarg(BUILD_ROOT_PATH) . ' ' . '--with-libxml-prefix=' . escapeshellarg(BUILD_ROOT_PATH) . ' ' .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . escapeshellarg(BUILD_ROOT_PATH)); ->exec('make install DESTDIR=' . escapeshellarg(BUILD_ROOT_PATH));
$this->patchPkgconfPrefix(['libexslt.pc']); $this->patchPkgconfPrefix(['libexslt.pc']);
} }
} }

View File

@ -11,9 +11,8 @@ trait ncurses
protected function build(): void protected function build(): void
{ {
$filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); $filelist = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -33,9 +32,9 @@ trait ncurses
'--libdir=' . BUILD_ROOT_PATH . '/lib ' . '--libdir=' . BUILD_ROOT_PATH . '/lib ' .
'--prefix=' . BUILD_ROOT_PATH '--prefix=' . BUILD_ROOT_PATH
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install'); ->exec('make install');
$final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true); $final = FileSystem::scanDirFiles(BUILD_BIN_PATH, relative: true);
// Remove the new files // Remove the new files

View File

@ -40,9 +40,8 @@ trait nghttp2
[,,$destdir] = SEPARATED_PATH; [,,$destdir] = SEPARATED_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -51,9 +50,9 @@ trait nghttp2
$args . ' ' . $args . ' ' .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv("make install DESTDIR={$destdir}"); ->exec("make install DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libnghttp2.pc']); $this->patchPkgconfPrefix(['libnghttp2.pc']);
} }
} }

View File

@ -15,13 +15,8 @@ trait nghttp3
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->exec(
'CFLAGS' => $this->getLibExtraCFlags(),
'LDFLAGS' => $this->getLibExtraLdFlags(),
'LIBS' => $this->getLibExtraLibs(),
])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -29,9 +24,9 @@ trait nghttp3
'--enable-lib-only ' . '--enable-lib-only ' .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libnghttp3.pc']); $this->patchPkgconfPrefix(['libnghttp3.pc']);
} }
} }

View File

@ -30,13 +30,8 @@ trait ngtcp2
$args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"'; $args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"';
} }
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv([ ->exec(
'CFLAGS' => $this->getLibExtraCFlags(),
'LDFLAGS' => $this->getLibExtraLdFlags(),
'LIBS' => $this->getLibExtraLibs(),
])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -45,9 +40,9 @@ trait ngtcp2
$args . ' ' . $args . ' ' .
'--prefix=' '--prefix='
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']); $this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']);
// on macOS, the static library may contain other static libraries? // on macOS, the static library may contain other static libraries?

View File

@ -17,11 +17,10 @@ trait onig
{ {
[,,$destdir] = SEPARATED_PATH; [,,$destdir] = SEPARATED_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec('./configure --enable-static --disable-shared --prefix=')
->execWithEnv('./configure --enable-static --disable-shared --prefix=') ->exec('make clean')
->execWithEnv('make clean') ->exec("make -j{$this->builder->concurrency}")
->execWithEnv("make -j{$this->builder->concurrency}")
->exec("make install DESTDIR={$destdir}"); ->exec("make install DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['oniguruma.pc']); $this->patchPkgconfPrefix(['oniguruma.pc']);
} }

View File

@ -13,9 +13,9 @@ trait pkgconfig
$cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $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'; $ldflags = !($this instanceof LinuxLibraryBase) || getenv('SPC_LIBC') === 'glibc' ? '' : '--static';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", 'LDFLAGS' => "{$this->getLibExtraLdFlags()} {$ldflags}", 'LIBS' => $this->getLibExtraLibs()]) ->appendEnv(['CFLAGS' => $cflags, 'LDFLAGS' => $ldflags])
->execWithEnv( ->exec(
'./configure ' . './configure ' .
'--disable-shared ' . '--disable-shared ' .
'--enable-static ' . '--enable-static ' .
@ -29,8 +29,8 @@ trait pkgconfig
'--without-pc-path' '--without-pc-path'
) )
->exec('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install-exec'); ->exec('make install-exec');
shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config'); shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config');
} }
} }

View File

@ -15,9 +15,8 @@ trait readline
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec(
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static=yes ' . '--enable-static=yes ' .
'--enable-shared=no ' . '--enable-shared=no ' .
@ -25,9 +24,9 @@ trait readline
'--with-curses ' . '--with-curses ' .
'--enable-multibyte=yes' '--enable-multibyte=yes'
) )
->execWithEnv('make clean') ->exec('make clean')
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['readline.pc']); $this->patchPkgconfPrefix(['readline.pc']);
} }
} }

View File

@ -8,12 +8,11 @@ trait sqlite
{ {
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec('./configure --enable-static --disable-shared --prefix=')
->execWithEnv('./configure --enable-static --disable-shared --prefix=') ->exec('make clean')
->execWithEnv('make clean') ->exec("make -j{$this->builder->concurrency}")
->execWithEnv("make -j{$this->builder->concurrency}") ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['sqlite3.pc']); $this->patchPkgconfPrefix(['sqlite3.pc']);
} }
} }

View File

@ -18,7 +18,10 @@ trait tidy
{ {
UnixCMakeExecutor::create($this) UnixCMakeExecutor::create($this)
->setBuildDir("{$this->source_dir}/build-dir") ->setBuildDir("{$this->source_dir}/build-dir")
->addConfigureArgs('-DSUPPORT_CONSOLE_APP=OFF') ->addConfigureArgs(
'-DSUPPORT_CONSOLE_APP=OFF',
'-DBUILD_SHARED_LIB=OFF'
)
->build(); ->build();
$this->patchPkgconfPrefix(['tidy.pc']); $this->patchPkgconfPrefix(['tidy.pc']);
} }

View File

@ -17,12 +17,11 @@ trait zlib
{ {
[,,$destdir] = SEPARATED_PATH; [,,$destdir] = SEPARATED_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)->initializeEnv($this)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->exec('./configure --static --prefix=')
->execWithEnv('./configure --static --prefix=') ->exec('make clean')
->execWithEnv('make clean') ->exec("make -j{$this->builder->concurrency}")
->execWithEnv("make -j{$this->builder->concurrency}") ->exec("make install DESTDIR={$destdir}");
->execWithEnv("make install DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['zlib.pc']); $this->patchPkgconfPrefix(['zlib.pc']);
} }
} }

View File

@ -4,6 +4,9 @@ declare(strict_types=1);
namespace SPC\util; 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 SPC\exception\RuntimeException;
use ZM\Logger\ConsoleColor; use ZM\Logger\ConsoleColor;
@ -42,6 +45,10 @@ class UnixShell
/* @phpstan-ignore-next-line */ /* @phpstan-ignore-next-line */
logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd)); logger()->info(ConsoleColor::yellow('[EXEC] ') . ConsoleColor::green($cmd));
logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']); logger()->debug('Executed at: ' . debug_backtrace()[0]['file'] . ':' . debug_backtrace()[0]['line']);
$env_str = $this->getEnvString();
if (!empty($env_str)) {
$cmd = "{$env_str} {$cmd}";
}
if ($this->cd !== null) { if ($this->cd !== null) {
$cmd = 'cd ' . escapeshellarg($this->cd) . ' && ' . $cmd; $cmd = 'cd ' . escapeshellarg($this->cd) . ' && ' . $cmd;
} }
@ -52,6 +59,37 @@ class UnixShell
return $this; return $this;
} }
/**
* Init the environment variable that common build will be used.
*
* @param BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library Library class
*/
public function initializeEnv(BSDLibraryBase|LinuxLibraryBase|MacOSLibraryBase $library): UnixShell
{
$this->setEnv([
'CFLAGS' => $library->getLibExtraCFlags(),
'LDFLAGS' => $library->getLibExtraLdFlags(),
'LIBS' => $library->getLibExtraLibs(),
'CXXFLAGS' => $library->getLibExtraCXXFlags(),
]);
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;
}
public function execWithResult(string $cmd, bool $with_log = true): array public function execWithResult(string $cmd, bool $with_log = true): array
{ {
if ($with_log) { if ($with_log) {
@ -80,14 +118,6 @@ class UnixShell
return $this; return $this;
} }
/**
* @throws RuntimeException
*/
public function execWithEnv(string $cmd): UnixShell
{
return $this->exec($this->getEnvString() . ' ' . $cmd);
}
private function getEnvString(): string private function getEnvString(): string
{ {
$str = ''; $str = '';

View File

@ -33,24 +33,17 @@ class UnixCMakeExecutor extends Executor
FileSystem::resetDir($this->build_dir); FileSystem::resetDir($this->build_dir);
} }
// prepare environment variables
$env = [
'CFLAGS' => $this->library->getLibExtraCFlags(),
'LDFLAGS' => $this->library->getLibExtraLdFlags(),
'LIBS' => $this->library->getLibExtraLibs(),
];
// prepare shell // prepare shell
$shell = shell()->cd($this->build_dir)->setEnv($env); $shell = shell()->cd($this->build_dir)->initializeEnv($this->library);
// config // 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 // 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 // install
$this->steps >= 3 && $shell->execWithEnv('make install'); $this->steps >= 3 && $shell->exec('make install');
} }
/** /**