@@ -220,7 +220,7 @@ public function patchBeforeSharedConfigure(): bool
220220 */
221221 public function patchBeforeSharedMake (): bool
222222 {
223- $ config = (new SPCConfigUtil ($ this ->builder ))->config ([ $ this -> getName ()], array_map ( fn ( $ l ) => $ l -> getName (), $ this -> builder -> getLibs ()) );
223+ $ config = (new SPCConfigUtil ($ this ->builder ))->getExtensionConfig ( $ this );
224224 [$ staticLibs , $ sharedLibs ] = $ this ->splitLibsIntoStaticAndShared ($ config ['libs ' ]);
225225 $ lstdcpp = str_contains ($ sharedLibs , '-l:libstdc++.a ' ) ? '-l:libstdc++.a ' : null ;
226226 $ lstdcpp ??= str_contains ($ sharedLibs , '-lstdc++ ' ) ? '-lstdc++ ' : '' ;
@@ -486,18 +486,46 @@ public function isBuildStatic(): bool
486486 return $ this ->build_static ;
487487 }
488488
489+ public function getLibraryDependencies (bool $ recursive = false ): array
490+ {
491+ $ ret = array_filter ($ this ->dependencies , fn ($ x ) => $ x instanceof LibraryBase);
492+ if (!$ recursive ) {
493+ return $ ret ;
494+ }
495+
496+ $ deps = [];
497+
498+ $ added = 1 ;
499+ while ($ added !== 0 ) {
500+ $ added = 0 ;
501+ foreach ($ ret as $ depName => $ dep ) {
502+ foreach ($ dep ->getDependencies (true ) as $ depdepName => $ depdep ) {
503+ if (!array_key_exists ($ depdepName , $ deps )) {
504+ $ deps [$ depdepName ] = $ depdep ;
505+ ++$ added ;
506+ }
507+ }
508+ if (!array_key_exists ($ depName , $ deps )) {
509+ $ deps [$ depName ] = $ dep ;
510+ }
511+ }
512+ }
513+
514+ if (array_key_exists (0 , $ deps )) {
515+ $ zero = [0 => $ deps [0 ]];
516+ unset($ deps [0 ]);
517+ return $ zero + $ deps ;
518+ }
519+ return $ deps ;
520+ }
521+
489522 /**
490523 * Returns the environment variables a shared extension needs to be built.
491524 * CFLAGS, CXXFLAGS, LDFLAGS and so on.
492525 */
493526 protected function getSharedExtensionEnv (): array
494527 {
495- $ config = (new SPCConfigUtil ($ this ->builder ))->config (
496- [$ this ->getName ()],
497- array_map (fn ($ l ) => $ l ->getName (), $ this ->getLibraryDependencies (recursive: true )),
498- $ this ->builder ->getOption ('with-suggested-exts ' ),
499- $ this ->builder ->getOption ('with-suggested-libs ' ),
500- );
528+ $ config = (new SPCConfigUtil ($ this ->builder ))->getExtensionConfig ($ this );
501529 [$ staticLibs , $ sharedLibs ] = $ this ->splitLibsIntoStaticAndShared ($ config ['libs ' ]);
502530 $ preStatic = PHP_OS_FAMILY === 'Darwin ' ? '' : '-Wl,--start-group ' ;
503531 $ postStatic = PHP_OS_FAMILY === 'Darwin ' ? '' : ' -Wl,--end-group ' ;
@@ -567,37 +595,4 @@ protected function splitLibsIntoStaticAndShared(string $allLibs): array
567595 }
568596 return [trim ($ staticLibString ), trim ($ sharedLibString )];
569597 }
570-
571- private function getLibraryDependencies (bool $ recursive = false ): array
572- {
573- $ ret = array_filter ($ this ->dependencies , fn ($ x ) => $ x instanceof LibraryBase);
574- if (!$ recursive ) {
575- return $ ret ;
576- }
577-
578- $ deps = [];
579-
580- $ added = 1 ;
581- while ($ added !== 0 ) {
582- $ added = 0 ;
583- foreach ($ ret as $ depName => $ dep ) {
584- foreach ($ dep ->getDependencies (true ) as $ depdepName => $ depdep ) {
585- if (!array_key_exists ($ depdepName , $ deps )) {
586- $ deps [$ depdepName ] = $ depdep ;
587- ++$ added ;
588- }
589- }
590- if (!array_key_exists ($ depName , $ deps )) {
591- $ deps [$ depName ] = $ dep ;
592- }
593- }
594- }
595-
596- if (array_key_exists (0 , $ deps )) {
597- $ zero = [0 => $ deps [0 ]];
598- unset($ deps [0 ]);
599- return $ zero + $ deps ;
600- }
601- return $ deps ;
602- }
603598}
0 commit comments