@@ -222,11 +222,23 @@ public function patchBeforeSharedMake(): bool
222222 {
223223 $ config = (new SPCConfigUtil ($ this ->builder ))->config ([$ this ->getName ()], array_map (fn ($ l ) => $ l ->getName (), $ this ->builder ->getLibs ()));
224224 [$ staticLibs , $ sharedLibs ] = $ this ->splitLibsIntoStaticAndShared ($ config ['libs ' ]);
225- FileSystem::replaceFileRegex (
226- $ this ->source_dir . '/Makefile ' ,
227- '/^(.*_SHARED_LIBADD\s*=.*)$/m ' ,
228- clean_spaces ("$1 {$ staticLibs } {$ sharedLibs }" )
229- );
225+ $ lstdcpp = str_contains ($ sharedLibs , '-lstdc++ ' ) ? '-lstdc++ ' : '' ;
226+
227+ $ makefileContent = file_get_contents ($ this ->source_dir . '/Makefile ' );
228+
229+ if (preg_match ('/^(.*_SHARED_LIBADD\s*=\s*)(.*)$/m ' , $ makefileContent , $ matches )) {
230+ $ prefix = $ matches [1 ];
231+ $ currentLibs = trim ($ matches [2 ]);
232+ $ newLibs = trim ("{$ currentLibs } {$ staticLibs } {$ lstdcpp }" );
233+ $ deduplicatedLibs = deduplicate_flags ($ newLibs );
234+
235+ FileSystem::replaceFileRegex (
236+ $ this ->source_dir . '/Makefile ' ,
237+ '/^(.*_SHARED_LIBADD\s*=.*)$/m ' ,
238+ $ prefix . $ deduplicatedLibs
239+ );
240+ }
241+
230242 if ($ objs = getenv ('SPC_EXTRA_RUNTIME_OBJECTS ' )) {
231243 FileSystem::replaceFileRegex (
232244 $ this ->source_dir . '/Makefile ' ,
0 commit comments