@@ -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,41 +105,31 @@ 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 }
123+ }
136124
137- key := "compiler.libraries.ldflags"
138- if ! ctx .BuildProperties .ContainsKey (key ) {
139- logger := ctx .GetLogger ()
140- logger .Fprintln (os .Stdout , constants .LOG_LEVEL_INFO , "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'." )
141- key = "compiler.ldflags"
142- }
143- currLDFlags := ctx .BuildProperties .Get (key )
144- ctx .BuildProperties .Set (key , currLDFlags + " \" -L" + path .String ()+ "\" " + libsCmd + " " )
125+ key := "compiler.libraries.ldflags"
126+ if ! ctx .BuildProperties .ContainsKey (key ) {
127+ logger := ctx .GetLogger ()
128+ logger .Fprintln (os .Stdout , constants .LOG_LEVEL_INFO , "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'." )
129+ key = "compiler.ldflags"
145130 }
146- return nil
131+ currLDFlags := ctx .BuildProperties .Get (key )
132+ ctx .BuildProperties .Set (key , currLDFlags + " \" -L" + path .String ()+ "\" " + libsCmd + " " )
147133}
148134
149135func compileLibraries (ctx * types.Context , libraries libraries.List , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
@@ -179,15 +165,15 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
179165 objectFiles := paths .NewPathList ()
180166
181167 if library .Precompiled {
182- // search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
183- extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
168+ if precompiledPath := findExpectedPrecompiledLibFolder (ctx , library ); precompiledPath != nil {
169+ // Add required LD flags
170+ fixLDFLAG (ctx , library , precompiledPath )
184171
185- filePaths := []string {}
186- precompiledPath := findExpectedPrecompiledLibFolder (ctx , library )
187- if precompiledPath != nil {
188172 // TODO: This codepath is just taken for .a with unusual names that would
189173 // be ignored by -L / -l methods.
190174 // Should we force precompiled libraries to start with "lib" ?
175+ extensions := func (ext string ) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC [ext ] }
176+ filePaths := []string {}
191177 err := utils .FindFilesInFolder (& filePaths , precompiledPath .String (), extensions , false )
192178 if err != nil {
193179 return nil , errors .WithStack (err )
0 commit comments