Skip to content

Commit 5577cd0

Browse files
committed
add cache file option to autoconf executor by default (if cflags and ldflags match default)
1 parent 0695fb9 commit 5577cd0

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

src/SPC/builder/linux/library/libffi.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ class libffi extends LinuxLibraryBase
1818
*/
1919
public function build(): void
2020
{
21-
$arch = getenv('SPC_ARCH');
2221
UnixAutoconfExecutor::create($this)
23-
->configure(
24-
"--host={$arch}-unknown-linux",
25-
"--target={$arch}-unknown-linux",
26-
"--libdir={$this->getLibDir()}"
27-
)
22+
->configure()
2823
->make();
2924

3025
if (is_file(BUILD_ROOT_PATH . '/lib64/libffi.a')) {

src/SPC/builder/unix/library/gettext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function build(): void
2424
if ($this->builder->getOption('enable-zts')) {
2525
$autoconf->addConfigureArgs('--enable-threads=isoc+posix')
2626
->appendEnv([
27-
'CFLAGS' => '-lpthread -D_REENTRANT',
27+
'CFLAGS' => '-D_REENTRANT',
2828
'LDFLGAS' => '-lpthread',
2929
]);
3030
} else {

src/SPC/builder/unix/library/unixodbc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ trait unixodbc
1717
protected function build(): void
1818
{
1919
UnixAutoconfExecutor::create($this)
20+
->removeConfigureArgs('--cache-file')
2021
->configure(
2122
'--disable-debug',
2223
'--disable-dependency-tracking',

src/SPC/util/UnixShell.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,9 @@ private function getExecString(string $cmd): string
129129
}
130130
return $cmd;
131131
}
132+
133+
public function getEnv(): array
134+
{
135+
return $this->env;
136+
}
132137
}

src/SPC/util/executor/UnixAutoconfExecutor.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function configure(...$args): static
3232
// remove all the ignored args
3333
$args = array_merge($args, $this->getDefaultConfigureArgs(), $this->configure_args);
3434
$args = array_diff($args, $this->ignore_args);
35+
$args = array_filter(
36+
$args,
37+
fn ($arg) => !array_filter(
38+
$this->ignore_args,
39+
fn ($ignore) => str_starts_with($arg, $ignore . '=')
40+
)
41+
);
3542
$configure_args = implode(' ', $args);
3643

3744
$this->shell->exec("./configure {$configure_args}");
@@ -46,7 +53,7 @@ public function getConfigureArgsString(): string
4653
/**
4754
* Run make
4855
*
49-
* @param string $target Build target
56+
* @param string $target Build target
5057
* @throws RuntimeException
5158
*/
5259
public function make(string $target = '', false|string $with_install = 'install', bool $with_clean = true, array $after_env_vars = []): static
@@ -72,9 +79,9 @@ public function exec(string $cmd): static
7279
* Add optional library configuration.
7380
* This method checks if a library is available and adds the corresponding arguments to the CMake configuration.
7481
*
75-
* @param string $name library name to check
76-
* @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string)
77-
* @param string $false_args arguments to use if the library is not available
82+
* @param string $name library name to check
83+
* @param \Closure|string $true_args arguments to use if the library is available (allow closure, returns string)
84+
* @param string $false_args arguments to use if the library is not available
7885
* @return $this
7986
*/
8087
public function optionalLib(string $name, \Closure|string $true_args, string $false_args = ''): static
@@ -119,13 +126,23 @@ public function appendEnv(array $env): static
119126
*/
120127
private function getDefaultConfigureArgs(): array
121128
{
122-
return [
129+
$args = [
123130
'--disable-shared',
124131
'--enable-static',
125132
"--prefix={$this->library->getBuildRootPath()}",
126133
'--with-pic',
127134
'--enable-pic',
128135
];
136+
137+
// only add the cache file if CFLAGS and LDFLAGS are defaulted
138+
$env = $this->shell->getEnv();
139+
$expected_cflags = '-I' . BUILD_INCLUDE_PATH . ' ' . getenv('SPC_DEFAULT_C_FLAGS');
140+
$expected_ldflags = '-L' . BUILD_LIB_PATH;
141+
142+
if (($env['CFLAGS'] ?? '') === $expected_cflags && ($env['LDFLAGS'] ?? '') === $expected_ldflags) {
143+
$args[] = '--cache-file=' . BUILD_ROOT_PATH . '/config.cache';
144+
}
145+
return $args;
129146
}
130147

131148
/**

0 commit comments

Comments
 (0)