@@ -88,24 +88,25 @@ public function config(array $extensions = [], array $libraries = [], bool $incl
88
88
if ($ this ->builder ->hasCpp ()) {
89
89
$ libs .= SPCTarget::getTargetOS () === 'Darwin ' ? ' -lc++ ' : ' -lstdc++ ' ;
90
90
}
91
+
91
92
if ($ this ->libs_only_deps ) {
92
- $ libs = '-L ' . BUILD_LIB_PATH . ' ' . $ libs ;
93
93
return [
94
94
'cflags ' => trim (getenv ('CFLAGS ' ) . ' ' . $ cflags ),
95
95
'ldflags ' => trim (getenv ('LDFLAGS ' ) . ' ' . $ ldflags ),
96
- 'libs ' => trim (getenv ('LIBS ' ) . ' ' . $ libs ),
96
+ 'libs ' => trim (getenv ('LIBS ' ) . ' ' . $ libs ),
97
97
];
98
98
}
99
99
100
100
// embed
101
101
if (!$ this ->no_php ) {
102
- $ libs = "-lphp -lc {$ libs }" ;
102
+ $ libs = "-lphp {$ libs } -lc " ;
103
103
}
104
- $ libs = ' -L ' . BUILD_LIB_PATH . ' ' . $ libs ;
104
+
105
105
// mimalloc must come first
106
106
if (str_contains ($ libs , BUILD_LIB_PATH . '/mimalloc.o ' )) {
107
107
$ libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace (BUILD_LIB_PATH . '/mimalloc.o ' , '' , $ libs );
108
108
}
109
+
109
110
return [
110
111
'cflags ' => trim (getenv ('CFLAGS ' ) . ' ' . $ cflags ),
111
112
'ldflags ' => trim (getenv ('LDFLAGS ' ) . ' ' . $ ldflags ),
@@ -202,6 +203,9 @@ private function getLibsString(array $libraries, bool $use_short_libs = true): s
202
203
if (in_array ('imap ' , $ libraries ) && SPCTarget::getLibc () === 'glibc ' ) {
203
204
$ lib_names [] = '-lcrypt ' ;
204
205
}
206
+ if (!$ use_short_libs ) {
207
+ $ lib_names = array_map (fn ($ l ) => $ this ->getFullLibName ($ l ), $ lib_names );
208
+ }
205
209
return implode (' ' , $ lib_names );
206
210
}
207
211
@@ -214,6 +218,19 @@ private function getShortLibName(string $lib): string
214
218
return '-l ' . substr ($ lib , 3 , -2 );
215
219
}
216
220
221
+ private function getFullLibName (string $ lib )
222
+ {
223
+ if (!str_starts_with ($ lib , '-l ' )) {
224
+ return $ lib ;
225
+ }
226
+ $ libname = substr ($ lib , 2 );
227
+ $ staticLib = BUILD_LIB_PATH . '/ ' . "lib {$ libname }.a " ;
228
+ if (file_exists ($ staticLib )) {
229
+ return $ staticLib ;
230
+ }
231
+ return $ lib ;
232
+ }
233
+
217
234
private function getFrameworksString (array $ extensions ): string
218
235
{
219
236
$ list = [];
0 commit comments