@@ -30,8 +30,6 @@ import (
30
30
"github.com/pkg/errors"
31
31
)
32
32
33
- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC = map [string ]bool {".a" : true }
34
- var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC = map [string ]bool {".so" : true }
35
33
var FLOAT_ABI_CFLAG = "float-abi"
36
34
var FPU_CFLAG = "fpu"
37
35
@@ -105,27 +103,6 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
105
103
return nil
106
104
}
107
105
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
-
129
106
func compileLibraries (ctx * types.Context , libraries libraries.List , buildPath * paths.Path , buildProperties * properties.Map , includes []string ) (paths.PathList , error ) {
130
107
ctx .Progress .AddSubSteps (len (libraries ))
131
108
defer ctx .Progress .RemoveSubSteps ()
@@ -160,19 +137,39 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
160
137
161
138
if library .Precompiled {
162
139
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
+
163
145
// 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 + " " )
165
164
166
165
// TODO: This codepath is just taken for .a with unusual names that would
167
166
// be ignored by -L / -l methods.
168
167
// 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 {
173
170
return nil , errors .WithStack (err )
174
171
}
175
- for _ , path := range filePaths {
172
+ for _ , path := range staticLibs {
176
173
if ! strings .HasPrefix (filepath .Base (path ), "lib" ) {
177
174
objectFiles .Add (paths .New (path ))
178
175
}
0 commit comments