@@ -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