Support -fPIC and -fPIE for most libs and PHP

This commit is contained in:
crazywhalecc 2025-03-10 00:39:20 +08:00
parent 4eeb48cdc2
commit 2a9cd436b6
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
37 changed files with 96 additions and 74 deletions

1
.gitignore vendored
View File

@ -33,6 +33,7 @@ packlib_files.txt
!/bin/setup-runtime* !/bin/setup-runtime*
!/bin/spc-alpine-docker !/bin/spc-alpine-docker
!/bin/php-cs-fixer-wrapper !/bin/php-cs-fixer-wrapper
!/bin/build-static-frankenphp
# exclude windows build tools # exclude windows build tools
/php-sdk-binary-tools/ /php-sdk-binary-tools/

View File

@ -76,13 +76,13 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
; buildconf command ; buildconf command
SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force" SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
; configure command ; configure command
SPC_CMD_PREFIX_PHP_CONFIGURE="${SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg" SPC_CMD_PREFIX_PHP_CONFIGURE="${SPC_PHP_DEFAULT_LD_LIBRARY_PATH_CMD} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --with-pic"
; make command ; make command
SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}" SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}"
; *** default build vars for building php *** ; *** default build vars for building php ***
; CFLAGS for configuring php ; CFLAGS for configuring php
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS}" SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
; CPPFLAGS for configuring php ; CPPFLAGS for configuring php
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}" SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS="-I${BUILD_INCLUDE_PATH}"
; LDFLAGS for configuring php ; LDFLAGS for configuring php
@ -90,7 +90,7 @@ SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS="-L${BUILD_LIB_PATH}"
; LIBS for configuring php ; LIBS for configuring php
SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm" SPC_CMD_VAR_PHP_CONFIGURE_LIBS="-ldl -lpthread -lm"
; EXTRA_CFLAGS for `make` php ; EXTRA_CFLAGS for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS} -fno-ident -fPIE" SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="${SPC_PHP_DEFAULT_OPTIMIZE_CFLAGS} -fno-ident -fPIE -fPIC"
; EXTRA_LIBS for `make` php ; EXTRA_LIBS for `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS="" SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS=""
; EXTRA_LDFLAGS_PROGRAM for `make` php ; EXTRA_LDFLAGS_PROGRAM for `make` php

View File

@ -120,6 +120,7 @@ class LinuxBuilder extends UnixBuilderBase
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : '');
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
$cflags = $this->arch_c_flags; $cflags = $this->arch_c_flags;
f_putenv('CFLAGS=' . $cflags);
$this->emitPatchPoint('before-php-buildconf'); $this->emitPatchPoint('before-php-buildconf');
SourcePatcher::patchBeforeBuildconf($this); SourcePatcher::patchBeforeBuildconf($this);

View File

@ -14,7 +14,7 @@ class icu extends LinuxLibraryBase
protected function build(): void protected function build(): void
{ {
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -fPIC -fPIE -fno-ident"';
$cxxflags = 'CXXFLAGS="-std=c++17"'; $cxxflags = 'CXXFLAGS="-std=c++17"';
$ldflags = $this->builder->libc !== 'glibc' ? 'LDFLAGS="-static"' : ''; $ldflags = $this->builder->libc !== 'glibc' ? 'LDFLAGS="-static"' : '';
shell()->cd($this->source_dir . '/source') shell()->cd($this->source_dir . '/source')

View File

@ -44,7 +44,7 @@ class libpng extends LinuxLibraryBase
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec('chmod +x ./configure') ->exec('chmod +x ./configure')
->exec('chmod +x ./install-sh') ->exec('chmod +x ./install-sh')
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv( ->execWithEnv(
'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' . 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ' .
'./configure ' . './configure ' .

View File

@ -21,7 +21,7 @@ class glfw extends MacOSLibraryBase
shell()->cd(SOURCE_PATH . '/ext-glfw/vendor/glfw') shell()->cd(SOURCE_PATH . '/ext-glfw/vendor/glfw')
->exec("cmake . {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF") ->exec("cmake . {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF")
->exec("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
// patch pkgconf // patch pkgconf
$this->patchPkgconfPrefix(['glfw3.pc']); $this->patchPkgconfPrefix(['glfw3.pc']);
} }

View File

@ -102,7 +102,11 @@ trait UnixLibraryTrait
public function getLibExtraCFlags(): string public function getLibExtraCFlags(): string
{ {
return getenv($this->getSnakeCaseName() . '_CFLAGS') ?: ''; $env = getenv($this->getSnakeCaseName() . '_CFLAGS') ?: '';
if (!str_contains($env, $this->builder->arch_c_flags)) {
$env .= $this->builder->arch_c_flags;
}
return $env;
} }
public function getLibExtraLdFlags(): string public function getLibExtraLdFlags(): string

View File

@ -33,11 +33,11 @@ trait UnixSystemUtilTrait
$root = BUILD_ROOT_PATH; $root = BUILD_ROOT_PATH;
$ccLine = ''; $ccLine = '';
if ($cc) { if ($cc) {
$ccLine = 'SET(CMAKE_C_COMPILER ' . self::findCommand($cc) . ')'; $ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
} }
$cxxLine = ''; $cxxLine = '';
if ($cxx) { if ($cxx) {
$cxxLine = 'SET(CMAKE_CXX_COMPILER ' . self::findCommand($cxx) . ')'; $cxxLine = 'SET(CMAKE_CXX_COMPILER ' . $cxx . ')';
} }
$toolchain = <<<CMAKE $toolchain = <<<CMAKE
{$ccLine} {$ccLine}
@ -46,6 +46,8 @@ SET(CMAKE_C_FLAGS "{$cflags}")
SET(CMAKE_CXX_FLAGS "{$cflags}") SET(CMAKE_CXX_FLAGS "{$cflags}")
SET(CMAKE_FIND_ROOT_PATH "{$root}") SET(CMAKE_FIND_ROOT_PATH "{$root}")
SET(CMAKE_PREFIX_PATH "{$root}") SET(CMAKE_PREFIX_PATH "{$root}")
SET(CMAKE_INSTALL_PREFIX "{$root}")
SET(CMAKE_INSTALL_LIBDIR "lib")
set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config") set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

View File

@ -61,10 +61,10 @@ abstract class UnixBuilderBase extends BuilderBase
$extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . getenv('CC') . ' ' : ''; $extra = $this instanceof LinuxBuilder ? '-DCMAKE_C_COMPILER=' . getenv('CC') . ' ' : '';
return $extra . return $extra .
'-DCMAKE_BUILD_TYPE=Release ' . '-DCMAKE_BUILD_TYPE=Release ' .
'-DCMAKE_INSTALL_PREFIX=/ ' . '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
'-DCMAKE_INSTALL_BINDIR=/bin ' . '-DCMAKE_INSTALL_BINDIR=bin ' .
'-DCMAKE_INSTALL_LIBDIR=/lib ' . '-DCMAKE_INSTALL_LIBDIR=lib ' .
'-DCMAKE_INSTALL_INCLUDEDIR=/include ' . '-DCMAKE_INSTALL_INCLUDEDIR=include ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}"; "-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}";
} }

View File

@ -21,12 +21,16 @@ trait brotli
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv( ->execWithEnv(
'cmake ' . 'cmake ' .
"{$this->builder->makeCmakeArgs()} " . '-DCMAKE_BUILD_TYPE=Release ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
'-DCMAKE_INSTALL_LIBDIR=lib ' .
'-DSHARE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
'-DBUILD_SHARED_LIBS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' .
'..' '..'
) )
->execWithEnv("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install');
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);
shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a'); shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a');
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) { foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace SPC\builder\unix\library; namespace SPC\builder\unix\library;
use SPC\builder\linux\library\LinuxLibraryBase;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
@ -53,14 +52,13 @@ trait curl
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');
$cflags = $this instanceof LinuxLibraryBase && $this->builder->libc === 'glibc' ? '-fPIC' : '';
// compile // compile
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $cflags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt') ->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt')
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..") ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
->execWithEnv("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install');
// patch pkgconf // patch pkgconf
$this->patchPkgconfPrefix(['libcurl.pc']); $this->patchPkgconfPrefix(['libcurl.pc']);
shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/') shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/')

View File

@ -17,7 +17,7 @@ trait gettext
$ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : ''; $ldflags = $this->builder->getOption('enable-zts') ? '-lpthread' : '';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $cflags, 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv( ->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .

View File

@ -23,6 +23,6 @@ trait gmssl
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..") ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..")
->execWithEnv("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install');
} }
} }

View File

@ -39,7 +39,7 @@ trait imagemagick
} }
} }
$ldflags = $this instanceof LinuxLibraryBase ? ('-static') : ''; $ldflags = ($this instanceof LinuxLibraryBase) && $this->builder->libc !== 'glibc' ? ('-static -ldl') : '-ldl';
// libxml iconv patch // libxml iconv patch
$required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : ''; $required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : '';

View File

@ -10,7 +10,8 @@ trait ldap
{ {
public function patchBeforeBuild(): bool public function patchBeforeBuild(): bool
{ {
FileSystem::replaceFileStr($this->source_dir . '/configure', '"-lssl -lcrypto', '"-lssl -lcrypto -lz'); $extra = ($this->builder->libc ?? '') === 'glibc' ? '-ldl -lpthread -lm -lresolv -lutil' : '';
FileSystem::replaceFileStr($this->source_dir . '/configure', '"-lssl -lcrypto', '"-lssl -lcrypto -lz ' . $extra);
return true; return true;
} }

View File

@ -25,7 +25,7 @@ trait libavif
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DAVIF_LIBYUV=OFF ..") ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DAVIF_LIBYUV=OFF ..")
->execWithEnv("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install');
// patch pkgconfig // patch pkgconfig
$this->patchPkgconfPrefix(['libavif.pc']); $this->patchPkgconfPrefix(['libavif.pc']);
$this->cleanLaFiles(); $this->cleanLaFiles();

View File

@ -11,16 +11,17 @@ trait libiconv
[,,$destdir] = SEPARATED_PATH; [,,$destdir] = SEPARATED_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
'--enable-extra-encodings ' . '--enable-extra-encodings ' .
'--prefix=' '--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);
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

@ -29,7 +29,7 @@ trait libjpeg
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
// patch pkgconfig // patch pkgconfig
$this->patchPkgconfPrefix(['libjpeg.pc', 'libturbojpeg.pc']); $this->patchPkgconfPrefix(['libjpeg.pc', 'libturbojpeg.pc']);
$this->cleanLaFiles(); $this->cleanLaFiles();

View File

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

View File

@ -22,7 +22,10 @@ trait libssh2
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->exec( ->exec(
'cmake ' . 'cmake ' .
"{$this->builder->makeCmakeArgs()} " . '-DCMAKE_BUILD_TYPE=Release ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
'-DCMAKE_INSTALL_LIBDIR=lib ' .
'-DBUILD_SHARED_LIBS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' .
'-DBUILD_EXAMPLES=OFF ' . '-DBUILD_EXAMPLES=OFF ' .
'-DBUILD_TESTING=OFF ' . '-DBUILD_TESTING=OFF ' .
@ -30,7 +33,7 @@ trait libssh2
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
$this->patchPkgconfPrefix(['libssh2.pc']); $this->patchPkgconfPrefix(['libssh2.pc']);
} }
} }

View File

@ -23,7 +23,8 @@ trait libtiff
$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)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared ' . '--enable-static --disable-shared ' .
"{$extra_libs} " . "{$extra_libs} " .
@ -33,12 +34,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->exec('make clean'); $shell->execWithEnv('make clean');
} }
$shell $shell
->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(['libtiff-4.pc']); $this->patchPkgconfPrefix(['libtiff-4.pc']);
} }
} }

View File

@ -22,7 +22,7 @@ trait libuv
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->exec("cmake {$this->builder->makeCmakeArgs()} -DLIBUV_BUILD_SHARED=OFF ..") ->exec("cmake {$this->builder->makeCmakeArgs()} -DLIBUV_BUILD_SHARED=OFF ..")
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
// patch pkgconfig // patch pkgconfig
$this->patchPkgconfPrefix(['libuv-static.pc']); $this->patchPkgconfPrefix(['libuv-static.pc']);
} }

View File

@ -30,7 +30,7 @@ trait libwebp
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
// patch pkgconfig // patch pkgconfig
$this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR); $this->patchPkgconfPrefix(['libsharpyuv.pc', 'libwebp.pc', 'libwebpdecoder.pc', 'libwebpdemux.pc', 'libwebpmux.pc'], PKGCONF_PATCH_PREFIX | PKGCONF_PATCH_LIBDIR);
$this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']); $this->patchPkgconfPrefix(['libsharpyuv.pc'], PKGCONF_PATCH_CUSTOM, ['/^includedir=.*$/m', 'includedir=${prefix}/include/webp']);

View File

@ -30,7 +30,9 @@ trait libzip
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->exec( ->exec(
'cmake ' . 'cmake ' .
"{$this->builder->makeCmakeArgs()} " . '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DENABLE_GNUTLS=OFF ' . '-DENABLE_GNUTLS=OFF ' .
'-DENABLE_MBEDTLS=OFF ' . '-DENABLE_MBEDTLS=OFF ' .
'-DBUILD_SHARED_LIBS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' .
@ -42,7 +44,7 @@ trait libzip
'..' '..'
) )
->exec("make -j{$this->builder->concurrency}") ->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
$this->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX); $this->patchPkgconfPrefix(['libzip.pc'], PKGCONF_PATCH_PREFIX);
} }
} }

View File

@ -12,7 +12,8 @@ trait ncurses
{ {
$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)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -32,9 +33,9 @@ trait ncurses
'--libdir=' . BUILD_ROOT_PATH . '/lib ' . '--libdir=' . BUILD_ROOT_PATH . '/lib ' .
'--prefix=' . BUILD_ROOT_PATH '--prefix=' . BUILD_ROOT_PATH
) )
->exec('make clean') ->execWithEnv('make clean')
->exec("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->exec('make install'); ->execWithEnv('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

@ -36,7 +36,8 @@ trait nghttp2
[,,$destdir] = SEPARATED_PATH; [,,$destdir] = SEPARATED_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@ -45,9 +46,9 @@ trait nghttp2
$args . ' ' . $args . ' ' .
'--prefix=' '--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(['libnghttp2.pc']); $this->patchPkgconfPrefix(['libnghttp2.pc']);
} }
} }

View File

@ -10,11 +10,11 @@ trait pkgconfig
{ {
protected function build(): void protected function build(): void
{ {
$cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : ''; $cflags = PHP_OS_FAMILY !== 'Linux' ? '-Wimplicit-function-declaration -Wno-int-conversion' : '';
$ldflags = !($this instanceof LinuxLibraryBase) || $this->builder->libc === 'glibc' ? '' : '--static'; $ldflags = !($this instanceof LinuxLibraryBase) || $this->builder->libc === 'glibc' ? '' : '--static';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $cflags, 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, 'LIBS' => $this->getLibExtraLibs()]) ->setEnv(['CFLAGS' => "{$this->getLibExtraCFlags()} {$cflags}", 'LDFLAGS' => "{$this->getLibExtraLdFlags()} {$ldflags}", 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv( ->execWithEnv(
'./configure ' . './configure ' .
'--disable-shared ' . '--disable-shared ' .

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace SPC\builder\unix\library; namespace SPC\builder\unix\library;
use SPC\builder\linux\library\LinuxLibraryBase; use SPC\builder\linux\library\LinuxLibraryBase;
use SPC\builder\macos\library\MacOSLibraryBase;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
@ -42,13 +41,13 @@ trait postgresql
$error_exec_cnt += $output[0] === 0 ? 0 : 1; $error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$cppflags = $output[1][0]; $cppflags = $output[1][0];
$envs .= " CPPFLAGS=\"{$cppflags}\""; $envs .= " CPPFLAGS=\"{$cppflags} -fPIC -fPIE -fno-ident\"";
} }
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}"); $output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1; $error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$ldflags = $output[1][0]; $ldflags = $output[1][0];
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" "; $envs .= !($this instanceof LinuxLibraryBase) || $this->builder->libc === 'glibc' ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
} }
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}"); $output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1; $error_exec_cnt += $output[0] === 0 ? 0 : 1;

View File

@ -16,7 +16,8 @@ trait readline
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static=yes ' . '--enable-static=yes ' .
'--enable-shared=no ' . '--enable-shared=no ' .
@ -24,9 +25,9 @@ trait readline
'--with-curses ' . '--with-curses ' .
'--enable-multibyte=yes' '--enable-multibyte=yes'
) )
->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(['readline.pc']); $this->patchPkgconfPrefix(['readline.pc']);
} }
} }

View File

@ -21,13 +21,12 @@ trait snappy
shell()->cd($this->source_dir . '/cmake/build') shell()->cd($this->source_dir . '/cmake/build')
->exec( ->exec(
'cmake ' . 'cmake ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
"{$this->builder->makeCmakeArgs()} " . "{$this->builder->makeCmakeArgs()} " .
'-DSNAPPY_BUILD_TESTS=OFF ' . '-DSNAPPY_BUILD_TESTS=OFF ' .
'-DSNAPPY_BUILD_BENCHMARKS=OFF ' . '-DSNAPPY_BUILD_BENCHMARKS=OFF ' .
'../..' '../..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
} }
} }

View File

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

View File

@ -26,7 +26,7 @@ trait tidy
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
$this->patchPkgconfPrefix(['tidy.pc']); $this->patchPkgconfPrefix(['tidy.pc']);
} }
} }

View File

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

View File

@ -26,7 +26,7 @@ trait zstd
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install');
$this->patchPkgconfPrefix(['libzstd.pc']); $this->patchPkgconfPrefix(['libzstd.pc']);
} }
} }

View File

@ -37,7 +37,7 @@ class LinuxToolCheckList
'git', 'autoconf', 'automake', 'git', 'autoconf', 'automake',
'tar', 'unzip', 'gzip', 'gcc', 'tar', 'unzip', 'gzip', 'gcc',
'bzip2', 'cmake', 'patch', 'bzip2', 'cmake', 'patch',
'xz', 'xz', 'libtool',
]; ];
public const TOOLS_ARCH = [ public const TOOLS_ARCH = [

View File

@ -36,7 +36,7 @@ class SPCConfigUtil
$libs = '-lphp -lc ' . $libs; $libs = '-lphp -lc ' . $libs;
$extra_env = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'); $extra_env = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS');
if (is_string($extra_env)) { if (is_string($extra_env)) {
$libs .= ' ' . $extra_env; $libs .= ' ' . trim($extra_env, '"');
} }
// c++ // c++
if ($this->builder->hasCpp()) { if ($this->builder->hasCpp()) {

View File

@ -38,7 +38,7 @@ $prefer_pre_built = false;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'imap,openssl,zlib,memcache', 'Linux', 'Darwin' => 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,ftp,gd,gmp,gettext,iconv,igbinary,imagick,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,parallel,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,ssh2,sysvmsg,sysvsem,sysvshm,tidy,tokenizer,xlswriter,xml,xmlreader,xmlwriter,zip,zlib,yaml,zstd',
'Windows' => 'gettext', 'Windows' => 'gettext',
}; };