@@ -30,8 +30,6 @@ import (
3030 "github.com/pkg/errors"
3131)
3232
33- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map [string ]bool {".a" : true }
34- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC = map [string ]bool {".so" : true }
3533var FLOAT_ABI_CFLAG = "float-abi"
3634var FPU_CFLAG = "fpu"
3735
@@ -105,27 +103,6 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
105103 return nil
106104}
107105
108- func fixLDFLAG (ctx * types.Context , library * libraries.Library , path * paths.Path ) {
109- // find all library names in the folder and prepend -l
110- filePaths := []string {}
111- libsCmd := library .LDflags + " "
112- extensions := func (ext string ) bool {
113- return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC [ext ] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ]
114- }
115- utils .FindFilesInFolder (& filePaths , path .String (), extensions , false )
116- for _ , lib := range filePaths {
117- name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
118- // strip "lib" first occurrence
119- if strings .HasPrefix (name , "lib" ) {
120- name = strings .Replace (name , "lib" , "" , 1 )
121- libsCmd += "-l" + name + " "
122- }
123- }
124-
125- currLDFlags := ctx .BuildProperties .Get (constants .BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS )
126- ctx .BuildProperties .Set (constants .BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS , currLDFlags + "\" -L" + path .String ()+ "\" " + libsCmd + " " )
127- }
128-
129106func compileLibraries (ctx * types.Context , libraries libraries.List , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
130107 ctx .Progress .AddSubSteps (len (libraries ))
131108 defer ctx .Progress .RemoveSubSteps ()
@@ -160,19 +137,39 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
160137
161138 if library .Precompiled {
162139 if precompiledPath := findExpectedPrecompiledLibFolder (ctx , library ); precompiledPath != nil {
140+ var staticLibExts = map [string ]bool {".a" : true }
141+ var dynamixLibExts = map [string ]bool {".so" : true }
142+ dynAndStatic := func (ext string ) bool { return dynamixLibExts [ext ] || staticLibExts [ext ] }
143+ staticOnly := func (ext string ) bool { return staticLibExts [ext ] }
144+
163145 // Add required LD flags
164- fixLDFLAG (ctx , library , precompiledPath )
146+
147+ // find all library names in the folder and prepend -l
148+ dynAndStaticLibs := []string {}
149+ libsCmd := library .LDflags + " "
150+ if err := utils .FindFilesInFolder (& dynAndStaticLibs , precompiledPath .String (), dynAndStatic , false ); err != nil {
151+ return nil , errors .WithStack (err )
152+ }
153+ for _ , lib := range dynAndStaticLibs {
154+ name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
155+ // strip "lib" first occurrence
156+ if strings .HasPrefix (name , "lib" ) {
157+ name = strings .Replace (name , "lib" , "" , 1 )
158+ libsCmd += "-l" + name + " "
159+ }
160+ }
161+
162+ currLDFlags := ctx .BuildProperties .Get (constants .BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS )
163+ ctx .BuildProperties .Set (constants .BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS , currLDFlags + "\" -L" + precompiledPath .String ()+ "\" " + libsCmd + " " )
165164
166165 // TODO: This codepath is just taken for .a with unusual names that would
167166 // be ignored by -L / -l methods.
168167 // Should we force precompiled libraries to start with "lib" ?
169- extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
170- filePaths := []string {}
171- err := utils .FindFilesInFolder (& filePaths , precompiledPath .String (), extensions , false )
172- if err != nil {
168+ staticLibs := []string {}
169+ if err := utils .FindFilesInFolder (& staticLibs , precompiledPath .String (), staticOnly , false ); err != nil {
173170 return nil , errors .WithStack (err )
174171 }
175- for _ , path := range filePaths {
172+ for _ , path := range staticLibs {
176173 if ! strings .HasPrefix (filepath .Base (path ), "lib" ) {
177174 objectFiles .Add (paths .New (path ))
178175 }
0 commit comments