@@ -53,10 +53,6 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
53
53
}
54
54
55
55
ctx .LibrariesObjectFiles = objectFiles
56
-
57
- // Search for precompiled libraries
58
- fixLDFLAG (ctx , libs )
59
-
60
56
return nil
61
57
}
62
58
@@ -109,41 +105,31 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
109
105
return nil
110
106
}
111
107
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 + " "
135
122
}
123
+ }
136
124
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"
145
130
}
146
- return nil
131
+ currLDFlags := ctx .BuildProperties .Get (key )
132
+ ctx .BuildProperties .Set (key , currLDFlags + " \" -L" + path .String ()+ "\" " + libsCmd + " " )
147
133
}
148
134
149
135
func 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
179
165
objectFiles := paths .NewPathList ()
180
166
181
167
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 )
184
171
185
- filePaths := []string {}
186
- precompiledPath := findExpectedPrecompiledLibFolder (ctx , library )
187
- if precompiledPath != nil {
188
172
// TODO: This codepath is just taken for .a with unusual names that would
189
173
// be ignored by -L / -l methods.
190
174
// 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 {}
191
177
err := utils .FindFilesInFolder (& filePaths , precompiledPath .String (), extensions , false )
192
178
if err != nil {
193
179
return nil , errors .WithStack (err )
0 commit comments