diff --git a/src/SPC/builder/linux/library/icu.php b/src/SPC/builder/linux/library/icu.php index 7b8bcf8e..3a41cb13 100644 --- a/src/SPC/builder/linux/library/icu.php +++ b/src/SPC/builder/linux/library/icu.php @@ -15,9 +15,11 @@ class icu extends LinuxLibraryBase protected function build(): void { + $userCxxFlags = trim((string) getenv('SPC_DEFAULT_CXX_FLAGS')); + $userLdFlags = trim((string) getenv('SPC_DEFAULT_LD_FLAGS')); $cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1 -DPIC -fPIC"'; - $cxxflags = 'CXXFLAGS="-std=c++17 -DPIC -fPIC -fno-ident"'; - $ldflags = SPCTarget::isStatic() ? 'LDFLAGS="-static"' : ''; + $cxxflags = "CXXFLAGS=\"-std=c++17 -DPIC -fPIC -fno-ident {$userCxxFlags}\""; + $ldflags = SPCTarget::isStatic() ? "LDFLAGS=\"-static {$userLdFlags}\"" : "LDFLAGS=\"{$userLdFlags}\""; shell()->cd($this->source_dir . '/source')->initializeEnv($this) ->exec( "{$cppflags} {$cxxflags} {$ldflags} " . diff --git a/src/SPC/builder/linux/library/openssl.php b/src/SPC/builder/linux/library/openssl.php index bfc3936b..c4efdfdf 100644 --- a/src/SPC/builder/linux/library/openssl.php +++ b/src/SPC/builder/linux/library/openssl.php @@ -57,6 +57,11 @@ class openssl extends LinuxLibraryBase $openssl_dir ??= '/etc/ssl'; $ex_lib = trim($ex_lib); + // OpenSSL's Configure ignores env CFLAGS for its target template; pass our flags as extra args after the target. + $userCFlags = trim((string) getenv('SPC_DEFAULT_C_FLAGS')); + $userLdFlags = trim((string) getenv('SPC_DEFAULT_LD_FLAGS')); + $userExtraFlags = trim($userCFlags . ' ' . $userLdFlags); + shell()->cd($this->source_dir)->initializeEnv($this) ->exec( "{$env} ./Configure no-shared {$extra} " . @@ -67,7 +72,8 @@ class openssl extends LinuxLibraryBase 'enable-pie ' . 'no-legacy ' . 'no-tests ' . - "linux-{$arch}" + "linux-{$arch} " . + $userExtraFlags ) ->exec('make clean') ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") diff --git a/src/SPC/builder/unix/library/bzip2.php b/src/SPC/builder/unix/library/bzip2.php index 32d87270..4ed3b46a 100644 --- a/src/SPC/builder/unix/library/bzip2.php +++ b/src/SPC/builder/unix/library/bzip2.php @@ -10,7 +10,8 @@ trait bzip2 { public function patchBeforeBuild(): bool { - FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'CFLAGS=-Wall', 'CFLAGS=-fPIC -Wall'); + $extra = trim((string) getenv('SPC_DEFAULT_C_FLAGS')); + FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'CFLAGS=-Wall', "CFLAGS=-Wall {$extra}"); return true; } diff --git a/src/SPC/command/CraftCommand.php b/src/SPC/command/CraftCommand.php index 6c40133d..7a4765ac 100644 --- a/src/SPC/command/CraftCommand.php +++ b/src/SPC/command/CraftCommand.php @@ -19,6 +19,9 @@ class CraftCommand extends BuildCommand public function configure(): void { $this->addArgument('craft', null, 'Path to craft.yml file', WORKING_DIR . '/craft.yml'); + $this->addOption('pgi', null, null, 'Forward --pgi to the inner build (instrumented binaries).'); + $this->addOption('cs-pgi', null, null, 'Forward --cs-pgi to the inner build (cs-instrumented binaries).'); + $this->addOption('pgo', null, null, 'Forward --pgo to the inner build (use collected profile data).'); } public function handle(): int @@ -105,6 +108,11 @@ class CraftCommand extends BuildCommand if ($craft['craft-options']['build']) { $args = [$static_extensions, "--with-libs={$libs}", "--build-shared={$shared_extensions}", ...array_map(fn ($x) => "--build-{$x}", $craft['sapi'])]; $this->optionsToArguments($craft['build-options'], $args); + foreach (['pgi', 'cs-pgi', 'pgo'] as $pgoFlag) { + if ($this->getOption($pgoFlag)) { + $args[] = "--{$pgoFlag}"; + } + } $retcode = $this->runCommand('build', ...$args); if ($retcode !== 0) { $this->output->writeln('craft build failed');