@@ -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,35 +105,25 @@ 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
}
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 + " " )
139
123
}
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 + " " )
141
127
}
142
128
143
129
func 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
173
159
objectFiles := paths .NewPathList ()
174
160
175
161
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 )
178
165
179
- filePaths := []string {}
180
- precompiledPath := findExpectedPrecompiledLibFolder (ctx , library )
181
- if precompiledPath != nil {
182
166
// TODO: This codepath is just taken for .a with unusual names that would
183
167
// be ignored by -L / -l methods.
184
168
// 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 {}
185
171
err := utils .FindFilesInFolder (& filePaths , precompiledPath .String (), extensions , false )
186
172
if err != nil {
187
173
return nil , errors .WithStack (err )
0 commit comments