@@ -53,10 +53,6 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
5353 }
5454
5555 ctx .LibrariesObjectFiles = objectFiles
56-
57- // Search for precompiled libraries
58- fixLDFLAG (ctx , libs )
59-
6056 return nil
6157}
6258
@@ -109,35 +105,25 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
109105 return nil
110106}
111107
112- func fixLDFLAG (ctx * types.Context , libs libraries.List ) error {
113-
114- for _ , library := range libs {
115- // add library src path to compiler.c.elf.extra_flags
116- // use library.Name as lib name and srcPath/{mcpu} as location
117- path := findExpectedPrecompiledLibFolder (ctx , library )
118- if path == nil {
119- break
120- }
121- // find all library names in the folder and prepend -l
122- filePaths := []string {}
123- libsCmd := library .LDflags + " "
124- extensions := func (ext string ) bool {
125- return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC [ext ] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ]
126- }
127- utils .FindFilesInFolder (& filePaths , path .String (), extensions , false )
128- for _ , lib := range filePaths {
129- name := strings .TrimSuffix (filepath .Base (lib ), filepath .Ext (lib ))
130- // strip "lib" first occurrence
131- if strings .HasPrefix (name , "lib" ) {
132- name = strings .Replace (name , "lib" , "" , 1 )
133- libsCmd += "-l" + name + " "
134- }
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 + " "
135122 }
136-
137- currLDFlags := ctx .BuildProperties .Get (constants .BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS )
138- ctx .BuildProperties .Set (constants .BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS , currLDFlags + "\" -L" + path .String ()+ "\" " + libsCmd + " " )
139123 }
140- return nil
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 + " " )
141127}
142128
143129func compileLibraries (ctx * types.Context , libraries libraries.List , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
@@ -173,15 +159,15 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
173159 objectFiles := paths .NewPathList ()
174160
175161 if library .Precompiled {
176- // search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
177- extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
162+ if precompiledPath := findExpectedPrecompiledLibFolder (ctx , library ); precompiledPath != nil {
163+ // Add required LD flags
164+ fixLDFLAG (ctx , library , precompiledPath )
178165
179- filePaths := []string {}
180- precompiledPath := findExpectedPrecompiledLibFolder (ctx , library )
181- if precompiledPath != nil {
182166 // TODO: This codepath is just taken for .a with unusual names that would
183167 // be ignored by -L / -l methods.
184168 // 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 {}
185171 err := utils .FindFilesInFolder (& filePaths , precompiledPath .String (), extensions , false )
186172 if err != nil {
187173 return nil , errors .WithStack (err )
0 commit comments